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

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 (72) hide show
  1. package/dist/assets/icons/ArrowRightIcon.d.ts +1 -1
  2. package/dist/components/common/CardShell/index.d.ts +1 -1
  3. package/dist/components/common/CardShell/types.d.ts +3 -1
  4. package/dist/components/common/IconWithSquareBackground/index.d.ts +12 -0
  5. package/dist/components/common/ServiceLinks/ServiceLinkItem/index.d.ts +15 -0
  6. package/dist/components/common/ServiceLinks/index.d.ts +3 -0
  7. package/dist/components/common/ServiceLinks/types.d.ts +34 -0
  8. package/dist/components/common/SideNav/SideNav.types.d.ts +20 -0
  9. package/dist/components/common/SideNav/SideNavLayout.d.ts +4 -0
  10. package/dist/components/common/SideNav/components/SideNavPill.d.ts +9 -0
  11. package/dist/components/common/SideNav/components/SideNavPillList.d.ts +9 -0
  12. package/dist/components/common/SideNav/components/SideNavRow.d.ts +9 -0
  13. package/dist/components/common/SideNav/hooks/useSideNavScrollSpy.d.ts +12 -0
  14. package/dist/components/common/SideNav/index.d.ts +4 -0
  15. package/dist/components/common/TitleBlock/index.d.ts +3 -0
  16. package/dist/components/common/TitleBlock/types.d.ts +73 -0
  17. package/dist/components/utils/normalizeSx.d.ts +4 -0
  18. package/dist/library/index.d.ts +8 -2
  19. package/dist/library/types.d.ts +6 -2
  20. package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
  21. package/dist/registrucentras-rc-ses-react-components.js +3412 -2728
  22. package/dist/stories/components/display/CardShell.stories.d.ts +1 -1
  23. package/dist/stories/components/display/SelectableCardList.stories.d.ts +1 -0
  24. package/dist/stories/components/display/ServiceLinks.stories.d.ts +28 -0
  25. package/dist/stories/components/display/TitleBlock.stories.d.ts +20 -0
  26. package/dist/stories/components/form/FormControlWrapper.stories.d.ts +1 -0
  27. package/dist/stories/components/icons/IconWithSquareBackground.stories.d.ts +7 -0
  28. package/dist/stories/components/navigation/SideNav.stories.d.ts +7 -0
  29. package/package.json +1 -1
  30. package/src/assets/icons/ArrowRightIcon.tsx +2 -1
  31. package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +8 -6
  32. package/src/components/common/Card/index.tsx +1 -23
  33. package/src/components/common/CardShell/index.tsx +4 -1
  34. package/src/components/common/CardShell/types.ts +3 -1
  35. package/src/components/common/IconWithSquareBackground/index.test.tsx +55 -0
  36. package/src/components/common/IconWithSquareBackground/index.tsx +83 -0
  37. package/src/components/common/ServiceLinks/ServiceLinkItem/index.tsx +177 -0
  38. package/src/components/common/ServiceLinks/index.test.tsx +166 -0
  39. package/src/components/common/ServiceLinks/index.tsx +66 -0
  40. package/src/components/common/ServiceLinks/types.ts +37 -0
  41. package/src/components/common/SideNav/SideNav.types.ts +24 -0
  42. package/src/components/common/SideNav/SideNavLayout.test.tsx +113 -0
  43. package/src/components/common/SideNav/SideNavLayout.tsx +67 -0
  44. package/src/components/common/SideNav/components/SideNavPill.tsx +62 -0
  45. package/src/components/common/SideNav/components/SideNavPillList.tsx +190 -0
  46. package/src/components/common/SideNav/components/SideNavRow.tsx +72 -0
  47. package/src/components/common/SideNav/hooks/useSideNavScrollSpy.test.ts +457 -0
  48. package/src/components/common/SideNav/hooks/useSideNavScrollSpy.ts +154 -0
  49. package/src/components/common/SideNav/index.test.tsx +99 -0
  50. package/src/components/common/SideNav/index.tsx +83 -0
  51. package/src/components/common/TitleBlock/index.test.tsx +366 -0
  52. package/src/components/common/TitleBlock/index.tsx +144 -0
  53. package/src/components/common/TitleBlock/types.ts +82 -0
  54. package/src/components/utils/normalizeSx.ts +24 -0
  55. package/src/i18n/namespaces/common/en.json +4 -0
  56. package/src/i18n/namespaces/common/lt.json +4 -0
  57. package/src/library/index.ts +8 -2
  58. package/src/library/types.ts +20 -8
  59. package/src/stories/components/display/CardShell.stories.tsx +14 -12
  60. package/src/stories/components/display/SelectableCardList.stories.tsx +33 -1
  61. package/src/stories/components/display/ServiceLinks.stories.tsx +154 -0
  62. package/src/stories/components/display/TitleBlock.stories.tsx +506 -0
  63. package/src/stories/components/form/FormControlWrapper.stories.tsx +23 -0
  64. package/src/stories/components/icons/IconWithSquareBackground.stories.tsx +60 -0
  65. package/src/stories/components/navigation/SideNav.stories.tsx +110 -0
  66. package/src/theme/cards.ts +1 -1
  67. package/src/theme/light/MuiButton.tsx +6 -0
  68. package/dist/components/common/CardShell/CardHeader/index.d.ts +0 -3
  69. package/dist/components/common/CardShell/CardHeader/types.d.ts +0 -33
  70. package/src/components/common/CardShell/CardHeader/index.test.tsx +0 -207
  71. package/src/components/common/CardShell/CardHeader/index.tsx +0 -104
  72. package/src/components/common/CardShell/CardHeader/types.ts +0 -36
