1
+ import { ForwardRefComponent as PolymorphicForwardRefComponent } from '../utils/polymorphic'
1
2
import React from 'react'
2
3
import styled from 'styled-components'
3
4
import Box , { BoxProps } from '../Box'
4
- import { useId } from '../hooks/useId'
5
- import { useSlots } from '../hooks/useSlots'
6
5
import sx , { BetterSystemStyleObject , merge , SxProp } from '../sx'
7
6
import { useTheme } from '../ThemeProvider'
8
- import { defaultSxProp } from '../utils/defaultSxProp'
9
- import { ForwardRefComponent as PolymorphicForwardRefComponent } from '../utils/polymorphic'
7
+ import { useId } from '../hooks/useId'
10
8
import { ActionListContainerContext } from './ActionListContainerContext'
11
- import { Description } from './Description'
12
9
import { ActionListGroupProps , GroupContext } from './Group'
13
10
import { ActionListProps , ListContext } from './List'
14
11
import { Selection } from './Selection'
15
- import { ActionListItemProps , getVariantStyles , ItemContext , TEXT_ROW_HEIGHT } from './shared'
16
- import { LeadingVisual , TrailingVisual } from './Visuals '
12
+ import { ActionListItemProps , Slots , TEXT_ROW_HEIGHT , getVariantStyles } from './shared'
13
+ import { defaultSxProp } from '../utils/defaultSxProp '
17
14
18
15
const LiBox = styled . li < SxProp > ( sx )
19
16
@@ -33,11 +30,6 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
33
30
} ,
34
31
forwardedRef ,
35
32
) : JSX . Element => {
36
- const [ slots , childrenWithoutSlots ] = useSlots ( props . children , {
37
- leadingVisual : LeadingVisual ,
38
- trailingVisual : TrailingVisual ,
39
- description : Description ,
40
- } )
41
33
const { variant : listVariant , showDividers, selectionVariant : listSelectionVariant } = React . useContext ( ListContext )
42
34
const { selectionVariant : groupSelectionVariant } = React . useContext ( GroupContext )
43
35
const { container, afterSelect, selectionAttribute} = React . useContext ( ActionListContainerContext )
@@ -177,57 +169,66 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
177
169
178
170
const ItemWrapper = _PrivateItemWrapper || React . Fragment
179
171
180
- const menuItemProps = {
181
- onClick : clickHandler ,
182
- onKeyPress : keyPressHandler ,
183
- 'aria-disabled' : disabled ? true : undefined ,
184
- tabIndex : disabled ? undefined : 0 ,
185
- 'aria-labelledby' : `${ labelId } ${
186
- slots . description && slots . description . props . variant !== 'block' ? inlineDescriptionId : ''
187
- } `,
188
- 'aria-describedby' : slots . description ?. props . variant === 'block' ? blockDescriptionId : undefined ,
189
- ...( selectionAttribute && { [ selectionAttribute ] : selected } ) ,
190
- role : role || itemRole ,
191
- }
192
-
193
- const containerProps = _PrivateItemWrapper ? { role : role || itemRole ? 'none' : undefined } : menuItemProps
194
-
195
- const wrapperProps = _PrivateItemWrapper ? menuItemProps : { }
196
-
197
172
return (
198
- < ItemContext . Provider value = { { variant, disabled, inlineDescriptionId, blockDescriptionId} } >
199
- < LiBox ref = { forwardedRef } sx = { merge < BetterSystemStyleObject > ( styles , sxProp ) } { ...containerProps } { ...props } >
200
- < ItemWrapper { ...wrapperProps } >
201
- < Selection selected = { selected } />
202
- { slots . leadingVisual }
203
- < Box
204
- data-component = "ActionList.Item--DividerContainer"
205
- sx = { { display : 'flex' , flexDirection : 'column' , flexGrow : 1 , minWidth : 0 } }
173
+ < Slots context = { { variant, disabled, inlineDescriptionId, blockDescriptionId} } >
174
+ { slots => {
175
+ const menuItemProps = {
176
+ onClick : clickHandler ,
177
+ onKeyPress : keyPressHandler ,
178
+ 'aria-disabled' : disabled ? true : undefined ,
179
+ tabIndex : disabled ? undefined : 0 ,
180
+ 'aria-labelledby' : `${ labelId } ${ slots . InlineDescription ? inlineDescriptionId : '' } ` ,
181
+ 'aria-describedby' : slots . BlockDescription ? blockDescriptionId : undefined ,
182
+ ...( selectionAttribute && { [ selectionAttribute ] : selected } ) ,
183
+ role : role || itemRole ,
184
+ }
185
+ const containerProps = _PrivateItemWrapper
186
+ ? {
187
+ role : role || itemRole ? 'none' : undefined ,
188
+ }
189
+ : menuItemProps
190
+ const wrapperProps = _PrivateItemWrapper ? menuItemProps : { }
191
+
192
+ return (
193
+ < LiBox
194
+ ref = { forwardedRef }
195
+ sx = { merge < BetterSystemStyleObject > ( styles , sxProp ) }
196
+ { ...containerProps }
197
+ { ...props }
206
198
>
207
- < ConditionalBox if = { Boolean ( slots . trailingVisual ) } sx = { { display : 'flex' , flexGrow : 1 } } >
208
- < ConditionalBox
209
- if = { ! ! slots . description && slots . description . props . variant !== 'block' }
210
- sx = { { display : 'flex' , flexGrow : 1 , alignItems : 'baseline' , minWidth : 0 } }
199
+ < ItemWrapper { ...wrapperProps } >
200
+ < Selection selected = { selected } />
201
+ { slots . LeadingVisual }
202
+ < Box
203
+ data-component = "ActionList.Item--DividerContainer"
204
+ sx = { { display : 'flex' , flexDirection : 'column' , flexGrow : 1 , minWidth : 0 } }
211
205
>
212
- < Box
213
- as = "span"
214
- id = { labelId }
215
- sx = { {
216
- flexGrow : slots . description && slots . description . props . variant !== 'block' ? 0 : 1 ,
217
- fontWeight : slots . description && slots . description . props . variant !== 'block' ? 'bold' : 'normal' ,
218
- } }
219
- >
220
- { childrenWithoutSlots }
221
- </ Box >
222
- { slots . description ?. props . variant !== 'block' ? slots . description : null }
223
- </ ConditionalBox >
224
- { slots . trailingVisual }
225
- </ ConditionalBox >
226
- { slots . description ?. props . variant === 'block' ? slots . description : null }
227
- </ Box >
228
- </ ItemWrapper >
229
- </ LiBox >
230
- </ ItemContext . Provider >
206
+ < ConditionalBox if = { Boolean ( slots . TrailingVisual ) } sx = { { display : 'flex' , flexGrow : 1 } } >
207
+ < ConditionalBox
208
+ if = { Boolean ( slots . InlineDescription ) }
209
+ sx = { { display : 'flex' , flexGrow : 1 , alignItems : 'baseline' , minWidth : 0 } }
210
+ >
211
+ < Box
212
+ as = "span"
213
+ id = { labelId }
214
+ sx = { {
215
+ flexGrow : slots . InlineDescription ? 0 : 1 ,
216
+ fontWeight : slots . InlineDescription ? 'bold' : 'normal' ,
217
+ } }
218
+ >
219
+ { props . children }
220
+ </ Box >
221
+ { slots . InlineDescription }
222
+ </ ConditionalBox >
223
+ { slots . TrailingVisual }
224
+ </ ConditionalBox >
225
+ { slots . BlockDescription }
226
+ </ Box >
227
+ </ ItemWrapper >
228
+ </ LiBox >
229
+ )
230
+ } }
231
+ </ Slots >
231
232
)
232
233
} ,
233
234
) as PolymorphicForwardRefComponent < 'li' , ActionListItemProps >
0 commit comments