-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8a3069
commit 1f63a8b
Showing
3 changed files
with
78 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {GrabberIcon} from '@primer/octicons-react' | ||
import type {Meta, Story} from '@storybook/react' | ||
import React from 'react' | ||
import Box from '../Box' | ||
import {TreeView} from './TreeView' | ||
|
||
const meta: Meta = { | ||
title: 'Components/TreeView/Examples', | ||
component: TreeView, | ||
decorators: [ | ||
Story => { | ||
return ( | ||
// Prevent TreeView from expanding to the full width of the screen | ||
<Box sx={{maxWidth: 400}}> | ||
<Story /> | ||
</Box> | ||
) | ||
}, | ||
], | ||
} | ||
|
||
export const DraggableListItem: Story = () => { | ||
return ( | ||
<Box | ||
sx={{ | ||
// using Box for css, this could be in a css file as well | ||
'.treeview-item': { | ||
'.treeview-leading-action': {visibility: 'hidden'}, | ||
'&:hover, &:focus': { | ||
'.treeview-leading-action': {visibility: 'visible'}, | ||
}, | ||
}, | ||
}} | ||
> | ||
<TreeView aria-label="Issues"> | ||
<ControlledDraggableItem id="item-1">Item 1</ControlledDraggableItem> | ||
<ControlledDraggableItem id="item-2"> | ||
Item 2 | ||
<TreeView.SubTree> | ||
<TreeView.Item id="item-2-sub-task-1">sub task 1</TreeView.Item> | ||
<TreeView.Item id="item-2-sub-task-2">sub task 2</TreeView.Item> | ||
</TreeView.SubTree> | ||
</ControlledDraggableItem> | ||
<ControlledDraggableItem id="item-3">Item 3</ControlledDraggableItem> | ||
</TreeView> | ||
</Box> | ||
) | ||
} | ||
|
||
const ControlledDraggableItem: React.FC<{id: string; children: React.ReactNode}> = ({id, children}) => { | ||
const [expanded, setExpanded] = React.useState(false) | ||
|
||
return ( | ||
<> | ||
<TreeView.Item id={id} className="treeview-item" expanded={expanded} onExpandedChange={setExpanded}> | ||
<TreeView.LeadingAction | ||
icon={GrabberIcon} | ||
aria-label="Reorder item" | ||
className="treeview-leading-action" | ||
draggable="true" | ||
onDragStart={() => { | ||
setExpanded(false) | ||
// other drag logic to follow | ||
}} | ||
/> | ||
{children} | ||
</TreeView.Item> | ||
</> | ||
) | ||
} | ||
|
||
export default meta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters