@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
98 lines (96 loc) • 3.5 kB
JavaScript
/*
* 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 } = {}) => ({
root: Object.assign(
Object.assign(
Object.assign(
{},
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)
}
}
),
styles === null || styles === void 0 ? void 0 : styles.root
),
icon: Object.assign({}, styles === null || styles === void 0 ? void 0 : styles.icon)
}));
const targets = {
background: 'backgroundColor',
icon: 'color'
};
export const PublishingStatusAvatar = React.forwardRef((props, ref) => {
var _a, _b;
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,
(_a = props.classes) === null || _a === void 0 ? void 0 : _a.root,
enabled ? status : 'error'
)
},
React.createElement(CloudUploadOutlined, {
className: cx((_b = props.classes) === null || _b === void 0 ? void 0 : _b.icon)
})
);
});
export default PublishingStatusAvatar;