Skip to content

Commit 8d53fa2

Browse files
Luke BowermanElliot Park
andauthored
Tree noIndent allows for nested Tree to align with adjacent TreeItems (#1600)
- Tree `branchAlign` allows for nested Tree to align with adjacent TreeItems - Renamed `visuallyAsBranch` to `branchFontWeight` to ensure consistency Co-authored-by: Elliot Park <[email protected]>
1 parent 5e661eb commit 8d53fa2

File tree

6 files changed

+31
-20
lines changed

6 files changed

+31
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- `IconButton` supports `toggle` prop (uses `key` color when toggled and `aria-pressed`)
1616
- Improved test coverage / added image-snapshots
1717
- `ScheduleOutline` Icon artwork
18+
- `Tree` `noIndent` prop allows `Tree` to be indented at the same depth as adjacent `TreeItem`(s)
1819

1920
### Changed
2021

-539 Bytes
Loading

packages/components/src/Tree/Tree.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ export interface TreeProps extends AccordionProps {
7777
* If true, the internal AccordionDisclosure will have fontWeight = 'Normal'
7878
* @default false
7979
*/
80-
visuallyAsBranch?: boolean
80+
branchFontWeight?: boolean
81+
/**
82+
* Tree will be indented at the same depth as adjacent `TreeItem`(s)
83+
* @default false
84+
*/
85+
branchAlign?: boolean
8186
/**
8287
* Prevent text wrapping on long labels and instead render truncated text
8388
**/
@@ -108,7 +113,8 @@ const TreeLayout: FC<TreeProps> = ({
108113
icon,
109114
label,
110115
className,
111-
visuallyAsBranch,
116+
branchAlign,
117+
branchFontWeight,
112118
truncate,
113119
dividers,
114120
...restProps
@@ -164,8 +170,9 @@ const TreeLayout: FC<TreeProps> = ({
164170
border={hasBorder}
165171
depth={depth}
166172
hovered={isHovered}
167-
visuallyAsBranch={visuallyAsBranch}
168173
dividers={dividers}
174+
branchAlign={branchAlign}
175+
branchFontWeight={branchFontWeight}
169176
>
170177
{innerAccordion}
171178
</TreeStyle>
@@ -215,7 +222,8 @@ interface TreeStyleProps {
215222
border?: boolean
216223
depth: number
217224
hovered: boolean
218-
visuallyAsBranch?: boolean
225+
branchAlign?: boolean
226+
branchFontWeight?: boolean
219227
dividers?: boolean
220228
}
221229

@@ -239,9 +247,10 @@ export const TreeStyle = styled.div<TreeStyleProps>`
239247
& > ${AccordionDisclosureStyle} {
240248
background-clip: padding-box;
241249
background-color: ${({ hovered }) => hovered && uiTransparencyBlend(2)};
242-
font-weight: ${({ visuallyAsBranch, theme: { fontWeights } }) =>
243-
visuallyAsBranch ? fontWeights.normal : fontWeights.semiBold};
244-
${({ depth, theme }) => generateIndent(depth, theme)}
250+
font-weight: ${({ branchFontWeight, theme: { fontWeights } }) =>
251+
branchFontWeight ? fontWeights.normal : fontWeights.semiBold};
252+
${({ depth, branchAlign, theme }) =>
253+
generateIndent(branchAlign ? depth - 1 : depth, theme)}
245254
}
246255
}
247256

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ const PickerItem = ({ children = 'Cost', truncate = false }) => {
116116
onClick={() => alert('Clicked on cost!')}
117117
onMetaEnter={() => alert("Cmd + Enter'ed on cost!")}
118118
selected={!!overlay}
119-
icon="FieldNumber"
120119
>
121120
<Space between>
122121
<TextWrapper>{children}</TextWrapper>
@@ -165,10 +164,10 @@ export const FieldPicker = () => (
165164
</PickerItem>
166165
</TreeGroup>
167166
<TreeGroup label="MEASURES" color="orange">
168-
<Tree visuallyAsBranch label="Hello">
167+
<Tree branchAlign branchFontWeight label="Hello">
169168
<PickerItem />
170169
</Tree>
171-
<TreeItem icon="FieldString">Name</TreeItem>
170+
<TreeItem>Name</TreeItem>
172171
<PickerItem />
173172
<PickerItem />
174173
<PickerItem />

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,31 @@ import { TreeItem } from '../TreeItem'
3131

3232
const Template: Story<TreeProps> = (args) => (
3333
<Tree label="thelook" icon="ExploreOutline" {...args}>
34-
<Tree visuallyAsBranch label="Orders" icon="VisibilityOutline" defaultOpen>
35-
<Tree visuallyAsBranch label="Orders" icon="Table" defaultOpen>
34+
<Tree label="Orders" icon="VisibilityOutline" defaultOpen>
35+
<Tree label="Orders" icon="Table" defaultOpen>
3636
<TreeItem icon="IdeDimension">ID</TreeItem>
3737
<TreeItem icon="IdeDimension">Status</TreeItem>
3838
<TreeItem icon="IdeDimensionGroup">Created</TreeItem>
3939
</Tree>
40-
<Tree visuallyAsBranch label="Products" icon="Table" defaultOpen>
40+
<Tree label="Products" icon="Table" defaultOpen>
4141
<TreeItem icon="IdeDimension">Brand</TreeItem>
4242
<TreeItem icon="IdeDimension">ID</TreeItem>
4343
<TreeItem icon="IdeDimension">Department</TreeItem>
4444
<TreeItem icon="IdeDimension">Sku</TreeItem>
4545
</Tree>
46-
<Tree visuallyAsBranch label="Users" icon="Table" defaultOpen>
46+
<Tree label="Users" icon="Table" defaultOpen>
4747
<TreeItem icon="IdeDimension">ID</TreeItem>
4848
<TreeItem icon="IdeDimension">Name</TreeItem>
4949
<TreeItem icon="IdeDimensionGroup">Created</TreeItem>
5050
</Tree>
5151
</Tree>
52-
<Tree visuallyAsBranch label="Users" icon="VisibilityOutline" defaultOpen>
53-
<Tree visuallyAsBranch label="Orders" icon="Table" defaultOpen>
52+
<Tree label="Users" icon="VisibilityOutline" defaultOpen>
53+
<Tree label="Orders" icon="Table" defaultOpen>
5454
<TreeItem icon="IdeDimension">ID</TreeItem>
5555
<TreeItem icon="IdeDimension">Status</TreeItem>
5656
<TreeItem icon="IdeDimensionGroup">Created</TreeItem>
5757
</Tree>
58-
<Tree visuallyAsBranch label="Users" icon="Table" defaultOpen>
58+
<Tree label="Users" icon="Table" defaultOpen>
5959
<TreeItem icon="IdeDimension">ID</TreeItem>
6060
<TreeItem icon="IdeDimension">Name</TreeItem>
6161
<TreeItem icon="IdeDimensionGroup">Created</TreeItem>

www/src/documentation/components/content/tree.mdx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ Use `detail` to display an element in the negative space of the `Tree` label.
3939
</Tree>
4040
```
4141

42-
Use the `visuallyAsBranch` prop if you'd like your `Tree`'s disclosure text to have a "normal" font weight.
42+
Use the `branchFontWeight` prop if you'd like your `Tree`'s disclosure text to have a "normal" font weight.
4343

44-
This is especially useful when you want a nested `Tree` to match its sibling `TreeItem`s
44+
Use the `branchAlign` prop to prevent your nested `Tree` from being indented so its label is vertically aligned with adjacent `TreeItem`s.
45+
46+
These is especially useful when you want a nested `Tree` to match its sibling `TreeItem`s
4547

4648
```jsx
4749
<Tree label="Orders" icon="Table" defaultOpen>
48-
<Tree visuallyAsBranch label="Created" defaultOpen>
50+
<Tree branchAlign branchFontWeight label="Created" defaultOpen>
4951
<TreeItem>Created Date</TreeItem>
5052
<TreeItem>Created Month</TreeItem>
5153
<TreeItem>Created Year</TreeItem>

0 commit comments

Comments
 (0)