Improve API for check boxes

This commit is contained in:
Dolan Miu
2023-06-25 03:09:29 +01:00
parent db85c3dd2f
commit 210d9c58f2
5 changed files with 54 additions and 6 deletions

View File

@ -16,6 +16,7 @@ export interface ICheckboxSymbolProperties {
}
export interface ICheckboxSymbolOptions {
readonly alias?: string;
readonly checked?: boolean;
readonly checkedState?: ICheckboxSymbolProperties;
readonly uncheckedState?: ICheckboxSymbolProperties;

View File

@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { CheckBox } from ".";
import { CheckBox } from "./checkbox";
describe("CheckBox", () => {
describe("#constructor()", () => {
@ -66,7 +67,8 @@ describe("CheckBox", () => {
["2713", "Segoe UI Symbol", "2713", "Segoe UI Symbol"],
[undefined, undefined, "2612", "MS Gothic"],
])("should create a CheckBox with proper root and custom values", (inputChar, inputFont, actualChar, actualFont) => {
const checkBox = new CheckBox("Custom Checkbox", {
const checkBox = new CheckBox({
alias: "Custom Checkbox",
checked: true,
checkedState: {
value: inputChar,
@ -141,7 +143,7 @@ describe("CheckBox", () => {
});
it("should create a CheckBox with proper root, custom state, and no alias", () => {
const checkBox = new CheckBox(undefined, {
const checkBox = new CheckBox({
checked: false,
checkedState: {
value: "2713",

View File

@ -9,10 +9,10 @@ export class CheckBox extends XmlComponent {
private readonly DEFAULT_UNCHECKED_SYMBOL: string = "2610";
private readonly DEFAULT_CHECKED_SYMBOL: string = "2612";
private readonly DEFAULT_FONT: string = "MS Gothic";
public constructor(alias?: string, options?: ICheckboxSymbolOptions) {
public constructor(options?: ICheckboxSymbolOptions) {
super("w:sdt");
const properties = new StructuredDocumentTagProperties(alias);
const properties = new StructuredDocumentTagProperties(options?.alias);
properties.addChildElement(new CheckBoxUtil(options));
this.root.push(properties);