@botonic/react
Version:
Build Chatbots using React
31 lines • 2.11 kB
JavaScript
;
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 contexts_1 = require("../../contexts");
const environment_1 = require("../../util/environment");
const styles_1 = require("./styles");
const TriggerButton = () => {
const { webchatState, getThemeProperty, toggleWebchat } = (0, react_1.useContext)(contexts_1.WebchatContext);
const getTriggerImage = () => {
const image = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.triggerButtonImage, undefined);
if (!image) {
webchatState.theme.triggerButtonImage = constants_1.WEBCHAT.DEFAULTS.LOGO;
return null;
}
return image;
};
const triggerButtonImage = getTriggerImage();
const triggerButtonStyle = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.triggerButtonStyle);
const notificationsEnabled = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.triggerButtonNotificationsEnabled, false);
const CustomTriggerButton = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.customTrigger, undefined);
const handleClick = (event) => {
toggleWebchat(true);
event.preventDefault();
};
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ onClick: handleClick }, { children: [webchatState.unreadMessages !== 0 && notificationsEnabled && ((0, jsx_runtime_1.jsx)(styles_1.UnreadMessagesCounter, Object.assign({ className: 'trigger-notifications' }, { children: webchatState.unreadMessages }))), 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