1
1
import React , { useCallback , useLayoutEffect , useState , forwardRef , useMemo } from 'react' ;
2
2
3
3
4
- import { AnimatedVisibility , Box , Flex , Margins , Scrollable } from '../Box' ;
4
+ import { AnimatedVisibility , Box , Margins , Scrollable } from '../Box' ;
5
+ import { Icon } from '../Icon' ;
5
6
import { Avatar } from '../Avatar' ;
6
7
import { CheckBox } from '../CheckBox' ;
7
8
import { Tile } from '../Tile' ;
@@ -21,24 +22,15 @@ const prevent = (e) => {
21
22
e . stopPropagation ( ) ;
22
23
} ;
23
24
24
- const Li = forwardRef ( function Li ( props , ref ) {
25
- return < Box is = 'li' rcx-option ref = { ref } { ...props } / >;
25
+ const Li = forwardRef ( function Li ( { children , ... props } , ref ) {
26
+ return < Box rcx-option withTruncatedText display = 'flex' alignItems = 'center' is = 'li' ref = { ref } { ...props } > < Margins inline = 'x4' > { children } </ Margins > </ Box > ;
26
27
} ) ;
27
28
28
- export const Empty = React . memo ( ( ) => < Box is = 'span' fontScale = 'p1' color = 'hint' > Empty </ Box > ) ;
29
+ export const Option = React . memo ( ( { id , avatar , children , label = children , focus , selected , icon , ... options } ) => < Li key = { id } rcx-option--focus = { focus } id = { id } rcx-option--selected = { selected } aria-selected = { selected } { ... options } > { avatar && < Avatar size = 'x28' url = { avatar } tile = { label } /> } { icon && < Icon size = 'x16' name = { icon } /> } < Box is = 'span' withTruncatedText flexGrow = { 1 } fontScale = 'p1' color = 'default' > { label } </ Box > { label !== children && children } </ Li > ) ;
29
30
30
- export const Option = React . memo ( ( { id , children : label , focus , selected , ... options } ) => < Li key = { id } rcx-option--focus = { focus } id = { id } rcx-option--selected = { selected } aria-selected = { selected } { ... options } > { label } </ Li > ) ;
31
+ export const Empty = React . memo ( ( ) => < Option is = 'span' fontScale = 'p1' color = 'hint' > Empty </ Option > ) ;
31
32
32
- export const CheckOption = React . memo ( ( { id, children : label , focus, selected, ...options } ) => < Li key = { id } rcx-option--focus = { focus } id = { id } aria-selected = { selected } { ...options } > < Margins inline = 'x4' > < CheckBox checked = { selected } /> </ Margins > < Margins inline = 'x4' > < Box is = 'span' fontScale = 'p1' color = 'default' > { label } </ Box > </ Margins > </ Li > ) ;
33
-
34
- export const OptionAvatar = React . memo ( ( { id, value, children : label , focus, selected, ...options } ) => (
35
- < Flex . Container >
36
- < Li key = { id } rcx-option--focus = { focus } id = { id } rcx-option--selected = { selected } aria-selected = { selected } { ...options } >
37
- < Margins inline = 'x4' > < Avatar size = 'x20' url = { value } tile = { label } /> </ Margins >
38
- < Margins inline = 'x4' > < Box is = 'span' fontScale = 'p1' color = 'default' > { label } </ Box > </ Margins >
39
- </ Li >
40
- </ Flex . Container >
41
- ) ) ;
33
+ export const CheckOption = React . memo ( ( { selected, children : label , ...options } ) => < Option label = { label } selected = { selected } { ...options } > < CheckBox checked = { selected } /> </ Option > ) ;
42
34
43
35
export const Options = React . forwardRef ( ( {
44
36
maxHeight = '144px' ,
@@ -63,14 +55,12 @@ export const Options = React.forwardRef(({
63
55
64
56
const optionsMemoized = useMemo ( ( ) => options . map ( ( [ value , label , selected ] , i ) => < OptionComponent role = 'option' onMouseDown = { ( e ) => prevent ( e ) & onSelect ( [ value , label ] ) && false } key = { value } value = { value } selected = { selected || ( multiple !== true && null ) } focus = { cursor === i || null } > { label } </ OptionComponent > ) , [ options , multiple , cursor , onSelect ] ) ;
65
57
return < Box rcx-options is = 'div' { ...props } >
66
- < Tile padding = 'x8' elevation = '2' >
58
+ < Tile padding = { 0 } paddingBlock = { 'x12' } paddingInline = { 0 } elevation = '2' >
67
59
< Scrollable vertical smooth >
68
- < Margins blockStart = 'x4' >
69
- < Tile ref = { ref } elevation = '0' padding = 'none' maxHeight = { maxHeight } onMouseDown = { prevent } onClick = { prevent } is = 'ol' aria-multiselectable = { multiple } role = 'listbox' aria-multiselectable = 'true' aria-activedescendant = { options && options [ cursor ] && options [ cursor ] [ 0 ] } >
70
- { ! options . length && < EmptyComponent /> }
71
- { optionsMemoized }
72
- </ Tile >
73
- </ Margins >
60
+ < Tile ref = { ref } elevation = '0' padding = 'none' maxHeight = { maxHeight } onMouseDown = { prevent } onClick = { prevent } is = 'ol' aria-multiselectable = { multiple } role = 'listbox' aria-multiselectable = 'true' aria-activedescendant = { options && options [ cursor ] && options [ cursor ] [ 0 ] } >
61
+ { ! options . length && < EmptyComponent /> }
62
+ { optionsMemoized }
63
+ </ Tile >
74
64
</ Scrollable >
75
65
</ Tile >
76
66
</ Box > ;
0 commit comments