UNPKG

@botonic/react

Version:

Build Chatbots using React

32 lines 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TriggerButton = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const constants_1 = require("../../constants"); const environment_1 = require("../../util/environment"); const context_1 = require("../../webchat/context"); const styles_1 = require("./styles"); const TriggerButton = () => { const { webchatState, getThemeProperty, toggleWebchat } = (0, react_1.useContext)(context_1.WebchatContext); const getTriggerImage = () => { const image = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.triggerButtonImage, undefined); if (!image) { webchatState.theme.triggerButton.image = constants_1.WEBCHAT.DEFAULTS.LOGO; return null; } return image; }; const triggerButtonImage = getTriggerImage(); const triggerButtonStyle = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.triggerButtonStyle); const notificationsTriggerButtonEnabled = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.notificationsTriggerButtonEnabled); const notificationsEnabled = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.notificationsEnabled, notificationsTriggerButtonEnabled); const CustomTriggerButton = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.customTrigger); const handleClick = (event) => { toggleWebchat(true); event.preventDefault(); }; return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ onClick: handleClick }, { children: [webchatState.numUnreadMessages !== 0 && notificationsEnabled && ((0, jsx_runtime_1.jsx)(styles_1.UnreadMessagesCounter, Object.assign({ className: 'trigger-notifications' }, { children: webchatState.numUnreadMessages }))), CustomTriggerButton ? ((0, jsx_runtime_1.jsx)(CustomTriggerButton, {})) : ((0, jsx_runtime_1.jsx)(styles_1.StyledTriggerButton, Object.assign({ role: constants_1.ROLES.TRIGGER_BUTTON, style: triggerButtonStyle }, { children: triggerButtonImage && ((0, jsx_runtime_1.jsx)(styles_1.TriggerImage, { src: (0, environment_1.resolveImage)(triggerButtonImage) })) })))] }))); }; exports.TriggerButton = TriggerButton; //# sourceMappingURL=index.js.map