@registrucentras/rc-ses-react-components 2.0.0-rc.2 → 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.
Files changed (33) hide show
  1. package/dist/components/common/CardShell/CardFooter/index.d.ts +3 -0
  2. package/dist/components/common/CardShell/CardFooter/types.d.ts +21 -0
  3. package/dist/components/common/CardShell/CardHeader/index.d.ts +3 -0
  4. package/dist/components/common/CardShell/CardHeader/types.d.ts +33 -0
  5. package/dist/components/common/CardShell/index.d.ts +5 -0
  6. package/dist/components/common/CardShell/types.d.ts +24 -0
  7. package/dist/library/index.d.ts +4 -1
  8. package/dist/library/types.d.ts +4 -1
  9. package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
  10. package/dist/registrucentras-rc-ses-react-components.js +2599 -2311
  11. package/dist/stories/components/display/CardShell.stories.d.ts +17 -0
  12. package/dist/stories/components/inputs/DatePicker.stories.d.ts +107 -0
  13. package/dist/theme/cards.d.ts +114 -0
  14. package/dist/theme/light/MuiPickersOutlinedInput.d.ts +8 -0
  15. package/package.json +1 -1
  16. package/src/components/common/CardShell/CardFooter/index.test.tsx +52 -0
  17. package/src/components/common/CardShell/CardFooter/index.tsx +38 -0
  18. package/src/components/common/CardShell/CardFooter/types.ts +24 -0
  19. package/src/components/common/CardShell/CardHeader/index.test.tsx +207 -0
  20. package/src/components/common/CardShell/CardHeader/index.tsx +104 -0
  21. package/src/components/common/CardShell/CardHeader/types.ts +36 -0
  22. package/src/components/common/CardShell/index.test.tsx +137 -0
  23. package/src/components/common/CardShell/index.tsx +75 -0
  24. package/src/components/common/CardShell/types.ts +28 -0
  25. package/src/components/form/inputs/Datepicker/index.test.tsx +117 -0
  26. package/src/library/index.ts +6 -0
  27. package/src/library/types.ts +26 -0
  28. package/src/stories/components/display/CardShell.stories.tsx +261 -0
  29. package/src/stories/components/inputs/DatePicker.stories.tsx +105 -9
  30. package/src/theme/cards.ts +60 -0
  31. package/src/theme/light/MuiPickersLayout.ts +10 -1
  32. package/src/theme/light/MuiPickersOutlinedInput.ts +88 -0
  33. package/src/theme/light/index.tsx +2 -0
