UNPKG

@selfcommunity/react-ui

Version:

React UI Components to integrate a Community created with SelfCommunity Platform.

50 lines (49 loc) 2.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const material_1 = require("@mui/material"); const styles_1 = require("@mui/material/styles"); const classnames_1 = tslib_1.__importDefault(require("classnames")); const Editor_1 = tslib_1.__importDefault(require("../../../Editor")); const constants_1 = require("../../constants"); const react_intl_1 = require("react-intl"); const classes = { root: `${constants_1.PREFIX}-content-post-root`, generalError: `${constants_1.PREFIX}-general-error`, medias: `${constants_1.PREFIX}-content-post-medias`, editor: `${constants_1.PREFIX}-content-post-editor` }; const Root = (0, styles_1.styled)(material_1.Box, { name: constants_1.PREFIX, slot: 'ContentPostRoot' })(({ theme }) => ({})); /** * Default post */ const DEFAULT_POST = { categories: [], medias: [], html: '', addressing: [], event: null, group: null }; exports.default = (props) => { // PROPS const { className = null, value = Object.assign({}, DEFAULT_POST), error = {}, disabled = false, onChange, EditorProps = {} } = props; const { error: generalError = null } = Object.assign({}, error); // REF const editorRef = (0, react_1.useRef)(); // EFFECTS (0, react_1.useEffect)(() => { editorRef && editorRef.current && editorRef.current.focus(); }, [editorRef]); // HANDLERS const handleChangeHtml = (0, react_1.useCallback)((html) => { onChange(Object.assign(Object.assign({}, value), { html })); }, [value]); // RENDER return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, { children: [generalError && ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ className: classes.generalError }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: `ui.composer.error.${generalError}`, defaultMessage: `ui.composer.error.${generalError}` }) }))), (0, jsx_runtime_1.jsx)(Editor_1.default, Object.assign({ ref: editorRef }, EditorProps, { editable: !disabled, className: classes.editor, onChange: handleChangeHtml, defaultValue: value.html }))] }))); };