@@ -31,29 +31,23 @@ import {
3131import { centerBaseline } from './CenterBaseline' ;
3232import { Checkbox } from './Checkbox' ;
3333import 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' } ;
3535import { DOMRef , forwardRefType , GlobalDOMAttributes , Key , LoadingState } from '@react-types/shared' ;
3636import { getAllowedOverrides , StylesPropWithHeight , UnsafeStyles } from './style-utils' with { type : 'macro' } ;
3737import { IconContext } from './Icon' ;
3838// @ts -ignore
3939import intlMessages from '../intl/*.json' ;
4040import { ProgressCircle } from './ProgressCircle' ;
4141import { 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' ;
4343import { Text , TextContext } from './Content' ;
4444import { useDOMRef } from '@react-spectrum/utils' ;
4545import { useLocale , useLocalizedStringFormatter } from 'react-aria' ;
4646import { useScale } from './utils' ;
4747
4848interface 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
5953export interface TreeViewProps < T > extends Omit < RACTreeProps < T > , 'style' | 'className' | 'onRowAction' | 'selectionBehavior' | 'onScroll' | 'onCellAction' | 'dragAndDropHooks' | keyof GlobalDOMAttributes > , UnsafeStyles , S2TreeProps {
@@ -77,8 +71,6 @@ interface TreeRendererContextValue {
7771const 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 */
110102export 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-
147133const 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-
296246const 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 } }
0 commit comments