@@ -0,0 +1,36 @@
1
+ import { ReactNode } from 'react'
2
+
3
+ export type CardHeadingLevel = 2 | 3 | 4 | 5 | 6
4
+
5
+ export type RcSesCardHeaderTestIds = {
6
+ root?: string
7
+ icon?: string
8
+ heading?: string
9
+ badge?: string
10
+ description?: string
11
+ actions?: string
12
+ }
13
+
14
+ export type RcSesCardHeaderProps = {
15
+ title: ReactNode
16
+ headingLevel?: CardHeadingLevel
17
+ /**
18
+ * Decorative leading visual, `Icon-tile` once SAV-6476 lands. Rendered
19
+ * `aria-hidden`, so it never contributes to the heading's accessible name.
20
+ */
21
+ icon?: ReactNode
22
+ /**
23
+ * Count rendered as a Neutral/Small `Badge` inside the heading, so it is
24
+ * announced together with the title. Intended for short section headings.
25
+ */
26
+ count?: number
27
+ description?: ReactNode
28
+ /**
29
+ * Up to two CTAs, rendered at the end of the header row. A trailing
30
+ * affordance such as the Category-tile chevron is not a CTA and will need its
31
+ * own slot.
32
+ */
33
+ actions?: ReactNode
34
+ className?: string
35
+ testIds?: RcSesCardHeaderTestIds
36
+ }
@@ -0,0 +1,137 @@
1
+ import { Box, Typography } from '@mui/material'
2
+ import { ThemeProvider } from '@mui/material/styles'
3
+ import '@testing-library/jest-dom'
4
+ import { render, screen } from '@testing-library/react'
5
+ import { type ReactElement } from 'react'
6
+ import { describe, expect, test } from 'vitest'
7
+
8
+ import RcSesButton from '@/components/common/Button'
9
+ import theme from '@/theme/light'
10
+
11
+ import RcSesCardShell from '.'
12
+
13
+ const renderCard = (ui: ReactElement) =>
14
+ render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
15
+
16
+ describe('RcSesCardShell', () => {
17
+ test('renders header, content and footer slots when provided', () => {
18
+ renderCard(
19
+ <RcSesCardShell
20
+ header={
21
+ <Box>
22
+ <Typography variant='h5' component='h3' sx={{ mb: 2.5 }}>
23
+ Kortelės antraštė
24
+ </Typography>
25
+ <Typography variant='body2' color='text.secondary'>
26
+ Paaiškinimas apie šios kortelės turinį
27
+ </Typography>
28
+ </Box>
29
+ }
30
+ footer={
31
+ <>
32
+ <RcSesButton color='grey' variant='outlined'>
33
+ Atšaukti
34
+ </RcSesButton>
35
+ <RcSesButton>Tęsti</RcSesButton>
36
+ </>
37
+ }
38
+ >
39
+ <div>Turinys</div>
40
+ </RcSesCardShell>,
41
+ )
42
+
43
+ expect(
44
+ screen.getByRole('heading', { level: 3, name: 'Kortelės antraštė' }),
45
+ ).toBeInTheDocument()
46
+ expect(screen.getByText('Paaiškinimas apie šios kortelės turinį')).toBeInTheDocument()
47
+ expect(screen.getByText('Turinys')).toBeInTheDocument()
48
+ expect(screen.getByRole('button', { name: 'Tęsti' })).toBeInTheDocument()
49
+ })
50
+
51
+ test('header slot is OFF when not provided (free-form slot content)', () => {
52
+ renderCard(
53
+ <RcSesCardShell testIds={{ header: 'card-header' }}>
54
+ <div>Laisvos formos turinys</div>
55
+ </RcSesCardShell>,
56
+ )
57
+
58
+ expect(screen.queryByTestId('card-header')).not.toBeInTheDocument()
59
+ expect(screen.queryByRole('heading')).not.toBeInTheDocument()
60
+ expect(screen.getByText('Laisvos formos turinys')).toBeInTheDocument()
61
+ })
62
+
63
+ test('omits content slot when no children provided', () => {
64
+ renderCard(
65
+ <RcSesCardShell header={<h3>Antraštė</h3>} testIds={{ content: 'card-content' }} />,
66
+ )
67
+
68
+ expect(screen.queryByTestId('card-content')).not.toBeInTheDocument()
69
+ })
70
+
71
+ test('omits footer when not provided', () => {
72
+ renderCard(
73
+ <RcSesCardShell
74
+ testIds={{ footer: 'card-footer', root: 'card-root' }}
75
+ variant='subcard'
76
+ >
77
+ <div>Turinys</div>
78
+ </RcSesCardShell>,
79
+ )
80
+
81
+ expect(screen.getByTestId('card-root')).toBeInTheDocument()
82
+ expect(screen.queryByTestId('card-footer')).not.toBeInTheDocument()
83
+ })
84
+
85
+ test('fullHeight stretches the card and grows the content slot', () => {
86
+ renderCard(
87
+ <RcSesCardShell fullHeight testIds={{ content: 'card-content', root: 'card-root' }}>
88
+ <div>Turinys</div>
89
+ </RcSesCardShell>,
90
+ )
91
+
92
+ expect(screen.getByTestId('card-root')).toHaveStyle({ height: '100%' })
93
+ expect(screen.getByTestId('card-content')).toHaveStyle({ flexGrow: '1' })
94
+ })
95
+
96
+ test('variant="card" applies larger border-radius', () => {
97
+ renderCard(
98
+ <RcSesCardShell variant='card' testIds={{ root: 'card-root' }}>
99
+ <div>Turinys</div>
100
+ </RcSesCardShell>,
101
+ )
102
+
103
+ const card = screen.getByTestId('card-root')
104
+ expect(card).toHaveStyle({ borderRadius: '0.75rem' })
105
+ })
106
+
107
+ test('variant="subcard" applies smaller border-radius', () => {
108
+ renderCard(
109
+ <RcSesCardShell variant='subcard' testIds={{ root: 'card-root' }}>
110
+ <div>Turinys</div>
111
+ </RcSesCardShell>,
112
+ )
113
+
114
+ const card = screen.getByTestId('card-root')
115
+ expect(card).toHaveStyle({ borderRadius: '0.5rem' })
116
+ })
117
+
118
+ test.each([
119
+ ['default', '#ffffff', '#c5cad1'],
120
+ ['brand', '#f3fbfe', '#b9e9fa'],
121
+ ['sunken', '#f0f2f5', '#dce0e5'],
122
+ ] as const)(
123
+ 'theme=%s paints its own background and border',
124
+ (name, background, border) => {
125
+ renderCard(
126
+ <RcSesCardShell theme={name} testIds={{ root: 'card-root' }}>
127
+ <div>Turinys</div>
128
+ </RcSesCardShell>,
129
+ )
130
+
131
+ expect(screen.getByTestId('card-root')).toHaveStyle({
132
+ backgroundColor: background,
133
+ borderColor: border,
134
+ })
135
+ },
136
+ )
137
+ })
@@ -0,0 +1,75 @@
1
+ import { Box, BoxProps } from '@mui/material'
2
+ import { ReactNode } from 'react'
3
+
4
+ import cards from '@/theme/cards'
5
+
6
+ import { RcSesCardShellProps } from './types'
7
+
8
+ // A conditional slot renders as false rather than as nothing, so false is absent
9
+ const hasSlot = (node: ReactNode) => node !== undefined && node !== null && node !== false
10
+
11
+ type ShellProps = RcSesCardShellProps &
12
+ Omit<BoxProps, keyof RcSesCardShellProps | 'children'>
13
+
14
+ function RcSesCardShell({
15
+ variant = 'card',
16
+ theme = 'default',
17
+ fullHeight = false,
18
+ header,
19
+ children,
20
+ footer,
21
+ className,
22
+ testIds,
23
+ sx,
24
+ ...boxProps
25
+ }: ShellProps) {
26
+ return (
27
+ <Box
28
+ {...boxProps}
29
+ className={className}
30
+ data-testid={testIds?.root}
31
+ sx={[
32
+ {
33
+ display: 'flex',
34
+ flexDirection: 'column',
35
+ height: fullHeight ? '100%' : 'auto',
36
+ minWidth: 0,
37
+ // enables stretched-link pattern in interactive compositions
38
+ position: 'relative',
39
+ backgroundColor: cards.themes[theme].backgroundColor,
40
+ border: `${cards.borderWidth} solid ${cards.themes[theme].borderColor}`,
41
+ borderRadius: cards[variant].borderRadius,
42
+ gap: cards[variant].gap,
43
+ p: cards[variant].padding,
44
+ },
45
+ ...(Array.isArray(sx) ? sx : [sx]),
46
+ ]}
47
+ >
48
+ {hasSlot(header) ? (
49
+ <Box data-testid={testIds?.header} sx={{ minWidth: 0, width: '100%' }}>
50
+ {header}
51
+ </Box>
52
+ ) : null}
53
+
54
+ {hasSlot(children) ? (
55
+ <Box
56
+ data-testid={testIds?.content}
57
+ sx={{ flexGrow: fullHeight ? 1 : 0, minWidth: 0, width: '100%' }}
58
+ >
59
+ {children}
60
+ </Box>
61
+ ) : null}
62
+
63
+ {hasSlot(footer) ? (
64
+ <Box
65
+ data-testid={testIds?.footer}
66
+ sx={{ minWidth: 0, mt: fullHeight ? 'auto' : 0, width: '100%' }}
67
+ >
68
+ {footer}
69
+ </Box>
70
+ ) : null}
71
+ </Box>
72
+ )
73
+ }
74
+
75
+ export default RcSesCardShell
@@ -0,0 +1,28 @@
1
+ import { ReactNode } from 'react'
2
+
3
+ export type CardShellVariant = 'card' | 'subcard'
4
+
5
+ export type CardShellTheme = 'default' | 'brand' | 'sunken'
6
+
7
+ export type RcSesCardShellTestIds = {
8
+ root?: string
9
+ header?: string
10
+ content?: string
11
+ footer?: string
12
+ }
13
+
14
+ export type RcSesCardShellProps = {
15
+ variant?: CardShellVariant
16
+ theme?: CardShellTheme
17
+ fullHeight?: boolean
18
+ /** Header row, normally `RcSesCardHeader`. The shell only provides the slot. */
19
+ header?: ReactNode
20
+ children?: ReactNode
21
+ /**
22
+ * Footer row, normally `RcSesCardFooter`. The shell only provides the slot, so
23
+ * direction and alignment belong to the footer block rather than here.
24
+ */
25
+ footer?: ReactNode
26
+ className?: string
27
+ testIds?: RcSesCardShellTestIds
28
+ }
@@ -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
+ })
@@ -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,
@@ -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,