UNPKG

@try-at-software/input-elements

Version:

A package providing different input elements that are extensible and easily configurable for your custom needs.

54 lines (53 loc) 3.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DynamicListMenu = void 0; const React = require("react"); const react_1 = require("@fluentui/react"); const Components_1 = require("../../Components"); class DynamicListMenu extends React.Component { render() { var _a, _b; if (!this.props) return null; return (React.createElement("div", { className: "tas-dynamic-list-menu" }, ((_a = this.props.insertButtonConfig) === null || _a === void 0 ? void 0 : _a.show) && this.renderInsertButton(), ((_b = this.props.removeButtonConfig) === null || _b === void 0 ? void 0 : _b.show) && this.renderRemoveButton())); } renderInsertButton() { var _a, _b; const addOptions = this.getItems(); const buttonText = ((_a = this.props.insertButtonConfig) === null || _a === void 0 ? void 0 : _a.label) || 'Insert'; const commonProps = { iconProps: { iconName: ((_b = this.props.insertButtonConfig) === null || _b === void 0 ? void 0 : _b.iconName) || 'Add' }, children: React.createElement(Components_1.FormTextRenderer, { text: buttonText }) }; if (!(addOptions === null || addOptions === void 0 ? void 0 : addOptions.items) || addOptions.items.length <= 0) return React.createElement(react_1.PrimaryButton, Object.assign({}, commonProps, { disabled: true })); else if (addOptions.items.length === 1) { return (React.createElement(react_1.CommandButton, Object.assign({}, commonProps, { disabled: false, onClick: () => { addOptions.items[0].onClick(); } }))); } else return React.createElement(react_1.CommandButton, Object.assign({}, commonProps, { menuProps: addOptions, disabled: false })); } renderRemoveButton() { var _a, _b, _c; const buttonText = ((_a = this.props.removeButtonConfig) === null || _a === void 0 ? void 0 : _a.label) || 'Remove'; return (React.createElement(react_1.CommandButton, { iconProps: { iconName: ((_b = this.props.removeButtonConfig) === null || _b === void 0 ? void 0 : _b.iconName) || 'Remove' }, disabled: !((_c = this.props.removeButtonConfig) === null || _c === void 0 ? void 0 : _c.isEnabled), onClick: () => !!this.props.onRemoveClicked && this.props.onRemoveClicked() }, React.createElement(Components_1.FormTextRenderer, { text: buttonText }))); } getItems() { return { items: this.props.options.map((option, index) => { return { key: index.toString(), iconProps: { iconName: option.icon }, name: option.name, onClick: () => !!this.props.onAddClicked && this.props.onAddClicked(option.createInput()) }; }) }; } } exports.DynamicListMenu = DynamicListMenu;