diff --git a/packages/survey-creator-core/src/toolbox.ts b/packages/survey-creator-core/src/toolbox.ts index 167a9bc6c8..8293c84e8a 100644 --- a/packages/survey-creator-core/src/toolbox.ts +++ b/packages/survey-creator-core/src/toolbox.ts @@ -30,7 +30,7 @@ export type overflowBehaviorType = "hideInMenu" | "scroll"; /** * A toolbox item configuration. * - * `IQuestionToolboxItem` objects are used in such Toolbox API methods as [`getItemByName(name)`](https://surveyjs.io/survey-creator/documentation/api-reference/questiontoolbox#getItemByName), [`addItem(item, index)`](https://surveyjs.io/survey-creator/documentation/api-reference/questiontoolbox#addItem), [`replaceItem(item)`](https://surveyjs.io/survey-creator/documentation/api-reference/questiontoolbox#replaceItem), and others. + * `IQuestionToolboxItem` objects are used in such Toolbox API methods as [`addItem(item, index)`](https://surveyjs.io/survey-creator/documentation/api-reference/questiontoolbox#addItem), [`replaceItem(item)`](https://surveyjs.io/survey-creator/documentation/api-reference/questiontoolbox#replaceItem), [`addSubitem(subitem, index)`](https://surveyjs.io/survey-creator/documentation/api-reference/questiontoolboxitem#addSubitem), and others. * * [Toolbox Customization](https://surveyjs.io/survey-creator/documentation/toolbox-customization (linkStyle)) */ @@ -46,7 +46,7 @@ export interface IQuestionToolboxItem extends IAction { * * [UI Icons](https://surveyjs.io/form-library/documentation/icons (linkStyle)) */ - iconName: string; + iconName?: string; /** * A JSON object used to create a new question or panel when users click this toolbox item. It must contain the `type` property. * @@ -57,11 +57,11 @@ export interface IQuestionToolboxItem extends IAction { * A user-friendly toolbox item title. */ title: string; - className: string; + className?: string; /** * A toolbox item tooltip. * - * If `tooltip` is undefined, the [`title`](https://surveyjs.io/survey-creator/documentation/api-reference/iquestiontoolboxitem#title) property value is used instead. + * If `tooltip` is undefined, the [`title`](#title) property value is used instead. */ tooltip?: string; isCopied?: boolean; @@ -80,32 +80,8 @@ export interface IQuestionToolboxItem extends IAction { */ enabled?: boolean; getArea?: (el: HTMLElement) => HTMLElement; - /** - * Removes all subitems from this toolbox item. - * - * [Manage Toolbox Subitems](https://surveyjs.io/survey-creator/documentation/toolbox-customization#manage-toolbox-subitems (linkStyle)) - * @see removeSubitem - * @see addSubitem - */ clearSubitems?(): void; - /** - * Adds a subitem to this toolbox item. - * - * [Manage Toolbox Subitems](https://surveyjs.io/survey-creator/documentation/toolbox-customization#manage-toolbox-subitems (linkStyle)) - * @param subitem An `IQuestionToolboxItem` object that represents a subitem configuration. - * @param index *(Optional)* A zero-based index at which to insert the subitem. If you do not specify this parameter, the subitem is added to the end. - * @see removeSubitem - * @see clearSubitems - */ addSubitem?(subitem: IQuestionToolboxItem, index: number): void; - /** - * Removes a specific subitem from this toolbox item. - * - * [Manage Toolbox Subitems](https://surveyjs.io/survey-creator/documentation/toolbox-customization#manage-toolbox-subitems (linkStyle)) - * @param subitem A subitem [`name`](https://surveyjs.io/survey-creator/documentation/api-reference/iquestiontoolboxitem#name) or an `IQuestionToolboxItem` object that represents a subitem configuration. - * @see clearSubitems - * @see addSubitem - */ removeSubitem?(subitem: IQuestionToolboxItem | string): void; } @@ -143,6 +119,11 @@ export class QuestionToolboxCategory extends Base { } } } +/** + * A toolbox item instance. + * + * An object of this class is returned by the `QuestionToolbox`'s [`getItemByName(name)`](https://surveyjs.io/survey-creator/documentation/api-reference/questiontoolbox#getItemByName) method. + */ export class QuestionToolboxItem extends Action implements IQuestionToolboxItem { static getItemClassNames(iconName?: string): string { return new CssClassBuilder() @@ -171,12 +152,59 @@ export class QuestionToolboxItem extends Action implements IQuestionToolboxItem .toString(); }) as any; } + /** + * A user-friendly toolbox item title. + */ + public get title(): string { + return this.getTitle(); + } + public set title(val: string) { + this.setTitle(val); + } + /** + * Specifies whether users can interact with the toolbox item. + * + * Default value: `true` + */ + public get enabled(): boolean { + return this.getEnabled(); + } + public set enabled(val: boolean) { + this.setEnabled(val); + } className: string; + /** + * An icon name. + * + * [UI Icons](https://surveyjs.io/form-library/documentation/icons (linkStyle)) + */ iconName: string; + /** + * A toolbox item identifier. + * + * > Toolbox item names must be unique. + */ name: string; + /** + * A JSON object used to create a new question or panel when users click this toolbox item. It must contain the `type` property. + * + * [View Toolbox Customization Demo](https://surveyjs.io/survey-creator/examples/survey-toolbox-customization/ (linkStyle)) + */ json: any; + /** + * A toolbox item tooltip. + * + * If `tooltip` is undefined, the [`title`](#title) property value is used instead. + */ tooltip: string; isCopied: boolean; + /** + * A category to which this toolbox item belongs. + * + * Out-of-the-box categories include `"general"`, `"choice"`, `"text"`, `"containers"`, `"matrix"`, and `"misc"`. + * + * Default value: `"general"` + */ category: string; toJSON() { return this.item; @@ -210,7 +238,13 @@ export class QuestionToolboxItem extends Action implements IQuestionToolboxItem this.setSubItems({ items: items }); this.component = QuestionToolbox.defaultItemGroupComponent; } - + /** + * Removes all subitems from this toolbox item. + * + * [Manage Toolbox Subitems](https://surveyjs.io/survey-creator/documentation/toolbox-customization#manage-toolbox-subitems (linkStyle)) + * @see removeSubitem + * @see addSubitem + */ public clearSubitems(): void { if (this.hasSubItems) { this.items = []; @@ -218,7 +252,15 @@ export class QuestionToolboxItem extends Action implements IQuestionToolboxItem this.popupModel.dispose(); } } - + /** + * Adds a subitem to this toolbox item. + * + * [Manage Toolbox Subitems](https://surveyjs.io/survey-creator/documentation/toolbox-customization#manage-toolbox-subitems (linkStyle)) + * @param subitem An [`IQuestionToolboxItem`](https://surveyjs.io/survey-creator/documentation/api-reference/iquestiontoolboxitem) object that represents a subitem configuration. + * @param index *(Optional)* A zero-based index at which to insert the subitem. If you do not specify this parameter, the subitem is added to the end. + * @see removeSubitem + * @see clearSubitems + */ public addSubitem(item: IQuestionToolboxItem, index: number = -1): void { if (!item) return; const newItem: QuestionToolboxItem = new QuestionToolboxItem(item); @@ -233,7 +275,14 @@ export class QuestionToolboxItem extends Action implements IQuestionToolboxItem } this.addSubitems(array); } - + /** + * Removes a specific subitem from this toolbox item. + * + * [Manage Toolbox Subitems](https://surveyjs.io/survey-creator/documentation/toolbox-customization#manage-toolbox-subitems (linkStyle)) + * @param subitem A subitem [`name`](https://surveyjs.io/survey-creator/documentation/api-reference/iquestiontoolboxitem#name) or an [`IQuestionToolboxItem`](https://surveyjs.io/survey-creator/documentation/api-reference/iquestiontoolboxitem) object that represents a subitem configuration. + * @see clearSubitems + * @see addSubitem + */ public removeSubitem(item: IQuestionToolboxItem | string): void { if (!this.hasSubItems || !item) return; @@ -757,11 +806,11 @@ export class QuestionToolbox } } /** - * Returns a [toolbox item](https://surveyjs.io/survey-creator/documentation/api-reference/iquestiontoolboxitem) with a specified name. + * Returns a [toolbox item](https://surveyjs.io/survey-creator/documentation/api-reference/questiontoolboxitem) with a specified name. * @param name A toolbox item's [`name`](https://surveyjs.io/survey-creator/documentation/api-reference/iquestiontoolboxitem#name). * @returns A toolbox item or `null` if a toolbox item with the specified name isn't found. */ - public getItemByName(name: string): IQuestionToolboxItem { + public getItemByName(name: string): QuestionToolboxItem { if (!name) return null; const index: number = this.indexOf(name); return index > -1 ? this.actions[index] : null;