@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.
- package/dist/assets/icons/ArrowRightIcon.d.ts +1 -1
- package/dist/assets/icons/WarningCircleIcon.d.ts +1 -1
- package/dist/components/common/Alert/index.d.ts +8 -2
- 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 +3489 -2703
- 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/feedback/Alert.stories.d.ts +4 -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/assets/icons/WarningCircleIcon.tsx +8 -2
- package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +8 -6
- package/src/components/common/Alert/index.test.tsx +157 -2
- package/src/components/common/Alert/index.tsx +144 -10
- 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/feedback/Alert.stories.tsx +135 -4
- 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/MuiAlert.tsx +28 -20
- 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;
|
|
@@ -7,4 +7,8 @@ export declare const Main: Story;
|
|
|
7
7
|
export declare const Outlined: Story;
|
|
8
8
|
export declare const Filled: Story;
|
|
9
9
|
export declare const Standard: Story;
|
|
10
|
+
export declare const WithActionAndClose: Story;
|
|
11
|
+
export declare const WithoutActionAndClose: Story;
|
|
12
|
+
export declare const Toggles: Story;
|
|
13
|
+
export declare const Dismissible: Story;
|
|
10
14
|
export declare const WithContainer: Story;
|
|
@@ -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
|
}
|
|
@@ -2,13 +2,19 @@ import { WarningCircleIcon as WarningCircle } from '@phosphor-icons/react'
|
|
|
2
2
|
|
|
3
3
|
import IconProps from '../IconProps'
|
|
4
4
|
|
|
5
|
-
function WarningCircleIcon({
|
|
5
|
+
function WarningCircleIcon({
|
|
6
|
+
className,
|
|
7
|
+
size = 24,
|
|
8
|
+
fillColor,
|
|
9
|
+
weight = 'fill',
|
|
10
|
+
...rest
|
|
11
|
+
}: IconProps) {
|
|
6
12
|
return (
|
|
7
13
|
<WarningCircle
|
|
8
14
|
{...rest}
|
|
9
15
|
className={className}
|
|
10
16
|
size={size}
|
|
11
|
-
weight=
|
|
17
|
+
weight={weight}
|
|
12
18
|
color={fillColor}
|
|
13
19
|
/>
|
|
14
20
|
)
|
|
@@ -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',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ThemeProvider } from '@mui/material/styles'
|
|
2
|
-
import { render, screen } from '@testing-library/react'
|
|
2
|
+
import { act, fireEvent, render, screen } from '@testing-library/react'
|
|
3
3
|
import { vi } from 'vitest'
|
|
4
4
|
|
|
5
5
|
import theme from '@/theme/light'
|
|
@@ -22,7 +22,7 @@ describe('RcSesAlert', () => {
|
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
test('renders with each severity', () => {
|
|
25
|
-
const severities = ['info', 'warning', 'error', 'success'] as const
|
|
25
|
+
const severities = ['grey', 'info', 'warning', 'error', 'success'] as const
|
|
26
26
|
severities.forEach((severity) => {
|
|
27
27
|
const { unmount } = renderAlert(
|
|
28
28
|
<RcSesAlert severity={severity}>{severity} message</RcSesAlert>,
|
|
@@ -32,6 +32,161 @@ describe('RcSesAlert', () => {
|
|
|
32
32
|
})
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
+
describe('accessibility', () => {
|
|
36
|
+
test.each([
|
|
37
|
+
['grey', 'status', 'polite'],
|
|
38
|
+
['info', 'status', 'polite'],
|
|
39
|
+
['success', 'status', 'polite'],
|
|
40
|
+
['warning', 'alert', 'assertive'],
|
|
41
|
+
['error', 'alert', 'assertive'],
|
|
42
|
+
] as const)(
|
|
43
|
+
'severity=%s gets role=%s and aria-live=%s',
|
|
44
|
+
(severity, expectedRole, expectedAriaLive) => {
|
|
45
|
+
const { unmount } = renderAlert(
|
|
46
|
+
<RcSesAlert severity={severity}>message</RcSesAlert>,
|
|
47
|
+
)
|
|
48
|
+
expect(screen.getByRole(expectedRole)).toHaveAttribute(
|
|
49
|
+
'aria-live',
|
|
50
|
+
expectedAriaLive,
|
|
51
|
+
)
|
|
52
|
+
unmount()
|
|
53
|
+
},
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
test('an explicit aria-live prop overrides the severity default', () => {
|
|
57
|
+
renderAlert(
|
|
58
|
+
<RcSesAlert severity='error' aria-live='polite'>
|
|
59
|
+
message
|
|
60
|
+
</RcSesAlert>,
|
|
61
|
+
)
|
|
62
|
+
expect(screen.getByRole('alert')).toHaveAttribute('aria-live', 'polite')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('an explicit role prop overrides the severity default', () => {
|
|
66
|
+
renderAlert(
|
|
67
|
+
<RcSesAlert severity='error' role='status'>
|
|
68
|
+
message
|
|
69
|
+
</RcSesAlert>,
|
|
70
|
+
)
|
|
71
|
+
expect(screen.getByRole('status')).toHaveAttribute('aria-live', 'polite')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('close button has a translated aria-label', () => {
|
|
75
|
+
renderAlert(<RcSesAlert onClose={() => {}}>message</RcSesAlert>)
|
|
76
|
+
expect(screen.getByRole('button', { name: 'close' })).toBeInTheDocument()
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('severity icon is hidden from assistive tech', () => {
|
|
80
|
+
const { container } = renderAlert(
|
|
81
|
+
<RcSesAlert severity='success'>message</RcSesAlert>,
|
|
82
|
+
)
|
|
83
|
+
expect(container.querySelector('.MuiAlert-icon svg')).toHaveAttribute('aria-hidden')
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('close and action controls are reachable in normal Tab order', () => {
|
|
87
|
+
renderAlert(
|
|
88
|
+
<RcSesAlert
|
|
89
|
+
severity='error'
|
|
90
|
+
actionLabel='Retry'
|
|
91
|
+
onActionClick={() => {}}
|
|
92
|
+
onClose={() => {}}
|
|
93
|
+
>
|
|
94
|
+
message
|
|
95
|
+
</RcSesAlert>,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
const actionButton = screen.getByRole('button', { name: 'Retry' })
|
|
99
|
+
const closeButton = screen.getByRole('button', { name: 'close' })
|
|
100
|
+
|
|
101
|
+
expect(actionButton.tagName).toBe('BUTTON')
|
|
102
|
+
expect(closeButton.tagName).toBe('BUTTON')
|
|
103
|
+
|
|
104
|
+
act(() => actionButton.focus())
|
|
105
|
+
expect(actionButton).toHaveFocus()
|
|
106
|
+
|
|
107
|
+
act(() => closeButton.focus())
|
|
108
|
+
expect(closeButton).toHaveFocus()
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
describe('close and action handlers', () => {
|
|
113
|
+
test('clicking close calls onClose', () => {
|
|
114
|
+
const onClose = vi.fn()
|
|
115
|
+
renderAlert(<RcSesAlert onClose={onClose}>message</RcSesAlert>)
|
|
116
|
+
|
|
117
|
+
fireEvent.click(screen.getByRole('button', { name: 'close' }))
|
|
118
|
+
|
|
119
|
+
expect(onClose).toHaveBeenCalledTimes(1)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test('clicking the action calls onActionClick', () => {
|
|
123
|
+
const onActionClick = vi.fn()
|
|
124
|
+
renderAlert(
|
|
125
|
+
<RcSesAlert actionLabel='Retry' onActionClick={onActionClick}>
|
|
126
|
+
message
|
|
127
|
+
</RcSesAlert>,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
fireEvent.click(screen.getByRole('button', { name: 'Retry' }))
|
|
131
|
+
|
|
132
|
+
expect(onActionClick).toHaveBeenCalledTimes(1)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('a consumer action renders alongside the close button', () => {
|
|
136
|
+
renderAlert(
|
|
137
|
+
<RcSesAlert action={<button type='button'>Custom</button>} onClose={() => {}}>
|
|
138
|
+
message
|
|
139
|
+
</RcSesAlert>,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
expect(screen.getByRole('button', { name: 'Custom' })).toBeInTheDocument()
|
|
143
|
+
expect(screen.getByRole('button', { name: 'close' })).toBeInTheDocument()
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
test('a consumer action renders when there is no close button', () => {
|
|
147
|
+
renderAlert(
|
|
148
|
+
<RcSesAlert action={<button type='button'>Custom</button>}>message</RcSesAlert>,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
expect(screen.getByRole('button', { name: 'Custom' })).toBeInTheDocument()
|
|
152
|
+
expect(screen.queryByRole('button', { name: 'close' })).not.toBeInTheDocument()
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
describe('show* toggles', () => {
|
|
157
|
+
test('showClose=false hides the close button even when onClose is provided', () => {
|
|
158
|
+
renderAlert(
|
|
159
|
+
<RcSesAlert onClose={() => {}} showClose={false}>
|
|
160
|
+
message
|
|
161
|
+
</RcSesAlert>,
|
|
162
|
+
)
|
|
163
|
+
expect(screen.queryByRole('button', { name: 'close' })).not.toBeInTheDocument()
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
test('showAction=false hides the action button even when actionLabel/onActionClick are provided', () => {
|
|
167
|
+
renderAlert(
|
|
168
|
+
<RcSesAlert actionLabel='Retry' onActionClick={() => {}} showAction={false}>
|
|
169
|
+
message
|
|
170
|
+
</RcSesAlert>,
|
|
171
|
+
)
|
|
172
|
+
expect(screen.queryByRole('button', { name: 'Retry' })).not.toBeInTheDocument()
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
test('action button does not render without onActionClick even if actionLabel is set', () => {
|
|
176
|
+
renderAlert(<RcSesAlert actionLabel='Retry'>message</RcSesAlert>)
|
|
177
|
+
expect(screen.queryByRole('button', { name: 'Retry' })).not.toBeInTheDocument()
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
test('showIcon=false hides the severity icon', () => {
|
|
181
|
+
const { container } = renderAlert(
|
|
182
|
+
<RcSesAlert severity='success' showIcon={false}>
|
|
183
|
+
message
|
|
184
|
+
</RcSesAlert>,
|
|
185
|
+
)
|
|
186
|
+
expect(container.querySelector('.MuiAlert-icon')).not.toBeInTheDocument()
|
|
187
|
+
})
|
|
188
|
+
})
|
|
189
|
+
|
|
35
190
|
describe('container prop', () => {
|
|
36
191
|
test('renders children correctly when container={true}', () => {
|
|
37
192
|
renderAlert(
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Box,
|
|
3
|
+
Button,
|
|
2
4
|
ContainerProps,
|
|
3
5
|
Alert as MuiAlert,
|
|
4
6
|
AlertProps as MuiAlertProps,
|
|
7
|
+
Theme,
|
|
5
8
|
} from '@mui/material'
|
|
6
9
|
import { useTranslation } from 'react-i18next'
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
import CloseIcon from '@/assets/icons/CloseIcon'
|
|
12
|
+
|
|
13
|
+
type Props = Omit<MuiAlertProps, 'onClose'> & {
|
|
9
14
|
container?: boolean | ContainerProps
|
|
15
|
+
showIcon?: boolean
|
|
16
|
+
showAction?: boolean
|
|
17
|
+
showClose?: boolean
|
|
18
|
+
actionLabel?: string
|
|
19
|
+
onActionClick?: () => void
|
|
20
|
+
onClose?: () => void
|
|
10
21
|
}
|
|
11
22
|
|
|
12
23
|
const defaultProps: Partial<MuiAlertProps> = {
|
|
@@ -14,9 +25,106 @@ const defaultProps: Partial<MuiAlertProps> = {
|
|
|
14
25
|
variant: 'outlined',
|
|
15
26
|
}
|
|
16
27
|
|
|
17
|
-
|
|
28
|
+
const closeButtonStyles = {
|
|
29
|
+
display: 'inline-flex',
|
|
30
|
+
alignItems: 'center',
|
|
31
|
+
justifyContent: 'center',
|
|
32
|
+
minHeight: '1.5rem',
|
|
33
|
+
minWidth: '1.5rem',
|
|
34
|
+
padding: 0,
|
|
35
|
+
border: 'none',
|
|
36
|
+
background: 'none',
|
|
37
|
+
cursor: 'pointer',
|
|
38
|
+
color: 'inherit',
|
|
39
|
+
opacity: 0.8,
|
|
40
|
+
'&:hover': { opacity: 1 },
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const actionContainerStyles = {
|
|
44
|
+
display: 'inline-flex',
|
|
45
|
+
alignItems: 'center',
|
|
46
|
+
gap: '.75rem',
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Only the alert body and its CTA form a row; the message slot itself stays a plain
|
|
50
|
+
// block container so rich or multi-node children keep flowing normally.
|
|
51
|
+
const messageRowStyles = (theme: Theme) => ({
|
|
52
|
+
display: 'flex',
|
|
53
|
+
flexWrap: 'wrap',
|
|
54
|
+
alignItems: 'center',
|
|
55
|
+
justifyContent: 'space-between',
|
|
56
|
+
gap: '.75rem',
|
|
57
|
+
|
|
58
|
+
[theme.breakpoints.up('md')]: {
|
|
59
|
+
flexWrap: 'nowrap',
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
// The close button is a fixed-size control, so it keeps the action slot tight instead of
|
|
64
|
+
// stacking onto its own row the way a consumer-supplied action does.
|
|
65
|
+
const closeOnlyActionStyles = {
|
|
66
|
+
'.MuiAlert-action': {
|
|
67
|
+
alignSelf: 'center',
|
|
68
|
+
flex: '0 0 auto',
|
|
69
|
+
margin: 0,
|
|
70
|
+
padding: 0,
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// `breakpoints.values.xs` is 0, so an xs container banner needs an explicit content width.
|
|
75
|
+
const XS_CONTAINER_MAX_WIDTH = 444
|
|
76
|
+
|
|
77
|
+
const URGENT_SEVERITIES: MuiAlertProps['severity'][] = ['warning', 'error']
|
|
78
|
+
|
|
79
|
+
function RcSesAlert({
|
|
80
|
+
container,
|
|
81
|
+
children,
|
|
82
|
+
icon,
|
|
83
|
+
showIcon = true,
|
|
84
|
+
showAction = true,
|
|
85
|
+
showClose = true,
|
|
86
|
+
actionLabel,
|
|
87
|
+
onActionClick,
|
|
88
|
+
onClose,
|
|
89
|
+
action,
|
|
90
|
+
severity,
|
|
91
|
+
role,
|
|
92
|
+
'aria-live': ariaLive,
|
|
93
|
+
sx,
|
|
94
|
+
...props
|
|
95
|
+
}: Props) {
|
|
18
96
|
const { t } = useTranslation('input', { keyPrefix: 'components.RcSesAlert' })
|
|
19
97
|
|
|
98
|
+
const hasAction = showAction && Boolean(onActionClick) && Boolean(actionLabel)
|
|
99
|
+
const hasClose = showClose && Boolean(onClose)
|
|
100
|
+
|
|
101
|
+
const closeButton = hasClose ? (
|
|
102
|
+
<Box
|
|
103
|
+
component='button'
|
|
104
|
+
type='button'
|
|
105
|
+
onClick={onClose}
|
|
106
|
+
aria-label={t('close')}
|
|
107
|
+
sx={closeButtonStyles}
|
|
108
|
+
>
|
|
109
|
+
<CloseIcon size={22} fillColor='currentColor' focusable={false} aria-hidden />
|
|
110
|
+
</Box>
|
|
111
|
+
) : null
|
|
112
|
+
|
|
113
|
+
let resolvedAction = action
|
|
114
|
+
if (hasClose) {
|
|
115
|
+
resolvedAction = action ? (
|
|
116
|
+
<Box sx={actionContainerStyles}>
|
|
117
|
+
{action}
|
|
118
|
+
{closeButton}
|
|
119
|
+
</Box>
|
|
120
|
+
) : (
|
|
121
|
+
closeButton
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const resolvedRole = role ?? (URGENT_SEVERITIES.includes(severity) ? 'alert' : 'status')
|
|
126
|
+
const resolvedAriaLive = ariaLive ?? (resolvedRole === 'alert' ? 'assertive' : 'polite')
|
|
127
|
+
|
|
20
128
|
const isContainer = Boolean(container)
|
|
21
129
|
const containerParams = typeof container === 'object' ? container : {}
|
|
22
130
|
const maxWidth =
|
|
@@ -32,17 +140,24 @@ function RcSesAlert({ container, children, sx, ...props }: Props) {
|
|
|
32
140
|
<MuiAlert
|
|
33
141
|
{...defaultProps}
|
|
34
142
|
{...props}
|
|
143
|
+
severity={severity}
|
|
144
|
+
role={resolvedRole}
|
|
145
|
+
aria-live={resolvedAriaLive}
|
|
146
|
+
icon={showIcon ? icon : false}
|
|
147
|
+
action={resolvedAction}
|
|
35
148
|
sx={[
|
|
36
149
|
isContainer &&
|
|
37
150
|
((theme) => {
|
|
38
|
-
let maxWidthValue:
|
|
151
|
+
let maxWidthValue: number | 'none' = 'none'
|
|
39
152
|
|
|
40
153
|
if (maxWidth !== false) {
|
|
41
154
|
if (typeof maxWidth === 'string') {
|
|
42
155
|
maxWidthValue =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
156
|
+
maxWidth === 'xs'
|
|
157
|
+
? XS_CONTAINER_MAX_WIDTH
|
|
158
|
+
: theme.breakpoints.values[
|
|
159
|
+
maxWidth as keyof typeof theme.breakpoints.values
|
|
160
|
+
]
|
|
46
161
|
} else {
|
|
47
162
|
maxWidthValue = maxWidth
|
|
48
163
|
}
|
|
@@ -54,8 +169,8 @@ function RcSesAlert({ container, children, sx, ...props }: Props) {
|
|
|
54
169
|
}
|
|
55
170
|
|
|
56
171
|
if (maxWidthValue !== 'none') {
|
|
57
|
-
const gutterXs = disableGutters ? '' :
|
|
58
|
-
const gutterSm = disableGutters ? '' :
|
|
172
|
+
const gutterXs = disableGutters ? '' : ` + ${theme.spacing(2)}`
|
|
173
|
+
const gutterSm = disableGutters ? '' : ` + ${theme.spacing(3)}`
|
|
59
174
|
|
|
60
175
|
containerStyles.px = `calc(max((100% - ${maxWidthValue}px) / 2, 0px)${gutterXs})`
|
|
61
176
|
containerStyles[theme.breakpoints.up('sm')] = {
|
|
@@ -65,11 +180,30 @@ function RcSesAlert({ container, children, sx, ...props }: Props) {
|
|
|
65
180
|
|
|
66
181
|
return containerStyles
|
|
67
182
|
}),
|
|
183
|
+
hasClose && !action && closeOnlyActionStyles,
|
|
68
184
|
...normalizedSx,
|
|
69
185
|
]}
|
|
70
|
-
closeText={t('close')}
|
|
71
186
|
>
|
|
72
|
-
{
|
|
187
|
+
{hasAction ? (
|
|
188
|
+
<Box sx={messageRowStyles}>
|
|
189
|
+
<Box sx={{ minWidth: 0 }}>{children}</Box>
|
|
190
|
+
<Button
|
|
191
|
+
variant='link'
|
|
192
|
+
onClick={onActionClick}
|
|
193
|
+
sx={(theme) => ({
|
|
194
|
+
flexBasis: '100%',
|
|
195
|
+
padding: '0.5rem 0.25rem',
|
|
196
|
+
[theme.breakpoints.up('md')]: {
|
|
197
|
+
flexBasis: 'auto',
|
|
198
|
+
},
|
|
199
|
+
})}
|
|
200
|
+
>
|
|
201
|
+
{actionLabel}
|
|
202
|
+
</Button>
|
|
203
|
+
</Box>
|
|
204
|
+
) : (
|
|
205
|
+
children
|
|
206
|
+
)}
|
|
73
207
|
</MuiAlert>
|
|
74
208
|
)
|
|
75
209
|
}
|
|
@@ -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
|
/**
|