From 86958296ff8f195084d5384c2bb30ebe2107ad5f Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:59:55 -0500 Subject: [PATCH] Remove sortable example --- .../ActionList.examples.stories.tsx | 121 ------------------ 1 file changed, 121 deletions(-) diff --git a/packages/react/src/ActionList/ActionList.examples.stories.tsx b/packages/react/src/ActionList/ActionList.examples.stories.tsx index 8b7da25fe97..61c0e5cf383 100644 --- a/packages/react/src/ActionList/ActionList.examples.stories.tsx +++ b/packages/react/src/ActionList/ActionList.examples.stories.tsx @@ -251,127 +251,6 @@ export function AsyncListWithSpinner(): JSX.Element { ) } -type Option = {text: string; icon: React.ReactNode; selected: boolean} -export function MemexSortable(): JSX.Element { - const [options, setOptions] = React.useState([ - {text: 'Status', icon: , selected: true}, - {text: 'Stage', icon: , selected: true}, - {text: 'Assignee', icon: , selected: true}, - {text: 'Team', icon: , selected: true}, - {text: 'Estimate', icon: , selected: false}, - {text: 'Due Date', icon: , selected: false}, - ]) - - const toggle = (text: string) => { - setOptions( - options.map(option => { - if (option.text === text) option.selected = !option.selected - return option - }), - ) - } - - const reorder = ({optionToMove, moveAfterOption}: {optionToMove: Option; moveAfterOption: Option}) => { - setOptions(currentOptions => { - const newOptions = [...currentOptions] - // remove option to move - const currentPosition = newOptions.findIndex(o => o.text === optionToMove.text) - newOptions.splice(currentPosition, 1) - // add it after the provided element - const newPosition = newOptions.findIndex(o => o.text === moveAfterOption.text) + 1 - newOptions.splice(newPosition, 0, optionToMove) - return newOptions - }) - } - - const visibleOptions = options.filter(option => option.selected) - const hiddenOptions = options.filter(option => !option.selected) - - return ( - // @ts-ignore react-dnd needs to be updated to support React 18 - - - - Visible fields (can be reordered) - {visibleOptions.map(option => ( - toggle(option.text)} - reorder={reorder} - /> - ))} - - - Hidden fields - {hiddenOptions.map((option, index) => ( - toggle(option.text)} - > - {option.icon} - {option.text} - - ))} - {hiddenOptions.length === 0 && No hidden fields} - - - - ) -} -MemexSortable.storyName = 'Memex Sortable List' - -type SortableItemProps = { - option: Option - role: ActionListItemProps['role'] - onSelect: ActionListItemProps['onSelect'] - reorder: ({optionToMove, moveAfterOption}: {optionToMove: Option; moveAfterOption: Option}) => void -} -const SortableItem: React.FC> = ({option, role, onSelect, reorder}) => { - const [{isDragging}, dragRef] = useDrag(() => ({ - type: 'ITEM', - item: option, - collect: monitor => { - return {isDragging: monitor.isDragging()} - }, - })) - - const [{isOver}, dropRef] = useDrop(() => ({ - accept: 'ITEM', - collect: monitor => { - return {isOver: monitor.isOver()} - }, - drop: (optionDropped: Option) => { - reorder({optionToMove: optionDropped, moveAfterOption: option}) - }, - })) - - return ( - dragRef(element) && dropRef(element)} // merge refs - selected={option.selected} - onSelect={onSelect} - sx={{ - opacity: isDragging ? 0.5 : 1, - boxShadow: isOver ? theme => `0px 2px 0 0px ${theme.colors.accent.emphasis}` : undefined, - borderRadius: isOver ? 0 : 2, - }} - > - {option.icon} - {option.text} - - ) -} - export function AllCombinations(): JSX.Element { return ( <>