UNPKG

@botonic/react

Version:

Build Chatbots using React

32 lines 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Attachment = void 0; const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const attachment_icon_svg_1 = tslib_1.__importDefault(require("../../assets/attachment-icon.svg")); const constants_1 = require("../../constants"); const context_1 = require("../../webchat/context"); const common_1 = require("../components/common"); const conditional_animation_1 = require("../components/conditional-animation"); const Attachment = ({ accept, onChange }) => { var _a, _b; const { webchatState } = (0, react_1.useContext)(context_1.WebchatContext); const fileInputRef = (0, react_1.useRef)(null); const CustomAttachments = (_b = (_a = webchatState.theme.userInput) === null || _a === void 0 ? void 0 : _a.attachments) === null || _b === void 0 ? void 0 : _b.custom; const isAttachmentsEnabled = () => { var _a, _b, _c; const hasCustomAttachments = !!CustomAttachments; return ((_c = (_b = (_a = webchatState.theme.userInput) === null || _a === void 0 ? void 0 : _a.attachments) === null || _b === void 0 ? void 0 : _b.enable) !== null && _c !== void 0 ? _c : hasCustomAttachments); }; const attachmentsEnabled = isAttachmentsEnabled(); const handleOnChange = event => { onChange(event); if (fileInputRef.current) { fileInputRef.current.value = ''; } }; return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: attachmentsEnabled ? ((0, jsx_runtime_1.jsx)(conditional_animation_1.ConditionalAnimation, { children: (0, jsx_runtime_1.jsxs)("div", Object.assign({ role: constants_1.ROLES.ATTACHMENT_ICON }, { children: [(0, jsx_runtime_1.jsx)("label", Object.assign({ htmlFor: 'attachment', style: { marginTop: 4 } }, { children: CustomAttachments ? ((0, jsx_runtime_1.jsx)(CustomAttachments, {})) : ((0, jsx_runtime_1.jsx)(common_1.Icon, { src: attachment_icon_svg_1.default })) })), (0, jsx_runtime_1.jsx)("input", { ref: fileInputRef, type: 'file', name: 'file', id: 'attachment', style: { display: 'none' }, onChange: handleOnChange, accept: accept })] })) })) : null })); }; exports.Attachment = Attachment; //# sourceMappingURL=attachment.js.map