import MoreVertIcon from '@mui/icons-material/MoreVert'; import { Grid, IconButton, Paper, Typography } from '@mui/material'; import { type DraggableSyntheticListeners, rectIntersection } from '@dnd-kit/core'; import { horizontalListSortingStrategy, rectSortingStrategy, type SortingStrategy, verticalListSortingStrategy } from '@dnd-kit/sortable'; import type { ComponentMeta, ComponentStory } from '@storybook/react'; import { not } from 'ramda'; import type { RefObject } from 'react'; import { makeStyles } from 'tss-react/mui'; import SortableItems, { type RootComponentProps } from '.'; export default { component: SortableItems, title: 'SortableItems' } as ComponentMeta; interface Entity { id: string; name: string; xs: number; } const items: Array = [ { id: 'label', name: 'This is a label content', xs: 6 }, { id: 'description', name: 'This is a description content', xs: 6 }, { id: 'custom', name: 'This is a custom content', xs: 12 }, { id: 'FQDN', name: 'This is a FQDN content', xs: 12 }, { id: 'music', name: 'This is a music content', xs: 3 }, { id: 'AWS', name: 'This is a AWS content', xs: 9 } ]; interface StylesProps { isDragging: boolean; } const useContentStyles = makeStyles()((theme, { isDragging }) => ({ content: { '&:hover': { boxShadow: theme.shadows[3] }, cursor: isDragging ? 'grabbing' : 'grab', padding: theme.spacing(1) }, contentWithHandler: { '&:hover': { boxShadow: theme.shadows[3] }, display: 'grid', gridTemplateColumns: 'min-content auto', padding: theme.spacing(1) }, handler: { cursor: isDragging ? 'grabbing' : 'grab' } })); interface ContentProps extends Entity { attributes; isDragging: boolean; itemRef: RefObject; listeners: DraggableSyntheticListeners; style; } const Content = ({ listeners, attributes, style, isDragging, itemRef, name }: ContentProps): JSX.Element => { const { classes } = useContentStyles({ isDragging }); return ( {name as string} ); }; const ContentWithHandler = ({ listeners, attributes, style, isDragging, itemRef, name }: ContentProps): JSX.Element => { const { classes } = useContentStyles({ isDragging }); return (
{name as string}
); }; const useStyles = makeStyles()((theme) => ({ gridContainer: { columnGap: theme.spacing(1), display: 'grid', grid: 'auto-flow / 1fr 1.2fr 1.1fr', height: '100%', rowGap: theme.spacing(1), width: '550px' }, horizontalContainer: { columnGap: theme.spacing(1), display: 'flex', flexDirection: 'row', height: '40px', width: '100%' }, verticalContainer: { display: 'flex', flexDirection: 'column', height: '100%', rowGap: theme.spacing(1), width: '550px' } })); interface StoryProps { direction: string; handler?: boolean; sortingStrategy: SortingStrategy; } const Story = ({ direction, sortingStrategy, handler = false }: StoryProps): JSX.Element => { const { classes } = useStyles(); return (
); }; const TemplateSortableItems: ComponentStory = (args) => ( ); export const PlaygroundSortableItems = TemplateSortableItems.bind({}); export const vertical = (): JSX.Element => ( ); export const horizontal = (): JSX.Element => ( ); export const grid = (): JSX.Element => ( ); const ContentWithGrid = ({ listeners, attributes, style, isDragging, itemRef, name, xs }: ContentProps): JSX.Element => { const { classes } = useContentStyles({ isDragging }); return ( {name as string} ); }; const RootComponent = ({ children, isInDragOverlay }: RootComponentProps): JSX.Element => ( {not(isInDragOverlay) && ( This item cannot move )} {children} ); const StoryWithRootComponent = (): JSX.Element => { const { classes } = useStyles(); return (
); }; export const gridWithRootComponent = (): JSX.Element => ( ); export const gridWithHandlers = (): JSX.Element => ( );