-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TreeView: Add support for leading and trailing visuals #2383
Changes from 9 commits
03c21cc
ef86924
48fb1af
0f30a19
9b8c2f2
76e180e
39201ca
8c300c3
039c29a
f48c098
9057ae4
1447bf5
3cfb814
6f4e25b
4787ccb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@primer/react": patch | ||
--- | ||
|
||
TreeView: Add support for leading and trailing visuals |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,63 +10,98 @@ description: A hierarchical list of items where nested items can be expanded and | |
### File tree navigation without directory links | ||
|
||
```jsx live drafts | ||
<nav aria-label="File navigation"> | ||
<TreeView aria-label="File navigation"> | ||
<TreeView.Item> | ||
src | ||
<TreeView.SubTree> | ||
<TreeView.LinkItem href="#">Avatar.tsx</TreeView.LinkItem> | ||
<TreeView.Item> | ||
Button | ||
<TreeView.SubTree> | ||
<TreeView.LinkItem href="#" current> | ||
Button.tsx | ||
</TreeView.LinkItem> | ||
<TreeView.LinkItem href="#">Button.test.tsx</TreeView.LinkItem> | ||
</TreeView.SubTree> | ||
</TreeView.Item> | ||
</TreeView.SubTree> | ||
</TreeView.Item> | ||
<TreeView.Item> | ||
public | ||
<TreeView.SubTree> | ||
<TreeView.LinkItem href="#">index.html</TreeView.LinkItem> | ||
<TreeView.LinkItem href="#">favicon.ico</TreeView.LinkItem> | ||
</TreeView.SubTree> | ||
</TreeView.Item> | ||
<TreeView.LinkItem href="#">package.json</TreeView.LinkItem> | ||
</TreeView> | ||
</nav> | ||
<Box sx={{maxWidth: 320}}> | ||
<nav aria-label="File navigation"> | ||
<TreeView aria-label="File navigation"> | ||
<TreeView.Item> | ||
<TreeView.LeadingVisual> | ||
<TreeView.DirectoryIcon /> | ||
</TreeView.LeadingVisual> | ||
src | ||
<TreeView.SubTree> | ||
<TreeView.LinkItem href="#"> | ||
<TreeView.LeadingVisual> | ||
<FileIcon /> | ||
</TreeView.LeadingVisual> | ||
Avatar.tsx | ||
<TreeView.TrailingVisual> | ||
<StyledOcticon icon={DiffAddedIcon} color="success.fg" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since these trailing visuals are used to visually communicate diff status, I'm pretty sure they should have an cc @ericwbailey There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. How should the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, the aria-label would be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the docs and stories to include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry to get to this after merging. I try to avoid using In addition to the mixed support concern, we're also going to be using the text string to construct |
||
</TreeView.TrailingVisual> | ||
</TreeView.LinkItem> | ||
<TreeView.LinkItem href="#" current> | ||
<TreeView.LeadingVisual> | ||
<FileIcon /> | ||
</TreeView.LeadingVisual> | ||
Button.tsx | ||
<TreeView.TrailingVisual> | ||
<StyledOcticon icon={DiffModifiedIcon} color="attention.fg" /> | ||
</TreeView.TrailingVisual> | ||
</TreeView.LinkItem> | ||
</TreeView.SubTree> | ||
</TreeView.Item> | ||
<TreeView.LinkItem href="#"> | ||
<TreeView.LeadingVisual> | ||
<FileIcon /> | ||
</TreeView.LeadingVisual> | ||
package.json | ||
<TreeView.TrailingVisual> | ||
<StyledOcticon icon={DiffModifiedIcon} color="attention.fg" /> | ||
</TreeView.TrailingVisual> | ||
</TreeView.LinkItem> | ||
</TreeView> | ||
</nav> | ||
</Box> | ||
``` | ||
|
||
### File tree navigation with directory links | ||
|
||
```jsx live drafts | ||
<nav aria-label="File navigation"> | ||
<TreeView aria-label="File navigation"> | ||
<TreeView.LinkItem href="#"> | ||
src | ||
<TreeView.SubTree> | ||
<TreeView.LinkItem href="#">Avatar.tsx</TreeView.LinkItem> | ||
<TreeView.LinkItem href="#" current> | ||
Button | ||
<TreeView.SubTree> | ||
<TreeView.LinkItem href="#">Button.tsx</TreeView.LinkItem> | ||
<TreeView.LinkItem href="#">Button.test.tsx</TreeView.LinkItem> | ||
</TreeView.SubTree> | ||
</TreeView.LinkItem> | ||
</TreeView.SubTree> | ||
</TreeView.LinkItem> | ||
<TreeView.LinkItem href="#"> | ||
public | ||
<TreeView.SubTree> | ||
<TreeView.LinkItem href="#">index.html</TreeView.LinkItem> | ||
<TreeView.LinkItem href="#">favicon.ico</TreeView.LinkItem> | ||
</TreeView.SubTree> | ||
</TreeView.LinkItem> | ||
<TreeView.LinkItem href="#">package.json</TreeView.LinkItem> | ||
</TreeView> | ||
</nav> | ||
<Box sx={{maxWidth: 320}}> | ||
<nav aria-label="File navigation"> | ||
<TreeView aria-label="File navigation"> | ||
<TreeView.LinkItem href="#"> | ||
<TreeView.LeadingVisual> | ||
<TreeView.DirectoryIcon /> | ||
</TreeView.LeadingVisual> | ||
src | ||
<TreeView.SubTree> | ||
<TreeView.LinkItem href="#"> | ||
<TreeView.LeadingVisual> | ||
<FileIcon /> | ||
</TreeView.LeadingVisual> | ||
Avatar.tsx | ||
</TreeView.LinkItem> | ||
<TreeView.LinkItem href="#" current> | ||
<TreeView.LeadingVisual> | ||
<TreeView.DirectoryIcon /> | ||
</TreeView.LeadingVisual> | ||
Button | ||
<TreeView.SubTree> | ||
<TreeView.LinkItem href="#"> | ||
<TreeView.LeadingVisual> | ||
<FileIcon /> | ||
</TreeView.LeadingVisual> | ||
Button.tsx | ||
</TreeView.LinkItem> | ||
<TreeView.LinkItem href="#"> | ||
<TreeView.LeadingVisual> | ||
<FileIcon /> | ||
</TreeView.LeadingVisual> | ||
Button.test.tsx | ||
</TreeView.LinkItem> | ||
</TreeView.SubTree> | ||
</TreeView.LinkItem> | ||
</TreeView.SubTree> | ||
</TreeView.LinkItem> | ||
<TreeView.LinkItem href="#"> | ||
<TreeView.LeadingVisual> | ||
<FileIcon /> | ||
</TreeView.LeadingVisual> | ||
package.json | ||
</TreeView.LinkItem> | ||
</TreeView> | ||
</nav> | ||
</Box> | ||
``` | ||
|
||
### With controlled expanded state | ||
|
@@ -76,7 +111,7 @@ function ControlledTreeView() { | |
const [expanded, setExpanded] = React.useState(false) | ||
|
||
return ( | ||
<Box sx={{display: 'grid', gap: 2}}> | ||
<Box sx={{display: 'grid', gap: 2, maxWidth: 320}}> | ||
<Button onClick={() => setExpanded(!expanded)}>{expanded ? 'Collapse' : 'Expand'}</Button> | ||
<nav aria-label="File navigation"> | ||
<TreeView aria-label="File navigation"> | ||
|
@@ -190,17 +225,15 @@ render(<ControlledTreeView />) | |
{/* <PropsTableSxRow /> */} | ||
</PropsTable> | ||
|
||
<!-- TODO: Add leading and trailing visuals --> | ||
|
||
<!-- ### TreeView.LeadingVisual | ||
### TreeView.LeadingVisual | ||
|
||
<PropsTable> | ||
<PropsTableRow | ||
name="children" | ||
type={`| React.ReactNode | ||
| (props: {isExpanded: boolean}) => React.ReactNode`} | ||
/> | ||
<PropsTableSxRow /> | ||
{/* <PropsTableSxRow /> */} | ||
</PropsTable> | ||
|
||
### TreeView.TrailingVisual | ||
|
@@ -211,14 +244,12 @@ render(<ControlledTreeView />) | |
type={`| React.ReactNode | ||
| (props: {isExpanded: boolean}) => React.ReactNode`} | ||
/> | ||
<PropsTableSxRow /> | ||
{/* <PropsTableSxRow /> */} | ||
</PropsTable> | ||
|
||
### TreeView.FolderIcon | ||
### TreeView.DirectoryIcon | ||
|
||
<PropsTable> | ||
<PropsTableSxRow /> | ||
</PropsTable> --> | ||
<PropsTable>{/* <PropsTableSxRow /> */}</PropsTable> | ||
|
||
<!-- TODO: Add components to support async behavior (e.g. LoadingItem) --> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we get an example (and maybe a story?) showing how to use the
isExpanded
render prop to set different icons for expanded and collapsed states.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea 👍 Let me know if the docs I added make sense