UNPKG

@botonic/react

Version:

Build Chatbots using React

24 lines 1.71 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import React, { useContext, useRef } from 'react'; import AttachmentIcon from '../../assets/attachment-icon.svg'; import { ROLES, WEBCHAT } from '../../constants'; import { WebchatContext } from '../../contexts'; import { ConditionalAnimation } from '../components/conditional-animation'; import { Icon } from './common'; export const Attachment = ({ onChange, accept, enableAttachments }) => { const { getThemeProperty } = useContext(WebchatContext); const fileInputRef = useRef(null); const CustomAttachments = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.customAttachments, undefined); const isAttachmentsEnabled = () => { var _a; const hasCustomAttachments = !!CustomAttachments; return ((_a = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.enableAttachments, enableAttachments)) !== null && _a !== void 0 ? _a : hasCustomAttachments); }; const attachmentsEnabled = isAttachmentsEnabled(); const handleOnChange = event => { onChange(event); fileInputRef.current.value = null; }; return (_jsx(_Fragment, { children: attachmentsEnabled ? (_jsx(ConditionalAnimation, { children: _jsxs("div", Object.assign({ role: ROLES.ATTACHMENT_ICON }, { children: [_jsx("label", Object.assign({ htmlFor: 'attachment', style: { marginTop: 4 } }, { children: CustomAttachments ? (_jsx(CustomAttachments, {})) : (_jsx(Icon, { src: AttachmentIcon })) })), _jsx("input", { ref: fileInputRef, type: 'file', name: 'file', id: 'attachment', style: { display: 'none' }, onChange: handleOnChange, accept: accept })] })) })) : null })); }; //# sourceMappingURL=attachment.js.map