import { ComponentStory, ComponentMeta } from '@storybook/react'; import { action } from '@storybook/addon-actions'; import uniqueId from 'lodash/uniqueId'; import MuiFormControlLabel from '@mui/material/FormControlLabel'; import MuiGrid from '@mui/material/Grid'; import { ASSETS_URL } from '../../../../consts/common'; import type { AvatarProps } from '../../../avatar'; import { CustomIcon } from '../../../custom-icon'; import { Switch } from '../../../@forms/switch'; import type { SwitchProps } from '../../../@forms/switch'; import { TextWithBG } from '../../../text-with-bg'; import { TextWithTooltip } from '../../../text-with-tooltip'; import { _palette } from '../../../@styles/theme-provider'; import { CardGridProps, CardGridColDef, RenderActionButtonsCell, RenderAvatarGroupCell, RenderTextGroupCell, RenderTextListCell } from '../../card-grid'; import Card from '../card'; const actionDeleteHandler = action('delete action clicked'); const actionEditHandler = action('edit action clicked'); const actionMoreHandler = action('more action clicked'); const actionViewHandler = action('view action clicked'); const cardClickHandler = action('card clicked'); const cellClickHandler: CardGridProps['onCellClick'] = (e, props) => { e.stopPropagation(); action(`${props?.field} cell clicked`)(e); }; const counterClickHandler: AvatarProps['onClick'] = e => { e.stopPropagation(); action('counter clicked')(e); }; const switchChangeHandler: SwitchProps['onChange'] = (e, checked) => { e.stopPropagation(); action('switch toggled')(e); }; const actionButtons: CardGridColDef['actions'] = [ { icon: { src: `${ASSETS_URL}/icons2/icon_trash.svg` }, value: 'delete', onClick: value => actionDeleteHandler }, { icon: { src: `${ASSETS_URL}/icons2/icon_edit.svg` }, value: 'edit', onClick: value => actionEditHandler }, { icon: { src: `${ASSETS_URL}/icons2/icon_view.svg` }, value: 'view', onClick: value => actionViewHandler }, { icon: { rotateDeg: -90, src: `${ASSETS_URL}/icons2/icon_3dots.svg` }, value: 'more', visible: true, onClick: value => actionMoreHandler } ]; export default { title: 'Cards/Card', component: Card, argTypes: { active: { description: 'Whether to display card in active state.', control: { type: 'boolean' } }, hovered: { description: 'Whether to display card in hovered state.', control: { type: 'boolean' } }, disabled: { description: 'Whether to display card in disabled state.', control: { type: 'boolean' } }, indicator: { description: 'Whether to show indicator (colored left border).', control: { type: 'boolean' } }, indicatorColor: { description: 'Custom color of the indicator.', control: { type: 'color' } } } } as ComponentMeta; const Template: ComponentStory = args => ; export const Group = Template.bind({}); Group.args = { columns: [ { field: 'groupName', children: ( ), flex: 'auto', minWidth: 224, maxWidth: 398 }, { field: 'members', children: ( ), width: 152 }, { field: 'groups', children: ( ), width: 232 }, { field: 'networks', children: ( ), width: 88 }, { field: 'actionButtons', children: ( ), align: 'end', hideDivider: true, marginLeft: 'auto', minWidth: 120, width: 120 } ], active: false, hovered: false, disabled: false, indicator: true, onCellClick: cellClickHandler, onClick: cardClickHandler }; export const Application = Template.bind({}); Application.args = { columns: [ { field: 'applicationName', children: ( ), subtitle: '10.0.0.5', avatarProps: { icon: { src: `${ASSETS_URL}/icons2/icon_security.svg` } } }} /> ), flex: 'auto', minWidth: 224, maxWidth: 398 }, { field: 'groups', children: ( ), width: 168 }, { field: 'devices', children: ( ), width: 192 }, { field: 'toggle', children: ( } label={} labelPlacement="start" sx={{ justifyContent: 'space-between', marginLeft: 0, width: '100%', '& .MuiFormControlLabel-label': { color: 'inherit' } }} /> ), flex: 'auto' }, { field: 'actionButtons', children: ( ), align: 'end', hideDivider: true, marginLeft: 'auto', minWidth: 120, width: 120 } ], indicatorColor: '#4DC9F6', onCellClick: cellClickHandler, onClick: cardClickHandler }; export const Gateways = Template.bind({}); Gateways.args = { columns: [ { field: 'gatewayName', children: ( ), flex: 'auto', minWidth: 180 }, { field: 'actionButtons', children: ( ), align: 'end', hideDivider: true, marginLeft: 'auto', minWidth: 44, width: 44 } ], onCellClick: cellClickHandler, onClick: cardClickHandler };