@@ -0,0 +1,99 @@
1
+ import { ThemeProvider } from '@mui/material/styles'
2
+ import { render, screen } from '@testing-library/react'
3
+ import { ReactElement } from 'react'
4
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
5
+
6
+ import i18n from '@/i18n/i18n'
7
+ import theme from '@/theme/light'
8
+
9
+ import RcSesSideNav from '.'
10
+ import { RcSesSideNavItem } from './SideNav.types'
11
+
12
+ function ResizeObserverMock() {
13
+ return { observe: () => {}, unobserve: () => {}, disconnect: () => {} }
14
+ }
15
+
16
+ vi.stubGlobal('ResizeObserver', ResizeObserverMock)
17
+ Element.prototype.scrollIntoView = vi.fn()
18
+
19
+ const items: RcSesSideNavItem[] = [
20
+ { id: 'family', label: 'Aš ir mano šeima', count: 4 },
21
+ { id: 'documents', label: 'Dokumentai apie gyventoją', count: 2 },
22
+ { id: 'signature', label: 'Elektroninis parašas' },
23
+ ]
24
+
25
+ const renderSideNav = (ui: ReactElement) =>
26
+ render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
27
+
28
+ describe('RcSesSideNav', () => {
29
+ beforeEach(async () => {
30
+ await i18n.changeLanguage('lt')
31
+ })
32
+
33
+ it('renders a nav landmark labelled with the title', () => {
34
+ renderSideNav(<RcSesSideNav items={items} />)
35
+
36
+ expect(screen.getByRole('navigation', { name: 'Temos' })).toBeInTheDocument()
37
+ })
38
+
39
+ it('renders a custom title when provided', () => {
40
+ renderSideNav(<RcSesSideNav items={items} title='Skyriai' />)
41
+
42
+ expect(screen.getByRole('navigation', { name: 'Skyriai' })).toBeInTheDocument()
43
+ expect(screen.getAllByText('Skyriai')[0]).toBeInTheDocument()
44
+ })
45
+
46
+ it('renders every item label and count for both the desktop and mobile layouts', () => {
47
+ renderSideNav(<RcSesSideNav items={items} activeItemId='family' />)
48
+
49
+ expect(screen.getAllByText('Aš ir mano šeima')).toHaveLength(2)
50
+ expect(screen.getAllByText('4')).toHaveLength(2)
51
+ })
52
+
53
+ it('marks the active item with aria-current and includes the count in its accessible name', () => {
54
+ renderSideNav(
55
+ <RcSesSideNav items={items} activeItemId='family' onItemClick={() => {}} />,
56
+ )
57
+
58
+ const activeButtons = screen.getAllByRole('button', { name: 'Aš ir mano šeima, 4' })
59
+ expect(activeButtons).toHaveLength(2)
60
+ activeButtons.forEach((button) =>
61
+ expect(button).toHaveAttribute('aria-current', 'page'),
62
+ )
63
+ })
64
+
65
+ it('does not set aria-current on inactive items', () => {
66
+ renderSideNav(
67
+ <RcSesSideNav items={items} activeItemId='family' onItemClick={() => {}} />,
68
+ )
69
+
70
+ const inactiveButtons = screen.getAllByRole('button', {
71
+ name: 'Dokumentai apie gyventoją, 2',
72
+ })
73
+ inactiveButtons.forEach((button) =>
74
+ expect(button).not.toHaveAttribute('aria-current'),
75
+ )
76
+ })
77
+
78
+ it('calls onItemClick with the clicked item id', () => {
79
+ const handleClick = vi.fn()
80
+ renderSideNav(<RcSesSideNav items={items} onItemClick={handleClick} />)
81
+
82
+ screen.getAllByRole('button', { name: 'Elektroninis parašas' })[0].click()
83
+
84
+ expect(handleClick).toHaveBeenCalledWith('signature')
85
+ })
86
+
87
+ it('renders static, non-interactive content with no onItemClick', () => {
88
+ renderSideNav(<RcSesSideNav items={items} activeItemId='family' />)
89
+
90
+ expect(screen.queryAllByRole('button')).toHaveLength(0)
91
+ })
92
+
93
+ it('renders in English when the language is changed', async () => {
94
+ await i18n.changeLanguage('en')
95
+ renderSideNav(<RcSesSideNav items={items} />)
96
+
97
+ expect(screen.getByRole('navigation', { name: 'Topics' })).toBeInTheDocument()
98
+ })
99
+ })
@@ -0,0 +1,83 @@
1
+ import { Box, Typography } from '@mui/material'
2
+ import { useTranslation } from 'react-i18next'
3
+
4
+ import normalizeSx from '@/components/utils/normalizeSx'
5
+ import palette, { common } from '@/theme/palette'
6
+
7
+ import { RcSesSideNavItem, RcSesSideNavProps } from './SideNav.types'
8
+ import SideNavPillList from './components/SideNavPillList'
9
+ import SideNavRow from './components/SideNavRow'
10
+
11
+ function RcSesSideNav({
12
+ items,
13
+ activeItemId,
14
+ onItemClick,
15
+ title,
16
+ sx,
17
+ }: RcSesSideNavProps) {
18
+ const { t } = useTranslation('common', { keyPrefix: 'components.RcSesSideNav' })
19
+ const navTitle = title ?? t('title')
20
+
21
+ const getItemAriaLabel = (item: RcSesSideNavItem) =>
22
+ item.count !== undefined
23
+ ? t('itemLabel', { label: item.label, count: item.count })
24
+ : undefined
25
+
26
+ return (
27
+ <Box
28
+ component='nav'
29
+ aria-label={navTitle}
30
+ sx={[
31
+ {
32
+ width: '100%',
33
+ // Only the mobile bar overlays scrolling content.
34
+ backgroundColor: { xs: common.white, md: 'transparent' },
35
+ // Above content setting zIndex: 1 - the nav precedes it in DOM order.
36
+ zIndex: 2,
37
+ },
38
+ ...normalizeSx(sx),
39
+ ]}
40
+ >
41
+ <Box
42
+ sx={{
43
+ display: { xs: 'none', md: 'flex' },
44
+ flexDirection: 'column',
45
+ gap: '0.25rem',
46
+ }}
47
+ >
48
+ <Typography
49
+ sx={{
50
+ width: '100%',
51
+ fontSize: '0.875rem',
52
+ lineHeight: '1.25rem',
53
+ color: palette.grey[600],
54
+ }}
55
+ >
56
+ {navTitle}
57
+ </Typography>
58
+ {items.map((item) => (
59
+ <SideNavRow
60
+ key={item.id}
61
+ label={item.label}
62
+ count={item.count}
63
+ ariaLabel={getItemAriaLabel(item)}
64
+ active={item.id === activeItemId}
65
+ onClick={onItemClick ? () => onItemClick(item.id) : undefined}
66
+ />
67
+ ))}
68
+ </Box>
69
+
70
+ <Box sx={{ display: { xs: 'block', md: 'none' } }}>
71
+ <SideNavPillList
72
+ items={items}
73
+ activeItemId={activeItemId}
74
+ onItemClick={onItemClick}
75
+ getItemAriaLabel={getItemAriaLabel}
76
+ />
77
+ </Box>
78
+ </Box>
79
+ )
80
+ }
81
+
82
+ export default RcSesSideNav
83
+ export type { RcSesSideNavItem, RcSesSideNavProps } from './SideNav.types'
@@ -0,0 +1,366 @@
1
+ import { ThemeProvider } from '@mui/material/styles'
2
+ import '@testing-library/jest-dom'
3
+ import { render, screen } from '@testing-library/react'
4
+ import { type ReactElement } from 'react'
5
+ import { describe, expect, test } from 'vitest'
6
+
7
+ import theme from '@/theme/light'
8
+ import palette from '@/theme/palette'
9
+
10
+ import RcSesTitleBlock from '.'
11
+
12
+ const renderTitleBlock = (ui: ReactElement) =>
13
+ render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
14
+
15
+ describe('RcSesTitleBlock', () => {
16
+ test('renders title and description', () => {
17
+ renderTitleBlock(
18
+ <RcSesTitleBlock title='Test Title' description='Test description' />,
19
+ )
20
+
21
+ expect(
22
+ screen.getByRole('heading', { level: 3, name: 'Test Title' }),
23
+ ).toBeInTheDocument()
24
+ expect(screen.getByText('Test description')).toBeInTheDocument()
25
+ })
26
+
27
+ test('uses default heading level 3 when not provided', () => {
28
+ renderTitleBlock(<RcSesTitleBlock title='Test Title' />)
29
+
30
+ expect(screen.getByRole('heading', { level: 3 })).toBeInTheDocument()
31
+ })
32
+
33
+ test('respects custom headingLevel prop', () => {
34
+ renderTitleBlock(<RcSesTitleBlock title='Test Title' headingLevel={2} />)
35
+
36
+ expect(
37
+ screen.getByRole('heading', { level: 2, name: 'Test Title' }),
38
+ ).toBeInTheDocument()
39
+ })
40
+
41
+ test('omits description when not provided', () => {
42
+ renderTitleBlock(
43
+ <RcSesTitleBlock title='Test Title' testIds={{ description: 'description' }} />,
44
+ )
45
+
46
+ expect(screen.queryByTestId('description')).not.toBeInTheDocument()
47
+ })
48
+
49
+ test('applies testIds correctly', () => {
50
+ renderTitleBlock(
51
+ <RcSesTitleBlock
52
+ description='Test description'
53
+ testIds={{
54
+ root: 'header-root',
55
+ heading: 'header-heading',
56
+ description: 'header-desc',
57
+ }}
58
+ title='Test Title'
59
+ />,
60
+ )
61
+
62
+ expect(screen.getByTestId('header-root')).toBeInTheDocument()
63
+ expect(screen.getByTestId('header-heading')).toBeInTheDocument()
64
+ expect(screen.getByTestId('header-desc')).toBeInTheDocument()
65
+ })
66
+
67
+ test('handles ReactNode as title', () => {
68
+ renderTitleBlock(
69
+ <RcSesTitleBlock
70
+ title={
71
+ <span>
72
+ Complex <strong>Title</strong>
73
+ </span>
74
+ }
75
+ />,
76
+ )
77
+
78
+ expect(screen.getByRole('heading', { level: 3 })).toBeInTheDocument()
79
+ expect(screen.getByText('Complex')).toBeInTheDocument()
80
+ expect(screen.getByText('Title')).toBeInTheDocument()
81
+ })
82
+
83
+ test('handles ReactNode as description', () => {
84
+ renderTitleBlock(
85
+ <RcSesTitleBlock
86
+ description={
87
+ <span>
88
+ Description with <em>emphasis</em>
89
+ </span>
90
+ }
91
+ title='Test Title'
92
+ />,
93
+ )
94
+
95
+ expect(screen.getByText('Description with')).toBeInTheDocument()
96
+ expect(screen.getByText('emphasis')).toBeInTheDocument()
97
+ })
98
+
99
+ test('heading levels 2 through 6 render correctly', () => {
100
+ const levels = [2, 3, 4, 5, 6] as const
101
+
102
+ levels.forEach((level) => {
103
+ const { unmount } = renderTitleBlock(
104
+ <RcSesTitleBlock headingLevel={level} title={`Level ${level} Title`} />,
105
+ )
106
+
107
+ expect(
108
+ screen.getByRole('heading', { level, name: `Level ${level} Title` }),
109
+ ).toBeInTheDocument()
110
+ unmount()
111
+ })
112
+ })
113
+
114
+ test('title and description keep the design type ramp', () => {
115
+ renderTitleBlock(
116
+ <RcSesTitleBlock
117
+ description='Test description'
118
+ testIds={{ description: 'description' }}
119
+ title='Test Title'
120
+ />,
121
+ )
122
+
123
+ expect(screen.getByText('Test Title')).toHaveStyle({
124
+ fontSize: '1.125rem',
125
+ fontWeight: '600',
126
+ lineHeight: '1.5rem',
127
+ })
128
+ expect(screen.getByTestId('description')).toHaveStyle({
129
+ fontSize: '0.875rem',
130
+ lineHeight: '1.25rem',
131
+ })
132
+ })
133
+
134
+ test('count renders a badge inside the heading accessible name', () => {
135
+ renderTitleBlock(<RcSesTitleBlock count={4} title='Pasirinktos teisės' />)
136
+
137
+ expect(
138
+ screen.getByRole('heading', { level: 3, name: 'Pasirinktos teisės 4' }),
139
+ ).toBeInTheDocument()
140
+ })
141
+
142
+ test('count of zero still renders the badge', () => {
143
+ renderTitleBlock(
144
+ <RcSesTitleBlock
145
+ count={0}
146
+ testIds={{ badge: 'badge' }}
147
+ title='Pasirinktos teisės'
148
+ />,
149
+ )
150
+
151
+ expect(screen.getByTestId('badge')).toHaveTextContent('0')
152
+ })
153
+
154
+ test('omits the badge when count is not provided', () => {
155
+ renderTitleBlock(<RcSesTitleBlock testIds={{ badge: 'badge' }} title='Test Title' />)
156
+
157
+ expect(screen.queryByTestId('badge')).not.toBeInTheDocument()
158
+ expect(
159
+ screen.getByRole('heading', { level: 3, name: 'Test Title' }),
160
+ ).toBeInTheDocument()
161
+ })
162
+
163
+ test('icon is decorative and stays out of the accessible name', () => {
164
+ renderTitleBlock(
165
+ <RcSesTitleBlock
166
+ icon={<span>dekoracija</span>}
167
+ testIds={{ icon: 'icon' }}
168
+ title='Test Title'
169
+ />,
170
+ )
171
+
172
+ expect(screen.getByTestId('icon')).toHaveAttribute('aria-hidden', 'true')
173
+ expect(
174
+ screen.getByRole('heading', { level: 3, name: 'Test Title' }),
175
+ ).toBeInTheDocument()
176
+ })
177
+
178
+ test('renders up to two actions in the actions slot', () => {
179
+ renderTitleBlock(
180
+ <RcSesTitleBlock
181
+ actions={
182
+ <>
183
+ <button type='button'>Atšaukti</button>
184
+ <button type='button'>Tęsti</button>
185
+ </>
186
+ }
187
+ testIds={{ actions: 'actions' }}
188
+ title='Test Title'
189
+ />,
190
+ )
191
+
192
+ const actions = screen.getByTestId('actions')
193
+ expect(actions).toContainElement(screen.getByRole('button', { name: 'Atšaukti' }))
194
+ expect(actions).toContainElement(screen.getByRole('button', { name: 'Tęsti' }))
195
+ })
196
+
197
+ test('renders a single action in the actions slot', () => {
198
+ renderTitleBlock(
199
+ <RcSesTitleBlock
200
+ actions={<button type='button'>Užsakyti</button>}
201
+ testIds={{ actions: 'actions' }}
202
+ title='Test Title'
203
+ />,
204
+ )
205
+
206
+ expect(screen.getByTestId('actions')).toContainElement(
207
+ screen.getByRole('button', { name: 'Užsakyti' }),
208
+ )
209
+ })
210
+
211
+ test('actions slot stacks vertically on mobile (xs)', () => {
212
+ // MUI's responsive `direction={{ xs: 'column', sm: 'row' }}` emits
213
+ // `flex-direction: column` as the base (xs) rule; the sm breakpoint
214
+ // override lives behind a media query and does not affect the base style.
215
+ renderTitleBlock(
216
+ <RcSesTitleBlock
217
+ actions={
218
+ <>
219
+ <button type='button'>Užsakyti</button>
220
+ <button type='button'>Plačiau</button>
221
+ </>
222
+ }
223
+ testIds={{ actions: 'actions' }}
224
+ title='Paslaugos pavadinimas'
225
+ />,
226
+ )
227
+
228
+ expect(screen.getByTestId('actions')).toHaveStyle({ flexDirection: 'column' })
229
+ })
230
+
231
+ test('actions slot stacks vertically on mobile even with a single action', () => {
232
+ renderTitleBlock(
233
+ <RcSesTitleBlock
234
+ actions={<button type='button'>Užsakyti</button>}
235
+ testIds={{ actions: 'actions' }}
236
+ title='Paslaugos pavadinimas'
237
+ />,
238
+ )
239
+
240
+ expect(screen.getByTestId('actions')).toHaveStyle({ flexDirection: 'column' })
241
+ })
242
+
243
+ test('omits the icon and actions slots when not provided', () => {
244
+ renderTitleBlock(
245
+ <RcSesTitleBlock
246
+ testIds={{ actions: 'actions', icon: 'icon' }}
247
+ title='Test Title'
248
+ />,
249
+ )
250
+
251
+ expect(screen.queryByTestId('icon')).not.toBeInTheDocument()
252
+ expect(screen.queryByTestId('actions')).not.toBeInTheDocument()
253
+ })
254
+
255
+ test('titleTone="brand" applies the brand title color', () => {
256
+ renderTitleBlock(<RcSesTitleBlock title='Test Title' titleTone='brand' />)
257
+
258
+ expect(screen.getByText('Test Title')).toHaveStyle({
259
+ color: palette.primary[700],
260
+ })
261
+ })
262
+
263
+ test('horizontal orientation glues icon and text into one group, separate from actions', () => {
264
+ renderTitleBlock(
265
+ <RcSesTitleBlock
266
+ actions={<button type='button'>Redaguoti</button>}
267
+ icon={<span>ikona</span>}
268
+ testIds={{ root: 'root', icon: 'icon', actions: 'actions' }}
269
+ title='Test Title'
270
+ />,
271
+ )
272
+
273
+ const root = screen.getByTestId('root')
274
+ // Two direct groups on horizontal: (icon + text) and (actions).
275
+ expect(root.children).toHaveLength(2)
276
+ const [textGroup, actionsGroup] = Array.from(root.children)
277
+ expect(textGroup).toContainElement(screen.getByTestId('icon'))
278
+ expect(textGroup).toContainElement(
279
+ screen.getByRole('heading', { level: 3, name: 'Test Title' }),
280
+ )
281
+ expect(actionsGroup).toContainElement(
282
+ screen.getByRole('button', { name: 'Redaguoti' }),
283
+ )
284
+ })
285
+
286
+ describe('orientation', () => {
287
+ test('defaults to horizontal layout', () => {
288
+ renderTitleBlock(
289
+ <RcSesTitleBlock
290
+ description='Test description'
291
+ icon={<span>ikona</span>}
292
+ testIds={{ root: 'root', icon: 'icon' }}
293
+ title='Test Title'
294
+ />,
295
+ )
296
+
297
+ // Icon precedes the heading in DOM order and lives in the same group.
298
+ const iconWrapper = screen.getByTestId('icon').parentElement
299
+ const heading = screen.getByRole('heading', { level: 3, name: 'Test Title' })
300
+ expect(iconWrapper).toContainElement(heading)
301
+ })
302
+
303
+ test('vertical orientation stacks children in a column', () => {
304
+ renderTitleBlock(
305
+ <RcSesTitleBlock
306
+ description='Test description'
307
+ icon={<span>ikona</span>}
308
+ orientation='vertical'
309
+ testIds={{ root: 'root' }}
310
+ title='Test Title'
311
+ />,
312
+ )
313
+
314
+ expect(screen.getByTestId('root')).toHaveStyle({ flexDirection: 'column' })
315
+ })
316
+
317
+ test('vertical orientation renders the icon before the text column', () => {
318
+ renderTitleBlock(
319
+ <RcSesTitleBlock
320
+ icon={<span>ikona</span>}
321
+ orientation='vertical'
322
+ testIds={{ root: 'root', icon: 'icon' }}
323
+ title='Test Title'
324
+ />,
325
+ )
326
+
327
+ const root = screen.getByTestId('root')
328
+ const iconWrapper = screen.getByTestId('icon')
329
+ const heading = screen.getByRole('heading', { level: 3, name: 'Test Title' })
330
+ // Icon and text column are siblings under root, icon comes first.
331
+ expect(iconWrapper.parentElement).toBe(root)
332
+ expect(root.children[0]).toBe(iconWrapper)
333
+ expect(root).toContainElement(heading)
334
+ })
335
+
336
+ test('vertical orientation rejects the actions slot at compile time', () => {
337
+ // The runtime guard trusts the discriminated union — `actions` is
338
+ // typed as `never` when orientation is 'vertical', so passing it is a
339
+ // compile error. The @ts-expect-error line documents the guarantee.
340
+ renderTitleBlock(
341
+ // @ts-expect-error `actions` is not assignable when orientation is 'vertical'.
342
+ <RcSesTitleBlock
343
+ actions={<button type='button'>Redaguoti</button>}
344
+ orientation='vertical'
345
+ title='Test Title'
346
+ />,
347
+ )
348
+
349
+ expect(screen.getByRole('heading', { name: 'Test Title' })).toBeInTheDocument()
350
+ })
351
+
352
+ test('horizontal orientation renders the actions slot when provided', () => {
353
+ renderTitleBlock(
354
+ <RcSesTitleBlock
355
+ actions={<button type='button'>Redaguoti</button>}
356
+ orientation='horizontal'
357
+ testIds={{ actions: 'actions' }}
358
+ title='Test Title'
359
+ />,
360
+ )
361
+
362
+ expect(screen.getByTestId('actions')).toBeInTheDocument()
363
+ expect(screen.getByRole('button', { name: 'Redaguoti' })).toBeInTheDocument()
364
+ })
365
+ })
366
+ })
@@ -0,0 +1,144 @@
1
+ import { Box, Stack, Typography } from '@mui/material'
2
+ import { type ReactNode } from 'react'
3
+
4
+ import RcSesBadge from '@/components/common/Badge'
5
+ import cards from '@/theme/cards'
6
+ import palette from '@/theme/palette'
7
+
8
+ import { RcSesTitleBlockProps } from './types'
9
+
10
+ function RcSesTitleBlock({
11
+ title,
12
+ headingLevel = 3,
13
+ titleVariant = 'h6',
14
+ titleTone = 'default',
15
+ orientation = 'horizontal',
16
+ icon,
17
+ count,
18
+ description,
19
+ actions,
20
+ headingId,
21
+ className,
22
+ testIds,
23
+ }: RcSesTitleBlockProps) {
24
+ const HeadingTag = `h${headingLevel}` as 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
25
+ const hasCount = count !== undefined && count !== null
26
+ const hasDescription = description !== undefined && description !== null
27
+ const isVertical = orientation === 'vertical'
28
+
29
+ const iconNode = icon ? (
30
+ <Box aria-hidden data-testid={testIds?.icon} sx={{ display: 'flex', flexShrink: 0 }}>
31
+ {icon}
32
+ </Box>
33
+ ) : null
34
+
35
+ const textColumn = (
36
+ <Stack spacing={cards.header.gap} sx={{ flex: 1, minWidth: 0, width: '100%' }}>
37
+ <HeadingTag id={headingId} data-testid={testIds?.heading} style={{ margin: 0 }}>
38
+ <Typography
39
+ component='span'
40
+ variant={titleVariant}
41
+ sx={{
42
+ color: titleTone === 'brand' ? palette.primary[700] : palette.grey[900],
43
+ // inline only when the badge has to sit on the heading's last line
44
+ display: hasCount ? 'inline' : 'block',
45
+ fontWeight: cards.header.titleFontWeight,
46
+ overflowWrap: 'anywhere',
47
+ }}
48
+ >
49
+ {title}
50
+ </Typography>
51
+
52
+ {hasCount ? (
53
+ <Box
54
+ component='span'
55
+ data-testid={testIds?.badge}
56
+ sx={{
57
+ display: 'inline-flex',
58
+ ml: cards.header.badgeGap,
59
+ verticalAlign: 'middle',
60
+ }}
61
+ >
62
+ <RcSesBadge
63
+ label={String(count)}
64
+ showIcon={false}
65
+ size='small'
66
+ variant='neutral'
67
+ />
68
+ </Box>
69
+ ) : null}
70
+ </HeadingTag>
71
+
72
+ {hasDescription ? (
73
+ <Typography
74
+ data-testid={testIds?.description}
75
+ variant='body2'
76
+ sx={{
77
+ color: palette.grey[700],
78
+ lineHeight: cards.header.descriptionLineHeight,
79
+ }}
80
+ >
81
+ {description}
82
+ </Typography>
83
+ ) : null}
84
+ </Stack>
85
+ )
86
+
87
+ const actionsSlot = actions ? (
88
+ <Stack
89
+ data-testid={testIds?.actions}
90
+ direction={{ xs: 'column', sm: 'row' }}
91
+ spacing={cards.header.actionsGap}
92
+ sx={{
93
+ alignItems: { xs: 'flex-start', sm: 'center' },
94
+ flexShrink: 0,
95
+ }}
96
+ >
97
+ {actions}
98
+ </Stack>
99
+ ) : null
100
+
101
+ return (
102
+ <Stack
103
+ className={className}
104
+ data-testid={testIds?.root}
105
+ direction={isVertical ? 'column' : { xs: 'column', sm: 'row' }}
106
+ spacing={cards.header.rowGap}
107
+ sx={{
108
+ alignItems:
109
+ isVertical || hasDescription
110
+ ? 'flex-start'
111
+ : { xs: 'flex-start', sm: 'center' },
112
+ width: '100%',
113
+ }}
114
+ >
115
+ {isVertical ? (
116
+ <>
117
+ {iconNode}
118
+ {textColumn}
119
+ </>
120
+ ) : (
121
+ // Icon + text stay glued together as one horizontal group so a mobile
122
+ // layout only breaks between the group and the actions slot, never
123
+ // between the icon and its title.
124
+ <Stack
125
+ direction='row'
126
+ spacing={cards.header.rowGap}
127
+ sx={{
128
+ alignItems: hasDescription ? 'flex-start' : 'center',
129
+ flex: 1,
130
+ minWidth: 0,
131
+ width: '100%',
132
+ }}
133
+ >
134
+ {iconNode}
135
+ {textColumn}
136
+ </Stack>
137
+ )}
138
+
139
+ {actionsSlot}
140
+ </Stack>
141
+ )
142
+ }
143
+
144
+ export default RcSesTitleBlock