Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(TreeList): Visual polish (#1367)

Ernest126400af5253
diff --git a/apps/storybook/stories/TreeList.stories.tsx b/apps/storybook/stories/TreeList.stories.tsx
index 255136aac6..b984b7a1f6 100644
--- a/apps/storybook/stories/TreeList.stories.tsx
+++ b/apps/storybook/stories/TreeList.stories.tsx
@@ -10,6 +10,8 @@ import {
ChevronRightIcon,
} from '@heroicons/react/24/outline';
+const noop = () => {};
+
const meta: Meta<typeof XDSTreeList> = {
title: 'Core/XDSTreeList',
component: XDSTreeList,
@@ -36,25 +38,25 @@ const fileTreeItems: XDSTreeListItemData[] = [
id: 'components',
label: 'components',
children: [
- {id: 'button', label: 'Button.tsx'},
- {id: 'card', label: 'Card.tsx'},
- {id: 'list', label: 'List.tsx'},
+ {id: 'button', label: 'Button.tsx', onClick: noop},
+ {id: 'card', label: 'Card.tsx', onClick: noop},
+ {id: 'list', label: 'List.tsx', onClick: noop},
],
},
- {id: 'app', label: 'App.tsx'},
- {id: 'index', label: 'index.tsx'},
+ {id: 'app', label: 'App.tsx', onClick: noop},
+ {id: 'index', label: 'index.tsx', onClick: noop},
],
},
{
id: 'public',
label: 'public',
children: [
- {id: 'favicon', label: 'favicon.ico'},
- {id: 'index-html', label: 'index.html'},
+ {id: 'favicon', label: 'favicon.ico', onClick: noop},
+ {id: 'index-html', label: 'index.html', onClick: noop},
],
},
- {id: 'pkg', label: 'package.json'},
- {id: 'readme', label: 'README.md'},
+ {id: 'pkg', label: 'package.json', onClick: noop},
+ {id: 'readme', label: 'README.md', onClick: noop},
];
export const Basic: Story = {
@@ -76,13 +78,13 @@ export const FullyExpanded: Story = {
label: 'components',
isExpanded: true,
children: [
- {id: 'button', label: 'Button.tsx'},
- {id: 'card', label: 'Card.tsx'},
- {id: 'list', label: 'List.tsx'},
+ {id: 'button', label: 'Button.tsx', onClick: noop},
+ {id: 'card', label: 'Card.tsx', onClick: noop},
+ {id: 'list', label: 'List.tsx', onClick: noop},
],
},
- {id: 'app', label: 'App.tsx'},
- {id: 'index', label: 'index.tsx'},
+ {id: 'app', label: 'App.tsx', onClick: noop},
+ {id: 'index', label: 'index.tsx', onClick: noop},
],
},
{
@@ -90,12 +92,12 @@ export const FullyExpanded: Story = {
label: 'public',
isExpanded: true,
children: [
- {id: 'favicon', label: 'favicon.ico'},
- {id: 'index-html', label: 'index.html'},
+ {id: 'favicon', label: 'favicon.ico', onClick: noop},
+ {id: 'index-html', label: 'index.html', onClick: noop},
],
},
- {id: 'pkg', label: 'package.json'},
- {id: 'readme', label: 'README.md'},
+ {id: 'pkg', label: 'package.json', onClick: noop},
+ {id: 'readme', label: 'README.md', onClick: noop},
],
},
};
@@ -112,11 +114,13 @@ export const WithIcons: Story = {
{
id: 'app',
label: 'App.tsx',
+ onClick: noop,
startContent: <XDSIcon icon={DocumentIcon} />,
},
{
id: 'index',
label: 'index.tsx',
+ onClick: noop,
startContent: <XDSIcon icon={DocumentIcon} />,
},
],
@@ -124,6 +128,7 @@ export const WithIcons: Story = {
{
id: 'pkg',
label: 'package.json',
+ onClick: noop,
startContent: <XDSIcon icon={DocumentIcon} />,
},
],
@@ -150,25 +155,25 @@ export const Compact: Story = {
label: 'components',
isExpanded: true,
children: [
- {id: 'button', label: 'Button.tsx'},
- {id: 'card', label: 'Card.tsx'},
- {id: 'list', label: 'List.tsx'},
+ {id: 'button', label: 'Button.tsx', onClick: noop},
+ {id: 'card', label: 'Card.tsx', onClick: noop},
+ {id: 'list', label: 'List.tsx', onClick: noop},
],
},
- {id: 'app', label: 'App.tsx'},
- {id: 'index', label: 'index.tsx'},
+ {id: 'app', label: 'App.tsx', onClick: noop},
+ {id: 'index', label: 'index.tsx', onClick: noop},
],
},
{
id: 'public',
label: 'public',
children: [
- {id: 'favicon', label: 'favicon.ico'},
- {id: 'index-html', label: 'index.html'},
+ {id: 'favicon', label: 'favicon.ico', onClick: noop},
+ {id: 'index-html', label: 'index.html', onClick: noop},
],
},
- {id: 'pkg', label: 'package.json'},
- {id: 'readme', label: 'README.md'},
+ {id: 'pkg', label: 'package.json', onClick: noop},
+ {id: 'readme', label: 'README.md', onClick: noop},
],
density: 'compact',
},
@@ -194,25 +199,25 @@ export const TopAligned: Story = {
label: 'components',
isExpanded: true,
children: [
- {id: 'button', label: 'Button.tsx'},
- {id: 'card', label: 'Card.tsx'},
- {id: 'list', label: 'List.tsx'},
+ {id: 'button', label: 'Button.tsx', onClick: noop},
+ {id: 'card', label: 'Card.tsx', onClick: noop},
+ {id: 'list', label: 'List.tsx', onClick: noop},
],
},
- {id: 'app', label: 'App.tsx'},
- {id: 'index', label: 'index.tsx'},
+ {id: 'app', label: 'App.tsx', onClick: noop},
+ {id: 'index', label: 'index.tsx', onClick: noop},
],
},
{
id: 'public',
label: 'public',
children: [
- {id: 'favicon', label: 'favicon.ico'},
- {id: 'index-html', label: 'index.html'},
+ {id: 'favicon', label: 'favicon.ico', onClick: noop},
+ {id: 'index-html', label: 'index.html', onClick: noop},
],
},
- {id: 'pkg', label: 'package.json'},
- {id: 'readme', label: 'README.md'},
+ {id: 'pkg', label: 'package.json', onClick: noop},
+ {id: 'readme', label: 'README.md', onClick: noop},
],
},
};
@@ -225,6 +230,7 @@ export const Interactive: Story = {
label: 'Settings',
isExpanded: true,
startContent: <XDSIcon icon={Cog6ToothIcon} />,
+ onClick: () => alert('Settings'),
children: [
{
id: 'general',
@@ -257,12 +263,12 @@ export const WithEndContent: Story = {
isExpanded: true,
endContent: <XDSBadge label="3" />,
children: [
- {id: 'unread', label: 'Unread', endContent: <XDSBadge label="3" />},
- {id: 'starred', label: 'Starred'},
+ {id: 'unread', label: 'Unread', onClick: noop, endContent: <XDSBadge label="3" />},
+ {id: 'starred', label: 'Starred', onClick: noop},
],
},
- {id: 'sent', label: 'Sent'},
- {id: 'drafts', label: 'Drafts', endContent: <XDSBadge label="1" />},
+ {id: 'sent', label: 'Sent', onClick: noop},
+ {id: 'drafts', label: 'Drafts', onClick: noop, endContent: <XDSBadge label="1" />},
],
},
};
@@ -275,16 +281,16 @@ export const DisabledItems: Story = {
label: 'Active Section',
isExpanded: true,
children: [
- {id: 'item1', label: 'Available Item', onClick: () => {}},
+ {id: 'item1', label: 'Available Item', onClick: noop},
{
id: 'item2',
label: 'Disabled Item',
- onClick: () => {},
+ onClick: noop,
isDisabled: true,
},
],
},
- {id: 'disabled-parent', label: 'Disabled Parent', isDisabled: true},
+ {id: 'disabled-parent', label: 'Disabled Parent', onClick: noop, isDisabled: true},
],
},
};
@@ -297,9 +303,9 @@ export const SelectedItems: Story = {
label: 'Navigation',
isExpanded: true,
children: [
- {id: 'home', label: 'Home', onClick: () => {}},
- {id: 'about', label: 'About', onClick: () => {}, isSelected: true},
- {id: 'contact', label: 'Contact', onClick: () => {}},
+ {id: 'home', label: 'Home', onClick: noop},
+ {id: 'about', label: 'About', onClick: noop, isSelected: true},
+ {id: 'contact', label: 'Contact', onClick: noop},
],
},
],
diff --git a/packages/core/src/TreeList/XDSTreeListBranches.tsx b/packages/core/src/TreeList/XDSTreeListBranches.tsx
index 5b89d701e5..a6de333c3c 100644
--- a/packages/core/src/TreeList/XDSTreeListBranches.tsx
+++ b/packages/core/src/TreeList/XDSTreeListBranches.tsx
@@ -13,7 +13,7 @@
import * as stylex from '@stylexjs/stylex';
import {colorVars, spacingVars} from '../theme/tokens.stylex';
-const LINE_WIDTH = 2;
+const LINE_WIDTH = 1;
/**
* Branch margin from the left edge. No exact spacing token for 10px,
@@ -21,8 +21,8 @@ const LINE_WIDTH = 2;
*/
const BRANCH_MARGIN = `calc(${spacingVars['--spacing-2']} + ${spacingVars['--spacing-0-5']})`;
-/** Per-level indent width, matching --spacing-5 (20px). */
-const LEVEL_INDENT = spacingVars['--spacing-5'];
+/** Per-level indent width, matching --spacing-4 (16px). */
+const LEVEL_INDENT = spacingVars['--spacing-4'];
const styles = stylex.create({
container: {
@@ -42,32 +42,8 @@ const styles = stylex.create({
verticalFull: {
height: 'calc(100% + 1px)',
},
- verticalToHalf: {
- height: '50%',
- },
- verticalToHalfWithTerminus: {
- height: '50%',
- borderBottomRightRadius: LINE_WIDTH * 2,
- },
- connectorContainer: {
- position: 'absolute',
- width: spacingVars['--spacing-5'],
- height: '100%',
- top: 0,
- },
- horizontalLine: {
- borderRadius: 1,
- height: LINE_WIDTH,
- left: '50%',
- position: 'absolute',
- top: '50%',
- transform: 'translateY(-50%)',
- width: '50%',
- backgroundColor: colorVars['--color-border-emphasized'],
- },
- horizontalLineFull: {
- width: '100%',
- },
+
+
});
// =============================================================================
@@ -80,11 +56,6 @@ interface XDSTreeListBranchesProps {
nestedLevel: number;
}
-interface XDSTreeListHorizontalConnectorProps {
- hasChildren: boolean;
- nestedLevel: number;
-}
-
// =============================================================================
// Components
// =============================================================================
@@ -128,7 +99,7 @@ export function XDSTreeListBranches({
<div
{...stylex.props(
styles.verticalLine,
- isLast ? styles.verticalToHalfWithTerminus : styles.verticalFull,
+ styles.verticalFull,
)}
/>
</div>
@@ -137,29 +108,3 @@ export function XDSTreeListBranches({
);
}
-/**
- * Renders the horizontal connector line from a parent branch to a child item.
- * Must be rendered inside a container whose height matches the content row,
- * so that top: 50% centers on the label, not the full item including children.
- */
-export function XDSTreeListHorizontalConnector({
- hasChildren,
- nestedLevel,
-}: XDSTreeListHorizontalConnectorProps) {
- if (nestedLevel <= 0) return null;
-
- return (
- <div
- {...stylex.props(styles.connectorContainer)}
- style={{
- left: `calc(${BRANCH_MARGIN} + ${nestedLevel - 1} * ${LEVEL_INDENT})`,
- }}>
- <div
- {...stylex.props(
- styles.horizontalLine,
- !hasChildren && styles.horizontalLineFull,
- )}
- />
- </div>
- );
-}
diff --git a/packages/core/src/TreeList/XDSTreeListItem.tsx b/packages/core/src/TreeList/XDSTreeListItem.tsx
index 1ed92f59f9..67a59d242f 100644
--- a/packages/core/src/TreeList/XDSTreeListItem.tsx
+++ b/packages/core/src/TreeList/XDSTreeListItem.tsx
@@ -23,10 +23,7 @@ import {
} from '../theme/tokens.stylex';
import {getIcon} from '../Icon/globalIconRegistry';
import {xdsClassName, mergeProps} from '../utils';
-import {
- XDSTreeListBranches,
- XDSTreeListHorizontalConnector,
-} from './XDSTreeListBranches';
+import {XDSTreeListBranches} from './XDSTreeListBranches';
import type {XDSTreeListDensity} from './XDSTreeListTypes';
// =============================================================================
@@ -47,7 +44,7 @@ const styles = stylex.create({
listStyleType: 'none',
},
treeBranches: {
- paddingInlineStart: `calc(${spacingVars['--spacing-2']} + ${spacingVars['--spacing-0-5']})`,
+ paddingInlineStart: spacingVars['--spacing-2'],
},
rowWrapper: {
position: 'relative',
@@ -200,7 +197,6 @@ const densityStyles = stylex.create({
},
spacious: {
paddingBlock: spacingVars['--spacing-3'],
- paddingInline: spacingVars['--spacing-3'],
fontSize: typeScaleVars['--text-body-size'],
lineHeight: typeScaleVars['--text-body-leading'],
},
@@ -303,8 +299,8 @@ export function XDSTreeListItem({
}, [onClick, hasChildren, onToggle, id, isDisabled]);
const computedMarginLeft = hasChildren
- ? `calc(${nestedLevel} * ${spacingVars['--spacing-5']})`
- : `calc(${nestedLevel} * ${spacingVars['--spacing-5']} + ${spacingVars['--spacing-4']} + ${spacingVars['--spacing-2']})`;
+ ? `calc(${nestedLevel} * ${spacingVars['--spacing-4']})`
+ : `calc(${nestedLevel} * ${spacingVars['--spacing-4']} + ${spacingVars['--spacing-4']} + ${spacingVars['--spacing-2']})`;
const labelAndDescription = (
<>
@@ -399,10 +395,6 @@ export function XDSTreeListItem({
/>
</div>
<div {...stylex.props(styles.rowWrapper)}>
- <XDSTreeListHorizontalConnector
- hasChildren={hasChildren}
- nestedLevel={nestedLevel}
- />
<div
{...mergeProps(
xdsClassName('tree-list-item', {