@registrucentras/rc-ses-react-components 2.0.0-rc.1 → 2.0.0-rc.2

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.
@@ -2912,8 +2912,12 @@ const De = (t) => t.stopPropagation(), Vr = (t, e) => t ? { "aria-label": t } :
2912
2912
  U,
2913
2913
  {
2914
2914
  variant: "body2",
2915
- sx: { fontSize: "0.9375rem", fontWeight: 400, lineHeight: "1.375rem" },
2916
- color: p.grey[600],
2915
+ sx: {
2916
+ color: p.grey[600],
2917
+ fontSize: "0.9375rem",
2918
+ fontWeight: 400,
2919
+ lineHeight: "1.375rem"
2920
+ },
2917
2921
  children: t.index
2918
2922
  }
2919
2923
  )
@@ -3234,8 +3238,12 @@ const fe = { flexShrink: 0 }, zr = {
3234
3238
  U,
3235
3239
  {
3236
3240
  variant: "body1",
3237
- sx: { fontSize: "1rem", fontWeight: 600, lineHeight: "1.375rem" },
3238
- color: p.grey[900],
3241
+ sx: {
3242
+ color: p.grey[900],
3243
+ fontSize: "1rem",
3244
+ fontWeight: 600,
3245
+ lineHeight: "1.375rem"
3246
+ },
3239
3247
  children: t.amount
3240
3248
  }
3241
3249
  ),
@@ -3243,8 +3251,11 @@ const fe = { flexShrink: 0 }, zr = {
3243
3251
  U,
3244
3252
  {
3245
3253
  variant: "caption",
3246
- sx: { fontSize: "0.8125rem", lineHeight: "1.125rem" },
3247
- color: p.grey[600],
3254
+ sx: {
3255
+ color: p.grey[600],
3256
+ fontSize: "0.8125rem",
3257
+ lineHeight: "1.125rem"
3258
+ },
3248
3259
  children: t.caption
3249
3260
  }
3250
3261
  )
@@ -3513,8 +3524,12 @@ const fe = { flexShrink: 0 }, zr = {
3513
3524
  {
3514
3525
  id: A,
3515
3526
  variant: "h3",
3516
- sx: { fontSize: "1rem", fontWeight: 600, lineHeight: "1.375rem" },
3517
- color: p.grey[900],
3527
+ sx: {
3528
+ color: p.grey[900],
3529
+ fontSize: "1rem",
3530
+ fontWeight: 600,
3531
+ lineHeight: "1.375rem"
3532
+ },
3518
3533
  children: t
3519
3534
  }
3520
3535
  ),
@@ -3526,8 +3541,12 @@ const fe = { flexShrink: 0 }, zr = {
3526
3541
  U,
3527
3542
  {
3528
3543
  variant: "body2",
3529
- sx: { fontSize: "0.875rem", fontWeight: 400, lineHeight: "1.25rem" },
3530
- color: p.grey[600],
3544
+ sx: {
3545
+ color: p.grey[600],
3546
+ fontSize: "0.875rem",
3547
+ fontWeight: 400,
3548
+ lineHeight: "1.25rem"
3549
+ },
3531
3550
  children: r
3532
3551
  }
3533
3552
  ),
