UNPKG

@botonic/react

Version:

Build Chatbots using React

73 lines 2.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ButtonsDisabler = void 0; const message_utils_1 = require("../message-utils"); const objects_1 = require("../util/objects"); const react_1 = require("../util/react"); const button_1 = require("./button"); class ButtonsDisabler { static constructBrowserProps(props) { const disabledProps = {}; if (props.autodisable !== undefined) disabledProps.autodisable = (0, objects_1.strToBool)(props.autodisable); if (props.disabledstyle !== undefined) disabledProps.disabledstyle = props.disabledstyle; return disabledProps; } static constructNodeProps(props) { const disabledProps = {}; if (props.autodisable !== undefined) disabledProps.autodisable = String(props.autodisable); if (props.disabledstyle !== undefined) disabledProps.disabledstyle = JSON.stringify(props.disabledstyle); return disabledProps; } static withDisabledProps(props) { return { disabled: props.disabled, autodisable: props.autodisable, disabledstyle: props.disabledstyle, }; } static updateChildrenButtons(children, additionalProps) { return (0, react_1.deepMapWithIndex)(children, (node) => { if (node.type === button_1.Button) return this.updateButtons(node, additionalProps); return node; }); } static updateButtons(node, additionalProps) { if (additionalProps) { additionalProps = { parentId: additionalProps.parentId, disabled: node.props.disabled === true ? node.props.disabled : additionalProps.disabled, setDisabled: additionalProps.setDisabled, }; } return Object.assign(Object.assign({}, node), { props: Object.assign(Object.assign({}, node.props), additionalProps) }); } static getUpdatedMessage(messageToUpdate) { const updateMsgButton = (button) => { return Object.assign(Object.assign({}, button), { disabled: true, }); }; if ((0, message_utils_1.isCarousel)(messageToUpdate) && messageToUpdate.data && messageToUpdate.data.elements) { messageToUpdate.data.elements = messageToUpdate.data.elements.map(e => (Object.assign(Object.assign({}, e), { buttons: e.buttons.map(updateMsgButton), }))); return messageToUpdate; } else { return Object.assign(Object.assign({}, messageToUpdate), { buttons: messageToUpdate.buttons.map(updateMsgButton), }); } } } exports.ButtonsDisabler = ButtonsDisabler; //# sourceMappingURL=buttons-disabler.js.map