@registrucentras/rc-ses-react-components 1.8.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/icons/PencilSimpleLineIcon.d.ts +1 -1
- package/dist/components/common/SegmentedControl/components/SegmentButton/index.d.ts +19 -0
- package/dist/components/common/SegmentedControl/index.d.ts +14 -0
- package/dist/components/form/inputs/SearchInput/index.d.ts +10 -0
- package/dist/components/loaders/FullPageLoader/index.d.ts +9 -0
- package/dist/components/loaders/Loader/index.d.ts +26 -0
- package/dist/library/index.d.ts +6 -2
- package/dist/library/types.d.ts +6 -2
- package/dist/registrucentras-rc-ses-react-components.cjs +10 -10
- package/dist/registrucentras-rc-ses-react-components.js +2569 -2277
- package/dist/stories/components/display/SegmentedControl.stories.d.ts +202 -0
- package/dist/stories/components/loaders/FullPageLoader.stories.d.ts +37 -0
- package/dist/stories/components/loaders/Loader.stories.d.ts +36 -0
- package/dist/stories/components/{spinner → loaders}/LoadingSpinner.stories.d.ts +4 -4
- package/package.json +1 -1
- package/src/assets/icons/PencilSimpleLineIcon.tsx +8 -2
- package/src/components/common/Button/index.tsx +1 -3
- package/src/components/common/SegmentedControl/components/SegmentButton/index.test.tsx +85 -0
- package/src/components/common/SegmentedControl/components/SegmentButton/index.tsx +110 -0
- package/src/components/common/SegmentedControl/index.test.tsx +164 -0
- package/src/components/common/SegmentedControl/index.tsx +188 -0
- package/src/components/common/SelectableCardList/components/SelectableCardListItem.test.tsx +74 -1
- package/src/components/common/SelectableCardList/components/SelectableCardListItem.tsx +16 -1
- package/src/components/common/Snackbar/index.test.tsx +10 -4
- package/src/components/form/inputs/CheckboxFormControl.test.tsx +11 -7
- package/src/components/form/inputs/SearchInput/index.test.tsx +68 -2
- package/src/components/form/inputs/SearchInput/index.tsx +24 -13
- package/src/components/loaders/FullPageLoader/index.test.tsx +80 -0
- package/src/components/loaders/FullPageLoader/index.tsx +68 -0
- package/src/components/loaders/Loader/index.test.tsx +58 -0
- package/src/components/loaders/Loader/index.tsx +65 -0
- package/src/components/{LoadingSpinner/LoadingSpinner.test.tsx → loaders/LoadingSpinner/index.test.tsx} +1 -1
- package/src/components/{LoadingSpinner/LoadingSpinner.tsx → loaders/LoadingSpinner/index.tsx} +1 -1
- package/src/components/overlays/Dialog/index.test.tsx +1 -1
- package/src/i18n/namespaces/common/en.json +7 -0
- package/src/i18n/namespaces/common/lt.json +7 -0
- package/src/library/index.ts +7 -1
- package/src/library/types.ts +21 -4
- package/src/setupTests.ts +13 -0
- package/src/stories/components/display/SegmentedControl.stories.tsx +311 -0
- package/src/stories/components/loaders/FullPageLoader.stories.tsx +126 -0
- package/src/stories/components/loaders/Loader.stories.tsx +76 -0
- package/src/stories/components/{spinner → loaders}/LoadingSpinner.stories.tsx +2 -2
- /package/dist/components/{LoadingSpinner/LoadingSpinner.d.ts → loaders/LoadingSpinner/index.d.ts} +0 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { ForwardRefExoticComponent, RefAttributes } from 'react';
|
|
2
|
+
import { RcSesSegmentedControlProps } from '../../../components/common/SegmentedControl';
|
|
3
|
+
declare const meta: {
|
|
4
|
+
title: string;
|
|
5
|
+
component: ForwardRefExoticComponent< RcSesSegmentedControlProps & RefAttributes<HTMLDivElement>>;
|
|
6
|
+
parameters: {
|
|
7
|
+
layout: string;
|
|
8
|
+
};
|
|
9
|
+
tags: string[];
|
|
10
|
+
argTypes: {
|
|
11
|
+
options: {
|
|
12
|
+
control: false;
|
|
13
|
+
description: string;
|
|
14
|
+
};
|
|
15
|
+
value: {
|
|
16
|
+
control: "text";
|
|
17
|
+
description: string;
|
|
18
|
+
};
|
|
19
|
+
onChange: {
|
|
20
|
+
control: false;
|
|
21
|
+
description: string;
|
|
22
|
+
};
|
|
23
|
+
size: {
|
|
24
|
+
control: "radio";
|
|
25
|
+
options: string[];
|
|
26
|
+
description: string;
|
|
27
|
+
};
|
|
28
|
+
role: {
|
|
29
|
+
control: "radio";
|
|
30
|
+
options: string[];
|
|
31
|
+
description: string;
|
|
32
|
+
};
|
|
33
|
+
disableBg: {
|
|
34
|
+
control: "boolean";
|
|
35
|
+
description: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export default meta;
|
|
40
|
+
export declare const Default: {
|
|
41
|
+
readonly args: {
|
|
42
|
+
readonly options: readonly [{
|
|
43
|
+
readonly id: "1";
|
|
44
|
+
readonly label: "Fizinis asmuo";
|
|
45
|
+
}, {
|
|
46
|
+
readonly id: "2";
|
|
47
|
+
readonly label: "Juridinis asmuo";
|
|
48
|
+
}, {
|
|
49
|
+
readonly id: "3";
|
|
50
|
+
readonly label: "Advokatas";
|
|
51
|
+
}];
|
|
52
|
+
readonly value: "1";
|
|
53
|
+
readonly onChange: () => void;
|
|
54
|
+
readonly size: "regular";
|
|
55
|
+
readonly role: "radiogroup";
|
|
56
|
+
readonly disableBg: false;
|
|
57
|
+
};
|
|
58
|
+
readonly render: ({ options, value: initialValue, onChange, size, role, disableBg }: any) => import("react/jsx-runtime").JSX.Element;
|
|
59
|
+
};
|
|
60
|
+
export declare const RegularTwoOptions: {
|
|
61
|
+
readonly args: {
|
|
62
|
+
readonly options: readonly [{
|
|
63
|
+
readonly id: "1";
|
|
64
|
+
readonly label: "Fizinis asmuo";
|
|
65
|
+
}, {
|
|
66
|
+
readonly id: "2";
|
|
67
|
+
readonly label: "Juridinis asmuo";
|
|
68
|
+
}];
|
|
69
|
+
readonly value: "1";
|
|
70
|
+
readonly size: "regular";
|
|
71
|
+
};
|
|
72
|
+
readonly render: (args: any) => import("react/jsx-runtime").JSX.Element;
|
|
73
|
+
readonly parameters: {
|
|
74
|
+
readonly docs: {
|
|
75
|
+
readonly source: {
|
|
76
|
+
readonly code: "const [value, setValue] = useState('1');\n\n<RcSesSegmentedControl\n options={[\n { id: '1', label: 'Fizinis asmuo' },\n { id: '2', label: 'Juridinis asmuo' },\n ]}\n value={value}\n onChange={(newValue) => setValue(newValue)}\n size=\"regular\"\n/>";
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
export declare const RegularFourOptions: {
|
|
82
|
+
args: {
|
|
83
|
+
options: {
|
|
84
|
+
id: string;
|
|
85
|
+
label: string;
|
|
86
|
+
}[];
|
|
87
|
+
value: string;
|
|
88
|
+
size: string;
|
|
89
|
+
};
|
|
90
|
+
render: (args: any) => import("react/jsx-runtime").JSX.Element;
|
|
91
|
+
parameters: {
|
|
92
|
+
docs: {
|
|
93
|
+
source: {
|
|
94
|
+
code: string;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
export declare const RegularWithDisabled: {
|
|
100
|
+
args: {
|
|
101
|
+
options: ({
|
|
102
|
+
id: string;
|
|
103
|
+
label: string;
|
|
104
|
+
disabled?: undefined;
|
|
105
|
+
} | {
|
|
106
|
+
id: string;
|
|
107
|
+
label: string;
|
|
108
|
+
disabled: boolean;
|
|
109
|
+
})[];
|
|
110
|
+
value: string;
|
|
111
|
+
size: string;
|
|
112
|
+
};
|
|
113
|
+
render: (args: any) => import("react/jsx-runtime").JSX.Element;
|
|
114
|
+
parameters: {
|
|
115
|
+
docs: {
|
|
116
|
+
source: {
|
|
117
|
+
code: string;
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
export declare const SmallTwoOptions: {
|
|
123
|
+
readonly args: {
|
|
124
|
+
readonly options: readonly [{
|
|
125
|
+
readonly id: "1";
|
|
126
|
+
readonly label: "Fizinis asmuo";
|
|
127
|
+
}, {
|
|
128
|
+
readonly id: "2";
|
|
129
|
+
readonly label: "Juridinis asmuo";
|
|
130
|
+
}];
|
|
131
|
+
readonly value: "1";
|
|
132
|
+
readonly size: "small";
|
|
133
|
+
};
|
|
134
|
+
readonly render: (args: any) => import("react/jsx-runtime").JSX.Element;
|
|
135
|
+
readonly parameters: {
|
|
136
|
+
readonly docs: {
|
|
137
|
+
readonly source: {
|
|
138
|
+
readonly code: "const [value, setValue] = useState('1');\n\n<RcSesSegmentedControl\n options={[\n { id: '1', label: 'Fizinis asmuo' },\n { id: '2', label: 'Juridinis asmuo' },\n ]}\n value={value}\n onChange={(newValue) => setValue(newValue)}\n size=\"small\"\n/>";
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
export declare const SmallFourOptions: {
|
|
144
|
+
args: {
|
|
145
|
+
options: {
|
|
146
|
+
id: string;
|
|
147
|
+
label: string;
|
|
148
|
+
}[];
|
|
149
|
+
value: string;
|
|
150
|
+
size: string;
|
|
151
|
+
};
|
|
152
|
+
render: (args: any) => import("react/jsx-runtime").JSX.Element;
|
|
153
|
+
parameters: {
|
|
154
|
+
docs: {
|
|
155
|
+
source: {
|
|
156
|
+
code: string;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
export declare const SmallWithDisabled: {
|
|
162
|
+
args: {
|
|
163
|
+
options: ({
|
|
164
|
+
id: string;
|
|
165
|
+
label: string;
|
|
166
|
+
disabled?: undefined;
|
|
167
|
+
} | {
|
|
168
|
+
id: string;
|
|
169
|
+
label: string;
|
|
170
|
+
disabled: boolean;
|
|
171
|
+
})[];
|
|
172
|
+
value: string;
|
|
173
|
+
size: string;
|
|
174
|
+
};
|
|
175
|
+
render: (args: any) => import("react/jsx-runtime").JSX.Element;
|
|
176
|
+
parameters: {
|
|
177
|
+
docs: {
|
|
178
|
+
source: {
|
|
179
|
+
code: string;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
export declare const RegularNoBackground: {
|
|
185
|
+
args: {
|
|
186
|
+
options: {
|
|
187
|
+
id: string;
|
|
188
|
+
label: string;
|
|
189
|
+
}[];
|
|
190
|
+
value: string;
|
|
191
|
+
size: string;
|
|
192
|
+
disableBg: boolean;
|
|
193
|
+
};
|
|
194
|
+
render: (args: any) => import("react/jsx-runtime").JSX.Element;
|
|
195
|
+
parameters: {
|
|
196
|
+
docs: {
|
|
197
|
+
source: {
|
|
198
|
+
code: string;
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as RcSesFullPageLoader } from '../../../components/loaders/FullPageLoader';
|
|
3
|
+
declare const meta: {
|
|
4
|
+
title: string;
|
|
5
|
+
component: typeof RcSesFullPageLoader;
|
|
6
|
+
tags: string[];
|
|
7
|
+
parameters: {
|
|
8
|
+
controls: {
|
|
9
|
+
include: string[];
|
|
10
|
+
};
|
|
11
|
+
docs: {
|
|
12
|
+
story: {
|
|
13
|
+
inline: boolean;
|
|
14
|
+
height: number;
|
|
15
|
+
};
|
|
16
|
+
description: {
|
|
17
|
+
component: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
argTypes: {
|
|
22
|
+
backdrop: {
|
|
23
|
+
control: "radio";
|
|
24
|
+
options: string[];
|
|
25
|
+
};
|
|
26
|
+
label: {
|
|
27
|
+
control: "text";
|
|
28
|
+
};
|
|
29
|
+
showLabel: {
|
|
30
|
+
control: "boolean";
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export default meta;
|
|
35
|
+
type Story = StoryObj<typeof meta>;
|
|
36
|
+
export declare const Default: Story;
|
|
37
|
+
export declare const DarkBackdrop: Story;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as RcSesLoader } from '../../../components/loaders/Loader';
|
|
3
|
+
declare const meta: {
|
|
4
|
+
title: string;
|
|
5
|
+
component: typeof RcSesLoader;
|
|
6
|
+
tags: string[];
|
|
7
|
+
parameters: {
|
|
8
|
+
controls: {
|
|
9
|
+
include: string[];
|
|
10
|
+
};
|
|
11
|
+
docs: {
|
|
12
|
+
description: {
|
|
13
|
+
component: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
argTypes: {
|
|
18
|
+
label: {
|
|
19
|
+
control: "text";
|
|
20
|
+
};
|
|
21
|
+
showLabel: {
|
|
22
|
+
control: "boolean";
|
|
23
|
+
};
|
|
24
|
+
size: {
|
|
25
|
+
control: "radio";
|
|
26
|
+
options: string[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export default meta;
|
|
31
|
+
type Story = StoryObj<typeof meta>;
|
|
32
|
+
export declare const Default: Story;
|
|
33
|
+
export declare const Small: Story;
|
|
34
|
+
export declare const Medium: Story;
|
|
35
|
+
export declare const Large: Story;
|
|
36
|
+
export declare const WithoutLabel: Story;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StoryObj } from '@storybook/react';
|
|
2
|
-
import { default as RcSesLoadingSpinner } from '../../../components/
|
|
2
|
+
import { default as RcSesLoadingSpinner } from '../../../components/loaders/LoadingSpinner';
|
|
3
3
|
declare const meta: {
|
|
4
4
|
title: string;
|
|
5
5
|
component: typeof RcSesLoadingSpinner;
|
|
@@ -14,11 +14,11 @@ declare const meta: {
|
|
|
14
14
|
argTypes: {
|
|
15
15
|
color: {
|
|
16
16
|
description: string;
|
|
17
|
-
options: ("
|
|
18
|
-
mapping: ("
|
|
17
|
+
options: ("inherit" | "success" | "info" | "warning" | "error" | "primary" | "secondary")[];
|
|
18
|
+
mapping: ("inherit" | "success" | "info" | "warning" | "error" | "primary" | "secondary")[];
|
|
19
19
|
control: {
|
|
20
20
|
type: "select";
|
|
21
|
-
labels: ("
|
|
21
|
+
labels: ("inherit" | "success" | "info" | "warning" | "error" | "primary" | "secondary")[];
|
|
22
22
|
};
|
|
23
23
|
table: {
|
|
24
24
|
defaultValue: {
|
package/package.json
CHANGED
|
@@ -2,13 +2,19 @@ import { PencilSimpleLineIcon as PencilSimpleLine } from '@phosphor-icons/react'
|
|
|
2
2
|
|
|
3
3
|
import IconProps from '../IconProps'
|
|
4
4
|
|
|
5
|
-
function PencilSimpleLineIcon({
|
|
5
|
+
function PencilSimpleLineIcon({
|
|
6
|
+
className,
|
|
7
|
+
fillColor,
|
|
8
|
+
size = 24,
|
|
9
|
+
weight = 'regular',
|
|
10
|
+
...rest
|
|
11
|
+
}: IconProps) {
|
|
6
12
|
return (
|
|
7
13
|
<PencilSimpleLine
|
|
8
14
|
{...rest}
|
|
9
15
|
className={className}
|
|
10
16
|
size={size}
|
|
11
|
-
weight=
|
|
17
|
+
weight={weight}
|
|
12
18
|
color={fillColor}
|
|
13
19
|
/>
|
|
14
20
|
)
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Button as MuiButton, ButtonProps as MuiButtonProps } from '@mui/material'
|
|
2
2
|
import { useTranslation } from 'react-i18next'
|
|
3
3
|
|
|
4
|
-
import RcSesLoadingSpinner, {
|
|
5
|
-
getSpinnerColor,
|
|
6
|
-
} from '@/components/LoadingSpinner/LoadingSpinner'
|
|
4
|
+
import RcSesLoadingSpinner, { getSpinnerColor } from '@/components/loaders/LoadingSpinner'
|
|
7
5
|
import { ButtonProps } from '@/types/buttons/ButtonProps'
|
|
8
6
|
|
|
9
7
|
const defaultProps: Partial<MuiButtonProps> = {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from '@testing-library/react'
|
|
2
|
+
import { describe, expect, test, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import RcSesSegmentButton, { type RcSesSegmentOption } from './index'
|
|
5
|
+
|
|
6
|
+
describe('RcSesSegmentButton', () => {
|
|
7
|
+
const defaultOption: RcSesSegmentOption = {
|
|
8
|
+
id: 'option-1',
|
|
9
|
+
label: 'Option 1',
|
|
10
|
+
disabled: false,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const defaultProps = {
|
|
14
|
+
option: defaultOption,
|
|
15
|
+
isSelected: false,
|
|
16
|
+
isFocused: false,
|
|
17
|
+
size: 'regular' as const,
|
|
18
|
+
ariaRole: 'radio' as const,
|
|
19
|
+
onClick: vi.fn(),
|
|
20
|
+
onKeyDown: vi.fn(),
|
|
21
|
+
onFocus: vi.fn(),
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
test('renders button with option label', () => {
|
|
25
|
+
render(<RcSesSegmentButton {...defaultProps} />)
|
|
26
|
+
expect(screen.getByRole('radio', { name: 'Option 1' })).toBeInTheDocument()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('calls onClick handler when clicked', () => {
|
|
30
|
+
const onClick = vi.fn()
|
|
31
|
+
|
|
32
|
+
render(<RcSesSegmentButton {...defaultProps} onClick={onClick} />)
|
|
33
|
+
|
|
34
|
+
fireEvent.click(screen.getByRole('radio'))
|
|
35
|
+
expect(onClick).toHaveBeenCalledWith('option-1')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('calls onFocus handler when focused', () => {
|
|
39
|
+
const onFocus = vi.fn()
|
|
40
|
+
|
|
41
|
+
render(<RcSesSegmentButton {...defaultProps} onFocus={onFocus} />)
|
|
42
|
+
|
|
43
|
+
fireEvent.focus(screen.getByRole('radio'))
|
|
44
|
+
expect(onFocus).toHaveBeenCalled()
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('calls onKeyDown handler when key pressed', () => {
|
|
48
|
+
const onKeyDown = vi.fn()
|
|
49
|
+
|
|
50
|
+
render(<RcSesSegmentButton {...defaultProps} onKeyDown={onKeyDown} />)
|
|
51
|
+
|
|
52
|
+
const button = screen.getByRole('radio')
|
|
53
|
+
fireEvent.keyDown(button, { key: 'ArrowRight', code: 'ArrowRight' })
|
|
54
|
+
expect(onKeyDown).toHaveBeenCalled()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('disables button when option.disabled is true', () => {
|
|
58
|
+
render(
|
|
59
|
+
<RcSesSegmentButton
|
|
60
|
+
{...defaultProps}
|
|
61
|
+
option={{ ...defaultOption, disabled: true }}
|
|
62
|
+
/>,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
expect(screen.getByRole('radio')).toBeDisabled()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('sets aria-checked when selected', () => {
|
|
69
|
+
render(<RcSesSegmentButton {...defaultProps} isSelected />)
|
|
70
|
+
|
|
71
|
+
expect(screen.getByRole('radio')).toHaveAttribute('aria-checked', 'true')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('sets tabIndex to 0 when focused', () => {
|
|
75
|
+
render(<RcSesSegmentButton {...defaultProps} isFocused />)
|
|
76
|
+
|
|
77
|
+
expect(screen.getByRole('radio')).toHaveAttribute('tabIndex', '0')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('supports tab role', () => {
|
|
81
|
+
render(<RcSesSegmentButton {...defaultProps} ariaRole='tab' />)
|
|
82
|
+
|
|
83
|
+
expect(screen.getByRole('tab')).toBeInTheDocument()
|
|
84
|
+
})
|
|
85
|
+
})
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Button as MuiButton } from '@mui/material'
|
|
2
|
+
import React, { useCallback, useMemo } from 'react'
|
|
3
|
+
|
|
4
|
+
import { grey, primary } from '@/theme/palette'
|
|
5
|
+
|
|
6
|
+
const SIZE_STYLES: Record<'small' | 'regular', React.CSSProperties> = {
|
|
7
|
+
small: {
|
|
8
|
+
width: 'auto',
|
|
9
|
+
maxWidth: '160px',
|
|
10
|
+
minHeight: '36px',
|
|
11
|
+
padding: '8px 12px',
|
|
12
|
+
fontSize: '14px',
|
|
13
|
+
lineHeight: '20px',
|
|
14
|
+
},
|
|
15
|
+
regular: {
|
|
16
|
+
width: 'auto',
|
|
17
|
+
maxWidth: '180px',
|
|
18
|
+
minHeight: '44px',
|
|
19
|
+
padding: '10px 16px',
|
|
20
|
+
fontSize: '15px',
|
|
21
|
+
lineHeight: '20px',
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface RcSesSegmentOption {
|
|
26
|
+
id: string
|
|
27
|
+
label: string
|
|
28
|
+
disabled?: boolean
|
|
29
|
+
panelId?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface RcSesSegmentButtonProps {
|
|
33
|
+
option: RcSesSegmentOption
|
|
34
|
+
isSelected: boolean
|
|
35
|
+
isFocused: boolean
|
|
36
|
+
size: 'small' | 'regular'
|
|
37
|
+
ariaRole: 'tab' | 'radio'
|
|
38
|
+
onClick: (optionId: string) => void
|
|
39
|
+
onKeyDown: (e: React.KeyboardEvent<HTMLButtonElement>) => void
|
|
40
|
+
onFocus: () => void
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const RcSesSegmentButton = React.forwardRef<HTMLButtonElement, RcSesSegmentButtonProps>(
|
|
44
|
+
(
|
|
45
|
+
{ option, isSelected, isFocused, size, ariaRole, onClick, onKeyDown, onFocus },
|
|
46
|
+
ref,
|
|
47
|
+
) => {
|
|
48
|
+
const isDisabled = option.disabled
|
|
49
|
+
const sizeStyles = SIZE_STYLES[size]
|
|
50
|
+
|
|
51
|
+
const textColor = useMemo(() => {
|
|
52
|
+
if (isDisabled) return `${grey['500']} !important`
|
|
53
|
+
if (isSelected) return `${grey['900']} !important`
|
|
54
|
+
return `${primary['700']} !important`
|
|
55
|
+
}, [isDisabled, isSelected])
|
|
56
|
+
|
|
57
|
+
const buttonStyles = useMemo(
|
|
58
|
+
() =>
|
|
59
|
+
({
|
|
60
|
+
flex: '0 1 auto',
|
|
61
|
+
minWidth: '0',
|
|
62
|
+
height: 'auto',
|
|
63
|
+
wordBreak: 'break-word',
|
|
64
|
+
fontFamily: '"Public Sans", sans-serif !important',
|
|
65
|
+
border: `2px solid ${isFocused && !isDisabled ? primary['500'] : 'transparent'}`,
|
|
66
|
+
backgroundColor: isSelected
|
|
67
|
+
? `${primary['50']} !important`
|
|
68
|
+
: 'transparent !important',
|
|
69
|
+
color: textColor,
|
|
70
|
+
cursor: isDisabled ? 'not-allowed' : 'pointer',
|
|
71
|
+
fontWeight: 500,
|
|
72
|
+
borderRadius: '8px',
|
|
73
|
+
transition: 'all 150ms ease-in-out',
|
|
74
|
+
whiteSpace: 'normal',
|
|
75
|
+
...sizeStyles,
|
|
76
|
+
}) as React.CSSProperties,
|
|
77
|
+
[sizeStyles, isDisabled, isSelected, isFocused, textColor],
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
const handleClick = useCallback(() => {
|
|
81
|
+
onClick(option.id)
|
|
82
|
+
}, [option.id, onClick])
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<MuiButton
|
|
86
|
+
ref={ref}
|
|
87
|
+
type='button'
|
|
88
|
+
onClick={handleClick}
|
|
89
|
+
onKeyDown={onKeyDown}
|
|
90
|
+
onFocus={onFocus}
|
|
91
|
+
disabled={isDisabled}
|
|
92
|
+
role={ariaRole}
|
|
93
|
+
aria-checked={ariaRole === 'radio' ? isSelected : undefined}
|
|
94
|
+
aria-selected={ariaRole === 'tab' ? isSelected : undefined}
|
|
95
|
+
aria-controls={option.panelId}
|
|
96
|
+
tabIndex={isFocused && !isDisabled ? 0 : -1}
|
|
97
|
+
sx={{
|
|
98
|
+
...buttonStyles,
|
|
99
|
+
'&.Mui-disabled': {
|
|
100
|
+
backgroundColor: 'transparent !important',
|
|
101
|
+
},
|
|
102
|
+
}}
|
|
103
|
+
>
|
|
104
|
+
{option.label}
|
|
105
|
+
</MuiButton>
|
|
106
|
+
)
|
|
107
|
+
},
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
export default RcSesSegmentButton
|