Skip to content

Commit bfba282

Browse files
author
Luke Bowerman
authored
Tree dividers support (#1599)
`Tree` now supports `dividers` to produce a small visual space between each `TreeItem` displayed in the list so that adjacent items in a "selected" or active state have visual separation.
1 parent 937c960 commit bfba282

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- `Tree` now supports `dividers` to produce a small visual space between each `TreeItem` displayed in the list so that adjacent items in a "selected" or active state have visual separation.
1213
- `Tooltip` and `useTooltip` now include a brief delay before showing
1314
- `delay` prop controls the length
1415
- `IconButton` supports `toggle` prop (uses `key` color when toggled and `aria-pressed`)
75 Bytes
Loading

packages/components/src/Tree/Tree.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ export interface TreeProps extends AccordionProps {
8282
* Prevent text wrapping on long labels and instead render truncated text
8383
**/
8484
truncate?: boolean
85+
/**
86+
* Produce a small visual space between each `TreeItem` displayed in the list so adjacent
87+
* items that are in a "selected" or active state have visual separation.
88+
* @default false
89+
*/
90+
dividers?: boolean
8591
}
8692

8793
const indicatorProps: AccordionIndicatorProps = {
@@ -104,6 +110,7 @@ const TreeLayout: FC<TreeProps> = ({
104110
className,
105111
visuallyAsBranch,
106112
truncate,
113+
dividers,
107114
...restProps
108115
}) => {
109116
const disclosureRef = useRef<HTMLDivElement>(null)
@@ -158,6 +165,7 @@ const TreeLayout: FC<TreeProps> = ({
158165
depth={depth}
159166
hovered={isHovered}
160167
visuallyAsBranch={visuallyAsBranch}
168+
dividers={dividers}
161169
>
162170
{innerAccordion}
163171
</TreeStyle>
@@ -208,8 +216,15 @@ interface TreeStyleProps {
208216
depth: number
209217
hovered: boolean
210218
visuallyAsBranch?: boolean
219+
dividers?: boolean
211220
}
212221

222+
export const dividersCSS = css`
223+
${TreeItem} {
224+
margin-top: 1px;
225+
}
226+
`
227+
213228
export const TreeStyle = styled.div<TreeStyleProps>`
214229
color: ${({ theme }) => theme.colors.text4};
215230
flex-shrink: 2;
@@ -230,6 +245,8 @@ export const TreeStyle = styled.div<TreeStyleProps>`
230245
}
231246
}
232247
248+
${({ dividers }) => dividers && dividersCSS}
249+
233250
${TreeItemInner} {
234251
border-width: 0;
235252
height: 100%;

packages/components/src/Tree/stories/BorderRadius.story.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { AccordionDisclosureStyle } from '../..'
3030
import { TreeItem, Tree, TreeItemLabel } from '..'
3131

3232
export const BorderRadiusOverride = () => (
33-
<BorderRadiusOverrideTree label="Created" defaultOpen>
33+
<BorderRadiusOverrideTree label="Created" defaultOpen dividers>
3434
<TreeItem>Created Date</TreeItem>
3535
<TreeItem>Created Month</TreeItem>
3636
<TreeItem>Created Year</TreeItem>

0 commit comments

Comments
 (0)