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

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 (80) hide show
  1. package/dist/assets/icons/ArrowRightIcon.d.ts +1 -1
  2. package/dist/assets/icons/WarningCircleIcon.d.ts +1 -1
  3. package/dist/components/common/Alert/index.d.ts +8 -2
  4. package/dist/components/common/CardShell/index.d.ts +1 -1
  5. package/dist/components/common/CardShell/types.d.ts +3 -1
  6. package/dist/components/common/IconWithSquareBackground/index.d.ts +12 -0
  7. package/dist/components/common/ServiceLinks/ServiceLinkItem/index.d.ts +15 -0
  8. package/dist/components/common/ServiceLinks/index.d.ts +3 -0
  9. package/dist/components/common/ServiceLinks/types.d.ts +34 -0
  10. package/dist/components/common/SideNav/SideNav.types.d.ts +20 -0
  11. package/dist/components/common/SideNav/SideNavLayout.d.ts +4 -0
  12. package/dist/components/common/SideNav/components/SideNavPill.d.ts +9 -0
  13. package/dist/components/common/SideNav/components/SideNavPillList.d.ts +9 -0
  14. package/dist/components/common/SideNav/components/SideNavRow.d.ts +9 -0
  15. package/dist/components/common/SideNav/hooks/useSideNavScrollSpy.d.ts +12 -0
  16. package/dist/components/common/SideNav/index.d.ts +4 -0
  17. package/dist/components/common/TitleBlock/index.d.ts +3 -0
  18. package/dist/components/common/TitleBlock/types.d.ts +73 -0
  19. package/dist/components/utils/normalizeSx.d.ts +4 -0
  20. package/dist/library/index.d.ts +8 -2
  21. package/dist/library/types.d.ts +6 -2
  22. package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
  23. package/dist/registrucentras-rc-ses-react-components.js +3489 -2703
  24. package/dist/stories/components/display/CardShell.stories.d.ts +1 -1
  25. package/dist/stories/components/display/SelectableCardList.stories.d.ts +1 -0
  26. package/dist/stories/components/display/ServiceLinks.stories.d.ts +28 -0
  27. package/dist/stories/components/display/TitleBlock.stories.d.ts +20 -0
  28. package/dist/stories/components/feedback/Alert.stories.d.ts +4 -0
  29. package/dist/stories/components/form/FormControlWrapper.stories.d.ts +1 -0
  30. package/dist/stories/components/icons/IconWithSquareBackground.stories.d.ts +7 -0
  31. package/dist/stories/components/navigation/SideNav.stories.d.ts +7 -0
  32. package/package.json +1 -1
  33. package/src/assets/icons/ArrowRightIcon.tsx +2 -1
  34. package/src/assets/icons/WarningCircleIcon.tsx +8 -2
  35. package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +8 -6
  36. package/src/components/common/Alert/index.test.tsx +157 -2
  37. package/src/components/common/Alert/index.tsx +144 -10
  38. package/src/components/common/Card/index.tsx +1 -23
  39. package/src/components/common/CardShell/index.tsx +4 -1
  40. package/src/components/common/CardShell/types.ts +3 -1
  41. package/src/components/common/IconWithSquareBackground/index.test.tsx +55 -0
  42. package/src/components/common/IconWithSquareBackground/index.tsx +83 -0
  43. package/src/components/common/ServiceLinks/ServiceLinkItem/index.tsx +177 -0
  44. package/src/components/common/ServiceLinks/index.test.tsx +166 -0
  45. package/src/components/common/ServiceLinks/index.tsx +66 -0
  46. package/src/components/common/ServiceLinks/types.ts +37 -0
  47. package/src/components/common/SideNav/SideNav.types.ts +24 -0
  48. package/src/components/common/SideNav/SideNavLayout.test.tsx +113 -0
  49. package/src/components/common/SideNav/SideNavLayout.tsx +67 -0
  50. package/src/components/common/SideNav/components/SideNavPill.tsx +62 -0
  51. package/src/components/common/SideNav/components/SideNavPillList.tsx +190 -0
  52. package/src/components/common/SideNav/components/SideNavRow.tsx +72 -0
  53. package/src/components/common/SideNav/hooks/useSideNavScrollSpy.test.ts +457 -0
  54. package/src/components/common/SideNav/hooks/useSideNavScrollSpy.ts +154 -0
  55. package/src/components/common/SideNav/index.test.tsx +99 -0
  56. package/src/components/common/SideNav/index.tsx +83 -0
  57. package/src/components/common/TitleBlock/index.test.tsx +366 -0
  58. package/src/components/common/TitleBlock/index.tsx +144 -0
  59. package/src/components/common/TitleBlock/types.ts +82 -0
  60. package/src/components/utils/normalizeSx.ts +24 -0
  61. package/src/i18n/namespaces/common/en.json +4 -0
  62. package/src/i18n/namespaces/common/lt.json +4 -0
  63. package/src/library/index.ts +8 -2
  64. package/src/library/types.ts +20 -8
  65. package/src/stories/components/display/CardShell.stories.tsx +14 -12
  66. package/src/stories/components/display/SelectableCardList.stories.tsx +33 -1
  67. package/src/stories/components/display/ServiceLinks.stories.tsx +154 -0
  68. package/src/stories/components/display/TitleBlock.stories.tsx +506 -0
  69. package/src/stories/components/feedback/Alert.stories.tsx +135 -4
  70. package/src/stories/components/form/FormControlWrapper.stories.tsx +23 -0
  71. package/src/stories/components/icons/IconWithSquareBackground.stories.tsx +60 -0
  72. package/src/stories/components/navigation/SideNav.stories.tsx +110 -0
  73. package/src/theme/cards.ts +1 -1
  74. package/src/theme/light/MuiAlert.tsx +28 -20
  75. package/src/theme/light/MuiButton.tsx +6 -0
  76. package/dist/components/common/CardShell/CardHeader/index.d.ts +0 -3
  77. package/dist/components/common/CardShell/CardHeader/types.d.ts +0 -33
  78. package/src/components/common/CardShell/CardHeader/index.test.tsx +0 -207
  79. package/src/components/common/CardShell/CardHeader/index.tsx +0 -104
  80. package/src/components/common/CardShell/CardHeader/types.ts +0 -36
