Files
docx-js/ts/docx/table/properties.ts

49 lines
1.3 KiB
TypeScript
Raw Normal View History

import { XmlAttributeComponent, XmlComponent } from "../xml-components";
2017-03-07 19:22:10 +01:00
export type WidthTypes = "dxa" | "pct" | "nil" | "auto";
2017-03-07 19:22:10 +01:00
export class TableProperties extends XmlComponent {
2017-03-07 19:22:10 +01:00
constructor() {
super("w:tblPr");
2017-03-07 19:22:10 +01:00
}
public setWidth(type: WidthTypes, w: number | string): TableProperties {
this.root.push(new PreferredTableWidth(type, w));
return this;
2017-03-07 19:22:10 +01:00
}
public fixedWidthLayout(): TableProperties {
this.root.push(new TableLayout("fixed"));
return this;
}
2017-03-07 19:22:10 +01:00
}
interface ITableWidth {
type: WidthTypes;
w: number | string;
}
class TableWidthAttributes extends XmlAttributeComponent<ITableWidth> {
protected xmlKeys = {type: "w:type", w: "w:w"};
}
2017-03-07 19:22:10 +01:00
class PreferredTableWidth extends XmlComponent {
constructor(type: WidthTypes, w: number | string) {
super("w:tblW");
this.root.push(new TableWidthAttributes({type, w}));
2017-03-07 19:22:10 +01:00
}
}
type TableLayoutOptions = "autofit" | "fixed";
class TableLayoutAttributes extends XmlAttributeComponent<{type: TableLayoutOptions}> {
protected xmlKeys = {type: "w:type"};
}
class TableLayout extends XmlComponent {
constructor(type: TableLayoutOptions) {
super("w:tblLayout");
this.root.push(new TableLayoutAttributes({type}));
}
}