@botonic/react
Version:
Build Chatbots using React
50 lines • 1.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Document = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const core_1 = require("@botonic/core");
const react_1 = require("react");
const styled_components_1 = tslib_1.__importDefault(require("styled-components"));
const constants_1 = require("../constants");
const environment_1 = require("../util/environment");
const context_1 = require("../webchat/context");
const message_1 = require("./message");
const StyledButton = styled_components_1.default.a `
display: block;
height: 25px;
background-color: #f0f0f0;
padding: 10px;
text-align: center;
border-radius: 5px;
color: black;
font-weight: bold;
line-height: 25px;
text-decoration: none;
border: 1px solid black;
opacity: 0.9;
&:hover {
opacity: 1;
}
`;
const serialize = (documentProps) => {
return { document: documentProps.src };
};
const Document = (props) => {
props = { ...props, src: (0, environment_1.staticAsset)(props.src) };
let content = props.children;
const { getThemeProperty } = (0, react_1.useContext)(context_1.WebchatContext);
let documentDownload = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.documentDownload, {});
if (typeof documentDownload === 'function') {
documentDownload = documentDownload(props.from);
}
if ((0, core_1.isBrowser)()) {
content = ((0, jsx_runtime_1.jsx)(StyledButton, { href: props.src, target: '_blank', rel: 'noreferrer', style: {
...documentDownload.style,
}, children: documentDownload.text || 'Download' }));
}
return ((0, jsx_runtime_1.jsx)(message_1.Message, { role: constants_1.ROLES.DOCUMENT_MESSAGE, json: serialize(props), ...props, type: core_1.INPUT.DOCUMENT, children: content }));
};
exports.Document = Document;
exports.Document.serialize = serialize;
//# sourceMappingURL=document.js.map