@registrucentras/rc-ses-react-components 2.0.0-rc.2 → 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.
- package/dist/assets/icons/ArrowRightIcon.d.ts +1 -1
- package/dist/components/common/CardShell/CardFooter/index.d.ts +3 -0
- package/dist/components/common/CardShell/CardFooter/types.d.ts +21 -0
- package/dist/components/common/CardShell/index.d.ts +5 -0
- package/dist/components/common/CardShell/types.d.ts +26 -0
- package/dist/components/common/IconWithSquareBackground/index.d.ts +12 -0
- package/dist/components/common/ServiceLinks/ServiceLinkItem/index.d.ts +15 -0
- package/dist/components/common/ServiceLinks/index.d.ts +3 -0
- package/dist/components/common/ServiceLinks/types.d.ts +34 -0
- package/dist/components/common/SideNav/SideNav.types.d.ts +20 -0
- package/dist/components/common/SideNav/SideNavLayout.d.ts +4 -0
- package/dist/components/common/SideNav/components/SideNavPill.d.ts +9 -0
- package/dist/components/common/SideNav/components/SideNavPillList.d.ts +9 -0
- package/dist/components/common/SideNav/components/SideNavRow.d.ts +9 -0
- package/dist/components/common/SideNav/hooks/useSideNavScrollSpy.d.ts +12 -0
- package/dist/components/common/SideNav/index.d.ts +4 -0
- package/dist/components/common/TitleBlock/index.d.ts +3 -0
- package/dist/components/common/TitleBlock/types.d.ts +73 -0
- package/dist/components/utils/normalizeSx.d.ts +4 -0
- package/dist/library/index.d.ts +10 -1
- package/dist/library/types.d.ts +8 -1
- package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
- package/dist/registrucentras-rc-ses-react-components.js +3535 -2563
- package/dist/stories/components/display/CardShell.stories.d.ts +17 -0
- package/dist/stories/components/display/SelectableCardList.stories.d.ts +1 -0
- package/dist/stories/components/display/ServiceLinks.stories.d.ts +28 -0
- package/dist/stories/components/display/TitleBlock.stories.d.ts +20 -0
- package/dist/stories/components/form/FormControlWrapper.stories.d.ts +1 -0
- package/dist/stories/components/icons/IconWithSquareBackground.stories.d.ts +7 -0
- package/dist/stories/components/inputs/DatePicker.stories.d.ts +107 -0
- package/dist/stories/components/navigation/SideNav.stories.d.ts +7 -0
- package/dist/theme/cards.d.ts +114 -0
- package/dist/theme/light/MuiPickersOutlinedInput.d.ts +8 -0
- package/package.json +1 -1
- package/src/assets/icons/ArrowRightIcon.tsx +2 -1
- package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +8 -6
- package/src/components/common/Card/index.tsx +1 -23
- package/src/components/common/CardShell/CardFooter/index.test.tsx +52 -0
- package/src/components/common/CardShell/CardFooter/index.tsx +38 -0
- package/src/components/common/CardShell/CardFooter/types.ts +24 -0
- package/src/components/common/CardShell/index.test.tsx +137 -0
- package/src/components/common/CardShell/index.tsx +78 -0
- package/src/components/common/CardShell/types.ts +30 -0
- package/src/components/common/IconWithSquareBackground/index.test.tsx +55 -0
- package/src/components/common/IconWithSquareBackground/index.tsx +83 -0
- package/src/components/common/ServiceLinks/ServiceLinkItem/index.tsx +177 -0
- package/src/components/common/ServiceLinks/index.test.tsx +166 -0
- package/src/components/common/ServiceLinks/index.tsx +66 -0
- package/src/components/common/ServiceLinks/types.ts +37 -0
- package/src/components/common/SideNav/SideNav.types.ts +24 -0
- package/src/components/common/SideNav/SideNavLayout.test.tsx +113 -0
- package/src/components/common/SideNav/SideNavLayout.tsx +67 -0
- package/src/components/common/SideNav/components/SideNavPill.tsx +62 -0
- package/src/components/common/SideNav/components/SideNavPillList.tsx +190 -0
- package/src/components/common/SideNav/components/SideNavRow.tsx +72 -0
- package/src/components/common/SideNav/hooks/useSideNavScrollSpy.test.ts +457 -0
- package/src/components/common/SideNav/hooks/useSideNavScrollSpy.ts +154 -0
- package/src/components/common/SideNav/index.test.tsx +99 -0
- package/src/components/common/SideNav/index.tsx +83 -0
- package/src/components/common/TitleBlock/index.test.tsx +366 -0
- package/src/components/common/TitleBlock/index.tsx +144 -0
- package/src/components/common/TitleBlock/types.ts +82 -0
- package/src/components/form/inputs/Datepicker/index.test.tsx +117 -0
- package/src/components/utils/normalizeSx.ts +24 -0
- package/src/i18n/namespaces/common/en.json +4 -0
- package/src/i18n/namespaces/common/lt.json +4 -0
- package/src/library/index.ts +12 -0
- package/src/library/types.ts +38 -0
- package/src/stories/components/display/CardShell.stories.tsx +263 -0
- package/src/stories/components/display/SelectableCardList.stories.tsx +33 -1
- package/src/stories/components/display/ServiceLinks.stories.tsx +154 -0
- package/src/stories/components/display/TitleBlock.stories.tsx +506 -0
- package/src/stories/components/form/FormControlWrapper.stories.tsx +23 -0
- package/src/stories/components/icons/IconWithSquareBackground.stories.tsx +60 -0
- package/src/stories/components/inputs/DatePicker.stories.tsx +105 -9
- package/src/stories/components/navigation/SideNav.stories.tsx +110 -0
- package/src/theme/cards.ts +60 -0
- package/src/theme/light/MuiButton.tsx +6 -0
- package/src/theme/light/MuiPickersLayout.ts +10 -1
- package/src/theme/light/MuiPickersOutlinedInput.ts +88 -0
- package/src/theme/light/index.tsx +2 -0
|
@@ -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,78 @@
|
|
|
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
|
+
borderless = false,
|
|
19
|
+
header,
|
|
20
|
+
children,
|
|
21
|
+
footer,
|
|
22
|
+
className,
|
|
23
|
+
testIds,
|
|
24
|
+
sx,
|
|
25
|
+
...boxProps
|
|
26
|
+
}: ShellProps) {
|
|
27
|
+
return (
|
|
28
|
+
<Box
|
|
29
|
+
{...boxProps}
|
|
30
|
+
className={className}
|
|
31
|
+
data-testid={testIds?.root}
|
|
32
|
+
sx={[
|
|
33
|
+
{
|
|
34
|
+
display: 'flex',
|
|
35
|
+
flexDirection: 'column',
|
|
36
|
+
height: fullHeight ? '100%' : 'auto',
|
|
37
|
+
minWidth: 0,
|
|
38
|
+
// enables stretched-link pattern in interactive compositions
|
|
39
|
+
position: 'relative',
|
|
40
|
+
backgroundColor: cards.themes[theme].backgroundColor,
|
|
41
|
+
border: borderless
|
|
42
|
+
? 'none'
|
|
43
|
+
: `${cards.borderWidth} solid ${cards.themes[theme].borderColor}`,
|
|
44
|
+
borderRadius: cards[variant].borderRadius,
|
|
45
|
+
gap: cards[variant].gap,
|
|
46
|
+
p: cards[variant].padding,
|
|
47
|
+
},
|
|
48
|
+
...(Array.isArray(sx) ? sx : [sx]),
|
|
49
|
+
]}
|
|
50
|
+
>
|
|
51
|
+
{hasSlot(header) ? (
|
|
52
|
+
<Box data-testid={testIds?.header} sx={{ minWidth: 0, width: '100%' }}>
|
|
53
|
+
{header}
|
|
54
|
+
</Box>
|
|
55
|
+
) : null}
|
|
56
|
+
|
|
57
|
+
{hasSlot(children) ? (
|
|
58
|
+
<Box
|
|
59
|
+
data-testid={testIds?.content}
|
|
60
|
+
sx={{ flexGrow: fullHeight ? 1 : 0, minWidth: 0, width: '100%' }}
|
|
61
|
+
>
|
|
62
|
+
{children}
|
|
63
|
+
</Box>
|
|
64
|
+
) : null}
|
|
65
|
+
|
|
66
|
+
{hasSlot(footer) ? (
|
|
67
|
+
<Box
|
|
68
|
+
data-testid={testIds?.footer}
|
|
69
|
+
sx={{ minWidth: 0, mt: fullHeight ? 'auto' : 0, width: '100%' }}
|
|
70
|
+
>
|
|
71
|
+
{footer}
|
|
72
|
+
</Box>
|
|
73
|
+
) : null}
|
|
74
|
+
</Box>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default RcSesCardShell
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
/** Renders the shell without any border. */
|
|
19
|
+
borderless?: boolean
|
|
20
|
+
/** Header row, normally `RcSesTitleBlock`. The shell only provides the slot. */
|
|
21
|
+
header?: ReactNode
|
|
22
|
+
children?: ReactNode
|
|
23
|
+
/**
|
|
24
|
+
* Footer row, normally `RcSesCardFooter`. The shell only provides the slot, so
|
|
25
|
+
* direction and alignment belong to the footer block rather than here.
|
|
26
|
+
*/
|
|
27
|
+
footer?: ReactNode
|
|
28
|
+
className?: string
|
|
29
|
+
testIds?: RcSesCardShellTestIds
|
|
30
|
+
}
|
|
@@ -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
|