1- import type {
2- Ref ,
3- ComponentProps ,
4- ReactNode ,
5- MouseEvent ,
6- AllHTMLAttributes ,
7- } from 'react' ;
1+ import type { Ref , ReactNode , MouseEvent , AllHTMLAttributes } from 'react' ;
82import { forwardRef , memo } from 'react' ;
93
10- import type { Icon } from '../..' ;
11- import { OptionColumn } from '../..' ;
124import { prevent } from '../../helpers/prevent' ;
13- import type Box from '../Box' ;
5+ import type { BoxProps } from '../Box' ;
6+ import type { IconProps } from '../Icon' ;
147
158import OptionAvatar from './OptionAvatar' ;
9+ import OptionColumn from './OptionColumn' ;
1610import OptionContent from './OptionContent' ;
1711import OptionIcon from './OptionIcon' ;
1812
19- type OptionProps = {
20- is ?: ComponentProps < typeof Box > [ 'is' ] ;
13+ export type OptionProps = {
14+ is ?: BoxProps [ 'is' ] ;
2115 id ?: string ;
2216 children ?: ReactNode ;
2317 label ?: ReactNode ;
2418 focus ?: boolean ;
2519 selected ?: boolean ;
26- className ?: ComponentProps < typeof Box > [ 'className' ] ;
20+ className ?: BoxProps [ 'className' ] ;
2721 ref ?: Ref < Element > ;
28- icon ?: ComponentProps < typeof Icon > [ 'name' ] ;
22+ icon ?: IconProps [ 'name' ] ;
2923 gap ?: boolean ;
3024 avatar ?: ReactNode ;
3125 title ?: string ;
@@ -39,72 +33,70 @@ type OptionProps = {
3933/**
4034 * The generic `Option` item of options. Can be freely used or inside the `Options` as well.
4135 */
42- const Option = memo (
43- forwardRef (
44- (
45- {
46- is : Tag = 'li' ,
47- id,
48- children,
49- label,
50- focus,
51- selected,
36+ const Option = forwardRef ( function Option (
37+ {
38+ is : Tag = 'li' ,
39+ id,
40+ children,
41+ label,
42+ focus,
43+ selected,
44+ className,
45+ icon,
46+ gap,
47+ avatar,
48+ title,
49+ disabled,
50+ variant,
51+ onClick,
52+ description,
53+ ...props
54+ } : OptionProps ,
55+ ref ,
56+ ) {
57+ return (
58+ < Tag
59+ { ...props }
60+ key = { id }
61+ id = { id }
62+ ref = { ref }
63+ aria-selected = { ! ! selected }
64+ aria-disabled = { ! ! disabled }
65+ title = { title }
66+ onClick = { ( e : MouseEvent < HTMLDivElement > ) => {
67+ if ( disabled ) {
68+ prevent ( e ) ;
69+ return ;
70+ }
71+ onClick ?.( e ) ;
72+ } }
73+ className = { [
74+ 'rcx-option' ,
5275 className ,
53- icon,
54- gap,
55- avatar,
56- title,
57- disabled,
58- variant,
59- onClick,
60- description,
61- ...props
62- } : OptionProps ,
63- ref ,
64- ) => (
65- < Tag
66- { ...props }
67- key = { id }
68- id = { id }
69- ref = { ref }
70- aria-selected = { ! ! selected }
71- aria-disabled = { ! ! disabled }
72- title = { title }
73- onClick = { ( e : MouseEvent < HTMLDivElement > ) => {
74- if ( disabled ) {
75- prevent ( e ) ;
76- return ;
77- }
78- onClick ?.( e ) ;
79- } }
76+ focus && 'rcx-option--focus' ,
77+ selected && 'rcx-option--selected' ,
78+ disabled && 'rcx-option--disabled' ,
79+ variant && `rcx-option--${ variant } ` ,
80+ ]
81+ . filter ( Boolean )
82+ . join ( ' ' ) }
83+ >
84+ < div
8085 className = { [
81- 'rcx-option' ,
82- className ,
83- focus && 'rcx-option--focus' ,
84- selected && 'rcx-option--selected' ,
85- disabled && 'rcx-option--disabled' ,
86- variant && `rcx-option--${ variant } ` ,
86+ 'rcx-option__wrapper' ,
87+ ! ! description && 'rcx-option__wrapper--align-top' ,
8788 ]
8889 . filter ( Boolean )
8990 . join ( ' ' ) }
9091 >
91- < div
92- className = { [
93- 'rcx-option__wrapper' ,
94- ! ! description && 'rcx-option__wrapper--align-top' ,
95- ]
96- . filter ( Boolean )
97- . join ( ' ' ) }
98- >
99- { avatar && < OptionAvatar > { avatar } </ OptionAvatar > }
100- { icon && < OptionIcon name = { icon } /> }
101- { gap && < OptionColumn /> }
102- { label && < OptionContent > { label } </ OptionContent > }
103- { label !== children && children }
104- </ div >
105- </ Tag >
106- ) ,
107- ) ,
108- ) ;
92+ { avatar && < OptionAvatar > { avatar } </ OptionAvatar > }
93+ { icon && < OptionIcon name = { icon } /> }
94+ { gap && < OptionColumn /> }
95+ { label && < OptionContent > { label } </ OptionContent > }
96+ { label !== children && children }
97+ </ div >
98+ </ Tag >
99+ ) ;
100+ } ) ;
109101
110- export default Option ;
102+ export default memo ( Option ) ;
0 commit comments