@registrucentras/rc-ses-react-components 1.9.0 → 1.11.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/Badge/index.d.ts +10 -0
- 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/common/Switch/index.d.ts +10 -0
- package/dist/components/form/inputs/SearchInput/index.d.ts +10 -0
- package/dist/library/index.d.ts +5 -1
- package/dist/library/types.d.ts +3 -1
- package/dist/registrucentras-rc-ses-react-components.cjs +10 -10
- package/dist/registrucentras-rc-ses-react-components.js +2885 -2460
- package/dist/stories/components/display/Badge.stories.d.ts +9 -0
- package/dist/stories/components/display/SegmentedControl.stories.d.ts +202 -0
- package/dist/stories/components/inputs/Switch.stories.d.ts +17 -0
- package/dist/theme/light/MuiSwitch.d.ts +3 -0
- package/package.json +1 -1
- package/src/assets/icons/PencilSimpleLineIcon.tsx +8 -2
- package/src/components/common/Badge/index.test.tsx +129 -0
- package/src/components/common/Badge/index.tsx +162 -0
- 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/Switch/index.test.tsx +214 -0
- package/src/components/common/Switch/index.tsx +49 -0
- package/src/components/form/inputs/SearchInput/index.test.tsx +68 -2
- package/src/components/form/inputs/SearchInput/index.tsx +24 -13
- package/src/i18n/namespaces/common/en.json +4 -0
- package/src/i18n/namespaces/common/lt.json +4 -0
- package/src/i18n/namespaces/input/en.json +6 -0
- package/src/i18n/namespaces/input/lt.json +6 -0
- package/src/library/index.ts +6 -0
- package/src/library/types.ts +8 -0
- package/src/stories/components/display/Badge.stories.tsx +165 -0
- package/src/stories/components/display/SegmentedControl.stories.tsx +311 -0
- package/src/stories/components/inputs/Switch.stories.tsx +70 -0
- package/src/theme/light/MuiSwitch.tsx +77 -0
- package/src/theme/light/index.tsx +2 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Box, Typography } from '@mui/material'
|
|
2
|
+
import { Meta, StoryObj } from '@storybook/react'
|
|
3
|
+
import { Fragment } from 'react'
|
|
4
|
+
|
|
5
|
+
import RcSesBadge, { RcSesBadgeProps } from '@/components/common/Badge'
|
|
6
|
+
import FieldPreview from '@/components/storybook/FieldPreview'
|
|
7
|
+
import FieldView from '@/components/storybook/FieldView'
|
|
8
|
+
import Fields from '@/components/storybook/Fields'
|
|
9
|
+
import PreviewTitle from '@/components/storybook/PreviewTitle'
|
|
10
|
+
|
|
11
|
+
const variants: RcSesBadgeProps['variant'][] = [
|
|
12
|
+
'neutral',
|
|
13
|
+
'success',
|
|
14
|
+
'warning',
|
|
15
|
+
'error',
|
|
16
|
+
'info',
|
|
17
|
+
'brand',
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
const sizes: RcSesBadgeProps['size'][] = ['small', 'regular']
|
|
21
|
+
|
|
22
|
+
const meta: Meta<typeof RcSesBadge> = {
|
|
23
|
+
title: 'components/display/Badge',
|
|
24
|
+
component: RcSesBadge,
|
|
25
|
+
tags: ['autodocs'],
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default meta
|
|
29
|
+
|
|
30
|
+
type Story = StoryObj<typeof RcSesBadge>
|
|
31
|
+
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Main (interactive / configurable via Controls panel)
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
export const Main: Story = {
|
|
37
|
+
render: (args) => (
|
|
38
|
+
<Fields>
|
|
39
|
+
<FieldView>
|
|
40
|
+
<RcSesBadge {...args} />
|
|
41
|
+
</FieldView>
|
|
42
|
+
</Fields>
|
|
43
|
+
),
|
|
44
|
+
args: {
|
|
45
|
+
label: 'Dabartinė',
|
|
46
|
+
variant: 'success',
|
|
47
|
+
size: 'regular',
|
|
48
|
+
showIcon: true,
|
|
49
|
+
showClose: false,
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Matrix — all 6 Type x 2 Size x show icon x show close combinations
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
const combos: { key: string; label: string; showIcon: boolean; showClose: boolean }[] = [
|
|
58
|
+
{ key: 'icon', label: 'Icon', showIcon: true, showClose: false },
|
|
59
|
+
{ key: 'close', label: 'Close', showIcon: false, showClose: true },
|
|
60
|
+
{ key: 'both', label: 'Icon + Close', showIcon: true, showClose: true },
|
|
61
|
+
{ key: 'plain', label: 'Plain', showIcon: false, showClose: false },
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
export const AllCombinations: Story = {
|
|
65
|
+
render: () => (
|
|
66
|
+
<>
|
|
67
|
+
<PreviewTitle>
|
|
68
|
+
6 types × 2 sizes × show icon × show close = 48 variants
|
|
69
|
+
</PreviewTitle>
|
|
70
|
+
<Box
|
|
71
|
+
sx={{
|
|
72
|
+
display: 'grid',
|
|
73
|
+
gridTemplateColumns: '90px 70px repeat(4, 1fr)',
|
|
74
|
+
rowGap: 1.5,
|
|
75
|
+
columnGap: 2,
|
|
76
|
+
alignItems: 'center',
|
|
77
|
+
maxWidth: 720,
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
<Box />
|
|
81
|
+
<Box />
|
|
82
|
+
{combos.map((combo) => (
|
|
83
|
+
<Typography
|
|
84
|
+
key={combo.key}
|
|
85
|
+
align='center'
|
|
86
|
+
color='text.secondary'
|
|
87
|
+
variant='body2'
|
|
88
|
+
>
|
|
89
|
+
{combo.label}
|
|
90
|
+
</Typography>
|
|
91
|
+
))}
|
|
92
|
+
{variants.map((variant) =>
|
|
93
|
+
sizes.map((size, sizeIndex) => (
|
|
94
|
+
<Fragment key={`${variant}-${size}`}>
|
|
95
|
+
{sizeIndex === 0 && (
|
|
96
|
+
<Typography sx={{ gridRow: 'span 2' }} variant='body2' fontWeight={600}>
|
|
97
|
+
{variant}
|
|
98
|
+
</Typography>
|
|
99
|
+
)}
|
|
100
|
+
<Typography color='text.secondary' variant='body2'>
|
|
101
|
+
{size}
|
|
102
|
+
</Typography>
|
|
103
|
+
{combos.map((combo) => (
|
|
104
|
+
<Box key={combo.key} display='flex' justifyContent='center'>
|
|
105
|
+
<RcSesBadge
|
|
106
|
+
label='Label'
|
|
107
|
+
variant={variant}
|
|
108
|
+
size={size}
|
|
109
|
+
showIcon={combo.showIcon}
|
|
110
|
+
showClose={combo.showClose}
|
|
111
|
+
onClose={combo.showClose ? () => {} : undefined}
|
|
112
|
+
/>
|
|
113
|
+
</Box>
|
|
114
|
+
))}
|
|
115
|
+
</Fragment>
|
|
116
|
+
)),
|
|
117
|
+
)}
|
|
118
|
+
</Box>
|
|
119
|
+
</>
|
|
120
|
+
),
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
// Edge cases
|
|
125
|
+
// ---------------------------------------------------------------------------
|
|
126
|
+
|
|
127
|
+
export const LongLabel: Story = {
|
|
128
|
+
render: () => (
|
|
129
|
+
<Fields>
|
|
130
|
+
<FieldView>
|
|
131
|
+
<PreviewTitle>
|
|
132
|
+
truncated in a constrained container (hover/focus for full text)
|
|
133
|
+
</PreviewTitle>
|
|
134
|
+
<Box sx={{ maxWidth: 160 }}>
|
|
135
|
+
<RcSesBadge
|
|
136
|
+
label='Labai ilgas būsenos pavadinimas, kuris netelpa'
|
|
137
|
+
variant='info'
|
|
138
|
+
size='regular'
|
|
139
|
+
showClose
|
|
140
|
+
onClose={() => {}}
|
|
141
|
+
/>
|
|
142
|
+
</Box>
|
|
143
|
+
</FieldView>
|
|
144
|
+
<FieldPreview>
|
|
145
|
+
<PreviewTitle>grows freely when space allows</PreviewTitle>
|
|
146
|
+
<RcSesBadge
|
|
147
|
+
label='Labai ilgas būsenos pavadinimas, kuris netelpa'
|
|
148
|
+
variant='info'
|
|
149
|
+
size='regular'
|
|
150
|
+
/>
|
|
151
|
+
</FieldPreview>
|
|
152
|
+
</Fields>
|
|
153
|
+
),
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export const BaselineAlignment: Story = {
|
|
157
|
+
render: () => (
|
|
158
|
+
<FieldView>
|
|
159
|
+
<Typography variant='body1' component='p'>
|
|
160
|
+
Įrašo būsena: <RcSesBadge label='Dabartinė' variant='success' size='small' />{' '}
|
|
161
|
+
greta teksto eilutėje.
|
|
162
|
+
</Typography>
|
|
163
|
+
</FieldView>
|
|
164
|
+
),
|
|
165
|
+
}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import type { Meta } from '@storybook/react'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import RcSesSegmentedControl from '../../../components/common/SegmentedControl'
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'components/display/SegmentedControl',
|
|
8
|
+
component: RcSesSegmentedControl,
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'centered',
|
|
11
|
+
},
|
|
12
|
+
tags: ['autodocs'],
|
|
13
|
+
argTypes: {
|
|
14
|
+
options: {
|
|
15
|
+
control: false,
|
|
16
|
+
description: 'Array of options to display',
|
|
17
|
+
},
|
|
18
|
+
value: {
|
|
19
|
+
control: 'text',
|
|
20
|
+
description: 'Currently selected option ID',
|
|
21
|
+
},
|
|
22
|
+
onChange: {
|
|
23
|
+
control: false,
|
|
24
|
+
description: 'Callback when selection changes',
|
|
25
|
+
},
|
|
26
|
+
size: {
|
|
27
|
+
control: 'radio',
|
|
28
|
+
options: ['small', 'regular'],
|
|
29
|
+
description: 'Size of the segmented control',
|
|
30
|
+
},
|
|
31
|
+
role: {
|
|
32
|
+
control: 'radio',
|
|
33
|
+
options: ['radiogroup', 'tablist'],
|
|
34
|
+
description: 'ARIA role for accessibility',
|
|
35
|
+
},
|
|
36
|
+
disableBg: {
|
|
37
|
+
control: 'boolean',
|
|
38
|
+
description: 'Disable container background',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
} satisfies Meta<typeof RcSesSegmentedControl>
|
|
42
|
+
|
|
43
|
+
export default meta
|
|
44
|
+
|
|
45
|
+
const DefaultComponent = ({
|
|
46
|
+
options,
|
|
47
|
+
value: initialValue,
|
|
48
|
+
onChange,
|
|
49
|
+
size,
|
|
50
|
+
role,
|
|
51
|
+
disableBg,
|
|
52
|
+
}: any) => {
|
|
53
|
+
const [value, setValue] = useState(initialValue)
|
|
54
|
+
return (
|
|
55
|
+
<RcSesSegmentedControl
|
|
56
|
+
options={options}
|
|
57
|
+
value={value}
|
|
58
|
+
onChange={(newValue) => {
|
|
59
|
+
setValue(newValue)
|
|
60
|
+
onChange?.(newValue)
|
|
61
|
+
}}
|
|
62
|
+
size={size}
|
|
63
|
+
role={role}
|
|
64
|
+
disableBg={disableBg}
|
|
65
|
+
/>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const Default = {
|
|
70
|
+
args: {
|
|
71
|
+
options: [
|
|
72
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
73
|
+
{ id: '2', label: 'Juridinis asmuo' },
|
|
74
|
+
{ id: '3', label: 'Advokatas' },
|
|
75
|
+
],
|
|
76
|
+
value: '1',
|
|
77
|
+
onChange: () => {},
|
|
78
|
+
size: 'regular' as const,
|
|
79
|
+
role: 'radiogroup' as const,
|
|
80
|
+
disableBg: false,
|
|
81
|
+
},
|
|
82
|
+
render: ({ options, value: initialValue, onChange, size, role, disableBg }: any) => (
|
|
83
|
+
<DefaultComponent
|
|
84
|
+
options={options}
|
|
85
|
+
value={initialValue}
|
|
86
|
+
onChange={onChange}
|
|
87
|
+
size={size}
|
|
88
|
+
role={role}
|
|
89
|
+
disableBg={disableBg}
|
|
90
|
+
/>
|
|
91
|
+
),
|
|
92
|
+
} as const
|
|
93
|
+
|
|
94
|
+
export const RegularTwoOptions = {
|
|
95
|
+
args: {
|
|
96
|
+
options: [
|
|
97
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
98
|
+
{ id: '2', label: 'Juridinis asmuo' },
|
|
99
|
+
],
|
|
100
|
+
value: '1',
|
|
101
|
+
size: 'regular',
|
|
102
|
+
},
|
|
103
|
+
render: (args: any) => <DefaultComponent {...args} />,
|
|
104
|
+
parameters: {
|
|
105
|
+
docs: {
|
|
106
|
+
source: {
|
|
107
|
+
code: `const [value, setValue] = useState('1');
|
|
108
|
+
|
|
109
|
+
<RcSesSegmentedControl
|
|
110
|
+
options={[
|
|
111
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
112
|
+
{ id: '2', label: 'Juridinis asmuo' },
|
|
113
|
+
]}
|
|
114
|
+
value={value}
|
|
115
|
+
onChange={(newValue) => setValue(newValue)}
|
|
116
|
+
size="regular"
|
|
117
|
+
/>`,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
} as const
|
|
122
|
+
|
|
123
|
+
export const RegularFourOptions = {
|
|
124
|
+
args: {
|
|
125
|
+
options: [
|
|
126
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
127
|
+
{ id: '2', label: 'Juridinis asmuo' },
|
|
128
|
+
{ id: '3', label: 'Advokatas' },
|
|
129
|
+
{ id: '4', label: 'Labai ilgas tekstas, netelpantis į vieną eilutę' },
|
|
130
|
+
],
|
|
131
|
+
value: '1',
|
|
132
|
+
size: 'regular',
|
|
133
|
+
},
|
|
134
|
+
render: (args: any) => <DefaultComponent {...args} />,
|
|
135
|
+
parameters: {
|
|
136
|
+
docs: {
|
|
137
|
+
source: {
|
|
138
|
+
code: `const [value, setValue] = useState('1');
|
|
139
|
+
|
|
140
|
+
<RcSesSegmentedControl
|
|
141
|
+
options={[
|
|
142
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
143
|
+
{ id: '2', label: 'Juridinis asmuo' },
|
|
144
|
+
{ id: '3', label: 'Advokatas' },
|
|
145
|
+
{ id: '4', label: 'Labai ilgas tekstas, netelpantis į vieną eilutę' },
|
|
146
|
+
]}
|
|
147
|
+
value={value}
|
|
148
|
+
onChange={(newValue) => setValue(newValue)}
|
|
149
|
+
size="regular"
|
|
150
|
+
/>`,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export const RegularWithDisabled = {
|
|
157
|
+
args: {
|
|
158
|
+
options: [
|
|
159
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
160
|
+
{ id: '2', label: 'Juridinis asmuo (Disabled)', disabled: true },
|
|
161
|
+
{ id: '3', label: 'Advokatas' },
|
|
162
|
+
],
|
|
163
|
+
value: '1',
|
|
164
|
+
size: 'regular',
|
|
165
|
+
},
|
|
166
|
+
render: (args: any) => <DefaultComponent {...args} />,
|
|
167
|
+
parameters: {
|
|
168
|
+
docs: {
|
|
169
|
+
source: {
|
|
170
|
+
code: `const [value, setValue] = useState('1');
|
|
171
|
+
|
|
172
|
+
<RcSesSegmentedControl
|
|
173
|
+
options={[
|
|
174
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
175
|
+
{ id: '2', label: 'Juridinis asmuo', disabled: true },
|
|
176
|
+
{ id: '3', label: 'Advokatas' },
|
|
177
|
+
]}
|
|
178
|
+
value={value}
|
|
179
|
+
onChange={(newValue) => setValue(newValue)}
|
|
180
|
+
size="regular"
|
|
181
|
+
/>`,
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export const SmallTwoOptions = {
|
|
188
|
+
args: {
|
|
189
|
+
options: [
|
|
190
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
191
|
+
{ id: '2', label: 'Juridinis asmuo' },
|
|
192
|
+
],
|
|
193
|
+
value: '1',
|
|
194
|
+
size: 'small',
|
|
195
|
+
},
|
|
196
|
+
render: (args: any) => <DefaultComponent {...args} />,
|
|
197
|
+
parameters: {
|
|
198
|
+
docs: {
|
|
199
|
+
source: {
|
|
200
|
+
code: `const [value, setValue] = useState('1');
|
|
201
|
+
|
|
202
|
+
<RcSesSegmentedControl
|
|
203
|
+
options={[
|
|
204
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
205
|
+
{ id: '2', label: 'Juridinis asmuo' },
|
|
206
|
+
]}
|
|
207
|
+
value={value}
|
|
208
|
+
onChange={(newValue) => setValue(newValue)}
|
|
209
|
+
size="small"
|
|
210
|
+
/>`,
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
} as const
|
|
215
|
+
|
|
216
|
+
export const SmallFourOptions = {
|
|
217
|
+
args: {
|
|
218
|
+
options: [
|
|
219
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
220
|
+
{ id: '2', label: 'Juridinis asmuo' },
|
|
221
|
+
{ id: '3', label: 'Advokatas' },
|
|
222
|
+
{ id: '4', label: 'Kita' },
|
|
223
|
+
],
|
|
224
|
+
value: '1',
|
|
225
|
+
size: 'small',
|
|
226
|
+
},
|
|
227
|
+
render: (args: any) => <DefaultComponent {...args} />,
|
|
228
|
+
parameters: {
|
|
229
|
+
docs: {
|
|
230
|
+
source: {
|
|
231
|
+
code: `const [value, setValue] = useState('1');
|
|
232
|
+
|
|
233
|
+
<RcSesSegmentedControl
|
|
234
|
+
options={[
|
|
235
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
236
|
+
{ id: '2', label: 'Juridinis asmuo' },
|
|
237
|
+
{ id: '3', label: 'Advokatas' },
|
|
238
|
+
{ id: '4', label: 'Kita' },
|
|
239
|
+
]}
|
|
240
|
+
value={value}
|
|
241
|
+
onChange={(newValue) => setValue(newValue)}
|
|
242
|
+
size="small"
|
|
243
|
+
/>`,
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export const SmallWithDisabled = {
|
|
250
|
+
args: {
|
|
251
|
+
options: [
|
|
252
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
253
|
+
{ id: '2', label: 'Juridinis asmuo (Disabled)', disabled: true },
|
|
254
|
+
{ id: '3', label: 'Advokatas' },
|
|
255
|
+
],
|
|
256
|
+
value: '1',
|
|
257
|
+
size: 'small',
|
|
258
|
+
},
|
|
259
|
+
render: (args: any) => <DefaultComponent {...args} />,
|
|
260
|
+
parameters: {
|
|
261
|
+
docs: {
|
|
262
|
+
source: {
|
|
263
|
+
code: `const [value, setValue] = useState('1');
|
|
264
|
+
|
|
265
|
+
<RcSesSegmentedControl
|
|
266
|
+
options={[
|
|
267
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
268
|
+
{ id: '2', label: 'Juridinis asmuo', disabled: true },
|
|
269
|
+
{ id: '3', label: 'Advokatas' },
|
|
270
|
+
]}
|
|
271
|
+
value={value}
|
|
272
|
+
onChange={(newValue) => setValue(newValue)}
|
|
273
|
+
size="small"
|
|
274
|
+
/>`,
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export const RegularNoBackground = {
|
|
281
|
+
args: {
|
|
282
|
+
options: [
|
|
283
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
284
|
+
{ id: '2', label: 'Juridinis asmuo' },
|
|
285
|
+
{ id: '3', label: 'Advokatas' },
|
|
286
|
+
],
|
|
287
|
+
value: '1',
|
|
288
|
+
size: 'regular',
|
|
289
|
+
disableBg: true,
|
|
290
|
+
},
|
|
291
|
+
render: (args: any) => <DefaultComponent {...args} />,
|
|
292
|
+
parameters: {
|
|
293
|
+
docs: {
|
|
294
|
+
source: {
|
|
295
|
+
code: `const [value, setValue] = useState('1');
|
|
296
|
+
|
|
297
|
+
<RcSesSegmentedControl
|
|
298
|
+
options={[
|
|
299
|
+
{ id: '1', label: 'Fizinis asmuo' },
|
|
300
|
+
{ id: '2', label: 'Juridinis asmuo' },
|
|
301
|
+
{ id: '3', label: 'Advokatas' },
|
|
302
|
+
]}
|
|
303
|
+
value={value}
|
|
304
|
+
onChange={(newValue) => setValue(newValue)}
|
|
305
|
+
size="regular"
|
|
306
|
+
disableBg
|
|
307
|
+
/>`,
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import RcSesSwitch from '@/components/common/Switch'
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'components/inputs/Switch',
|
|
8
|
+
component: RcSesSwitch,
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'centered',
|
|
11
|
+
},
|
|
12
|
+
tags: ['autodocs'],
|
|
13
|
+
} satisfies Meta<typeof RcSesSwitch>
|
|
14
|
+
|
|
15
|
+
export default meta
|
|
16
|
+
type Story = StoryObj<typeof meta>
|
|
17
|
+
|
|
18
|
+
type ControlledDemoProps = {
|
|
19
|
+
initialChecked?: boolean
|
|
20
|
+
disabled?: boolean
|
|
21
|
+
label?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function ControlledDemo({
|
|
25
|
+
initialChecked = false,
|
|
26
|
+
disabled = false,
|
|
27
|
+
label = 'Notifications',
|
|
28
|
+
}: ControlledDemoProps) {
|
|
29
|
+
const [checked, setChecked] = useState(initialChecked)
|
|
30
|
+
return (
|
|
31
|
+
<RcSesSwitch
|
|
32
|
+
label={label}
|
|
33
|
+
checked={checked}
|
|
34
|
+
disabled={disabled}
|
|
35
|
+
onChange={(_event, value) => setChecked(value)}
|
|
36
|
+
/>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const On: Story = {
|
|
41
|
+
args: { label: 'Notifications', checked: true, onChange: () => {} },
|
|
42
|
+
render: () => <ControlledDemo initialChecked />,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const Off: Story = {
|
|
46
|
+
args: { label: 'Notifications', checked: false, onChange: () => {} },
|
|
47
|
+
render: () => <ControlledDemo />,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const OnDisabled: Story = {
|
|
51
|
+
name: 'On, Disabled',
|
|
52
|
+
args: { label: 'Notifications', checked: true, onChange: () => {} },
|
|
53
|
+
render: () => <ControlledDemo initialChecked disabled />,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const OffDisabled: Story = {
|
|
57
|
+
name: 'Off, Disabled',
|
|
58
|
+
args: { label: 'Notifications', checked: false, onChange: () => {} },
|
|
59
|
+
render: () => <ControlledDemo disabled />,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const LongLabel: Story = {
|
|
63
|
+
name: 'Long label',
|
|
64
|
+
args: { label: 'Notifications', checked: false, onChange: () => {} },
|
|
65
|
+
render: () => (
|
|
66
|
+
<div style={{ maxWidth: '16rem' }}>
|
|
67
|
+
<ControlledDemo label='Send me an email whenever there is a new comment on any of my open service requests' />
|
|
68
|
+
</div>
|
|
69
|
+
),
|
|
70
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Components } from '@mui/material'
|
|
2
|
+
|
|
3
|
+
import palette, { common } from '../palette'
|
|
4
|
+
|
|
5
|
+
const MuiSwitch: Components['MuiSwitch'] = {
|
|
6
|
+
defaultProps: {
|
|
7
|
+
disableRipple: true,
|
|
8
|
+
},
|
|
9
|
+
styleOverrides: {
|
|
10
|
+
root: {
|
|
11
|
+
width: '2.25rem',
|
|
12
|
+
height: '1.25rem',
|
|
13
|
+
padding: 0,
|
|
14
|
+
},
|
|
15
|
+
switchBase: {
|
|
16
|
+
padding: 0,
|
|
17
|
+
margin: '0.125rem',
|
|
18
|
+
transition: 'transform 200ms ease-in-out',
|
|
19
|
+
|
|
20
|
+
'@media (prefers-reduced-motion: reduce)': {
|
|
21
|
+
transition: 'none',
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
'&:hover': {
|
|
25
|
+
backgroundColor: 'transparent',
|
|
26
|
+
},
|
|
27
|
+
'&:hover + .MuiSwitch-track': {
|
|
28
|
+
backgroundColor: palette.grey['500'], // unchecked hover
|
|
29
|
+
},
|
|
30
|
+
'&.Mui-focusVisible + .MuiSwitch-track': {
|
|
31
|
+
boxShadow: `0 0 0 2px ${common.white}, 0 0 0 4px ${palette.grey['950']}`, // DS focus ring, >=3:1 against surrounding background
|
|
32
|
+
},
|
|
33
|
+
'&.Mui-disabled + .MuiSwitch-track': {
|
|
34
|
+
backgroundColor: palette.grey['200'], // unchecked disabled
|
|
35
|
+
opacity: 1,
|
|
36
|
+
},
|
|
37
|
+
'&.Mui-disabled .MuiSwitch-thumb': {
|
|
38
|
+
color: common.white,
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
'&.Mui-checked': {
|
|
42
|
+
transform: 'translateX(1rem)',
|
|
43
|
+
color: common.white,
|
|
44
|
+
|
|
45
|
+
'& + .MuiSwitch-track': {
|
|
46
|
+
backgroundColor: palette.primary['500'], // checked default
|
|
47
|
+
opacity: 1,
|
|
48
|
+
border: 0,
|
|
49
|
+
},
|
|
50
|
+
'&:hover + .MuiSwitch-track': {
|
|
51
|
+
backgroundColor: palette.primary['600'], // checked hover
|
|
52
|
+
},
|
|
53
|
+
'&.Mui-disabled + .MuiSwitch-track': {
|
|
54
|
+
backgroundColor: palette.grey['500'], // checked disabled
|
|
55
|
+
opacity: 1,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
thumb: {
|
|
60
|
+
boxSizing: 'border-box',
|
|
61
|
+
width: '1rem',
|
|
62
|
+
height: '1rem',
|
|
63
|
+
borderRadius: '9999px',
|
|
64
|
+
backgroundColor: common.white,
|
|
65
|
+
boxShadow: '0 1px 2px 0 rgba(0, 0, 0, 0.18)',
|
|
66
|
+
},
|
|
67
|
+
track: {
|
|
68
|
+
borderRadius: '9999px',
|
|
69
|
+
backgroundColor: palette.grey['400'], // unchecked default
|
|
70
|
+
opacity: 1,
|
|
71
|
+
// kept active under prefers-reduced-motion: only the sliding transform is suppressed
|
|
72
|
+
transition: 'background-color 200ms ease-in-out',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default MuiSwitch
|
|
@@ -33,6 +33,7 @@ import MuiRadio from '@/theme/light/MuiRadio'
|
|
|
33
33
|
import MuiSelect from '@/theme/light/MuiSelect'
|
|
34
34
|
import MuiStepper from '@/theme/light/MuiStepper'
|
|
35
35
|
import MuiSvgIcon from '@/theme/light/MuiSvgIcon'
|
|
36
|
+
import MuiSwitch from '@/theme/light/MuiSwitch'
|
|
36
37
|
import MuiTab from '@/theme/light/MuiTab'
|
|
37
38
|
import MuiTable from '@/theme/light/MuiTable'
|
|
38
39
|
import MuiTableCell from '@/theme/light/MuiTableCell'
|
|
@@ -124,6 +125,7 @@ const theme = createTheme(themePalette, ltLT, enUS, {
|
|
|
124
125
|
MuiSelect,
|
|
125
126
|
MuiStepper,
|
|
126
127
|
MuiSvgIcon,
|
|
128
|
+
MuiSwitch,
|
|
127
129
|
MuiTab,
|
|
128
130
|
MuiTabs,
|
|
129
131
|
MuiTable,
|