@@ -3794,12 +3813,12 @@ function cr({
3794
3813
  /* @__PURE__ */ s(
3795
3814
  U,
3796
3815
  {
3797
- color: p.grey[900],
3798
3816
  "data-testid": d?.title,
3799
3817
  variant: "h5",
3800
3818
  ...E,
3801
3819
  sx: [
3802
3820
  {
3821
+ color: p.grey[900],
3803
3822
  lineHeight: "1.75rem",
3804
3823
  ...o ? { textAlign: "center" } : {}
3805
3824
  },
@@ -3811,12 +3830,12 @@ function cr({
3811
3830
  !!e && /* @__PURE__ */ s(
3812
3831
  U,
3813
3832
  {
3814
- color: p.grey[800],
3815
3833
  "data-testid": d?.description,
3816
3834
  variant: "body2",
3817
3835
  ...b,
3818
3836
  sx: [
3819
3837
  {
3838
+ color: p.grey[800],
3820
3839
  fontWeight: 300,
3821
3840
  lineHeight: "1.25rem",
3822
3841
  ...o ? { textAlign: "center" } : {}
@@ -7442,7 +7461,8 @@ function dd(t) {
7442
7461
  } = Le({
7443
7462
  control: r,
7444
7463
  name: c,
7445
- rules: i
7464
+ rules: i,
7465
+ ...l?.controller
7446
7466
  }), b = oe((L) => {
7447
7467
  m(L);
7448
7468
  }, []), { getRootProps: x, getInputProps: w, isDragActive: S } = mi({
@@ -7603,7 +7623,8 @@ function ud(t) {
7603
7623
  } = Le({
7604
7624
  control: r,
7605
7625
  name: c,
7606
- rules: i
7626
+ rules: i,
7627
+ ...l?.controller
7607
7628
  }), m = (g) => h(g.target.files);
7608
7629
  return /* @__PURE__ */ s(
7609
7630
  xe,
@@ -7765,7 +7786,8 @@ function pd(t) {
7765
7786
  } = Le({
7766
7787
  control: o,
7767
7788
  name: b,
7768
- rules: u
7789
+ rules: u,
7790
+ ...h?.controller
7769
7791
  });
7770
7792
  W.useEffect(() => {
7771
7793
  if (g) {
@@ -8032,7 +8054,7 @@ function zl(t) {
8032
8054
  }
8033
8055
  }
8034
8056
  ) }),
8035
- /* @__PURE__ */ s(tt, { position: "start", children: /* @__PURE__ */ s(U, { color: p.grey[900], component: "span", children: a.code }) })
8057
+ /* @__PURE__ */ s(tt, { position: "start", children: /* @__PURE__ */ s(U, { sx: { color: p.grey[900] }, component: "span", children: a.code }) })
8036
8058
  ]
8037
8059
  }
8038
8060
  )
@@ -8124,7 +8146,8 @@ function Hl(t) {
8124
8146
  } = t, h = H(() => t.id ?? ye(), [t.id]), { field: f } = Le({
8125
8147
  control: e,
8126
8148
  name: l,
8127
- rules: c
8149
+ rules: c,
8150
+ ...d?.controller
8128
8151
  });
8129
8152
  return /* @__PURE__ */ s(
8130
8153
  xe,
@@ -8440,7 +8463,8 @@ function bd(t) {
8440
8463
  control: f,
8441
8464
  name: B,
8442
8465
  rules: E,
8443
- shouldUnregister: !0
8466
+ shouldUnregister: !0,
8467
+ ...L?.controller
8444
8468
  }), F = !!m, Y = typeof L?.field?.groupBy == "function", Z = H(() => u ? Array.isArray(z) ? S.filter((D) => z.includes(D.value)) : [] : S.find((D) => D.value === z) ?? null, [z, S, u]), N = !u && Z && !Array.isArray(Z) ? Z.label : "", j = u && Array.isArray(Z) ? Z.length : 0, ce = u && (b ?? -1) > -1 && j > (b ?? -1) ? c : a, [de, Ae] = W.useState(""), Te = v ? "" : de, ct = H(
8445
8469
  () => ({ label: "", value: i }),
8446
8470
  [i]
@@ -8841,9 +8865,12 @@ function yd({ text: t }) {
8841
8865
  children: /* @__PURE__ */ s(We, { children: /* @__PURE__ */ s(
8842
8866
  U,
8843
8867
  {
8844
- color: p.grey[200],
8845
8868
  component: "div",
8846
- sx: { lineHeight: "1.25rem", whiteSpace: "pre-line" },
8869
+ sx: {
8870
+ color: p.grey[200],
8871
+ lineHeight: "1.25rem",
8872
+ whiteSpace: "pre-line"
8873
+ },
8847
8874
  variant: "caption",
8848
8875
  children: t
8849
8876
  }
@@ -23,6 +23,7 @@ export declare const Main: Story;
23
23
  export declare const Error: Story;
24
24
  export declare const KitchenSink: Story;
25
25
  export declare const OwnerTypeExpand: Story;
26
+ export declare const RadioBranchForm: Story;
26
27
  export declare const FigmaAnatomy: Story;
27
28
  export declare const LeadingOptions: Story;
28
29
  export declare const TrailingOptions: Story;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@registrucentras/rc-ses-react-components",
3
3
  "author": "VĮ REGISTRŲ CENTRAS",
4
- "version": "2.0.0-rc.1",
4
+ "version": "2.0.0-rc.2",
5
5
  "description": "RC SES React komponentų biblioteka",
6
6
  "type": "module",
7
7
  "private": false,
@@ -157,8 +157,12 @@ const AdvancedListItemLeading = ({
157
157
  >
158
158
  <Typography
159
159
  variant='body2'
160
- sx={{ fontSize: '0.9375rem', fontWeight: 400, lineHeight: '1.375rem' }}
161
- color={palette.grey[600]}
160
+ sx={{
161
+ color: palette.grey[600],
162
+ fontSize: '0.9375rem',
163
+ fontWeight: 400,
164
+ lineHeight: '1.375rem',
165
+ }}
162
166
  >
163
167
  {leading.index}
164
168
  </Typography>
@@ -146,16 +146,23 @@ const AdvancedListItemTrailing = ({ trailing, disabled }: Props) => {
146
146
  <Box sx={PRICE_BLOCK_SX}>
147
147
  <Typography
148
148
  variant='body1'
149
- sx={{ fontSize: '1rem', fontWeight: 600, lineHeight: '1.375rem' }}
150
- color={palette.grey[900]}
149
+ sx={{
150
+ color: palette.grey[900],
151
+ fontSize: '1rem',
152
+ fontWeight: 600,
153
+ lineHeight: '1.375rem',
154
+ }}
151
155
  >
152
156
  {trailing.amount}
153
157
  </Typography>
154
158
  {!!trailing.caption && (
155
159
  <Typography
156
160
  variant='caption'
157
- sx={{ fontSize: '0.8125rem', lineHeight: '1.125rem' }}
158
- color={palette.grey[600]}
161
+ sx={{
162
+ color: palette.grey[600],
163
+ fontSize: '0.8125rem',
164
+ lineHeight: '1.125rem',
165
+ }}
159
166
  >
160
167
  {trailing.caption}
161
168
  </Typography>
@@ -265,8 +265,12 @@ const AdvancedListItem = ({
265
265
  <Typography
266
266
  id={titleId}
267
267
  variant='h3'
268
- sx={{ fontSize: '1rem', fontWeight: 600, lineHeight: '1.375rem' }}
269
- color={palette.grey[900]}
268
+ sx={{
269
+ color: palette.grey[900],
270
+ fontSize: '1rem',
271
+ fontWeight: 600,
272
+ lineHeight: '1.375rem',
273
+ }}
270
274
  >
271
275
  {title}
272
276
  </Typography>
@@ -276,8 +280,12 @@ const AdvancedListItem = ({
276
280
  {!!subtitle && (
277
281
  <Typography
278
282
  variant='body2'
279
- sx={{ fontSize: '0.875rem', fontWeight: 400, lineHeight: '1.25rem' }}
280
- color={palette.grey[600]}
283
+ sx={{
284
+ color: palette.grey[600],
285
+ fontSize: '0.875rem',
286
+ fontWeight: 400,
287
+ lineHeight: '1.25rem',
288
+ }}
281
289
  >
282
290
  {subtitle}
283
291
  </Typography>
@@ -162,12 +162,12 @@ function RcSesCard({
162
162
  ]}
163
163
  >
164
164
  <Typography
165
- color={palette.grey[900]}
166
165
  data-testid={testIds?.title}
167
166
  variant='h5'
168
167
  {...titleProps}
169
168
  sx={[
170
169
  {
170
+ color: palette.grey[900],
171
171
  lineHeight: '1.75rem',
172
172
  ...(centered ? { textAlign: 'center' } : {}),
173
173
  },
@@ -179,12 +179,12 @@ function RcSesCard({
179
179
 
180
180
  {!!description && (
181
181
  <Typography
182
- color={palette.grey[800]}
183
182
  data-testid={testIds?.description}
184
183
  variant='body2'
185
184
  {...descriptionProps}
186
185
  sx={[
187
186
  {
187
+ color: palette.grey[800],
188
188
  fontWeight: 300,
189
189
  lineHeight: '1.25rem',
190
190
  ...(centered ? { textAlign: 'center' } : {}),
@@ -55,6 +55,7 @@ function RcSesFileDropzone(props: Props) {
55
55
  control,
56
56
  name,
57
57
  rules,
58
+ ...slotProps?.controller,
58
59
  })
59
60
 
60
61
  const onDrop = useCallback((acceptedFiles: Blob[]) => {
@@ -57,6 +57,7 @@ function RcSesFileUpload(props: Props) {
57
57
  control,
58
58
  name,
59
59
  rules,
60
+ ...slotProps?.controller,
60
61
  })
61
62
 
62
63
  const handleChange = (e: { target: { files: any } }) => onChange(e.target.files)
@@ -135,6 +135,7 @@ function RcSesNumberStepper(props: Props) {
135
135
  control,
136
136
  name,
137
137
  rules,
138
+ ...slotProps?.controller,
138
139
  })
139
140
 
140
141
  React.useEffect(() => {
@@ -179,7 +179,7 @@ function RcSesPhoneInputFormControl(props: Props) {
179
179
  </InputAdornment>
180
180
 
181
181
  <InputAdornment position='start'>
182
- <Typography color={palette.grey[900]} component='span'>
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
+ })
@@ -65,6 +65,7 @@ function UnstyledRcSesRadioButtonGroup(props: Props) {
65
65
  control,
66
66
  name,
67
67
  rules,
68
+ ...slotProps?.controller,
68
69
  })
69
70
 
70
71
  return (
@@ -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={{ lineHeight: '1.25rem', whiteSpace: 'pre-line' }}
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}