@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
134 lines (132 loc) • 4.43 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 React from 'react';
import { makeStyles } from 'tss-react/mui';
import { ListItem, ListItemText, Snackbar } from '@mui/material';
import palette from '../../styles/palette';
import { defineMessages, useIntl } from 'react-intl';
import List from '@mui/material/List';
import Skeleton from '@mui/material/Skeleton';
import { rand } from '../PathNavigator/utils';
import Button from '@mui/material/Button';
const useStyles = makeStyles()((theme) => ({
actionsBar: {
zIndex: theme.zIndex.modal,
'& .MuiSnackbarContent-root': {
backgroundColor: palette.blue.highlightHex,
color: palette.black,
borderRadius: '6px',
padding: '0 10px',
minWidth: 'unset'
},
'& .MuiSnackbarContent-message': {
display: 'flex',
padding: 0
}
},
actionsList: {
display: 'flex',
flexDirection: 'row',
padding: 0
},
loadingItem: {
width: 'fit-content',
padding: '0 10px'
}
}));
const messages = defineMessages({
acceptSelection: {
id: 'search.acceptSelection',
defaultMessage: 'Accept Selection'
},
noOptionsAvailable: {
id: 'siteSearch.noOptionsAvailable',
defaultMessage: 'No options available'
}
});
function ItemActionsSnackbar(props) {
const { open, options, onActionClicked, append, prepend } = props;
const { classes } = useStyles();
const { formatMessage } = useIntl();
return React.createElement(Snackbar, {
anchorOrigin: { vertical: 'top', horizontal: 'center' },
open: open,
classes: {
root: classes.actionsBar
},
message: React.createElement(
React.Fragment,
null,
prepend,
React.createElement(
List,
{ className: classes.actionsList },
options
? options.length
? options.map((option) =>
React.createElement(
Button,
{
size: 'small',
variant: 'text',
color: 'primary',
key: option.id,
onClick: (e) => onActionClicked(option.id, e)
},
React.createElement(ListItemText, { primary: option.label })
)
)
: React.createElement(
ListItem,
null,
React.createElement(ListItemText, { primary: formatMessage(messages.noOptionsAvailable) })
)
: new Array(5)
.fill(null)
.map((_, index) =>
React.createElement(
ListItem,
{ key: index, disableGutters: true, className: classes.loadingItem },
React.createElement(ListItemText, {
primary: React.createElement(Skeleton, {
animation: 'pulse',
height: '10px',
width: `${rand(60, 80)}px`
})
})
)
),
append
)
)
});
}
export default ItemActionsSnackbar;