@registrucentras/rc-ses-react-components 2.0.0-rc.1 → 2.0.0-rc.3
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/CardShell/CardFooter/index.d.ts +3 -0
- package/dist/components/common/CardShell/CardFooter/types.d.ts +21 -0
- package/dist/components/common/CardShell/CardHeader/index.d.ts +3 -0
- package/dist/components/common/CardShell/CardHeader/types.d.ts +33 -0
- package/dist/components/common/CardShell/index.d.ts +5 -0
- package/dist/components/common/CardShell/types.d.ts +24 -0
- package/dist/components/form/inputs/Select/index.d.ts +1 -0
- package/dist/library/index.d.ts +4 -1
- package/dist/library/types.d.ts +4 -1
- package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
- package/dist/registrucentras-rc-ses-react-components.js +2634 -2319
- package/dist/stories/components/display/AdvancedList.stories.d.ts +1 -0
- package/dist/stories/components/display/CardShell.stories.d.ts +17 -0
- package/dist/stories/components/inputs/DatePicker.stories.d.ts +107 -0
- package/dist/theme/cards.d.ts +114 -0
- package/dist/theme/light/MuiPickersOutlinedInput.d.ts +8 -0
- package/package.json +1 -1
- package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.tsx +6 -2
- package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.tsx +11 -4
- package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +12 -4
- package/src/components/common/Card/index.tsx +2 -2
- package/src/components/common/CardShell/CardFooter/index.test.tsx +52 -0
- package/src/components/common/CardShell/CardFooter/index.tsx +38 -0
- package/src/components/common/CardShell/CardFooter/types.ts +24 -0
- package/src/components/common/CardShell/CardHeader/index.test.tsx +207 -0
- package/src/components/common/CardShell/CardHeader/index.tsx +104 -0
- package/src/components/common/CardShell/CardHeader/types.ts +36 -0
- package/src/components/common/CardShell/index.test.tsx +137 -0
- package/src/components/common/CardShell/index.tsx +75 -0
- package/src/components/common/CardShell/types.ts +28 -0
- package/src/components/form/inputs/Datepicker/index.test.tsx +117 -0
- package/src/components/form/inputs/FileDropzone.tsx +1 -0
- package/src/components/form/inputs/FileUpload.tsx +1 -0
- package/src/components/form/inputs/NumberStepper.tsx +1 -0
- package/src/components/form/inputs/PhoneInputFormControl/index.tsx +1 -1
- package/src/components/form/inputs/RadioButtonGroup.test.tsx +71 -0
- package/src/components/form/inputs/RadioButtonGroup.tsx +1 -0
- package/src/components/form/inputs/Select/index.test.tsx +57 -0
- package/src/components/form/inputs/Select/index.tsx +2 -0
- package/src/components/layout/Footer/index.test.tsx +13 -0
- package/src/components/layout/Footer/index.tsx +5 -2
- package/src/library/index.ts +6 -0
- package/src/library/types.ts +26 -0
- package/src/stories/components/display/AdvancedList.stories.tsx +131 -0
- package/src/stories/components/display/CardShell.stories.tsx +261 -0
- package/src/stories/components/inputs/DatePicker.stories.tsx +105 -9
- package/src/theme/cards.ts +60 -0
- package/src/theme/light/MuiPickersLayout.ts +10 -1
- package/src/theme/light/MuiPickersOutlinedInput.ts +88 -0
- package/src/theme/light/index.tsx +2 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { ThemeProvider } from '@mui/material/styles'
|
|
2
|
+
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns'
|
|
3
|
+
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'
|
|
4
|
+
import '@testing-library/jest-dom'
|
|
5
|
+
import { render, screen } from '@testing-library/react'
|
|
6
|
+
import { lt } from 'date-fns/locale/lt'
|
|
7
|
+
import { useForm } from 'react-hook-form'
|
|
8
|
+
import { describe, expect, test } from 'vitest'
|
|
9
|
+
|
|
10
|
+
import theme from '@/theme/light'
|
|
11
|
+
import palette, { common } from '@/theme/palette'
|
|
12
|
+
|
|
13
|
+
import RcSesDatepicker from '.'
|
|
14
|
+
|
|
15
|
+
// Pinned so the calendar does not follow the current date.
|
|
16
|
+
const REFERENCE = new Date(2026, 0, 15)
|
|
17
|
+
const MAX = new Date(2026, 0, 20)
|
|
18
|
+
|
|
19
|
+
type HarnessProps = {
|
|
20
|
+
/** Seeds the field, so a day renders as selected. */
|
|
21
|
+
value?: string | null
|
|
22
|
+
/** Bounds the calendar, so later days render as disabled. */
|
|
23
|
+
maxDate?: Date
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function Harness({ value = null, maxDate }: HarnessProps) {
|
|
27
|
+
const {
|
|
28
|
+
control,
|
|
29
|
+
formState: { errors },
|
|
30
|
+
} = useForm<{ date: string | null }>({ defaultValues: { date: value } })
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<ThemeProvider theme={theme}>
|
|
34
|
+
<LocalizationProvider dateAdapter={AdapterDateFns} adapterLocale={lt}>
|
|
35
|
+
<RcSesDatepicker
|
|
36
|
+
id='date'
|
|
37
|
+
name='date'
|
|
38
|
+
control={control}
|
|
39
|
+
label='Data'
|
|
40
|
+
errors={errors?.date}
|
|
41
|
+
slotProps={{
|
|
42
|
+
datepicker: { open: true, referenceDate: REFERENCE, maxDate },
|
|
43
|
+
}}
|
|
44
|
+
/>
|
|
45
|
+
</LocalizationProvider>
|
|
46
|
+
</ThemeProvider>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const rgb = (hex: string) => {
|
|
51
|
+
const n = parseInt(hex.slice(1), 16)
|
|
52
|
+
// eslint-disable-next-line no-bitwise
|
|
53
|
+
return `rgb(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255})`
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const dayColour = (label: string) =>
|
|
57
|
+
window.getComputedStyle(screen.getByRole('gridcell', { name: label })).color
|
|
58
|
+
|
|
59
|
+
describe('RcSesDatepicker calendar day colours', () => {
|
|
60
|
+
// Pinned here rather than left to the visual suite: a colour-only change on a
|
|
61
|
+
// few glyphs stays under its diff budget.
|
|
62
|
+
test('a selectable weekday uses the default day colour', () => {
|
|
63
|
+
render(<Harness maxDate={MAX} />)
|
|
64
|
+
|
|
65
|
+
expect(dayColour('19')).toBe(rgb(palette.grey['900']))
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('a disabled weekday is greyed out', () => {
|
|
69
|
+
render(<Harness maxDate={MAX} />)
|
|
70
|
+
|
|
71
|
+
expect(dayColour('21')).toBe(rgb(palette.grey['400']))
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
// 1.x paints it white; v9 lost that to the theme's day colour.
|
|
75
|
+
test('the selected day is white on the blue fill', () => {
|
|
76
|
+
render(<Harness value='2026-01-15T00:00:00.000Z' />)
|
|
77
|
+
|
|
78
|
+
const selected = document.querySelector('.Mui-selected') as HTMLElement
|
|
79
|
+
const cs = window.getComputedStyle(selected)
|
|
80
|
+
|
|
81
|
+
expect(cs.backgroundColor).toBe(rgb(palette.primary['500']))
|
|
82
|
+
expect(cs.color).toBe(rgb(common.white))
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('a disabled weekend day stays red, as in 1.x', () => {
|
|
86
|
+
render(<Harness maxDate={MAX} />)
|
|
87
|
+
|
|
88
|
+
expect(dayColour('24')).toBe(rgb(palette.error['600']))
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
// The picker field is not a MUI OutlinedInput, so it needs its own overrides to
|
|
93
|
+
// match the other inputs.
|
|
94
|
+
describe('RcSesDatepicker field styling', () => {
|
|
95
|
+
test('the field keeps the shared input radius and background', () => {
|
|
96
|
+
render(<Harness />)
|
|
97
|
+
|
|
98
|
+
const field = document.querySelector('.MuiPickersInputBase-root') as HTMLElement
|
|
99
|
+
const cs = window.getComputedStyle(field)
|
|
100
|
+
|
|
101
|
+
expect(cs.borderRadius).toBe('0.5rem')
|
|
102
|
+
expect(cs.backgroundColor).toBe(rgb(common.white))
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('the value text matches a plain input', () => {
|
|
106
|
+
render(<Harness />)
|
|
107
|
+
|
|
108
|
+
const sections = document.querySelector(
|
|
109
|
+
'.MuiPickersInputBase-sectionsContainer',
|
|
110
|
+
) as HTMLElement
|
|
111
|
+
const cs = window.getComputedStyle(sections)
|
|
112
|
+
|
|
113
|
+
expect(cs.fontSize).toBe('0.9375rem')
|
|
114
|
+
expect(cs.height).toBe('1.125rem')
|
|
115
|
+
expect(cs.color).toBe(rgb(palette.grey['900']))
|
|
116
|
+
})
|
|
117
|
+
})
|
|
@@ -179,7 +179,7 @@ function RcSesPhoneInputFormControl(props: Props) {
|
|
|
179
179
|
</InputAdornment>
|
|
180
180
|
|
|
181
181
|
<InputAdornment position='start'>
|
|
182
|
-
<Typography
|
|
182
|
+
<Typography sx={{ color: palette.grey[900] }} component='span'>
|
|
183
183
|
{country.code}
|
|
184
184
|
</Typography>
|
|
185
185
|
</InputAdornment>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ThemeProvider } from '@mui/material/styles'
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react'
|
|
3
|
+
import { useState } from 'react'
|
|
4
|
+
import { useForm } from 'react-hook-form'
|
|
5
|
+
|
|
6
|
+
import theme from '@/theme/light'
|
|
7
|
+
|
|
8
|
+
import RcSesRadioButtonGroup from './RadioButtonGroup'
|
|
9
|
+
|
|
10
|
+
const options = [
|
|
11
|
+
{ label: 'Fizinis asmuo', value: 'natural' },
|
|
12
|
+
{ label: 'Juridinis asmuo', value: 'legal' },
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
type TestWrapperProps = {
|
|
16
|
+
shouldUnregister?: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const TestWrapper = ({ shouldUnregister }: TestWrapperProps) => {
|
|
20
|
+
const { control, getValues } = useForm({
|
|
21
|
+
defaultValues: { ownerType: 'natural' },
|
|
22
|
+
})
|
|
23
|
+
const [mounted, setMounted] = useState(true)
|
|
24
|
+
const [formValues, setFormValues] = useState('')
|
|
25
|
+
|
|
26
|
+
const slotProps =
|
|
27
|
+
shouldUnregister === undefined ? undefined : { controller: { shouldUnregister } }
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<ThemeProvider theme={theme}>
|
|
31
|
+
{mounted && (
|
|
32
|
+
<RcSesRadioButtonGroup
|
|
33
|
+
id='ownerType'
|
|
34
|
+
name='ownerType'
|
|
35
|
+
control={control}
|
|
36
|
+
label='Savininko tipas'
|
|
37
|
+
options={options}
|
|
38
|
+
slotProps={slotProps}
|
|
39
|
+
/>
|
|
40
|
+
)}
|
|
41
|
+
|
|
42
|
+
<button type='button' onClick={() => setMounted(false)}>
|
|
43
|
+
Hide
|
|
44
|
+
</button>
|
|
45
|
+
<button type='button' onClick={() => setFormValues(JSON.stringify(getValues()))}>
|
|
46
|
+
Read
|
|
47
|
+
</button>
|
|
48
|
+
<div data-testid='form-values'>{formValues}</div>
|
|
49
|
+
</ThemeProvider>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe('RcSesRadioButtonGroup', () => {
|
|
54
|
+
test('keeps the value in the form by default when the field unmounts', () => {
|
|
55
|
+
render(<TestWrapper />)
|
|
56
|
+
|
|
57
|
+
fireEvent.click(screen.getByRole('button', { name: 'Hide' }))
|
|
58
|
+
fireEvent.click(screen.getByRole('button', { name: 'Read' }))
|
|
59
|
+
|
|
60
|
+
expect(screen.getByTestId('form-values')).toHaveTextContent('natural')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('drops the value when slotProps.controller turns shouldUnregister on', () => {
|
|
64
|
+
render(<TestWrapper shouldUnregister />)
|
|
65
|
+
|
|
66
|
+
fireEvent.click(screen.getByRole('button', { name: 'Hide' }))
|
|
67
|
+
fireEvent.click(screen.getByRole('button', { name: 'Read' }))
|
|
68
|
+
|
|
69
|
+
expect(screen.getByTestId('form-values')).not.toHaveTextContent('natural')
|
|
70
|
+
})
|
|
71
|
+
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ThemeProvider } from '@mui/material/styles'
|
|
2
2
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
3
|
+
import { useState } from 'react'
|
|
3
4
|
import { useForm } from 'react-hook-form'
|
|
4
5
|
|
|
5
6
|
import theme from '@/theme/light'
|
|
@@ -21,6 +22,44 @@ const options = [
|
|
|
21
22
|
},
|
|
22
23
|
]
|
|
23
24
|
|
|
25
|
+
type UnregisterTestWrapperProps = {
|
|
26
|
+
shouldUnregister?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const UnregisterTestWrapper = ({ shouldUnregister }: UnregisterTestWrapperProps) => {
|
|
30
|
+
const { control, getValues } = useForm({
|
|
31
|
+
defaultValues: { selection: 'short-option' as string | null },
|
|
32
|
+
})
|
|
33
|
+
const [mounted, setMounted] = useState(true)
|
|
34
|
+
const [formValues, setFormValues] = useState('')
|
|
35
|
+
|
|
36
|
+
const slotProps =
|
|
37
|
+
shouldUnregister === undefined ? undefined : { controller: { shouldUnregister } }
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<ThemeProvider theme={theme}>
|
|
41
|
+
{mounted && (
|
|
42
|
+
<RcSesSelect
|
|
43
|
+
id='selection'
|
|
44
|
+
name='selection'
|
|
45
|
+
control={control}
|
|
46
|
+
label='Pasirinkti'
|
|
47
|
+
options={options}
|
|
48
|
+
slotProps={slotProps}
|
|
49
|
+
/>
|
|
50
|
+
)}
|
|
51
|
+
|
|
52
|
+
<button type='button' onClick={() => setMounted(false)}>
|
|
53
|
+
Hide
|
|
54
|
+
</button>
|
|
55
|
+
<button type='button' onClick={() => setFormValues(JSON.stringify(getValues()))}>
|
|
56
|
+
Read
|
|
57
|
+
</button>
|
|
58
|
+
<div data-testid='form-values'>{formValues}</div>
|
|
59
|
+
</ThemeProvider>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
24
63
|
const TestWrapper = ({ defaultValue = null }: TestWrapperProps) => {
|
|
25
64
|
const { control } = useForm({
|
|
26
65
|
defaultValues: {
|
|
@@ -99,4 +138,22 @@ describe('RcSesSelect', () => {
|
|
|
99
138
|
|
|
100
139
|
expect(screen.getByRole('combobox')).toHaveAttribute('readonly')
|
|
101
140
|
})
|
|
141
|
+
|
|
142
|
+
test('drops the value from the form by default when the field unmounts', () => {
|
|
143
|
+
render(<UnregisterTestWrapper />)
|
|
144
|
+
|
|
145
|
+
fireEvent.click(screen.getByRole('button', { name: 'Hide' }))
|
|
146
|
+
fireEvent.click(screen.getByRole('button', { name: 'Read' }))
|
|
147
|
+
|
|
148
|
+
expect(screen.getByTestId('form-values')).not.toHaveTextContent('short-option')
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
test('keeps the value when slotProps.controller turns shouldUnregister off', () => {
|
|
152
|
+
render(<UnregisterTestWrapper shouldUnregister={false} />)
|
|
153
|
+
|
|
154
|
+
fireEvent.click(screen.getByRole('button', { name: 'Hide' }))
|
|
155
|
+
fireEvent.click(screen.getByRole('button', { name: 'Read' }))
|
|
156
|
+
|
|
157
|
+
expect(screen.getByTestId('form-values')).toHaveTextContent('short-option')
|
|
158
|
+
})
|
|
102
159
|
})
|
|
@@ -42,6 +42,7 @@ type Props = Pick<TControllerProps, ImmediateControllerProps> &
|
|
|
42
42
|
onInputChange?: AutocompleteProps<Option, boolean, boolean, false>['onInputChange']
|
|
43
43
|
|
|
44
44
|
slotProps?: {
|
|
45
|
+
controller?: Partial<Omit<TControllerProps, ImmediateControllerProps>>
|
|
45
46
|
field?: Partial<
|
|
46
47
|
Omit<
|
|
47
48
|
AutocompleteProps<Option, boolean, boolean, false>,
|
|
@@ -94,6 +95,7 @@ function RcSesSelect(props: Props) {
|
|
|
94
95
|
name,
|
|
95
96
|
rules,
|
|
96
97
|
shouldUnregister: true,
|
|
98
|
+
...slotProps?.controller,
|
|
97
99
|
})
|
|
98
100
|
|
|
99
101
|
const hasError = !!errors
|
|
@@ -17,4 +17,17 @@ describe('RcSesFooter', () => {
|
|
|
17
17
|
|
|
18
18
|
expect(screen.getByText('Footer text')).toBeInTheDocument()
|
|
19
19
|
})
|
|
20
|
+
|
|
21
|
+
// The footer sits on grey[900], so if the text colour is ever dropped it turns
|
|
22
|
+
// black on near black and the footer reads as an empty band. That is how it
|
|
23
|
+
// shipped in 2.0.0-rc.1: MUI 9 takes `color` only as a palette key, so a raw
|
|
24
|
+
// value handed to it is discarded. The visual suite does not catch this - the
|
|
25
|
+
// text is ~6.5k pixels of a 921k full page shot, under the 1% diff budget.
|
|
26
|
+
test('renders the text in grey[200] rather than inheriting', () => {
|
|
27
|
+
renderFooter(<RcSesFooter text='Footer text' />)
|
|
28
|
+
|
|
29
|
+
expect(window.getComputedStyle(screen.getByText('Footer text')).color).toBe(
|
|
30
|
+
'rgb(220, 224, 229)',
|
|
31
|
+
)
|
|
32
|
+
})
|
|
20
33
|
})
|
|
@@ -18,9 +18,12 @@ function RcSesFooter({ text }: Props) {
|
|
|
18
18
|
>
|
|
19
19
|
<Container>
|
|
20
20
|
<Typography
|
|
21
|
-
color={palette.grey['200']}
|
|
22
21
|
component='div'
|
|
23
|
-
sx={{
|
|
22
|
+
sx={{
|
|
23
|
+
color: palette.grey['200'],
|
|
24
|
+
lineHeight: '1.25rem',
|
|
25
|
+
whiteSpace: 'pre-line',
|
|
26
|
+
}}
|
|
24
27
|
variant='caption'
|
|
25
28
|
>
|
|
26
29
|
{text}
|
package/src/library/index.ts
CHANGED
|
@@ -13,6 +13,9 @@ import RcSesBreadcrumbs from '@/components/common/Breadcrumbs'
|
|
|
13
13
|
import RcSesButton from '@/components/common/Button'
|
|
14
14
|
import RcSesButtonWithPopover from '@/components/common/Button/ButtonWithPopover'
|
|
15
15
|
import RcSesCard from '@/components/common/Card'
|
|
16
|
+
import RcSesCardShell from '@/components/common/CardShell'
|
|
17
|
+
import RcSesCardFooter from '@/components/common/CardShell/CardFooter'
|
|
18
|
+
import RcSesCardHeader from '@/components/common/CardShell/CardHeader'
|
|
16
19
|
import DataPagination from '@/components/common/DataPagination'
|
|
17
20
|
import RcSesIconWithCircularBackground from '@/components/common/IconWithCircularBackground'
|
|
18
21
|
import RcSesImageCard from '@/components/common/ImageCard'
|
|
@@ -81,6 +84,9 @@ export {
|
|
|
81
84
|
RcSesLoader,
|
|
82
85
|
RcSesLoadingSpinner,
|
|
83
86
|
RcSesCard,
|
|
87
|
+
RcSesCardShell,
|
|
88
|
+
RcSesCardHeader,
|
|
89
|
+
RcSesCardFooter,
|
|
84
90
|
RcSesDialog,
|
|
85
91
|
RcSesFooter,
|
|
86
92
|
RcSesImageCard,
|
package/src/library/types.ts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { RcSesCardProps } from '@/components/common/Card'
|
|
2
|
+
import {
|
|
3
|
+
CardFooterAlign,
|
|
4
|
+
RcSesCardFooterProps,
|
|
5
|
+
RcSesCardFooterTestIds,
|
|
6
|
+
} from '@/components/common/CardShell/CardFooter/types'
|
|
7
|
+
import {
|
|
8
|
+
CardHeadingLevel,
|
|
9
|
+
RcSesCardHeaderProps,
|
|
10
|
+
RcSesCardHeaderTestIds,
|
|
11
|
+
} from '@/components/common/CardShell/CardHeader/types'
|
|
12
|
+
import {
|
|
13
|
+
CardShellTheme,
|
|
14
|
+
CardShellVariant,
|
|
15
|
+
RcSesCardShellProps,
|
|
16
|
+
RcSesCardShellTestIds,
|
|
17
|
+
} from '@/components/common/CardShell/types'
|
|
2
18
|
import { ListWithIconsProps } from '@/components/common/ListWithIcons'
|
|
3
19
|
import { ListWithIconsItemData } from '@/components/common/ListWithIcons/ListWithIcons.types'
|
|
4
20
|
import {
|
|
@@ -34,6 +50,16 @@ export type {
|
|
|
34
50
|
RcSesLoaderSize,
|
|
35
51
|
RcSesCardFormContainerProps,
|
|
36
52
|
RcSesCardProps,
|
|
53
|
+
RcSesCardShellProps,
|
|
54
|
+
RcSesCardShellTestIds,
|
|
55
|
+
RcSesCardHeaderProps,
|
|
56
|
+
RcSesCardHeaderTestIds,
|
|
57
|
+
RcSesCardFooterProps,
|
|
58
|
+
RcSesCardFooterTestIds,
|
|
59
|
+
CardFooterAlign,
|
|
60
|
+
CardShellVariant,
|
|
61
|
+
CardShellTheme,
|
|
62
|
+
CardHeadingLevel,
|
|
37
63
|
RcSesSegmentedControlProps,
|
|
38
64
|
RcSesSegmentButtonProps,
|
|
39
65
|
RcSesSegmentOption,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Avatar,
|
|
3
|
+
Box,
|
|
4
|
+
Checkbox,
|
|
3
5
|
FormControl,
|
|
4
6
|
FormControlLabel,
|
|
5
7
|
FormLabel,
|
|
@@ -7,15 +9,18 @@ import {
|
|
|
7
9
|
RadioGroup,
|
|
8
10
|
Stack,
|
|
9
11
|
TextField,
|
|
12
|
+
Typography,
|
|
10
13
|
} from '@mui/material'
|
|
11
14
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
12
15
|
import { useState } from 'react'
|
|
16
|
+
import { useForm } from 'react-hook-form'
|
|
13
17
|
|
|
14
18
|
import InfoFillIcon from '@/assets/icons/InfoFillIcon'
|
|
15
19
|
import NotePencilIcon from '@/assets/icons/NotePencilIcon'
|
|
16
20
|
import TrashIcon from '@/assets/icons/TrashIcon'
|
|
17
21
|
import UserIcon from '@/assets/icons/UserIcon'
|
|
18
22
|
import AdvancedList, { type AdvancedListItemData } from '@/components/common/AdvancedList'
|
|
23
|
+
import RcSesSelect from '@/components/form/inputs/Select'
|
|
19
24
|
|
|
20
25
|
const buildItems = (): AdvancedListItemData[] =>
|
|
21
26
|
Array.from({ length: 8 }, (_, index) => ({
|
|
@@ -191,6 +196,132 @@ export const OwnerTypeExpand: Story = {
|
|
|
191
196
|
render: () => <OwnerTypeExpandStory />,
|
|
192
197
|
}
|
|
193
198
|
|
|
199
|
+
type OwnerBranchFormModel = {
|
|
200
|
+
individual: { municipality: string | null }
|
|
201
|
+
legalEntity: { legalForm: string | null }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const MUNICIPALITY_OPTIONS = [
|
|
205
|
+
{ value: 'vilnius', label: 'Vilniaus m. sav.' },
|
|
206
|
+
{ value: 'kaunas', label: 'Kauno m. sav.' },
|
|
207
|
+
]
|
|
208
|
+
|
|
209
|
+
const LEGAL_FORM_OPTIONS = [
|
|
210
|
+
{ value: 'uab', label: 'UAB' },
|
|
211
|
+
{ value: 'mb', label: 'Mažoji bendrija' },
|
|
212
|
+
]
|
|
213
|
+
|
|
214
|
+
const PANEL_SX = {
|
|
215
|
+
backgroundColor: 'grey.100',
|
|
216
|
+
borderRadius: '.5rem',
|
|
217
|
+
fontSize: '.75rem',
|
|
218
|
+
m: 0,
|
|
219
|
+
overflowX: 'auto',
|
|
220
|
+
p: 1.5,
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const RadioBranchFormStory = () => {
|
|
224
|
+
const [ownerTypeId, setOwnerTypeId] = useState(OWNER_TYPE_OPTIONS[0].id)
|
|
225
|
+
const [shouldUnregister, setShouldUnregister] = useState(true)
|
|
226
|
+
|
|
227
|
+
const { control, watch } = useForm<OwnerBranchFormModel>({
|
|
228
|
+
defaultValues: {
|
|
229
|
+
individual: { municipality: null },
|
|
230
|
+
legalEntity: { legalForm: null },
|
|
231
|
+
},
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
const formState = watch()
|
|
235
|
+
|
|
236
|
+
// The non-selected branch stays in form state when shouldUnregister is off, so the
|
|
237
|
+
// submitted payload is built from the selected branch instead of the whole form.
|
|
238
|
+
const payload =
|
|
239
|
+
ownerTypeId === 'owner-legal'
|
|
240
|
+
? { legalEntity: formState.legalEntity }
|
|
241
|
+
: { individual: formState.individual }
|
|
242
|
+
|
|
243
|
+
// Only the selected branch renders its fields, so switching unmounts the other one -
|
|
244
|
+
// that unmount is what makes shouldUnregister observable.
|
|
245
|
+
const renderBranchFields = (optionId: string) => {
|
|
246
|
+
if (optionId !== ownerTypeId) return undefined
|
|
247
|
+
|
|
248
|
+
if (optionId === 'owner-legal') {
|
|
249
|
+
return (
|
|
250
|
+
<RcSesSelect
|
|
251
|
+
id='owner-branch-legal-form'
|
|
252
|
+
control={control}
|
|
253
|
+
name='legalEntity.legalForm'
|
|
254
|
+
label='Juridinio asmens forma'
|
|
255
|
+
options={LEGAL_FORM_OPTIONS}
|
|
256
|
+
slotProps={{ controller: { shouldUnregister } }}
|
|
257
|
+
/>
|
|
258
|
+
)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return (
|
|
262
|
+
<RcSesSelect
|
|
263
|
+
id='owner-branch-municipality'
|
|
264
|
+
control={control}
|
|
265
|
+
name='individual.municipality'
|
|
266
|
+
label='Savivaldybė'
|
|
267
|
+
options={MUNICIPALITY_OPTIONS}
|
|
268
|
+
slotProps={{ controller: { shouldUnregister } }}
|
|
269
|
+
/>
|
|
270
|
+
)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const items: AdvancedListItemData[] = OWNER_TYPE_OPTIONS.map((option) => ({
|
|
274
|
+
id: option.id,
|
|
275
|
+
title: option.title,
|
|
276
|
+
state: ownerTypeId === option.id ? 'selected' : 'rest',
|
|
277
|
+
leading: {
|
|
278
|
+
type: 'radio',
|
|
279
|
+
name: 'owner-branch-form',
|
|
280
|
+
checked: ownerTypeId === option.id,
|
|
281
|
+
onChange: () => setOwnerTypeId(option.id),
|
|
282
|
+
},
|
|
283
|
+
expanded: ownerTypeId === option.id,
|
|
284
|
+
expandedContent: renderBranchFields(option.id),
|
|
285
|
+
}))
|
|
286
|
+
|
|
287
|
+
return (
|
|
288
|
+
<Stack sx={{ gap: 2 }}>
|
|
289
|
+
<FormControlLabel
|
|
290
|
+
control={
|
|
291
|
+
<Checkbox
|
|
292
|
+
checked={shouldUnregister}
|
|
293
|
+
onChange={(event) => setShouldUnregister(event.target.checked)}
|
|
294
|
+
/>
|
|
295
|
+
}
|
|
296
|
+
label='slotProps.controller.shouldUnregister (bibliotekos numatytoji reikšmė - true)'
|
|
297
|
+
/>
|
|
298
|
+
|
|
299
|
+
<AdvancedList items={items} />
|
|
300
|
+
|
|
301
|
+
<Stack direction={{ xs: 'column', md: 'row' }} sx={{ gap: 2 }}>
|
|
302
|
+
<Box sx={{ flex: 1, minWidth: 0 }}>
|
|
303
|
+
<Typography variant='body2'>Formos būsena</Typography>
|
|
304
|
+
<Box component='pre' sx={PANEL_SX}>
|
|
305
|
+
{JSON.stringify(formState, null, 2)}
|
|
306
|
+
</Box>
|
|
307
|
+
</Box>
|
|
308
|
+
|
|
309
|
+
<Box sx={{ flex: 1, minWidth: 0 }}>
|
|
310
|
+
<Typography variant='body2'>Submit payload (tik pasirinkta šaka)</Typography>
|
|
311
|
+
<Box component='pre' sx={PANEL_SX}>
|
|
312
|
+
{JSON.stringify(payload, null, 2)}
|
|
313
|
+
</Box>
|
|
314
|
+
</Box>
|
|
315
|
+
</Stack>
|
|
316
|
+
</Stack>
|
|
317
|
+
)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export const RadioBranchForm: Story = {
|
|
321
|
+
name: 'Preset: radio šakos su react-hook-form',
|
|
322
|
+
render: () => <RadioBranchFormStory />,
|
|
323
|
+
}
|
|
324
|
+
|
|
194
325
|
const FigmaAnatomyStory = () => {
|
|
195
326
|
const [selectedId, setSelectedId] = useState<string | null>(null)
|
|
196
327
|
|