Add table row height
This commit is contained in:
@ -2,3 +2,4 @@ export * from "./table";
|
||||
export * from "./table-cell";
|
||||
export * from "./table-properties";
|
||||
export * from "./shading";
|
||||
export * from "./table-row";
|
||||
|
@ -1,2 +1,3 @@
|
||||
export * from "./table-row";
|
||||
export * from "./table-row-properties";
|
||||
export * from "./table-row-height";
|
||||
|
32
src/file/table/table-row/table-row-height.ts
Normal file
32
src/file/table/table-row/table-row-height.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export enum HeightRule {
|
||||
/** Height is determined based on the content, so value is ignored. */
|
||||
AUTO = "auto",
|
||||
/** At least the value specified */
|
||||
ATLEAST = "atLeast",
|
||||
/** Exactly the value specified */
|
||||
EXACT = "exact",
|
||||
}
|
||||
|
||||
interface ITableRowHeight {
|
||||
readonly height: number;
|
||||
readonly rule: HeightRule;
|
||||
}
|
||||
|
||||
export class TableRowHeightAttributes extends XmlAttributeComponent<ITableRowHeight> {
|
||||
protected readonly xmlKeys = { height: "w:val", rule: "w:hRule" };
|
||||
}
|
||||
|
||||
export class TableRowHeight extends XmlComponent {
|
||||
constructor(value: number, rule: HeightRule) {
|
||||
super("w:trHeight");
|
||||
|
||||
this.root.push(
|
||||
new TableRowHeightAttributes({
|
||||
height: value,
|
||||
rule: rule,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import { expect } from "chai";
|
||||
import { Formatter } from "export/formatter";
|
||||
import { HeightRule } from "file/table/table-row/table-row-height";
|
||||
import { TableRowProperties } from "./table-row-properties";
|
||||
|
||||
describe("TableRowProperties", () => {
|
||||
@ -31,4 +32,31 @@ describe("TableRowProperties", () => {
|
||||
expect(tree).to.deep.equal({ "w:trPr": [{ "w:tblHeader": { _attr: { "w:val": true } } }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#setHeight", () => {
|
||||
it("sets exact row height", () => {
|
||||
const rowProperties = new TableRowProperties();
|
||||
rowProperties.setHeight(100, HeightRule.EXACT);
|
||||
const tree = new Formatter().format(rowProperties);
|
||||
expect(tree).to.deep.equal({ "w:trPr": [{ "w:trHeight": { _attr: { "w:val": 100, "w:hRule": "exact" } } }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#setHeight", () => {
|
||||
it("sets auto row height", () => {
|
||||
const rowProperties = new TableRowProperties();
|
||||
rowProperties.setHeight(100, HeightRule.AUTO);
|
||||
const tree = new Formatter().format(rowProperties);
|
||||
expect(tree).to.deep.equal({ "w:trPr": [{ "w:trHeight": { _attr: { "w:val": 100, "w:hRule": "auto" } } }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("#setHeight", () => {
|
||||
it("sets at least row height", () => {
|
||||
const rowProperties = new TableRowProperties();
|
||||
rowProperties.setHeight(100, HeightRule.ATLEAST);
|
||||
const tree = new Formatter().format(rowProperties);
|
||||
expect(tree).to.deep.equal({ "w:trPr": [{ "w:trHeight": { _attr: { "w:val": 100, "w:hRule": "atLeast" } } }] });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { HeightRule, TableRowHeight } from "file/table/table-row/table-row-height";
|
||||
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export class TableRowProperties extends IgnoreIfEmptyXmlComponent {
|
||||
@ -16,6 +17,12 @@ export class TableRowProperties extends IgnoreIfEmptyXmlComponent {
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public setHeight(height: number, rule: HeightRule): TableRowProperties {
|
||||
this.root.push(new TableRowHeight(height, rule));
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
class CantSplitAttributes extends XmlAttributeComponent<{ readonly val: boolean }> {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { HeightRule } from "file/table/table-row/table-row-height";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
import { TableCell } from "../table-cell";
|
||||
import { TableRowProperties } from "./table-row-properties";
|
||||
|
||||
@ -49,4 +49,10 @@ export class TableRow extends XmlComponent {
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public setHeight(height: number, rule: HeightRule): TableRow {
|
||||
this.properties.setHeight(height, rule);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user