Skip to content

Commit 65e58b5

Browse files
authored
chore: Update S2 TreeView and TableView to be more inline with new designs (#9249)
* update treeview not to have emphasizied/detached removing for now, to be readded when designs settle * update table colors * make consistent with tree and future design * fix lint
1 parent 6028a29 commit 65e58b5

File tree

4 files changed

+26
-118
lines changed

4 files changed

+26
-118
lines changed

packages/@react-spectrum/s2/chromatic/TreeView.stories.tsx

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -152,43 +152,6 @@ export const TreeSelection: StoryObj<typeof TreeExample> = {
152152
}
153153
};
154154

155-
export const TreeIsDetached: StoryObj<typeof TreeExample> = {
156-
...TreeStatic,
157-
args: {
158-
isDetached: true,
159-
selectionMode: 'multiple',
160-
defaultSelectedKeys: ['projects-2', 'projects-3']
161-
}
162-
};
163-
164-
export const TreeIsEmphasized: StoryObj<typeof TreeExample> = {
165-
...TreeStatic,
166-
args: {
167-
isEmphasized: true,
168-
selectionMode: 'multiple',
169-
defaultSelectedKeys: ['projects-2', 'projects-3']
170-
}
171-
};
172-
173-
export const TreeIsDetachedIsEmphasized: StoryObj<typeof TreeExample> = {
174-
...TreeStatic,
175-
args: {
176-
isDetached: true,
177-
isEmphasized: true,
178-
selectionMode: 'multiple',
179-
defaultSelectedKeys: ['projects-2', 'projects-3']
180-
}
181-
};
182-
183-
export const TreeIsDetachedMobile: StoryObj<typeof TreeExample> = {
184-
...TreeStatic,
185-
args: {
186-
isDetached: true,
187-
selectionMode: 'multiple',
188-
defaultSelectedKeys: ['projects-2', 'projects-3']
189-
}
190-
};
191-
192155
interface TreeViewItemType {
193156
id: string,
194157
name: string,

packages/@react-spectrum/s2/src/TableView.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ export const TableHeader = /*#__PURE__*/ (forwardRef as forwardRefType)(function
908908
</>
909909
}
910910
{selectionMode === 'multiple' &&
911-
<Checkbox isEmphasized styles={selectAllCheckbox} slot="selection" />
911+
<Checkbox styles={selectAllCheckbox} slot="selection" />
912912
}
913913
</>
914914
)}
@@ -1362,8 +1362,8 @@ function EditableCellInner(props: EditableCellProps & {isFocusVisible: boolean,
13621362
};
13631363

13641364
// Use color-mix instead of transparency so sticky cells work correctly.
1365-
const selectedBackground = lightDark(colorMix('gray-25', 'informative-900', 10), colorMix('gray-25', 'informative-700', 10));
1366-
const selectedActiveBackground = lightDark(colorMix('gray-25', 'informative-900', 15), colorMix('gray-25', 'informative-700', 15));
1365+
const selectedBackground = colorMix('gray-25', 'gray-900', 7);
1366+
const selectedActiveBackground = colorMix('gray-25', 'gray-900', 10);
13671367
const rowBackgroundColor = {
13681368
default: {
13691369
default: 'gray-25',
@@ -1462,7 +1462,7 @@ export const Row = /*#__PURE__*/ (forwardRef as forwardRefType)(function Row<T e
14621462
// The `spread` otherProps must be after className in Cell.
14631463
// @ts-ignore
14641464
<Cell isSticky className={checkboxCellStyle}>
1465-
<Checkbox isEmphasized slot="selection" />
1465+
<Checkbox slot="selection" />
14661466
</Cell>
14671467
)}
14681468
<Collection items={columns} dependencies={[...dependencies, columns]}>

packages/@react-spectrum/s2/src/TreeView.tsx

Lines changed: 21 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,23 @@ import {
3131
import {centerBaseline} from './CenterBaseline';
3232
import {Checkbox} from './Checkbox';
3333
import Chevron from '../ui-icons/Chevron';
34-
import {colorMix, focusRing, fontRelative, lightDark, style} from '../style' with {type: 'macro'};
34+
import {colorMix, focusRing, fontRelative, style} from '../style' with {type: 'macro'};
3535
import {DOMRef, forwardRefType, GlobalDOMAttributes, Key, LoadingState} from '@react-types/shared';
3636
import {getAllowedOverrides, StylesPropWithHeight, UnsafeStyles} from './style-utils' with {type: 'macro'};
3737
import {IconContext} from './Icon';
3838
// @ts-ignore
3939
import intlMessages from '../intl/*.json';
4040
import {ProgressCircle} from './ProgressCircle';
4141
import {raw} from '../style/style-macro' with {type: 'macro'};
42-
import React, {createContext, forwardRef, JSXElementConstructor, ReactElement, ReactNode, useContext, useRef} from 'react';
42+
import React, {createContext, forwardRef, JSXElementConstructor, ReactElement, ReactNode, useRef} from 'react';
4343
import {Text, TextContext} from './Content';
4444
import {useDOMRef} from '@react-spectrum/utils';
4545
import {useLocale, useLocalizedStringFormatter} from 'react-aria';
4646
import {useScale} from './utils';
4747

4848
interface S2TreeProps {
49-
// Only detatched is supported right now with the current styles from Spectrum
50-
// See https://github.com/adobe/react-spectrum/pull/7343 for what remaining combinations are left
51-
/** Whether the tree should be displayed with a [detached style](https://spectrum.adobe.com/page/tree-view/#Detached). */
52-
isDetached?: boolean,
5349
/** Handler that is called when a user performs an action on a row. */
54-
onAction?: (key: Key) => void,
55-
/** Whether the tree should be displayed with a [emphasized style](https://spectrum.adobe.com/page/tree-view/#Emphasis). */
56-
isEmphasized?: boolean
50+
onAction?: (key: Key) => void
5751
}
5852

5953
export interface TreeViewProps<T> extends Omit<RACTreeProps<T>, 'style' | 'className' | 'onRowAction' | 'selectionBehavior' | 'onScroll' | 'onCellAction' | 'dragAndDropHooks' | keyof GlobalDOMAttributes>, UnsafeStyles, S2TreeProps {
@@ -77,8 +71,6 @@ interface TreeRendererContextValue {
7771
const TreeRendererContext = createContext<TreeRendererContextValue>({});
7872

7973

80-
let InternalTreeContext = createContext<{isDetached?: boolean, isEmphasized?: boolean}>({});
81-
8274
// TODO: the below is needed so the borders of the top and bottom row isn't cut off if the TreeView is wrapped within a container by always reserving the 2px needed for the
8375
// keyboard focus ring. Perhaps find a different way of rendering the outlines since the top of the item doesn't
8476
// scroll into view due to how the ring is offset. Alternatively, have the tree render the top/bottom outline like it does in Listview
@@ -108,7 +100,7 @@ const tree = style({
108100
* A tree view provides users with a way to navigate nested hierarchical information.
109101
*/
110102
export const TreeView = /*#__PURE__*/ (forwardRef as forwardRefType)(function TreeView<T extends object>(props: TreeViewProps<T>, ref: DOMRef<HTMLDivElement>) {
111-
let {children, isDetached, isEmphasized, UNSAFE_className, UNSAFE_style} = props;
103+
let {children, UNSAFE_className, UNSAFE_style} = props;
112104
let scale = useScale();
113105

114106
let renderer;
@@ -122,48 +114,32 @@ export const TreeView = /*#__PURE__*/ (forwardRef as forwardRefType)(function Tr
122114
<Virtualizer
123115
layout={ListLayout}
124116
layoutOptions={{
125-
rowHeight: scale === 'large' ? 50 : 40,
126-
gap: isDetached ? 2 : 0
117+
rowHeight: scale === 'large' ? 50 : 40
127118
}}>
128119
<TreeRendererContext.Provider value={{renderer}}>
129-
<InternalTreeContext.Provider value={{isDetached, isEmphasized}}>
130-
<Tree
131-
{...props}
132-
style={UNSAFE_style}
133-
className={renderProps => (UNSAFE_className ?? '') + tree({isDetached, ...renderProps}, props.styles)}
134-
selectionBehavior="toggle"
135-
ref={domRef}>
136-
{props.children}
137-
</Tree>
138-
</InternalTreeContext.Provider>
120+
<Tree
121+
{...props}
122+
style={UNSAFE_style}
123+
className={renderProps => (UNSAFE_className ?? '') + tree({...renderProps}, props.styles)}
124+
selectionBehavior="toggle"
125+
ref={domRef}>
126+
{props.children}
127+
</Tree>
139128
</TreeRendererContext.Provider>
140129
</Virtualizer>
141130
);
142131
});
143132

144-
const selectedBackground = lightDark(colorMix('gray-25', 'informative-900', 10), colorMix('gray-25', 'informative-700', 10));
145-
const selectedActiveBackground = lightDark(colorMix('gray-25', 'informative-900', 15), colorMix('gray-25', 'informative-700', 15));
146-
147133
const rowBackgroundColor = {
148134
default: '--s2-container-bg',
149135
isFocusVisibleWithin: colorMix('gray-25', 'gray-900', 7),
150136
isHovered: colorMix('gray-25', 'gray-900', 7),
151137
isPressed: colorMix('gray-25', 'gray-900', 10),
152138
isSelected: {
153139
default: colorMix('gray-25', 'gray-900', 7),
154-
isEmphasized: selectedBackground,
155-
isFocusVisibleWithin: {
156-
default: colorMix('gray-25', 'gray-900', 10),
157-
isEmphasized: selectedActiveBackground
158-
},
159-
isHovered: {
160-
default: colorMix('gray-25', 'gray-900', 10),
161-
isEmphasized: selectedActiveBackground
162-
},
163-
isPressed: {
164-
default: colorMix('gray-25', 'gray-900', 10),
165-
isEmphasized: selectedActiveBackground
166-
}
140+
isFocusVisibleWithin: colorMix('gray-25', 'gray-900', 10),
141+
isHovered: colorMix('gray-25', 'gray-900', 10),
142+
isPressed: colorMix('gray-25', 'gray-900', 10)
167143
},
168144
forcedColors: {
169145
default: 'Background'
@@ -230,21 +206,6 @@ const treeCellGrid = style({
230206
default: 'focus-ring',
231207
forcedColors: 'Highlight'
232208
}
233-
},
234-
borderColor: {
235-
isDetached: {
236-
default: 'transparent',
237-
isSelected: '--rowSelectedBorderColor'
238-
}
239-
},
240-
borderWidth: {
241-
isDetached: 1
242-
},
243-
borderRadius: {
244-
isDetached: 'default'
245-
},
246-
borderStyle: {
247-
isDetached: 'solid'
248209
}
249210
});
250211

@@ -282,17 +243,6 @@ const treeActionMenu = style({
282243
gridArea: 'actionmenu'
283244
});
284245

285-
const cellFocus = {
286-
outlineStyle: {
287-
default: 'none',
288-
isFocusVisible: 'solid'
289-
},
290-
outlineOffset: -2,
291-
outlineWidth: 2,
292-
outlineColor: 'focus-ring',
293-
borderRadius: '[6px]'
294-
} as const;
295-
296246
const treeRowFocusIndicator = raw(`
297247
&:before {
298248
content: "";
@@ -312,15 +262,14 @@ export const TreeViewItem = (props: TreeViewItemProps): ReactNode => {
312262
let {
313263
href
314264
} = props;
315-
let {isDetached, isEmphasized} = useContext(InternalTreeContext);
316265

317266
return (
318267
<TreeItem
319268
{...props}
320269
className={(renderProps) => treeRow({
321270
...renderProps,
322-
isLink: !!href, isEmphasized
323-
}) + (renderProps.isFocusVisible && !isDetached ? ' ' + treeRowFocusIndicator : '')} />
271+
isLink: !!href
272+
}) + (renderProps.isFocusVisible ? ' ' + treeRowFocusIndicator : '')} />
324273
);
325274
};
326275

@@ -333,12 +282,11 @@ export const TreeViewItemContent = (props: TreeViewItemContentProps): ReactNode
333282
let {
334283
children
335284
} = props;
336-
let {isDetached, isEmphasized} = useContext(InternalTreeContext);
337285
let scale = useScale();
338286

339287
return (
340288
<TreeItemContent>
341-
{({isExpanded, hasChildItems, selectionMode, selectionBehavior, isDisabled, isFocusVisible, isSelected, id, state}) => {
289+
{({isExpanded, hasChildItems, selectionMode, selectionBehavior, isDisabled, isSelected, id, state}) => {
342290
let isNextSelected = false;
343291
let isNextFocused = false;
344292
let keyAfter = state.collection.getKeyAfter(id);
@@ -347,13 +295,11 @@ export const TreeViewItemContent = (props: TreeViewItemContentProps): ReactNode
347295
}
348296
let isFirst = state.collection.getFirstKey() === id;
349297
return (
350-
<div className={treeCellGrid({isDisabled, isNextSelected, isSelected, isFirst, isNextFocused, isDetached})}>
298+
<div className={treeCellGrid({isDisabled, isNextSelected, isSelected, isFirst, isNextFocused})}>
351299
{selectionMode !== 'none' && selectionBehavior === 'toggle' && (
352300
// TODO: add transition?
353301
<div className={treeCheckbox}>
354-
<Checkbox
355-
isEmphasized={isEmphasized}
356-
slot="selection" />
302+
<Checkbox slot="selection" />
357303
</div>
358304
)}
359305
<div
@@ -374,7 +320,6 @@ export const TreeViewItemContent = (props: TreeViewItemContentProps): ReactNode
374320
]}>
375321
{typeof children === 'string' ? <Text>{children}</Text> : children}
376322
</Provider>
377-
{isFocusVisible && isDetached && <div role="presentation" className={style({...cellFocus, position: 'absolute', inset: 0})({isFocusVisible: true})} />}
378323
</div>
379324
);
380325
}}

packages/dev/s2-docs/pages/s2/TreeView.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const description = 'Displays hierarchical data with selection and collap
1414

1515
<PageDescription>{docs.exports.TreeView.description}</PageDescription>
1616

17-
```tsx render docs={docs.exports.TreeView} links={docs.links} props={['selectionMode', 'isDetached', 'isEmphasized']} initialProps={{selectionMode: 'multiple'}} type="s2"
17+
```tsx render docs={docs.exports.TreeView} links={docs.links} props={['selectionMode']} initialProps={{selectionMode: 'multiple'}} type="s2"
1818
import {TreeView, TreeViewItem, TreeViewItemContent} from '@react-spectrum/s2';
1919

2020
<TreeView

0 commit comments

Comments
 (0)