Files
docx-js/src/file/table/table-properties/table-cell-margin.ts

55 lines
1.6 KiB
TypeScript
Raw Normal View History

import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
2018-10-23 23:44:50 +01:00
import { WidthType } from "../table-cell";
2018-08-23 00:55:33 +01:00
class TableCellMarginAttributes extends XmlAttributeComponent<{ readonly type: WidthType; readonly value: number }> {
protected readonly xmlKeys = { value: "w:w", type: "w:type" };
2018-08-23 00:55:33 +01:00
}
2021-03-04 01:42:58 +00:00
interface IBaseTableCellMarginOptions {
readonly value: number;
readonly type?: WidthType;
}
2018-08-23 00:55:33 +01:00
class BaseTableCellMargin extends XmlComponent {
2021-03-04 01:42:58 +00:00
constructor(rootKey: string, options: IBaseTableCellMarginOptions) {
super(rootKey);
this.root.push(
new TableCellMarginAttributes({
type: options.type ?? WidthType.DXA,
value: options.value,
}),
);
}
2018-08-23 00:55:33 +01:00
}
2021-03-04 01:42:58 +00:00
export interface ITableCellMarginOptions {
readonly top?: IBaseTableCellMarginOptions;
readonly bottom?: IBaseTableCellMarginOptions;
readonly left?: IBaseTableCellMarginOptions;
readonly right?: IBaseTableCellMarginOptions;
}
export class TableCellMargin extends IgnoreIfEmptyXmlComponent {
2021-03-04 01:42:58 +00:00
constructor(options: ITableCellMarginOptions) {
2018-08-23 00:55:33 +01:00
super("w:tblCellMar");
2021-03-04 01:42:58 +00:00
if (options.bottom) {
this.root.push(new BaseTableCellMargin("w:bottom", options.bottom));
}
2018-08-23 00:55:33 +01:00
2021-03-04 01:42:58 +00:00
if (options.top) {
this.root.push(new BaseTableCellMargin("w:top", options.top));
}
2018-08-23 00:55:33 +01:00
2021-03-04 01:42:58 +00:00
if (options.left) {
this.root.push(new BaseTableCellMargin("w:left", options.left));
}
2018-08-23 00:55:33 +01:00
2021-03-04 01:42:58 +00:00
if (options.right) {
this.root.push(new BaseTableCellMargin("w:right", options.right));
}
2018-08-23 00:55:33 +01:00
}
}