@@ -0,0 +1,55 @@
1
+ import { ThemeProvider } from '@mui/material/styles'
2
+ import '@testing-library/jest-dom'
3
+ import { render } from '@testing-library/react'
4
+ import { type ReactElement } from 'react'
5
+ import { describe, expect, test } from 'vitest'
6
+
7
+ import InfoFillIcon from '@/assets/icons/InfoFillIcon'
8
+ import theme from '@/theme/light'
9
+
10
+ import RcSesIconWithSquareBackground from '.'
11
+
12
+ const renderTile = (ui: ReactElement) =>
13
+ render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
14
+
15
+ describe('RcSesIconWithSquareBackground', () => {
16
+ test('renders the provided icon inside the tile', () => {
17
+ const { container } = renderTile(
18
+ <RcSesIconWithSquareBackground Icon={InfoFillIcon} />,
19
+ )
20
+
21
+ expect(container.querySelector('.IconWithSquareBackground-root')).toBeInTheDocument()
22
+ expect(container.querySelector('svg')).toBeInTheDocument()
23
+ })
24
+
25
+ test('defaults to the 44 size', () => {
26
+ const { container } = renderTile(
27
+ <RcSesIconWithSquareBackground Icon={InfoFillIcon} />,
28
+ )
29
+
30
+ const root = container.querySelector('.IconWithSquareBackground-root') as HTMLElement
31
+ expect(root).toHaveStyle({ height: '2.75rem', width: '2.75rem' })
32
+ })
33
+
34
+ test('applies the 40 size tokens when size=40', () => {
35
+ const { container } = renderTile(
36
+ <RcSesIconWithSquareBackground Icon={InfoFillIcon} size={40} />,
37
+ )
38
+
39
+ const root = container.querySelector('.IconWithSquareBackground-root') as HTMLElement
40
+ expect(root).toHaveStyle({ height: '2.5rem', width: '2.5rem' })
41
+ })
42
+
43
+ test.each(['solid', 'soft', 'muted'] as const)(
44
+ 'renders without crashing for the %s variant',
45
+ (variant) => {
46
+ const { container } = renderTile(
47
+ <RcSesIconWithSquareBackground Icon={InfoFillIcon} variant={variant} />,
48
+ )
49
+
50
+ expect(
51
+ container.querySelector('.IconWithSquareBackground-root'),
52
+ ).toBeInTheDocument()
53
+ },
54
+ )
55
+ })
@@ -0,0 +1,83 @@
1
+ import { Box, styled } from '@mui/material'
2
+ import React, { memo, useMemo } from 'react'
3
+
4
+ import IconProps from '@/assets/IconProps'
5
+ import { ThemeColors } from '@/assets/ThemeColors'
6
+ import resolvePaletteColorPath from '@/assets/resolvePaletteColorPath'
7
+ import palette from '@/theme/palette'
8
+
9
+ type SquareTileSize = 40 | 44
10
+ type SquareTileVariant = 'solid' | 'soft' | 'muted'
11
+
12
+ type Props = {
13
+ Icon: React.JSXElementConstructor<IconProps>
14
+ size?: SquareTileSize
15
+ variant?: SquareTileVariant
16
+ }
17
+
18
+ const SIZE_TOKENS: Record<SquareTileSize, [string, string, string]> = {
19
+ 40: ['2.5rem', '1.375rem', '0.5rem'], // 40 / 22 / 8
20
+ 44: ['2.75rem', '1.5rem', '0.625rem'], // 44 / 24 / 10
21
+ }
22
+
23
+ function IconWithSquareBackground(props: Props) {
24
+ const { Icon } = props
25
+
26
+ const size = props?.size ?? 44
27
+ const variant = props?.variant ?? 'solid'
28
+
29
+ const [boxSize, iconSize, radius] = SIZE_TOKENS[size]
30
+
31
+ const { backgroundColor, iconColorPath } = useMemo<{
32
+ backgroundColor: string
33
+ iconColorPath: ThemeColors | 'white'
34
+ }>(() => {
35
+ switch (variant) {
36
+ case 'soft':
37
+ return {
38
+ backgroundColor: palette.primary[50],
39
+ iconColorPath: 'grey.900',
40
+ }
41
+ case 'muted':
42
+ return {
43
+ backgroundColor: palette.grey[100],
44
+ iconColorPath: 'grey.900',
45
+ }
46
+ case 'solid':
47
+ default:
48
+ return {
49
+ backgroundColor: palette.primary[500],
50
+ iconColorPath: 'white',
51
+ }
52
+ }
53
+ }, [variant])
54
+
55
+ const StyledIcon = styled(Icon)({
56
+ height: iconSize,
57
+ width: iconSize,
58
+ })
59
+
60
+ return (
61
+ <Box
62
+ className='IconWithSquareBackground-root'
63
+ sx={{
64
+ alignItems: 'center',
65
+ backgroundColor,
66
+ borderRadius: radius,
67
+ display: 'flex',
68
+ justifyContent: 'center',
69
+ height: boxSize,
70
+ width: boxSize,
71
+ aspectRatio: '1 / 1',
72
+
73
+ 'svg path': {
74
+ fill: resolvePaletteColorPath(iconColorPath),
75
+ },
76
+ }}
77
+ >
78
+ <StyledIcon />
79
+ </Box>
80
+ )
81
+ }
82
+
83
+ export default memo(IconWithSquareBackground)
@@ -0,0 +1,177 @@
1
+ import { Box, Skeleton, Stack, Typography } from '@mui/material'
2
+ import { ElementType } from 'react'
3
+
4
+ import ArrowRightIcon from '@/assets/icons/ArrowRightIcon'
5
+ import { subcard } from '@/theme/cards'
6
+ import palette from '@/theme/palette'
7
+
8
+ import { RcSesServiceLinkItem, RcSesServiceLinksTestIds } from '../types'
9
+
10
+ const linkRow = {
11
+ borderRadius: subcard.borderRadius,
12
+ gap: '1rem',
13
+ iconSize: 20,
14
+ labelFontWeight: 500,
15
+ lineHeight: '1.5rem',
16
+ paddingBlock: '0.75rem',
17
+ }
18
+
19
+ type Props = RcSesServiceLinkItem & {
20
+ isLoading?: boolean
21
+ testIds?: RcSesServiceLinksTestIds
22
+ /**
23
+ * Custom element used to render navigable rows. Receives `href` (and other
24
+ * anchor props) and must render an interactive element. Falls back to `<a>`.
25
+ * For router links, pass a small adapter, e.g.
26
+ * `({ href, ...rest }) => <RouterLink to={href} {...rest} />`.
27
+ */
28
+ linkComponent?: ElementType
29
+ }
30
+
31
+ function ServiceLinkItem({
32
+ label,
33
+ href,
34
+ target,
35
+ onClick,
36
+ disabled = false,
37
+ isLoading = false,
38
+ linkComponent,
39
+ testIds,
40
+ }: Props) {
41
+ if (isLoading) {
42
+ return (
43
+ <Box
44
+ sx={{
45
+ alignItems: 'center',
46
+ display: 'flex',
47
+ justifyContent: 'space-between',
48
+ minHeight: linkRow.lineHeight,
49
+ py: linkRow.paddingBlock,
50
+ width: '100%',
51
+ }}
52
+ >
53
+ <Skeleton
54
+ sx={{ borderRadius: 1, height: '1rem', width: '60%' }}
55
+ variant='rounded'
56
+ />
57
+ <Skeleton
58
+ sx={{ height: linkRow.iconSize, width: linkRow.iconSize }}
59
+ variant='rounded'
60
+ />
61
+ </Box>
62
+ )
63
+ }
64
+
65
+ const isLink = href !== undefined && !disabled
66
+ const isButton = !isLink && onClick !== undefined && !disabled
67
+ const isInteractive = isLink || isButton
68
+
69
+ // Navigable rows render as `linkComponent` (or native `<a>`); click-only rows
70
+ // render as a native `<button>` so they stay keyboard reachable; a disabled or
71
+ // static row degrades to a plain div. The Stack itself is the interactive
72
+ // element, so hover/focus styles, aria state and semantics live on one node.
73
+ let RowComponent: ElementType = 'div'
74
+ if (isLink) RowComponent = linkComponent ?? 'a'
75
+ else if (isButton) RowComponent = 'button'
76
+
77
+ let interactiveProps: Record<string, unknown> = {}
78
+ if (isLink) {
79
+ interactiveProps = {
80
+ href,
81
+ target,
82
+ rel: target === '_blank' ? 'noopener noreferrer' : undefined,
83
+ onClick,
84
+ }
85
+ } else if (isButton) {
86
+ interactiveProps = {
87
+ type: 'button',
88
+ onClick,
89
+ }
90
+ }
91
+
92
+ return (
93
+ <Stack
94
+ component={RowComponent}
95
+ data-testid={testIds?.item}
96
+ direction='row'
97
+ {...interactiveProps}
98
+ aria-disabled={disabled || undefined}
99
+ tabIndex={disabled ? -1 : undefined}
100
+ sx={{
101
+ alignItems: 'center',
102
+ appearance: 'none',
103
+ background: 'none',
104
+ border: 0,
105
+ borderRadius: linkRow.borderRadius,
106
+ color: 'inherit',
107
+ cursor: !disabled && isInteractive ? 'pointer' : 'default',
108
+ font: 'inherit',
109
+ gap: linkRow.gap,
110
+ justifyContent: 'space-between',
111
+ minHeight: linkRow.lineHeight,
112
+ opacity: disabled ? 0.5 : 1,
113
+ p: `${linkRow.paddingBlock} 0`,
114
+ pointerEvents: disabled ? 'none' : 'auto',
115
+ textAlign: 'left',
116
+ textDecoration: 'none',
117
+ width: '100%',
118
+
119
+ '&:focus-visible': {
120
+ outline: `2px solid ${palette.primary[500]}`,
121
+ outlineOffset: '2px',
122
+ },
123
+
124
+ ...(isInteractive && {
125
+ '&:hover .RcSesServiceLink-label, &:hover .RcSesServiceLink-icon': {
126
+ color: palette.primary[600],
127
+ },
128
+ '&:hover .RcSesServiceLink-icon': {
129
+ transform: 'translateX(2px)',
130
+ },
131
+ }),
132
+
133
+ '@media (prefers-reduced-motion: reduce)': {
134
+ '& .RcSesServiceLink-label, & .RcSesServiceLink-icon': {
135
+ transition: 'none',
136
+ },
137
+ '&:hover .RcSesServiceLink-icon': {
138
+ transform: 'none',
139
+ },
140
+ },
141
+ }}
142
+ >
143
+ <Typography
144
+ className='RcSesServiceLink-label'
145
+ component='span'
146
+ data-testid={testIds?.itemLabel}
147
+ variant='body1'
148
+ sx={{
149
+ color: palette.primary[700],
150
+ fontWeight: linkRow.labelFontWeight,
151
+ lineHeight: linkRow.lineHeight,
152
+ minWidth: 0,
153
+ overflowWrap: 'anywhere',
154
+ transition: 'color 150ms ease',
155
+ }}
156
+ >
157
+ {label}
158
+ </Typography>
159
+
160
+ <Box
161
+ aria-hidden
162
+ className='RcSesServiceLink-icon'
163
+ data-testid={testIds?.itemIcon}
164
+ sx={{
165
+ color: palette.primary[600],
166
+ display: 'flex',
167
+ flexShrink: 0,
168
+ transition: 'color 150ms ease, transform 150ms ease',
169
+ }}
170
+ >
171
+ <ArrowRightIcon fillColor='currentColor' size={linkRow.iconSize} weight='bold' />
172
+ </Box>
173
+ </Stack>
174
+ )
175
+ }
176
+
177
+ export default ServiceLinkItem
@@ -0,0 +1,166 @@
1
+ import { ThemeProvider } from '@mui/material/styles'
2
+ import '@testing-library/jest-dom'
3
+ import { fireEvent, render, screen } from '@testing-library/react'
4
+ import { type ReactElement } from 'react'
5
+ import { describe, expect, test, vi } from 'vitest'
6
+
7
+ import theme from '@/theme/light'
8
+
9
+ import RcSesServiceLinks from '.'
10
+
11
+ const renderServiceLinks = (ui: ReactElement) =>
12
+ render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
13
+
14
+ const baseItems = [
15
+ { label: 'First service', href: '#first' },
16
+ { label: 'Second service', href: '#second' },
17
+ ]
18
+
19
+ describe('RcSesServiceLinks', () => {
20
+ test('renders all provided items with their labels', () => {
21
+ renderServiceLinks(<RcSesServiceLinks items={baseItems} />)
22
+
23
+ expect(screen.getByText('First service')).toBeInTheDocument()
24
+ expect(screen.getByText('Second service')).toBeInTheDocument()
25
+ })
26
+
27
+ test('renders an item with href as a link pointing to the href', () => {
28
+ renderServiceLinks(<RcSesServiceLinks items={[{ label: 'Go', href: '/target' }]} />)
29
+
30
+ const link = screen.getByRole('link', { name: 'Go' })
31
+ expect(link).toHaveAttribute('href', '/target')
32
+ })
33
+
34
+ test('adds rel="noopener noreferrer" for links opening in a new tab', () => {
35
+ renderServiceLinks(
36
+ <RcSesServiceLinks items={[{ label: 'Ext', href: '/x', target: '_blank' }]} />,
37
+ )
38
+
39
+ const link = screen.getByRole('link', { name: 'Ext' })
40
+ expect(link).toHaveAttribute('target', '_blank')
41
+ expect(link).toHaveAttribute('rel', 'noopener noreferrer')
42
+ })
43
+
44
+ test('does not set rel on same-tab links', () => {
45
+ renderServiceLinks(<RcSesServiceLinks items={[{ label: 'Same', href: '/s' }]} />)
46
+
47
+ const link = screen.getByRole('link', { name: 'Same' })
48
+ expect(link).not.toHaveAttribute('rel')
49
+ expect(link).not.toHaveAttribute('target')
50
+ })
51
+
52
+ test('fires onClick on a link while keeping it a link', () => {
53
+ const onClick = vi.fn()
54
+ renderServiceLinks(
55
+ <RcSesServiceLinks items={[{ label: 'Both', href: '/b', onClick }]} />,
56
+ )
57
+
58
+ const link = screen.getByRole('link', { name: 'Both' })
59
+ fireEvent.click(link)
60
+ expect(onClick).toHaveBeenCalledTimes(1)
61
+ })
62
+
63
+ test('does not render disabled item as a link', () => {
64
+ renderServiceLinks(
65
+ <RcSesServiceLinks items={[{ label: 'Off', href: '/off', disabled: true }]} />,
66
+ )
67
+
68
+ expect(screen.queryByRole('link', { name: 'Off' })).not.toBeInTheDocument()
69
+ expect(screen.getByText('Off')).toBeInTheDocument()
70
+ })
71
+
72
+ test('removes disabled item from the keyboard tab order', () => {
73
+ renderServiceLinks(
74
+ <RcSesServiceLinks
75
+ items={[{ label: 'Off', href: '/off', disabled: true }]}
76
+ testIds={{ item: 'row' }}
77
+ />,
78
+ )
79
+
80
+ expect(screen.getByTestId('row')).toHaveAttribute('tabindex', '-1')
81
+ })
82
+
83
+ test('renders navigable rows through a custom linkComponent', () => {
84
+ const RouterLink = ({ href, children, ...rest }: React.ComponentProps<'a'>) => (
85
+ <a href={href} data-router-link {...rest}>
86
+ {children}
87
+ </a>
88
+ )
89
+
90
+ renderServiceLinks(<RcSesServiceLinks items={baseItems} linkComponent={RouterLink} />)
91
+
92
+ const links = screen.getAllByRole('link')
93
+ expect(links).toHaveLength(2)
94
+ links.forEach((link) => expect(link).toHaveAttribute('data-router-link'))
95
+ expect(links[0]).toHaveAttribute('href', '#first')
96
+ })
97
+
98
+ test('linkComponent receives href, target, rel and onClick', () => {
99
+ const onClick = vi.fn()
100
+ const linkComponent = vi.fn(
101
+ ({ href, children, ...rest }: React.ComponentProps<'a'>) => (
102
+ <a href={href} {...rest}>
103
+ {children}
104
+ </a>
105
+ ),
106
+ )
107
+
108
+ renderServiceLinks(
109
+ <RcSesServiceLinks
110
+ items={[{ label: 'Go', href: '/target', target: '_blank', onClick }]}
111
+ linkComponent={linkComponent}
112
+ />,
113
+ )
114
+
115
+ expect(linkComponent).toHaveBeenCalled()
116
+ expect(linkComponent.mock.calls[0][0]).toEqual(
117
+ expect.objectContaining({
118
+ href: '/target',
119
+ target: '_blank',
120
+ rel: 'noopener noreferrer',
121
+ onClick,
122
+ }),
123
+ )
124
+ })
125
+
126
+ test('linkComponent does not receive rel for same-tab links', () => {
127
+ const linkComponent = vi.fn(
128
+ ({ href, children, ...rest }: React.ComponentProps<'a'>) => (
129
+ <a href={href} {...rest}>
130
+ {children}
131
+ </a>
132
+ ),
133
+ )
134
+
135
+ renderServiceLinks(
136
+ <RcSesServiceLinks
137
+ items={[{ label: 'Go', href: '/target' }]}
138
+ linkComponent={linkComponent}
139
+ />,
140
+ )
141
+
142
+ const props = linkComponent.mock.calls[0][0]
143
+ expect(props.rel).toBeUndefined()
144
+ expect(props.target).toBeUndefined()
145
+ })
146
+
147
+ test('linkComponent is not used for disabled items', () => {
148
+ const linkComponent = vi.fn(
149
+ ({ href, children, ...rest }: React.ComponentProps<'a'>) => (
150
+ <a href={href} {...rest}>
151
+ {children}
152
+ </a>
153
+ ),
154
+ )
155
+
156
+ renderServiceLinks(
157
+ <RcSesServiceLinks
158
+ items={[{ label: 'Off', href: '/off', disabled: true }]}
159
+ linkComponent={linkComponent}
160
+ />,
161
+ )
162
+
163
+ expect(linkComponent).not.toHaveBeenCalled()
164
+ expect(screen.queryByRole('link', { name: 'Off' })).not.toBeInTheDocument()
165
+ })
166
+ })
@@ -0,0 +1,66 @@
1
+ import { Box, Divider } from '@mui/material'
2
+ import { Fragment } from 'react'
3
+
4
+ import palette from '@/theme/palette'
5
+
6
+ import ServiceLinkItem from './ServiceLinkItem'
7
+ import { RcSesServiceLinksProps } from './types'
8
+
9
+ function RcSesServiceLinks({
10
+ items,
11
+ dividers = true,
12
+ isLoading = false,
13
+ skeletonCount = 4,
14
+ linkComponent,
15
+ className,
16
+ testIds,
17
+ }: RcSesServiceLinksProps) {
18
+ const rowCount = isLoading ? skeletonCount : items.length
19
+
20
+ return (
21
+ <Box
22
+ className={className}
23
+ data-testid={testIds?.root}
24
+ sx={{
25
+ display: 'flex',
26
+ flexDirection: 'column',
27
+ width: '100%',
28
+ }}
29
+ >
30
+ {Array.from({ length: rowCount }).map((_, index) => {
31
+ if (isLoading) {
32
+ return (
33
+ // Skeleton rows are indistinguishable and the list length is fixed
34
+ // by `skeletonCount`, so index is a stable identity here.
35
+ // eslint-disable-next-line react/no-array-index-key
36
+ <Fragment key={`skeleton-${index}`}>
37
+ {dividers && index > 0 ? (
38
+ <Divider sx={{ borderColor: palette.grey[200] }} />
39
+ ) : null}
40
+ <ServiceLinkItem label='' isLoading testIds={testIds} />
41
+ </Fragment>
42
+ )
43
+ }
44
+
45
+ const item = items[index]
46
+ const { key: itemKey, ...itemProps } = item
47
+ const key = itemKey || String(index)
48
+
49
+ return (
50
+ <Fragment key={key}>
51
+ {dividers && index > 0 ? (
52
+ <Divider sx={{ borderColor: palette.grey[200] }} />
53
+ ) : null}
54
+ <ServiceLinkItem
55
+ {...itemProps}
56
+ linkComponent={linkComponent}
57
+ testIds={testIds}
58
+ />
59
+ </Fragment>
60
+ )
61
+ })}
62
+ </Box>
63
+ )
64
+ }
65
+
66
+ export default RcSesServiceLinks
@@ -0,0 +1,37 @@
1
+ import { ElementType, ReactNode } from 'react'
2
+
3
+ export type RcSesServiceLinksTestIds = {
4
+ root?: string
5
+ item?: string
6
+ itemLabel?: string
7
+ itemIcon?: string
8
+ }
9
+
10
+ export type RcSesServiceLinkItem = {
11
+ label: ReactNode
12
+ href?: string
13
+ target?: string
14
+ onClick?: (event: React.MouseEvent<HTMLElement>) => void
15
+ disabled?: boolean
16
+ /**
17
+ * Optional stable identity used as the React key when rendering the list.
18
+ * Stripped out before spreading onto the row, so it never reaches the DOM.
19
+ */
20
+ key?: string
21
+ }
22
+
23
+ export type RcSesServiceLinksProps = {
24
+ items: RcSesServiceLinkItem[]
25
+ dividers?: boolean
26
+ isLoading?: boolean
27
+ skeletonCount?: number
28
+ /**
29
+ * Custom element used to render navigable rows. Receives `href` (and other
30
+ * anchor props). Falls back to a native `<a>` when omitted. For router
31
+ * links pass a small adapter, e.g.
32
+ * `({ href, ...rest }) => <RouterLink to={href} {...rest} />`.
33
+ */
34
+ linkComponent?: ElementType
35
+ className?: string
36
+ testIds?: RcSesServiceLinksTestIds
37
+ }
@@ -0,0 +1,24 @@
1
+ import { SxProps, Theme } from '@mui/material'
2
+ import { ReactNode } from 'react'
3
+
4
+ export type RcSesSideNavItem = {
5
+ id: string
6
+ label: string
7
+ count?: number
8
+ }
9
+
10
+ export type RcSesSideNavProps = {
11
+ // In document order - scroll-spy compares section positions in list order.
12
+ items: RcSesSideNavItem[]
13
+ activeItemId?: string
14
+ onItemClick?: (id: string) => void
15
+ title?: string
16
+ sx?: SxProps<Theme>
17
+ }
18
+
19
+ export type RcSesSideNavLayoutProps = Omit<RcSesSideNavProps, 'sx'> & {
20
+ children: ReactNode
21
+ sidebarWidth?: string
22
+ offset?: number
23
+ sx?: SxProps<Theme>
24
+ }