@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.
- package/dist/assets/icons/ArrowRightIcon.d.ts +1 -1
- package/dist/components/common/CardShell/index.d.ts +1 -1
- package/dist/components/common/CardShell/types.d.ts +3 -1
- 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 +8 -2
- package/dist/library/types.d.ts +6 -2
- package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
- package/dist/registrucentras-rc-ses-react-components.js +3412 -2728
- package/dist/stories/components/display/CardShell.stories.d.ts +1 -1
- 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/navigation/SideNav.stories.d.ts +7 -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/index.tsx +4 -1
- package/src/components/common/CardShell/types.ts +3 -1
- 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/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 +8 -2
- package/src/library/types.ts +20 -8
- package/src/stories/components/display/CardShell.stories.tsx +14 -12
- 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/navigation/SideNav.stories.tsx +110 -0
- package/src/theme/cards.ts +1 -1
- package/src/theme/light/MuiButton.tsx +6 -0
- package/dist/components/common/CardShell/CardHeader/index.d.ts +0 -3
- package/dist/components/common/CardShell/CardHeader/types.d.ts +0 -33
- package/src/components/common/CardShell/CardHeader/index.test.tsx +0 -207
- package/src/components/common/CardShell/CardHeader/index.tsx +0 -104
- package/src/components/common/CardShell/CardHeader/types.ts +0 -36
|
@@ -8,8 +8,8 @@ export declare const SubcardVariant: Story;
|
|
|
8
8
|
export declare const BrandTheme: Story;
|
|
9
9
|
export declare const SunkenTheme: Story;
|
|
10
10
|
export declare const HeaderComplete: Story;
|
|
11
|
+
export declare const Borderless: Story;
|
|
11
12
|
export declare const WithoutHeader: Story;
|
|
12
|
-
export declare const FooterSingleLink: Story;
|
|
13
13
|
export declare const WithoutFooter: Story;
|
|
14
14
|
export declare const ContentOnly: Story;
|
|
15
15
|
export declare const FullHeight: Story;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { default as RcSesServiceLinks } from '../../../components/common/ServiceLinks';
|
|
3
|
+
declare const meta: Meta<typeof RcSesServiceLinks>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof RcSesServiceLinks>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const WithoutDividers: Story;
|
|
8
|
+
export declare const WithDisabledItem: Story;
|
|
9
|
+
export declare const Loading: Story;
|
|
10
|
+
/**
|
|
11
|
+
* Items with `target='_blank'` open in a new tab. The shell automatically
|
|
12
|
+
* adds `rel='noopener noreferrer'` on those rows for safety; other rows get
|
|
13
|
+
* no `rel` attribute.
|
|
14
|
+
*/
|
|
15
|
+
export declare const ExternalLinks: Story;
|
|
16
|
+
/**
|
|
17
|
+
* Passing a `linkComponent` renders every navigable row through it. The shell
|
|
18
|
+
* forwards `href`, `onClick`, and (when the item sets `target='_blank'`) also
|
|
19
|
+
* `target` and `rel='noopener noreferrer'`. Adapt a router `Link` with a
|
|
20
|
+
* one-line wrapper — as long as it renders a real `<a>` underneath,
|
|
21
|
+
* middle-click and "open in new tab" keep working.
|
|
22
|
+
*/
|
|
23
|
+
export declare const WithRouterLink: Story;
|
|
24
|
+
/**
|
|
25
|
+
* The intended composition: ServiceLinks placed inside a CardShell as the
|
|
26
|
+
* content slot, framed by a CardHeader and a CardFooter.
|
|
27
|
+
*/
|
|
28
|
+
export declare const InsideCardShell: Story;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { default as RcSesTitleBlock } from '../../../components/common/TitleBlock';
|
|
3
|
+
declare const meta: Meta<typeof RcSesTitleBlock>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof RcSesTitleBlock>;
|
|
6
|
+
export declare const TitleBlock: Story;
|
|
7
|
+
export declare const WithPrimaryAction: Story;
|
|
8
|
+
export declare const WithLinkAction: Story;
|
|
9
|
+
export declare const WithPrimaryAndSecondaryActions: Story;
|
|
10
|
+
export declare const RowList: Story;
|
|
11
|
+
export declare const RowListWithIcons: Story;
|
|
12
|
+
export declare const RowListWithIconsAndTwoActions: Story;
|
|
13
|
+
export declare const HorizontalTitleBlockWithIconAndArrow: Story;
|
|
14
|
+
export declare const HorizontalTitleBlockWithArrowAndBrandCardShellTheme: Story;
|
|
15
|
+
export declare const HorizontalTitleBlockWithArrowAndSunkenCardShellTheme: Story;
|
|
16
|
+
export declare const ClickableHorizontalTitleBlockWithCardShellBase: Story;
|
|
17
|
+
export declare const VerticalTitleBlockWithCardShellBase: Story;
|
|
18
|
+
export declare const VerticalTitleBlock: Story;
|
|
19
|
+
export declare const MobileViewport: Story;
|
|
20
|
+
export declare const TabletViewport: Story;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { default as RcSesIconWithSquareBackground } from '../../../components/common/IconWithSquareBackground';
|
|
3
|
+
declare const meta: Meta<typeof RcSesIconWithSquareBackground>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof meta>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const AllVariantsAndSizes: Story;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { default as RcSesSideNavLayout } from '../../../components/common/SideNav/SideNavLayout';
|
|
3
|
+
declare const meta: Meta<typeof RcSesSideNavLayout>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof RcSesSideNavLayout>;
|
|
6
|
+
export declare const Main: Story;
|
|
7
|
+
export declare const WithScrollSpy: Story;
|
package/package.json
CHANGED
|
@@ -2,13 +2,14 @@ import { ArrowRightIcon as PhosphorArrowRightIcon } from '@phosphor-icons/react'
|
|
|
2
2
|
|
|
3
3
|
import IconProps from '../IconProps'
|
|
4
4
|
|
|
5
|
-
function ArrowRightIcon({ className, size = 24, fillColor, ...rest }: IconProps) {
|
|
5
|
+
function ArrowRightIcon({ className, size = 24, fillColor, weight, ...rest }: IconProps) {
|
|
6
6
|
return (
|
|
7
7
|
<PhosphorArrowRightIcon
|
|
8
8
|
{...rest}
|
|
9
9
|
className={className}
|
|
10
10
|
size={size}
|
|
11
11
|
color={fillColor}
|
|
12
|
+
weight={weight}
|
|
12
13
|
/>
|
|
13
14
|
)
|
|
14
15
|
}
|
|
@@ -62,6 +62,9 @@ const AdvancedListItem = ({
|
|
|
62
62
|
const isSelectable = leading.type === 'checkbox' || leading.type === 'radio'
|
|
63
63
|
const isClickable = (!!onClick || isSelectable) && !isDisabled
|
|
64
64
|
|
|
65
|
+
const effectiveState: AdvancedListItemState =
|
|
66
|
+
state === 'rest' && 'checked' in leading && leading.checked ? 'selected' : state
|
|
67
|
+
|
|
65
68
|
const hasInteractiveChild =
|
|
66
69
|
INTERACTIVE_LEADING_TYPES.has(leading.type) ||
|
|
67
70
|
INTERACTIVE_TRAILING_TYPES.has(trailing.type) ||
|
|
@@ -88,8 +91,8 @@ const AdvancedListItem = ({
|
|
|
88
91
|
const contentRef = useRef<HTMLDivElement>(null)
|
|
89
92
|
const prefersReducedMotion = usePrefersReducedMotion()
|
|
90
93
|
|
|
91
|
-
const borderColor = STATE_BORDER_COLOR[
|
|
92
|
-
const backgroundColor =
|
|
94
|
+
const borderColor = STATE_BORDER_COLOR[effectiveState]
|
|
95
|
+
const backgroundColor = effectiveState === 'selected' ? palette.primary[50] : undefined
|
|
93
96
|
const focusRingShadow = `0 0 0 ${FOCUS_RING_WIDTH} ${palette.primary.main}`
|
|
94
97
|
const transitionTiming = `${motion.duration.standard}ms ${motion.easing.standard}`
|
|
95
98
|
|
|
@@ -184,7 +187,6 @@ const AdvancedListItem = ({
|
|
|
184
187
|
sx={{
|
|
185
188
|
display: 'flex',
|
|
186
189
|
flexDirection: 'column',
|
|
187
|
-
gap: '0.75rem',
|
|
188
190
|
width: '100%',
|
|
189
191
|
boxSizing: 'border-box',
|
|
190
192
|
border: `${BORDER_WIDTH} solid`,
|
|
@@ -195,12 +197,12 @@ const AdvancedListItem = ({
|
|
|
195
197
|
opacity: isDisabled ? 0.6 : 1,
|
|
196
198
|
pointerEvents: isDisabled ? 'none' : 'auto',
|
|
197
199
|
cursor: isClickable ? 'pointer' : 'default',
|
|
198
|
-
boxShadow:
|
|
200
|
+
boxShadow: effectiveState === 'selected' ? focusRingShadow : 'none',
|
|
199
201
|
transition: prefersReducedMotion
|
|
200
202
|
? 'none'
|
|
201
203
|
: `border-color ${transitionTiming}, box-shadow ${transitionTiming}`,
|
|
202
204
|
'&:hover': isClickable
|
|
203
|
-
? { borderColor:
|
|
205
|
+
? { borderColor: effectiveState === 'rest' ? palette.grey[400] : borderColor }
|
|
204
206
|
: undefined,
|
|
205
207
|
'&:focus-visible, &:focus-within': !isDisabled
|
|
206
208
|
? { borderColor: palette.primary.main, boxShadow: focusRingShadow }
|
|
@@ -319,7 +321,7 @@ const AdvancedListItem = ({
|
|
|
319
321
|
ref={contentRef}
|
|
320
322
|
id={contentId}
|
|
321
323
|
sx={{
|
|
322
|
-
|
|
324
|
+
marginTop: '0.5rem',
|
|
323
325
|
backgroundColor: palette.grey[50],
|
|
324
326
|
borderRadius: BORDER_RADIUS,
|
|
325
327
|
padding: '0.75rem 1rem',
|
|
@@ -5,13 +5,12 @@ import {
|
|
|
5
5
|
Card as MuiCard,
|
|
6
6
|
Stack,
|
|
7
7
|
StackProps,
|
|
8
|
-
SxProps,
|
|
9
|
-
Theme,
|
|
10
8
|
Typography,
|
|
11
9
|
TypographyProps,
|
|
12
10
|
} from '@mui/material'
|
|
13
11
|
import { ReactNode } from 'react'
|
|
14
12
|
|
|
13
|
+
import normalizeSx from '@/components/utils/normalizeSx'
|
|
15
14
|
import palette from '@/theme/palette'
|
|
16
15
|
|
|
17
16
|
export type RcSesCardTestIds = {
|
|
@@ -51,27 +50,6 @@ export type RcSesCardProps = Omit<CardProps, 'children' | 'title'> & {
|
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
type SxEntry =
|
|
55
|
-
Extract<SxProps<Theme>, ReadonlyArray<unknown>> extends ReadonlyArray<infer T>
|
|
56
|
-
? T
|
|
57
|
-
: never
|
|
58
|
-
|
|
59
|
-
function isSxArray(sx: SxProps<Theme>): sx is ReadonlyArray<SxEntry> {
|
|
60
|
-
return Array.isArray(sx)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function normalizeSx(sx: SxProps<Theme> | undefined): SxEntry[] {
|
|
64
|
-
if (sx === undefined) {
|
|
65
|
-
return []
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (isSxArray(sx)) {
|
|
69
|
-
return [...sx]
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return [sx]
|
|
73
|
-
}
|
|
74
|
-
|
|
75
53
|
function RcSesCard({
|
|
76
54
|
title,
|
|
77
55
|
description,
|
|
@@ -15,6 +15,7 @@ function RcSesCardShell({
|
|
|
15
15
|
variant = 'card',
|
|
16
16
|
theme = 'default',
|
|
17
17
|
fullHeight = false,
|
|
18
|
+
borderless = false,
|
|
18
19
|
header,
|
|
19
20
|
children,
|
|
20
21
|
footer,
|
|
@@ -37,7 +38,9 @@ function RcSesCardShell({
|
|
|
37
38
|
// enables stretched-link pattern in interactive compositions
|
|
38
39
|
position: 'relative',
|
|
39
40
|
backgroundColor: cards.themes[theme].backgroundColor,
|
|
40
|
-
border:
|
|
41
|
+
border: borderless
|
|
42
|
+
? 'none'
|
|
43
|
+
: `${cards.borderWidth} solid ${cards.themes[theme].borderColor}`,
|
|
41
44
|
borderRadius: cards[variant].borderRadius,
|
|
42
45
|
gap: cards[variant].gap,
|
|
43
46
|
p: cards[variant].padding,
|
|
@@ -15,7 +15,9 @@ export type RcSesCardShellProps = {
|
|
|
15
15
|
variant?: CardShellVariant
|
|
16
16
|
theme?: CardShellTheme
|
|
17
17
|
fullHeight?: boolean
|
|
18
|
-
/**
|
|
18
|
+
/** Renders the shell without any border. */
|
|
19
|
+
borderless?: boolean
|
|
20
|
+
/** Header row, normally `RcSesTitleBlock`. The shell only provides the slot. */
|
|
19
21
|
header?: ReactNode
|
|
20
22
|
children?: ReactNode
|
|
21
23
|
/**
|
|
@@ -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
|