-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
TreeView.LeadingAction
sub-component (#4546)
* add grid area for drag handle when data-drag-and-drop is true * add test to verify dnd attribute * css updates * add docs * test(vrt): update snapshots * Sid/treeview leading action (#4569) * wip: leading action slot * clean up a little * change from prop to subcomponent * remove outdated test * spacer should come before leadingAction * merge snapshots from main * merge package-lock from main * add visual tests * use IconButton for leadingAction * add example of drag handle on hover * Create tame-nails-live.md * test(vrt): update snapshots * change LeadingActio type to React.FC<TreeViewVisualProps> and accept children * change LeadingAction of type React.FC<TreeViewVisualProps> * typo * add `variant="invisible"` to icon button in stories * add leadingActionId and aria-hidden to LeadingAction subcomponent * remove `leadingActionId` to describe the tree view item * remove unused leadingActionId * remove docs from changeset --------- Co-authored-by: ayy-bc <[email protected]> Co-authored-by: Siddharth Kshetrapal <[email protected]> Co-authored-by: siddharthkp <[email protected]>
- Loading branch information
1 parent
5647054
commit c81898c
Showing
15 changed files
with
217 additions
and
4 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,5 @@ | ||
--- | ||
"@primer/react": minor | ||
--- | ||
|
||
TreeView: Add support for `TreeView.LeadingAction` |
Binary file added
BIN
+9.27 KB
...ts/TreeView.test.ts-snapshots/TreeView-Leading-Action-dark-colorblind-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.37 KB
...onents/TreeView.test.ts-snapshots/TreeView-Leading-Action-dark-dimmed-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.25 KB
...TreeView.test.ts-snapshots/TreeView-Leading-Action-dark-high-contrast-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.24 KB
...ts/components/TreeView.test.ts-snapshots/TreeView-Leading-Action-dark-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.25 KB
...ts/TreeView.test.ts-snapshots/TreeView-Leading-Action-dark-tritanopia-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.27 KB
...s/TreeView.test.ts-snapshots/TreeView-Leading-Action-light-colorblind-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.3 KB
...reeView.test.ts-snapshots/TreeView-Leading-Action-light-high-contrast-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.29 KB
...s/components/TreeView.test.ts-snapshots/TreeView-Leading-Action-light-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.25 KB
...s/TreeView.test.ts-snapshots/TreeView-Leading-Action-light-tritanopia-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,76 @@ | ||
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' | ||
import {IconButton} from '../Button' | ||
|
||
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> | ||
<IconButton | ||
icon={GrabberIcon} | ||
variant="invisible" | ||
aria-label="Reorder item" | ||
className="treeview-leading-action" | ||
draggable="true" | ||
onDragStart={() => { | ||
setExpanded(false) | ||
// other drag logic to follow | ||
}} | ||
/> | ||
</TreeView.LeadingAction> | ||
{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