@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
125 lines (123 loc) • 4.28 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 IconButton from '@mui/material/IconButton';
import MoreVertIcon from '@mui/icons-material/MoreVertRounded';
import { makeStyles } from 'tss-react/mui';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
import Link from '@mui/material/Link';
import ListItem from '@mui/material/ListItem';
import ListItemText from '@mui/material/ListItemText';
import ListItemSecondaryAction from '@mui/material/ListItemSecondaryAction';
import Box from '@mui/material/Box';
const useStyles = makeStyles()((theme) => ({
card: {
paddingTop: theme.spacing(2.5),
paddingBottom: theme.spacing(2.5),
borderRadius: 5,
backgroundColor: theme.palette.background.paper
},
siteName: {
fontWeight: 600
}
}));
function LauncherSiteCard(props) {
var _a;
const { title, value, onCardClick, options, selected = false } = props;
const [anchorEl, setAnchorEl] = React.useState(null);
const { classes, cx } = useStyles();
const hasOptions = Boolean(options && options.length);
const handleClose = (event, action) => {
var _a;
event.stopPropagation();
setAnchorEl(null);
(_a = action === null || action === void 0 ? void 0 : action.onClick) === null || _a === void 0
? void 0
: _a.call(action, value, event);
};
const handleOptions = (event) => {
event.stopPropagation();
setAnchorEl(event.currentTarget);
};
return React.createElement(
React.Fragment,
null,
React.createElement(
Box,
// @ts-ignore
{
// @ts-ignore
button: true,
selected: selected,
boxShadow: 1,
component: ListItem,
onClick: () => onCardClick(value),
className: cx(classes.card, (_a = props.classes) === null || _a === void 0 ? void 0 : _a.root),
title: title
},
React.createElement(ListItemText, {
primary: title,
primaryTypographyProps: { className: classes.siteName, noWrap: true }
}),
hasOptions &&
React.createElement(
ListItemSecondaryAction,
null,
React.createElement(
IconButton,
{ 'aria-label': 'settings', onClick: handleOptions, size: 'large' },
React.createElement(MoreVertIcon, null)
)
)
),
React.createElement(
Menu,
{ anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handleClose },
hasOptions &&
options.map((action, i) =>
React.createElement(
MenuItem,
{
key: i,
component: Link,
color: 'inherit',
underline: 'none',
href: typeof action.href === 'function' ? action.href(value) : action.href,
onClick: (e) => handleClose(e, action)
},
action.name
)
)
)
);
}
export default LauncherSiteCard;