UNPKG

@selfcommunity/react-ui

Version:

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

72 lines (67 loc) 2.75 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 = tslib_1.__importStar(require("react")); const system_1 = require("@mui/system"); const styles_1 = require("@mui/material/styles"); const Dialog_1 = tslib_1.__importDefault(require("@mui/material/Dialog")); const ConsentSolution_1 = tslib_1.__importDefault(require("../ConsentSolution")); const material_1 = require("@mui/material"); const react_intl_1 = require("react-intl"); const react_core_1 = require("@selfcommunity/react-core"); const PREFIX = 'SCConsentSolutionButton'; const classes = { root: `${PREFIX}-root` }; const Root = (0, styles_1.styled)(Dialog_1.default, { name: PREFIX, slot: 'Root', overridesResolver: (props, styles) => styles.root })(({ theme }) => ({})); /** *> API documentation for the Community-JS ConsentSolutionButton component. Learn about the available props and the CSS API. * #### Import ```jsx import {ConsentSolutionButton} from '@selfcommunity/react-ui'; ``` #### Component Name The name `SCConsentSolutionButton` can be used when providing style overrides in the theme. #### CSS |Rule Name|Global class|Description| |---|---|---| |root|.SCConsentSolution-root|Styles applied to the root element.| * @param inProps */ function ConsentSolutionButton(inProps) { //PROPS const props = (0, system_1.useThemeProps)({ props: inProps, name: PREFIX }); const { className, ConsentSolutionProps = {} } = props, rest = tslib_1.__rest(props, ["className", "ConsentSolutionProps"]); // CONTEXT const scUserContext = (0, react_1.useContext)(react_core_1.SCUserContext); // STATE const [open, setOpen] = react_1.default.useState(false); // CONST const authUserId = scUserContext.user ? scUserContext.user.id : null; /** * Handle click on button */ const handleClick = () => { setOpen((p) => !p); }; /** * If there's no authUserId, component is hidden. */ if (!authUserId) { return null; } /** * Renders root object */ return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ onClick: handleClick, size: "small", variant: "outlined" }, rest, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.consentSolutionButton.viewStateButton", defaultMessage: "ui.consentSolutionButton.viewStateButton" }) })), open && (0, jsx_runtime_1.jsx)(ConsentSolution_1.default, Object.assign({}, ConsentSolutionProps, { open: true, onClose: handleClick }))] })); } exports.default = ConsentSolutionButton;