UNPKG

@craftercms/studio-ui

Version:

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

99 lines (97 loc) 4.45 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 { styled } from '@mui/material/styles'; import MuiList from '@mui/material/List'; import MuiListItemAvatar from '@mui/material/ListItemAvatar'; import Checkbox from '@mui/material/Checkbox'; import MuiCheckbox from '@mui/material/Checkbox'; import ListItemText from '@mui/material/ListItemText'; import Skeleton from '@mui/material/Skeleton'; import Typography from '@mui/material/Typography'; import React from 'react'; import MuiListItem from '@mui/material/ListItem'; import MuiListItemIcon from '@mui/material/ListItemIcon'; import MuiListSubheader from '@mui/material/ListSubheader'; import { CheckRounded } from '@mui/icons-material'; import Box from '@mui/material/Box'; import { UNDEFINED } from '../../utils/constants'; import { getInitials } from '../../utils/string'; import Avatar from '@mui/material/Avatar'; import { getPersonFullName } from '../SiteDashboard/utils'; export const List = styled(MuiList)({ paddingTop: 0 }); export const ListSubheader = styled(MuiListSubheader)({ paddingLeft: 0, paddingRight: 0, lineHeight: 2 }); export const ListItem = styled(MuiListItem)({ padding: 0 }); export const ListItemIcon = styled(MuiListItemIcon)({ marginRight: 0 }); export const ListItemAvatar = styled(MuiListItemAvatar)({ minWidth: 50 }); export const DenseCheckbox = styled(MuiCheckbox)({ padding: '5px' }); export const DashletAvatar = styled(Avatar)({ width: 40, height: 40 }); export function PersonAvatar(props) { var _a; const { person } = props; return React.createElement(DashletAvatar, { src: (_a = person.avatar) !== null && _a !== void 0 ? _a : UNDEFINED, children: person.avatar ? UNDEFINED : getInitials(person) }); } export const getItemSkeleton = ({ numOfItems = 1, showCheckbox = false, showAvatar = false }) => React.createElement( List, null, new Array(numOfItems) .fill(null) .map((nothing, index) => React.createElement( ListItem, { key: index }, showCheckbox && React.createElement(ListItemIcon, null, React.createElement(Checkbox, { edge: 'start', disabled: true })), showAvatar && React.createElement(ListItemAvatar, null, React.createElement(DashletAvatar, null)), React.createElement(ListItemText, { primary: React.createElement(Skeleton, { variant: 'text' }), secondary: React.createElement( Typography, { color: 'text.secondary', variant: 'body2' }, React.createElement(Skeleton, { variant: 'text' }) ) }) ) ) ); export const DashletEmptyMessage = ({ children, sx }) => React.createElement( Box, { display: 'flex', flexDirection: 'column', alignItems: 'center', sx: Object.assign({ mt: 2 }, sx) }, React.createElement(CheckRounded, { sx: { color: 'success.main', mb: 1 } }), React.createElement(Typography, { color: 'text.secondary', variant: 'body2' }, children) ); export function PersonFullName({ person }) { return React.createElement(Typography, { variant: 'h6' }, getPersonFullName(person)); }