UNPKG

@craftercms/studio-ui

Version:

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

108 lines (106 loc) 3.72 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 Avatar from '@mui/material/Avatar'; import CloudUploadOutlined from '@mui/icons-material/CloudUploadOutlined'; import * as React from 'react'; import { makeStyles } from 'tss-react/mui'; import { getPublishingStatusCodeColor } from './util'; const useStyles = makeStyles()((theme, { styles, stylingTarget } = {}) => { return { root: { ...(stylingTarget === 'color' && { background: 'none', color: theme.palette.text.secondary }), '&.ready': { [stylingTarget]: getPublishingStatusCodeColor('ready', theme) }, '&.processing': { [stylingTarget]: getPublishingStatusCodeColor('processing', theme) }, '&.publishing': { [stylingTarget]: getPublishingStatusCodeColor('publishing', theme) }, '&.queued': { [stylingTarget]: getPublishingStatusCodeColor('queued', theme) }, '&.stopped': { [stylingTarget]: getPublishingStatusCodeColor('stopped', theme) }, '&.error': { [stylingTarget]: getPublishingStatusCodeColor('error', theme) }, '&.readyWithErrors': { [stylingTarget]: getPublishingStatusCodeColor('readyWithErrors', theme) }, ...styles?.root }, icon: { ...styles?.icon } }; // region Compiler hints // Var below is for typescript to complain if we ever add/remove codes. // eslint-disable-next-line no-unreachable,@typescript-eslint/no-unused-vars const control = { error: undefined, processing: undefined, publishing: undefined, queued: undefined, ready: undefined, readyWithErrors: undefined, stopped: undefined }; // endregion }); const targets = { background: 'backgroundColor', icon: 'color' }; export const PublishingStatusAvatar = React.forwardRef((props, ref) => { const { status, enabled, styles, variant = 'icon' } = props; const { classes, cx } = useStyles({ styles, stylingTarget: targets[variant] }); return React.createElement( Avatar, { ref: ref, variant: 'circular', className: cx( classes.root, props.className, props.classes?.root, enabled ? status : enabled === false ? 'error' : null ) }, React.createElement(CloudUploadOutlined, { className: cx(props.classes?.icon) }) ); }); export default PublishingStatusAvatar;