UNPKG

@selfcommunity/react-ui

Version:

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

30 lines (29 loc) 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const material_1 = require("@mui/material"); const react_intl_1 = require("react-intl"); const constants_1 = require("../constants"); const classnames_1 = tslib_1.__importDefault(require("classnames")); const pubsub_js_1 = tslib_1.__importDefault(require("pubsub-js")); const PubSub_1 = require("../../../constants/PubSub"); const react_1 = require("react"); const classes = { sectionButton: `${constants_1.PREFIX}-section-button`, sectionButtonTypography: `${constants_1.PREFIX}-section-button-typography` }; function AddButton(props) { // PROPS const { label, handleAddRow, className } = props, rest = tslib_1.__rest(props, ["label", "handleAddRow", "className"]); // HOOKS const theme = (0, material_1.useTheme)(); const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('md')); // HANDLERS const handleClick = (0, react_1.useCallback)(() => { handleAddRow(); pubsub_js_1.default.publish(`${PubSub_1.SCTopicType.COURSE}.${PubSub_1.SCGroupEventType.UPDATE}`, true); }, [handleAddRow]); return ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: isMobile ? ((0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: handleClick }, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "add_circle_outline" }) }))) : ((0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ className: (0, classnames_1.default)(classes.sectionButton, className), size: "small", startIcon: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "add_circle_outline" }), onClick: handleClick }, rest, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ className: classes.sectionButtonTypography, variant: "body1" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: label, defaultMessage: label }) })) }))) })); } exports.default = (0, react_1.memo)(AddButton);