@registrucentras/rc-ses-react-components 2.0.0-rc.4 → 2.0.0-rc.6

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.
@@ -16,5 +16,6 @@ export declare const HorizontalTitleBlockWithArrowAndSunkenCardShellTheme: Story
16
16
  export declare const ClickableHorizontalTitleBlockWithCardShellBase: Story;
17
17
  export declare const VerticalTitleBlockWithCardShellBase: Story;
18
18
  export declare const VerticalTitleBlock: Story;
19
+ export declare const BodyScaleTitleInCard: Story;
19
20
  export declare const MobileViewport: Story;
20
21
  export declare const TabletViewport: Story;
@@ -7,4 +7,8 @@ export declare const Main: Story;
7
7
  export declare const Outlined: Story;
8
8
  export declare const Filled: Story;
9
9
  export declare const Standard: Story;
10
+ export declare const WithActionAndClose: Story;
11
+ export declare const WithoutActionAndClose: Story;
12
+ export declare const Toggles: Story;
13
+ export declare const Dismissible: Story;
10
14
  export declare const WithContainer: 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.4",
4
+ "version": "2.0.0-rc.6",
5
5
  "description": "RC SES React komponentų biblioteka",
6
6
  "type": "module",
7
7
  "private": false,
@@ -2,13 +2,19 @@ import { WarningCircleIcon as WarningCircle } from '@phosphor-icons/react'
2
2
 
3
3
  import IconProps from '../IconProps'
4
4
 
