UNPKG

@botonic/react

Version:

Build Chatbots using React

29 lines 2.15 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 = tslib_1.__importStar(require("react")); const attachment_icon_svg_1 = tslib_1.__importDefault(require("../../assets/attachment-icon.svg")); const constants_1 = require("../../constants"); const contexts_1 = require("../../contexts"); const conditional_animation_1 = require("../components/conditional-animation"); const common_1 = require("./common"); const Attachment = ({ onChange, accept, enableAttachments }) => { const { getThemeProperty } = (0, react_1.useContext)(contexts_1.WebchatContext); const fileInputRef = (0, react_1.useRef)(null); const CustomAttachments = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.customAttachments, undefined); const isAttachmentsEnabled = () => { var _a; const hasCustomAttachments = !!CustomAttachments; return ((_a = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.enableAttachments, enableAttachments)) !== null && _a !== void 0 ? _a : hasCustomAttachments); }; const attachmentsEnabled = isAttachmentsEnabled(); const handleOnChange = event => { onChange(event); fileInputRef.current.value = null; }; 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