Skip to content

Commit 8695829

Browse files
committed
Remove sortable example
1 parent 88ffc0d commit 8695829

File tree

1 file changed

+0
-121
lines changed

1 file changed

+0
-121
lines changed

packages/react/src/ActionList/ActionList.examples.stories.tsx

-121
Original file line numberDiff line numberDiff line change
@@ -251,127 +251,6 @@ export function AsyncListWithSpinner(): JSX.Element {
251251
)
252252
}
253253

254-
type Option = {text: string; icon: React.ReactNode; selected: boolean}
255-
export function MemexSortable(): JSX.Element {
256-
const [options, setOptions] = React.useState<Option[]>([
257-
{text: 'Status', icon: <IssueOpenedIcon />, selected: true},
258-
{text: 'Stage', icon: <TableIcon />, selected: true},
259-
{text: 'Assignee', icon: <PeopleIcon />, selected: true},
260-
{text: 'Team', icon: <TypographyIcon />, selected: true},
261-
{text: 'Estimate', icon: <NumberIcon />, selected: false},
262-
{text: 'Due Date', icon: <CalendarIcon />, selected: false},
263-
])
264-
265-
const toggle = (text: string) => {
266-
setOptions(
267-
options.map(option => {
268-
if (option.text === text) option.selected = !option.selected
269-
return option
270-
}),
271-
)
272-
}
273-
274-
const reorder = ({optionToMove, moveAfterOption}: {optionToMove: Option; moveAfterOption: Option}) => {
275-
setOptions(currentOptions => {
276-
const newOptions = [...currentOptions]
277-
// remove option to move
278-
const currentPosition = newOptions.findIndex(o => o.text === optionToMove.text)
279-
newOptions.splice(currentPosition, 1)
280-
// add it after the provided element
281-
const newPosition = newOptions.findIndex(o => o.text === moveAfterOption.text) + 1
282-
newOptions.splice(newPosition, 0, optionToMove)
283-
return newOptions
284-
})
285-
}
286-
287-
const visibleOptions = options.filter(option => option.selected)
288-
const hiddenOptions = options.filter(option => !option.selected)
289-
290-
return (
291-
// @ts-ignore react-dnd needs to be updated to support React 18
292-
<DndProvider backend={HTML5Backend}>
293-
<ActionList selectionVariant="multiple" role="menu">
294-
<ActionList.Group>
295-
<ActionList.GroupHeading>Visible fields (can be reordered)</ActionList.GroupHeading>
296-
{visibleOptions.map(option => (
297-
<SortableItem
298-
key={option.text}
299-
role="menuitemcheckbox"
300-
option={option}
301-
onSelect={() => toggle(option.text)}
302-
reorder={reorder}
303-
/>
304-
))}
305-
</ActionList.Group>
306-
<ActionList.Group
307-
selectionVariant={
308-
/** selectionVariant override on Group: disable selection if there are no options */
309-
hiddenOptions.length ? 'multiple' : false
310-
}
311-
>
312-
<ActionList.GroupHeading>Hidden fields</ActionList.GroupHeading>
313-
{hiddenOptions.map((option, index) => (
314-
<ActionList.Item
315-
key={index}
316-
role="menuitemcheckbox"
317-
selected={option.selected}
318-
onSelect={() => toggle(option.text)}
319-
>
320-
<ActionList.LeadingVisual>{option.icon}</ActionList.LeadingVisual>
321-
{option.text}
322-
</ActionList.Item>
323-
))}
324-
{hiddenOptions.length === 0 && <ActionList.Item disabled>No hidden fields</ActionList.Item>}
325-
</ActionList.Group>
326-
</ActionList>
327-
</DndProvider>
328-
)
329-
}
330-
MemexSortable.storyName = 'Memex Sortable List'
331-
332-
type SortableItemProps = {
333-
option: Option
334-
role: ActionListItemProps['role']
335-
onSelect: ActionListItemProps['onSelect']
336-
reorder: ({optionToMove, moveAfterOption}: {optionToMove: Option; moveAfterOption: Option}) => void
337-
}
338-
const SortableItem: React.FC<React.PropsWithChildren<SortableItemProps>> = ({option, role, onSelect, reorder}) => {
339-
const [{isDragging}, dragRef] = useDrag(() => ({
340-
type: 'ITEM',
341-
item: option,
342-
collect: monitor => {
343-
return {isDragging: monitor.isDragging()}
344-
},
345-
}))
346-
347-
const [{isOver}, dropRef] = useDrop(() => ({
348-
accept: 'ITEM',
349-
collect: monitor => {
350-
return {isOver: monitor.isOver()}
351-
},
352-
drop: (optionDropped: Option) => {
353-
reorder({optionToMove: optionDropped, moveAfterOption: option})
354-
},
355-
}))
356-
357-
return (
358-
<ActionList.Item
359-
role={role}
360-
ref={element => dragRef(element) && dropRef(element)} // merge refs
361-
selected={option.selected}
362-
onSelect={onSelect}
363-
sx={{
364-
opacity: isDragging ? 0.5 : 1,
365-
boxShadow: isOver ? theme => `0px 2px 0 0px ${theme.colors.accent.emphasis}` : undefined,
366-
borderRadius: isOver ? 0 : 2,
367-
}}
368-
>
369-
<ActionList.LeadingVisual>{option.icon}</ActionList.LeadingVisual>
370-
{option.text}
371-
</ActionList.Item>
372-
)
373-
}
374-
375254
export function AllCombinations(): JSX.Element {
376255
return (
377256
<>

0 commit comments

Comments
 (0)