@botonic/react
Version:
Build Chatbots using React
30 lines • 2 kB
JavaScript
;
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 }) => {
const { webchatState } = (0, react_1.useContext)(context_1.WebchatContext);
const fileInputRef = (0, react_1.useRef)(null);
const CustomAttachments = webchatState.theme.userInput?.attachments?.custom;
const isAttachmentsEnabled = () => {
const hasCustomAttachments = !!CustomAttachments;
return (webchatState.theme.userInput?.attachments?.enable ?? 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", { role: constants_1.ROLES.ATTACHMENT_ICON, children: [(0, jsx_runtime_1.jsx)("label", { 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