@registrucentras/rc-ses-react-components 2.0.0-rc.4 → 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/WarningCircleIcon.d.ts +1 -1
- package/dist/components/common/Alert/index.d.ts +8 -2
- package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
- package/dist/registrucentras-rc-ses-react-components.js +1549 -1447
- package/dist/stories/components/feedback/Alert.stories.d.ts +4 -0
- package/package.json +1 -1
- package/src/assets/icons/WarningCircleIcon.tsx +8 -2
- package/src/components/common/Alert/index.test.tsx +157 -2
- package/src/components/common/Alert/index.tsx +144 -10
- package/src/stories/components/feedback/Alert.stories.tsx +135 -4
- package/src/theme/light/MuiAlert.tsx +28 -20
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -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
|
)
|
|
@@ -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
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { Meta, StoryObj } from '@storybook/react-vite'
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { fn } from 'storybook/test'
|
|
2
4
|
|
|
3
5
|
import RcSesAlert from '@/components/common/Alert'
|
|
4
6
|
import FieldPreview from '@/components/storybook/FieldPreview'
|
|
@@ -9,12 +11,40 @@ import PreviewTitle from '@/components/storybook/PreviewTitle'
|
|
|
9
11
|
const lorem =
|
|
10
12
|
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard."
|
|
11
13
|
|
|
12
|
-
const severities
|
|
14
|
+
const severities: Array<'grey' | 'info' | 'success' | 'warning' | 'error'> = [
|
|
15
|
+
'grey',
|
|
16
|
+
'info',
|
|
17
|
+
'success',
|
|
18
|
+
'warning',
|
|
19
|
+
'error',
|
|
20
|
+
]
|
|
13
21
|
|
|
14
22
|
const meta: Meta<typeof RcSesAlert> = {
|
|
15
23
|
title: 'components/feedback/Alert',
|
|
16
24
|
component: RcSesAlert,
|
|
17
25
|
tags: ['autodocs'],
|
|
26
|
+
argTypes: {
|
|
27
|
+
severity: {
|
|
28
|
+
options: severities,
|
|
29
|
+
control: { type: 'select' },
|
|
30
|
+
},
|
|
31
|
+
variant: {
|
|
32
|
+
options: ['outlined', 'filled', 'standard'],
|
|
33
|
+
control: { type: 'select' },
|
|
34
|
+
},
|
|
35
|
+
showIcon: {
|
|
36
|
+
control: 'boolean',
|
|
37
|
+
},
|
|
38
|
+
showAction: {
|
|
39
|
+
control: 'boolean',
|
|
40
|
+
},
|
|
41
|
+
showClose: {
|
|
42
|
+
control: 'boolean',
|
|
43
|
+
},
|
|
44
|
+
actionLabel: {
|
|
45
|
+
control: 'text',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
18
48
|
}
|
|
19
49
|
|
|
20
50
|
export default meta
|
|
@@ -34,7 +64,7 @@ export const Main: Story = {
|
|
|
34
64
|
<FieldPreview>
|
|
35
65
|
<PreviewTitle>State previews</PreviewTitle>
|
|
36
66
|
{severities.map((severity) => (
|
|
37
|
-
<RcSesAlert key={severity} severity={severity}>
|
|
67
|
+
<RcSesAlert key={severity} severity={severity} sx={{ mb: 1 }}>
|
|
38
68
|
{lorem}
|
|
39
69
|
</RcSesAlert>
|
|
40
70
|
))}
|
|
@@ -44,6 +74,9 @@ export const Main: Story = {
|
|
|
44
74
|
args: {
|
|
45
75
|
children: lorem,
|
|
46
76
|
severity: 'info',
|
|
77
|
+
actionLabel: 'Veiksmas',
|
|
78
|
+
onActionClick: fn(),
|
|
79
|
+
onClose: fn(),
|
|
47
80
|
},
|
|
48
81
|
}
|
|
49
82
|
|
|
@@ -54,7 +87,7 @@ export const Main: Story = {
|
|
|
54
87
|
const renderVariants: Story['render'] = (args) => (
|
|
55
88
|
<>
|
|
56
89
|
{severities.map((severity) => (
|
|
57
|
-
<RcSesAlert key={severity} {...args} severity={severity}>
|
|
90
|
+
<RcSesAlert key={severity} {...args} severity={severity} sx={{ mb: 1 }}>
|
|
58
91
|
{lorem}
|
|
59
92
|
</RcSesAlert>
|
|
60
93
|
))}
|
|
@@ -76,6 +109,104 @@ export const Standard: Story = {
|
|
|
76
109
|
args: { variant: 'standard' },
|
|
77
110
|
}
|
|
78
111
|
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
// Action & close — buttons wired up, but not removing the alert on close
|
|
114
|
+
// (see Dismissible below for that). Clicks are logged in the Actions panel.
|
|
115
|
+
// ---------------------------------------------------------------------------
|
|
116
|
+
|
|
117
|
+
export const WithActionAndClose: Story = {
|
|
118
|
+
render: renderVariants,
|
|
119
|
+
args: {
|
|
120
|
+
actionLabel: 'Veiksmas',
|
|
121
|
+
onActionClick: fn(),
|
|
122
|
+
onClose: fn(),
|
|
123
|
+
},
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const WithoutActionAndClose: Story = {
|
|
127
|
+
render: renderVariants,
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
// Toggles — Type × showIcon/showAction/showClose combinations
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
|
|
134
|
+
export const Toggles: Story = {
|
|
135
|
+
render: () => (
|
|
136
|
+
<>
|
|
137
|
+
<PreviewTitle>showIcon = false</PreviewTitle>
|
|
138
|
+
{severities.map((severity) => (
|
|
139
|
+
<RcSesAlert key={severity} severity={severity} showIcon={false} sx={{ mb: 1 }}>
|
|
140
|
+
{lorem}
|
|
141
|
+
</RcSesAlert>
|
|
142
|
+
))}
|
|
143
|
+
|
|
144
|
+
<PreviewTitle>action only (showClose = false)</PreviewTitle>
|
|
145
|
+
{severities.map((severity) => (
|
|
146
|
+
<RcSesAlert
|
|
147
|
+
key={severity}
|
|
148
|
+
severity={severity}
|
|
149
|
+
actionLabel='Veiksmas'
|
|
150
|
+
onActionClick={fn()}
|
|
151
|
+
onClose={fn()}
|
|
152
|
+
showClose={false}
|
|
153
|
+
sx={{ mb: 1 }}
|
|
154
|
+
>
|
|
155
|
+
{lorem}
|
|
156
|
+
</RcSesAlert>
|
|
157
|
+
))}
|
|
158
|
+
|
|
159
|
+
<PreviewTitle>close only (showAction = false)</PreviewTitle>
|
|
160
|
+
{severities.map((severity) => (
|
|
161
|
+
<RcSesAlert
|
|
162
|
+
key={severity}
|
|
163
|
+
severity={severity}
|
|
164
|
+
actionLabel='Veiksmas'
|
|
165
|
+
onActionClick={fn()}
|
|
166
|
+
onClose={fn()}
|
|
167
|
+
showAction={false}
|
|
168
|
+
sx={{ mb: 1 }}
|
|
169
|
+
>
|
|
170
|
+
{lorem}
|
|
171
|
+
</RcSesAlert>
|
|
172
|
+
))}
|
|
173
|
+
</>
|
|
174
|
+
),
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ---------------------------------------------------------------------------
|
|
178
|
+
// Dismissible — action logs to the console, close actually removes the alert
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
|
|
181
|
+
function DismissibleTemplate() {
|
|
182
|
+
const [visibleSeverities, setVisibleSeverities] = useState<
|
|
183
|
+
Array<(typeof severities)[number]>
|
|
184
|
+
>([...severities])
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<>
|
|
188
|
+
{visibleSeverities.map((severity) => (
|
|
189
|
+
<RcSesAlert
|
|
190
|
+
key={severity}
|
|
191
|
+
severity={severity}
|
|
192
|
+
actionLabel='Veiksmas'
|
|
193
|
+
onActionClick={() => console.log(`${severity} alert action clicked`)}
|
|
194
|
+
onClose={() =>
|
|
195
|
+
setVisibleSeverities((prev) => prev.filter((item) => item !== severity))
|
|
196
|
+
}
|
|
197
|
+
sx={{ mb: 1 }}
|
|
198
|
+
>
|
|
199
|
+
{lorem}
|
|
200
|
+
</RcSesAlert>
|
|
201
|
+
))}
|
|
202
|
+
</>
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export const Dismissible: Story = {
|
|
207
|
+
render: () => <DismissibleTemplate />,
|
|
208
|
+
}
|
|
209
|
+
|
|
79
210
|
// ---------------------------------------------------------------------------
|
|
80
211
|
// Container — full-bleed banner keeping content width-constrained
|
|
81
212
|
// ---------------------------------------------------------------------------
|