Skip to content

Commit aba9c50

Browse files
authored
feat(fuselage): Remove deprecated Option.* component namespace (#1770)
1 parent e0b2dd1 commit aba9c50

30 files changed

+148
-166
lines changed

.changeset/better-lines-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rocket.chat/fuselage': minor
3+
---
4+
5+
feat(fuselage): Remove deprecated `Option.*` component namespace

packages/fuselage/src/components/AutoComplete/AutoComplete.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { exampleAvatar, DECORATOR_LABEL } from '../../../.storybook/helpers';
55
import { Avatar } from '../Avatar';
66
import Box from '../Box';
77
import Chip from '../Chip';
8-
import Option from '../Option';
8+
import { Option } from '../Option';
99

1010
import { AutoComplete } from './AutoComplete';
1111

packages/fuselage/src/components/Divider/Divider.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { ComponentProps, ReactNode } from 'react';
1+
import type { ReactNode } from 'react';
22

3-
import Box from '../Box';
3+
import Box, { type BoxProps } from '../Box';
44

5-
type DividerProps = ComponentProps<typeof Box> & {
5+
export type DividerProps = BoxProps & {
66
variation?: 'danger';
77
children?: ReactNode;
88
vertical?: boolean;

packages/fuselage/src/components/Dropdown/Dropdown.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useRef } from 'react';
33

44
import Box from '../Box';
55
import { IconButton } from '../Button';
6-
import Option from '../Option';
6+
import { Option } from '../Option';
77

88
import { Dropdown } from './Dropdown';
99

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import type { ComponentProps } from 'react';
21
import { memo } from 'react';
32

43
import { CheckBox } from '../CheckBox';
54

6-
import Option from './Option';
5+
import Option, { type OptionProps } from './Option';
76

8-
type CheckOptionProps = ComponentProps<typeof Option>;
7+
export type CheckOptionProps = OptionProps;
98

10-
export const CheckOption = memo(function CheckOption({
9+
const CheckOption = ({
1110
selected,
1211
children: label,
1312
...options
14-
}: CheckOptionProps) {
13+
}: CheckOptionProps) => {
1514
return (
1615
<Option label={label as string} selected={selected} {...options}>
1716
<CheckBox checked={selected} />
1817
</Option>
1918
);
20-
});
19+
};
20+
21+
export default memo(CheckOption);

packages/fuselage/src/components/Option/Option.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { prevent } from '../../helpers/prevent';
22
import { render } from '../../testing';
33

4-
import Option, { OptionContent } from '.';
4+
import Option from './Option';
5+
import OptionContent from './OptionContent';
56

67
jest.mock('../../helpers/prevent');
78

Lines changed: 68 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
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';
82
import { forwardRef, memo } from 'react';
93

10-
import type { Icon } from '../..';
11-
import { OptionColumn } from '../..';
124
import { prevent } from '../../helpers/prevent';
13-
import type Box from '../Box';
5+
import type { BoxProps } from '../Box';
6+
import type { IconProps } from '../Icon';
147

158
import OptionAvatar from './OptionAvatar';
9+
import OptionColumn from './OptionColumn';
1610
import OptionContent from './OptionContent';
1711
import 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);

packages/fuselage/src/components/Option/OptionAvatar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ReactNode } from 'react';
22

3-
type OptionAvatarProps = {
3+
export type OptionAvatarProps = {
44
children?: ReactNode;
55
};
66

packages/fuselage/src/components/Option/OptionColumn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ReactNode } from 'react';
22

3-
type OptionColumnProps = {
3+
export type OptionColumnProps = {
44
children?: ReactNode;
55
};
66

packages/fuselage/src/components/Option/OptionContent.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { HTMLAttributes } from 'react';
22

3-
const OptionContent = (props: HTMLAttributes<HTMLDivElement>) => (
3+
export type OptionContentProps = HTMLAttributes<HTMLDivElement>;
4+
5+
const OptionContent = (props: OptionContentProps) => (
46
<div className='rcx-option__content' {...props} />
57
);
68

0 commit comments

Comments
 (0)