UNPKG

@craftercms/studio-ui

Version:

Services, components, models & utils to build CrafterCMS authoring extensions.

116 lines (114 loc) 4.31 kB
/* * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import { useIntl } from 'react-intl'; import Checkbox from '@mui/material/Checkbox'; import React from 'react'; import { getPossibleTranslation } from '../../utils/i18n'; import Button from '@mui/material/Button'; import Skeleton from '@mui/material/Skeleton'; import { rand } from '../PathNavigator/utils'; import Box from '@mui/material/Box'; export function ActionsBar(props) { var _a, _b; const { formatMessage } = useIntl(); const { options, onOptionClicked, isIndeterminate, onCheckboxChange, isChecked, isLoading = false, numOfSkeletonItems = 5, buttonProps, sxs, disabled = false } = props; return React.createElement( Box, { className: (_a = props.classes) === null || _a === void 0 ? void 0 : _a.root, sx: Object.assign({ bgcolor: 'background.paper' }, sxs === null || sxs === void 0 ? void 0 : sxs.root) }, React.createElement( Box, { sx: Object.assign({ bgcolor: 'action.selected' }, sxs === null || sxs === void 0 ? void 0 : sxs.container) }, React.createElement(Checkbox, { disabled: disabled, sx: Object.assign({ width: 48 }, sxs === null || sxs === void 0 ? void 0 : sxs.checkbox), color: 'primary', indeterminate: isIndeterminate, checked: isChecked, className: (_b = props.classes) === null || _b === void 0 ? void 0 : _b.checkbox, onChange: onCheckboxChange }), isLoading ? new Array(numOfSkeletonItems).fill(null).map((nothing, index) => { var _a; return React.createElement( Button, Object.assign( { key: index, color: 'primary', className: (_a = props.classes) === null || _a === void 0 ? void 0 : _a.button, sx: sxs === null || sxs === void 0 ? void 0 : sxs.button, disabled: disabled }, buttonProps ), React.createElement(Skeleton, { animation: 'pulse', height: '12px', width: `${rand(40, 60)}px` }) ); }) : options === null || options === void 0 ? void 0 : options.map((option) => { var _a; return React.createElement( Button, Object.assign( { key: option.id, color: 'primary', variant: 'text', className: (_a = props.classes) === null || _a === void 0 ? void 0 : _a.button, sx: sxs === null || sxs === void 0 ? void 0 : sxs.button, disabled: disabled }, buttonProps, { onClick: () => onOptionClicked(option.id) } ), getPossibleTranslation(option.label, formatMessage) ); }) ) ); } export default ActionsBar;