@registrucentras/rc-ses-react-components 1.10.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/components/common/Badge/index.d.ts +10 -0
- package/dist/components/common/Switch/index.d.ts +10 -0
- package/dist/library/index.d.ts +3 -1
- package/dist/registrucentras-rc-ses-react-components.cjs +10 -10
- package/dist/registrucentras-rc-ses-react-components.js +2016 -1789
- package/dist/stories/components/display/Badge.stories.d.ts +9 -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/components/common/Badge/index.test.tsx +129 -0
- package/src/components/common/Badge/index.tsx +162 -0
- package/src/components/common/Switch/index.test.tsx +214 -0
- package/src/components/common/Switch/index.tsx +49 -0
- package/src/i18n/namespaces/input/en.json +6 -0
- package/src/i18n/namespaces/input/lt.json +6 -0
- package/src/library/index.ts +4 -0
- package/src/stories/components/display/Badge.stories.tsx +165 -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,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,
|