@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
38 lines (37 loc) • 3.26 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = tslib_1.__importStar(require("react"));
const react_intl_1 = require("react-intl");
const material_1 = require("@mui/material");
const styles_1 = require("@mui/material/styles");
const Icon_1 = tslib_1.__importDefault(require("@mui/material/Icon"));
const DialogContent_1 = tslib_1.__importDefault(require("@mui/material/DialogContent"));
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const constants_1 = require("./constants");
const PreviewComponent_1 = tslib_1.__importDefault(require("./PreviewComponent"));
const UrlTextField_1 = tslib_1.__importDefault(require("./UrlTextField"));
const classes = {
layerRoot: `${constants_1.PREFIX}-layer-root`,
title: `${constants_1.PREFIX}-layer-title`,
content: `${constants_1.PREFIX}-layer-content`,
media: `${constants_1.PREFIX}-media`,
delete: `${constants_1.PREFIX}-delete`
};
const Root = (0, styles_1.styled)(material_1.Box, {
name: constants_1.PREFIX,
slot: 'LayerRoot'
})(() => ({}));
const LayerComponent = react_1.default.forwardRef((props, ref) => {
// PROPS
const { className, onClose, onSave, defaultValue = [] } = props, rest = tslib_1.__rest(props, ["className", "onClose", "onSave", "defaultValue"]);
// STATE
const [value, setValue] = (0, react_1.useState)(defaultValue);
// HANDLERS
const handleSave = (0, react_1.useCallback)(() => onSave(value), [value]);
const handleAdd = (0, react_1.useCallback)((media) => setValue([...value, media]), [value]);
const handleChange = (0, react_1.useCallback)((medias) => setValue(medias), []);
return (0, jsx_runtime_1.jsxs)(Root, Object.assign({ ref: ref, className: (0, classnames_1.default)(className, classes.layerRoot) }, rest, { children: [(0, jsx_runtime_1.jsxs)(material_1.DialogTitle, Object.assign({ className: classes.title }, { children: [(0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: onClose }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "arrow_back" }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.media.link.layer.title", defaultMessage: "ui.composer.media.link.layer.title" }) }), (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ size: "small", color: "secondary", variant: "contained", onClick: handleSave }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.save", defaultMessage: "ui.composer.layer.save" }) }))] })), (0, jsx_runtime_1.jsxs)(DialogContent_1.default, Object.assign({ className: classes.content }, { children: [(0, jsx_runtime_1.jsx)(UrlTextField_1.default, { id: "page", name: "page", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.media.link.add.label", defaultMessage: "ui.composer.media.link.add.label" }), fullWidth: true, variant: "outlined", placeholder: "https://", onSuccess: handleAdd }), (0, jsx_runtime_1.jsx)(PreviewComponent_1.default, { onChange: handleChange, value: value })] }))] }));
});
exports.default = LayerComponent;