5
- function WarningCircleIcon({ className, size = 24, fillColor, ...rest }: IconProps) {
5
+ function WarningCircleIcon({
6
+ className,
7
+ size = 24,
8
+ fillColor,
9
+ weight = 'fill',
10
+ ...rest
11
+ }: IconProps) {
6
12
  return (
7
13
  <WarningCircle
8
14
  {...rest}
9
15
  className={className}
10
16
  size={size}
11
- weight='fill'
17
+ weight={weight}
12
18
  color={fillColor}
13
19
  />
14
20
  )
@@ -1,5 +1,5 @@
1
1
  import { ThemeProvider } from '@mui/material/styles'
2
- import { render, screen } from '@testing-library/react'
2
+ import { act, fireEvent, render, screen } from '@testing-library/react'
3
3
  import { vi } from 'vitest'
4
4
 
5
5
  import theme from '@/theme/light'
@@ -22,7 +22,7 @@ describe('RcSesAlert', () => {
22
22
  })
23
23
 
24
24
  test('renders with each severity', () => {
25
- const severities = ['info', 'warning', 'error', 'success'] as const
25
+ const severities = ['grey', 'info', 'warning', 'error', 'success'] as const
26
26
  severities.forEach((severity) => {
27
27
  const { unmount } = renderAlert(
28
28
  <RcSesAlert severity={severity}>{severity} message</RcSesAlert>,
@@ -32,6 +32,161 @@ describe('RcSesAlert', () => {
32
32
  })
33
33
  })
34
34
 
35
+ describe('accessibility', () => {
36
+ test.each([
37
+ ['grey', 'status', 'polite'],
38
+ ['info', 'status', 'polite'],
39
+ ['success', 'status', 'polite'],
40
+ ['warning', 'alert', 'assertive'],
41
+ ['error', 'alert', 'assertive'],
42
+ ] as const)(
43
+ 'severity=%s gets role=%s and aria-live=%s',
44
+ (severity, expectedRole, expectedAriaLive) => {
45
+ const { unmount } = renderAlert(
46
+ <RcSesAlert severity={severity}>message</RcSesAlert>,
47
+ )
48
+ expect(screen.getByRole(expectedRole)).toHaveAttribute(
49
+ 'aria-live',
50
+ expectedAriaLive,
51
+ )
52
+ unmount()
53
+ },
54
+ )
55
+
56
+ test('an explicit aria-live prop overrides the severity default', () => {
57
+ renderAlert(
58
+ <RcSesAlert severity='error' aria-live='polite'>
59
+ message
60
+ </RcSesAlert>,
61
+ )
62
+ expect(screen.getByRole('alert')).toHaveAttribute('aria-live', 'polite')
63
+ })
64
+
65
+ test('an explicit role prop overrides the severity default', () => {
66
+ renderAlert(
67
+ <RcSesAlert severity='error' role='status'>
68
+ message
69
+ </RcSesAlert>,
70
+ )
71
+ expect(screen.getByRole('status')).toHaveAttribute('aria-live', 'polite')
72
+ })
73
+
74
+ test('close button has a translated aria-label', () => {
75
+ renderAlert(<RcSesAlert onClose={() => {}}>message</RcSesAlert>)
76
+ expect(screen.getByRole('button', { name: 'close' })).toBeInTheDocument()
77
+ })
78
+
79
+ test('severity icon is hidden from assistive tech', () => {
80
+ const { container } = renderAlert(
81
+ <RcSesAlert severity='success'>message</RcSesAlert>,
82
+ )
83
+ expect(container.querySelector('.MuiAlert-icon svg')).toHaveAttribute('aria-hidden')
84
+ })
85
+
86
+ test('close and action controls are reachable in normal Tab order', () => {
87
+ renderAlert(
88
+ <RcSesAlert
89
+ severity='error'
90
+ actionLabel='Retry'
91
+ onActionClick={() => {}}
92
+ onClose={() => {}}
93
+ >
94
+ message
95
+ </RcSesAlert>,
96
+ )
97
+
98
+ const actionButton = screen.getByRole('button', { name: 'Retry' })
99
+ const closeButton = screen.getByRole('button', { name: 'close' })
100
+
101
+ expect(actionButton.tagName).toBe('BUTTON')
102
+ expect(closeButton.tagName).toBe('BUTTON')
103
+
104
+ act(() => actionButton.focus())
105
+ expect(actionButton).toHaveFocus()
106
+
107
+ act(() => closeButton.focus())
108
+ expect(closeButton).toHaveFocus()
109
+ })
110
+ })
111
+
112
+ describe('close and action handlers', () => {
113
+ test('clicking close calls onClose', () => {
114
+ const onClose = vi.fn()
115
+ renderAlert(<RcSesAlert onClose={onClose}>message</RcSesAlert>)
116
+
117
+ fireEvent.click(screen.getByRole('button', { name: 'close' }))
118
+
119
+ expect(onClose).toHaveBeenCalledTimes(1)
120
+ })
121
+
122
+ test('clicking the action calls onActionClick', () => {
123
+ const onActionClick = vi.fn()
124
+ renderAlert(
125
+ <RcSesAlert actionLabel='Retry' onActionClick={onActionClick}>
126
+ message
127
+ </RcSesAlert>,
128
+ )
129
+
130
+ fireEvent.click(screen.getByRole('button', { name: 'Retry' }))
131
+
132
+ expect(onActionClick).toHaveBeenCalledTimes(1)
133
+ })
134
+
135
+ test('a consumer action renders alongside the close button', () => {
136
+ renderAlert(
137
+ <RcSesAlert action={<button type='button'>Custom</button>} onClose={() => {}}>
138
+ message
139
+ </RcSesAlert>,
140
+ )
141
+
142
+ expect(screen.getByRole('button', { name: 'Custom' })).toBeInTheDocument()
143
+ expect(screen.getByRole('button', { name: 'close' })).toBeInTheDocument()
144
+ })
145
+
146
+ test('a consumer action renders when there is no close button', () => {
147
+ renderAlert(
148
+ <RcSesAlert action={<button type='button'>Custom</button>}>message</RcSesAlert>,
149
+ )
150
+
151
+ expect(screen.getByRole('button', { name: 'Custom' })).toBeInTheDocument()
152
+ expect(screen.queryByRole('button', { name: 'close' })).not.toBeInTheDocument()
153
+ })
154
+ })
155
+
156
+ describe('show* toggles', () => {
157
+ test('showClose=false hides the close button even when onClose is provided', () => {
158
+ renderAlert(
159
+ <RcSesAlert onClose={() => {}} showClose={false}>
160
+ message
161
+ </RcSesAlert>,
162
+ )
163
+ expect(screen.queryByRole('button', { name: 'close' })).not.toBeInTheDocument()
164
+ })
165
+
166
+ test('showAction=false hides the action button even when actionLabel/onActionClick are provided', () => {
167
+ renderAlert(
168
+ <RcSesAlert actionLabel='Retry' onActionClick={() => {}} showAction={false}>
169
+ message
170
+ </RcSesAlert>,
171
+ )
172
+ expect(screen.queryByRole('button', { name: 'Retry' })).not.toBeInTheDocument()
173
+ })
174
+
175
+ test('action button does not render without onActionClick even if actionLabel is set', () => {
176
+ renderAlert(<RcSesAlert actionLabel='Retry'>message</RcSesAlert>)
177
+ expect(screen.queryByRole('button', { name: 'Retry' })).not.toBeInTheDocument()
178
+ })
179
+
180
+ test('showIcon=false hides the severity icon', () => {
181
+ const { container } = renderAlert(
182
+ <RcSesAlert severity='success' showIcon={false}>
183
+ message
184
+ </RcSesAlert>,
185
+ )
186
+ expect(container.querySelector('.MuiAlert-icon')).not.toBeInTheDocument()
187
+ })
188
+ })
189
+
35
190
  describe('container prop', () => {
36
191
  test('renders children correctly when container={true}', () => {
37
192
  renderAlert(
@@ -1,12 +1,23 @@
1
1
  import {
2
+ Box,
3
+ Button,
2
4
  ContainerProps,
3
5
  Alert as MuiAlert,
4
6
  AlertProps as MuiAlertProps,
7
+ Theme,
5
8
  } from '@mui/material'
6
9
  import { useTranslation } from 'react-i18next'
7
10
 
8
- type Props = MuiAlertProps & {
11
+ import CloseIcon from '@/assets/icons/CloseIcon'
12
+
13
+ type Props = Omit<MuiAlertProps, 'onClose'> & {
9
14
  container?: boolean | ContainerProps
15
+ showIcon?: boolean
16
+ showAction?: boolean
17
+ showClose?: boolean
18
+ actionLabel?: string
19
+ onActionClick?: () => void
20
+ onClose?: () => void
10
21
  }
11
22
 
12
23
  const defaultProps: Partial<MuiAlertProps> = {
@@ -14,9 +25,106 @@ const defaultProps: Partial<MuiAlertProps> = {
14
25
  variant: 'outlined',
15
26
  }
16
27
 
17
- function RcSesAlert({ container, children, sx, ...props }: Props) {
28
+ const closeButtonStyles = {
29
+ display: 'inline-flex',
30
+ alignItems: 'center',
31
+ justifyContent: 'center',
32
+ minHeight: '1.5rem',
33
+ minWidth: '1.5rem',
34
+ padding: 0,
35
+ border: 'none',
36
+ background: 'none',
37
+ cursor: 'pointer',
38
+ color: 'inherit',
39
+ opacity: 0.8,
40
+ '&:hover': { opacity: 1 },
41
+ }
42
+
43
+ const actionContainerStyles = {
44
+ display: 'inline-flex',
45
+ alignItems: 'center',
46
+ gap: '.75rem',
47
+ }
48
+
49
+ // Only the alert body and its CTA form a row; the message slot itself stays a plain
50
+ // block container so rich or multi-node children keep flowing normally.
51
+ const messageRowStyles = (theme: Theme) => ({
52
+ display: 'flex',
53
+ flexWrap: 'wrap',
54
+ alignItems: 'center',
55
+ justifyContent: 'space-between',
56
+ gap: '.75rem',
57
+
58
+ [theme.breakpoints.up('md')]: {
59
+ flexWrap: 'nowrap',
60
+ },
61
+ })
62
+
63
+ // The close button is a fixed-size control, so it keeps the action slot tight instead of
64
+ // stacking onto its own row the way a consumer-supplied action does.
65
+ const closeOnlyActionStyles = {
66
+ '.MuiAlert-action': {
67
+ alignSelf: 'center',
68
+ flex: '0 0 auto',
69
+ margin: 0,
70
+ padding: 0,
71
+ },
72
+ }
73
+
74
+ // `breakpoints.values.xs` is 0, so an xs container banner needs an explicit content width.
75
+ const XS_CONTAINER_MAX_WIDTH = 444
76
+
77
+ const URGENT_SEVERITIES: MuiAlertProps['severity'][] = ['warning', 'error']
78
+
79
+ function RcSesAlert({
80
+ container,
81
+ children,
82
+ icon,
83
+ showIcon = true,
84
+ showAction = true,
85
+ showClose = true,
86
+ actionLabel,
87
+ onActionClick,
88
+ onClose,
89
+ action,
90
+ severity,
91
+ role,
92
+ 'aria-live': ariaLive,
93
+ sx,
94
+ ...props
95
+ }: Props) {
18
96
  const { t } = useTranslation('input', { keyPrefix: 'components.RcSesAlert' })
19
97
 
98
+ const hasAction = showAction && Boolean(onActionClick) && Boolean(actionLabel)
99
+ const hasClose = showClose && Boolean(onClose)
100
+
101
+ const closeButton = hasClose ? (
102
+ <Box
103
+ component='button'
104
+ type='button'
105
+ onClick={onClose}
106
+ aria-label={t('close')}
107
+ sx={closeButtonStyles}
108
+ >
109
+ <CloseIcon size={22} fillColor='currentColor' focusable={false} aria-hidden />
110
+ </Box>
111
+ ) : null
112
+
113
+ let resolvedAction = action
114
+ if (hasClose) {
115
+ resolvedAction = action ? (
116
+ <Box sx={actionContainerStyles}>
117
+ {action}
118
+ {closeButton}
119
+ </Box>
120
+ ) : (
121
+ closeButton
122
+ )
123
+ }
124
+
125
+ const resolvedRole = role ?? (URGENT_SEVERITIES.includes(severity) ? 'alert' : 'status')
126
+ const resolvedAriaLive = ariaLive ?? (resolvedRole === 'alert' ? 'assertive' : 'polite')
127
+
20
128
  const isContainer = Boolean(container)
21
129
  const containerParams = typeof container === 'object' ? container : {}
22
130
  const maxWidth =
@@ -32,17 +140,24 @@ function RcSesAlert({ container, children, sx, ...props }: Props) {
32
140
  <MuiAlert
33
141
  {...defaultProps}
34
142
  {...props}
143
+ severity={severity}
144
+ role={resolvedRole}
145
+ aria-live={resolvedAriaLive}
146
+ icon={showIcon ? icon : false}
147
+ action={resolvedAction}
35
148
  sx={[
36
149
  isContainer &&
37
150
  ((theme) => {
38
- let maxWidthValue: string | number = 'none'
151
+ let maxWidthValue: number | 'none' = 'none'
39
152
 
40
153
  if (maxWidth !== false) {
41
154
  if (typeof maxWidth === 'string') {
42
155
  maxWidthValue =
43
- theme.breakpoints.values[
44
- maxWidth as keyof typeof theme.breakpoints.values
45
- ] || maxWidth
156
+ maxWidth === 'xs'
157
+ ? XS_CONTAINER_MAX_WIDTH
158
+ : theme.breakpoints.values[
159
+ maxWidth as keyof typeof theme.breakpoints.values
160
+ ]
46
161
  } else {
47
162
  maxWidthValue = maxWidth
48
163
  }
@@ -54,8 +169,8 @@ function RcSesAlert({ container, children, sx, ...props }: Props) {
54
169
  }
55
170
 
56
171
  if (maxWidthValue !== 'none') {
57
- const gutterXs = disableGutters ? '' : ' + 16px'
58
- const gutterSm = disableGutters ? '' : ' + 24px'
172
+ const gutterXs = disableGutters ? '' : ` + ${theme.spacing(2)}`
173
+ const gutterSm = disableGutters ? '' : ` + ${theme.spacing(3)}`
59
174
 
60
175
  containerStyles.px = `calc(max((100% - ${maxWidthValue}px) / 2, 0px)${gutterXs})`
61
176
  containerStyles[theme.breakpoints.up('sm')] = {
@@ -65,11 +180,30 @@ function RcSesAlert({ container, children, sx, ...props }: Props) {
65
180
 
66
181
  return containerStyles
67
182
  }),
183
+ hasClose && !action && closeOnlyActionStyles,
68
184
  ...normalizedSx,
69
185
  ]}
70
- closeText={t('close')}
71
186
  >
72
- {children}
187
+ {hasAction ? (
188
+ <Box sx={messageRowStyles}>
189
+ <Box sx={{ minWidth: 0 }}>{children}</Box>
190
+ <Button
191
+ variant='link'
192
+ onClick={onActionClick}
193
+ sx={(theme) => ({
194
+ flexBasis: '100%',
195
+ padding: '0.5rem 0.25rem',
196
+ [theme.breakpoints.up('md')]: {
197
+ flexBasis: 'auto',
198
+ },
199
+ })}
200
+ >
201
+ {actionLabel}
202
+ </Button>
203
+ </Box>
204
+ ) : (
205
+ children
206
+ )}
73
207
  </MuiAlert>
74
208
  )
75
209
  }
@@ -131,6 +131,39 @@ describe('RcSesTitleBlock', () => {
131
131
  })
132
132
  })
133
133
 
134
+ test('heading title variants keep the card-header weight', () => {
135
+ const variants = ['h4', 'h5', 'h6'] as const
136
+
137
+ variants.forEach((variant) => {
138
+ const { unmount } = renderTitleBlock(
139
+ <RcSesTitleBlock title={`${variant} Title`} titleVariant={variant} />,
140
+ )
141
+
142
+ expect(screen.getByText(`${variant} Title`)).toHaveStyle({ fontWeight: '600' })
143
+ unmount()
144
+ })
145
+ })
146
+
147
+ test('titleVariant="body1" drops the header weight for the body type scale', () => {
148
+ renderTitleBlock(<RcSesTitleBlock title='Test Title' titleVariant='body1' />)
149
+
150
+ expect(screen.getByText('Test Title')).toHaveStyle({
151
+ fontSize: '0.9375rem',
152
+ fontWeight: '400',
153
+ lineHeight: '1.125rem',
154
+ })
155
+ })
156
+
157
+ test('titleVariant="body1" still renders a heading at the requested level', () => {
158
+ renderTitleBlock(
159
+ <RcSesTitleBlock headingLevel={2} title='Test Title' titleVariant='body1' />,
160
+ )
161
+
162
+ expect(
163
+ screen.getByRole('heading', { level: 2, name: 'Test Title' }),
164
+ ).toBeInTheDocument()
165
+ })
166
+
134
167
  test('count renders a badge inside the heading accessible name', () => {
135
168
  renderTitleBlock(<RcSesTitleBlock count={4} title='Pasirinktos teisės' />)
136
169
 
@@ -1,5 +1,4 @@
1
1
  import { Box, Stack, Typography } from '@mui/material'
2
- import { type ReactNode } from 'react'
3
2
 
4
3
  import RcSesBadge from '@/components/common/Badge'
5
4
  import cards from '@/theme/cards'
@@ -25,6 +24,8 @@ function RcSesTitleBlock({
25
24
  const hasCount = count !== undefined && count !== null
26
25
  const hasDescription = description !== undefined && description !== null
27
26
  const isVertical = orientation === 'vertical'
27
+ // The card-header weight belongs to the heading variants only.
28
+ const isHeadingScale = titleVariant !== 'body1'
28
29
 
29
30
  const iconNode = icon ? (
30
31
  <Box aria-hidden data-testid={testIds?.icon} sx={{ display: 'flex', flexShrink: 0 }}>
@@ -42,7 +43,7 @@ function RcSesTitleBlock({
42
43
  color: titleTone === 'brand' ? palette.primary[700] : palette.grey[900],
43
44
  // inline only when the badge has to sit on the heading's last line
44
45
  display: hasCount ? 'inline' : 'block',
45
- fontWeight: cards.header.titleFontWeight,
46
+ fontWeight: isHeadingScale ? cards.header.titleFontWeight : undefined,
46
47
  overflowWrap: 'anywhere',
47
48
  }}
48
49
  >
@@ -2,7 +2,7 @@ import { ReactNode } from 'react'
2
2
 
3
3
  export type TitleBlockHeadingLevel = 2 | 3 | 4 | 5 | 6
4
4
 
5
- export type TitleBlockTitleVariant = 'h4' | 'h5' | 'h6'
5
+ export type TitleBlockTitleVariant = 'h4' | 'h5' | 'h6' | 'body1'
6
6
 
7
7
  export type TitleBlockOrientation = 'horizontal' | 'vertical'
8
8
 
@@ -22,6 +22,8 @@ export type RcSesTitleBlockBaseProps = {
22
22
  * Visual size of the title, independent of `headingLevel`. The semantic tag
23
23
  * (`headingLevel`) sets document structure; this sets the type scale.
24
24
  * Defaults to `h6` (18px).
25
+ * `body1` (15px) draws the title as running copy: body scale, and the
26
+ * type scale's own weight instead of the card-header one.
25
27
  */
26
28
  titleVariant?: TitleBlockTitleVariant
27
29
  /**
@@ -427,6 +427,72 @@ export const VerticalTitleBlock: Story = {
427
427
  ),
428
428
  }
429
429
 
430
+ // Card title as running body copy: `titleVariant` moves the type scale only,
431
+ // `headingLevel` keeps the heading.
432
+ export const BodyScaleTitleInCard: Story = {
433
+ render: () => {
434
+ const services = [
435
+ {
436
+ id: 'body-scale-title-a',
437
+ title: 'Pažymos apie asmens duomenis Gyventojų registre užsakymas',
438
+ },
439
+ {
440
+ id: 'body-scale-title-b',
441
+ title: 'Nekilnojamojo turto registro išrašo užsakymas',
442
+ },
443
+ {
444
+ id: 'body-scale-title-c',
445
+ title: 'Pažymos santuokai sudaryti užsienyje užsakymas',
446
+ },
447
+ ]
448
+
449
+ return (
450
+ <Box
451
+ sx={{
452
+ display: 'grid',
453
+ gap: 2,
454
+ gridTemplateColumns: { xs: '1fr', md: 'repeat(3, 1fr)' },
455
+ }}
456
+ >
457
+ {services.map((service) => (
458
+ <RcSesCardShell
459
+ key={service.id}
460
+ variant='card'
461
+ theme='brand'
462
+ fullHeight
463
+ header={
464
+ <RcSesTitleBlock
465
+ headingId={service.id}
466
+ headingLevel={3}
467
+ title={service.title}
468
+ titleVariant='body1'
469
+ titleTone='brand'
470
+ />
471
+ }
472
+ footer={
473
+ <RcSesCardFooter align='start'>
474
+ <RcSesButton
475
+ id={`${service.id}-order`}
476
+ aria-labelledby={`${service.id}-order ${service.id}`}
477
+ >
478
+ Užsakyti
479
+ </RcSesButton>
480
+ <RcSesButton
481
+ variant='link'
482
+ id={`${service.id}-more`}
483
+ aria-labelledby={`${service.id}-more ${service.id}`}
484
+ >
485
+ Plačiau
486
+ </RcSesButton>
487
+ </RcSesCardFooter>
488
+ }
489
+ />
490
+ ))}
491
+ </Box>
492
+ )
493
+ },
494
+ }
495
+
430
496
  // Responsive baselines for SAV-6509 / SAV-6480 DoD ("Responsive patikra 375 /
431
497
  // 768 / 1440"). Exercises the mobile stacking of the actions slot
432
498
  // (direction={{ xs: 'column', sm: 'row' }}) so both the two-action and