@registrucentras/rc-ses-react-components 1.2.2 → 1.3.0
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/components/common/Alert/index.d.ts +5 -2
- package/dist/registrucentras-rc-ses-react-components.cjs +2 -2
- package/dist/registrucentras-rc-ses-react-components.js +526 -505
- package/dist/stories/components/Alert.stories.d.ts +15 -3
- package/package.json +1 -1
- package/src/components/common/Alert/index.test.tsx +82 -0
- package/src/components/common/Alert/index.tsx +33 -5
- package/src/stories/components/Alert.stories.tsx +68 -4
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import { Meta, ReactRenderer } from '@storybook/react';
|
|
1
|
+
import { Meta, StoryFn, ReactRenderer } from '@storybook/react';
|
|
2
2
|
import { default as RcSesAlert } from '../../components/common/Alert';
|
|
3
3
|
import { AnnotatedStoryFn } from '@storybook/core/csf';
|
|
4
|
-
import { AlertProps } from '@mui/material';
|
|
4
|
+
import { AlertProps, ContainerProps } from '@mui/material';
|
|
5
5
|
declare const meta: Meta<typeof RcSesAlert>;
|
|
6
6
|
export default meta;
|
|
7
|
-
export declare const Main: AnnotatedStoryFn<ReactRenderer, AlertProps
|
|
7
|
+
export declare const Main: AnnotatedStoryFn<ReactRenderer, AlertProps & {
|
|
8
|
+
container?: boolean | ContainerProps;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const Outlined: AnnotatedStoryFn<ReactRenderer, AlertProps & {
|
|
11
|
+
container?: boolean | ContainerProps;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const Filled: AnnotatedStoryFn<ReactRenderer, AlertProps & {
|
|
14
|
+
container?: boolean | ContainerProps;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const Standard: AnnotatedStoryFn<ReactRenderer, AlertProps & {
|
|
17
|
+
container?: boolean | ContainerProps;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const WithContainer: StoryFn<typeof RcSesAlert>;
|
package/package.json
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ThemeProvider } from '@mui/material/styles'
|
|
2
|
+
import { render, screen } from '@testing-library/react'
|
|
3
|
+
import { vi } from 'vitest'
|
|
4
|
+
|
|
5
|
+
import theme from '@/theme/light'
|
|
6
|
+
|
|
7
|
+
import RcSesAlert from './index'
|
|
8
|
+
|
|
9
|
+
vi.mock('react-i18next', () => ({
|
|
10
|
+
useTranslation: () => ({
|
|
11
|
+
t: (key: string) => key,
|
|
12
|
+
}),
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
const renderAlert = (ui: React.ReactElement) =>
|
|
16
|
+
render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
|
|
17
|
+
|
|
18
|
+
describe('RcSesAlert', () => {
|
|
19
|
+
test('renders children', () => {
|
|
20
|
+
renderAlert(<RcSesAlert>Alert message</RcSesAlert>)
|
|
21
|
+
expect(screen.getByText('Alert message')).toBeInTheDocument()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('renders with each severity', () => {
|
|
25
|
+
const severities = ['info', 'warning', 'error', 'success'] as const
|
|
26
|
+
severities.forEach((severity) => {
|
|
27
|
+
const { unmount } = renderAlert(
|
|
28
|
+
<RcSesAlert severity={severity}>{severity} message</RcSesAlert>,
|
|
29
|
+
)
|
|
30
|
+
expect(screen.getByText(`${severity} message`)).toBeInTheDocument()
|
|
31
|
+
unmount()
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
describe('container prop', () => {
|
|
36
|
+
test('wraps children in a Container when container={true}', () => {
|
|
37
|
+
renderAlert(
|
|
38
|
+
<RcSesAlert container data-testid='alert'>
|
|
39
|
+
inside
|
|
40
|
+
</RcSesAlert>,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
expect(screen.getByText('inside')).toBeInTheDocument()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('wraps children in a Container when container is ContainerProps object', () => {
|
|
47
|
+
renderAlert(
|
|
48
|
+
<RcSesAlert container={{ maxWidth: 'sm' }} data-testid='alert'>
|
|
49
|
+
inside sm
|
|
50
|
+
</RcSesAlert>,
|
|
51
|
+
)
|
|
52
|
+
expect(screen.getByText('inside sm')).toBeInTheDocument()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('does not wrap children in a Container when container is not set', () => {
|
|
56
|
+
const { container } = renderAlert(<RcSesAlert>no container</RcSesAlert>)
|
|
57
|
+
// No MUI Container = no element with class MuiContainer-root
|
|
58
|
+
expect(container.querySelector('.MuiContainer-root')).toBeNull()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('applies full-bleed sx overrides when container is set', () => {
|
|
62
|
+
const { container } = renderAlert(
|
|
63
|
+
<RcSesAlert container data-testid='alert'>
|
|
64
|
+
text
|
|
65
|
+
</RcSesAlert>,
|
|
66
|
+
)
|
|
67
|
+
// Verify the alert renders and the Container is present (full-bleed layout)
|
|
68
|
+
expect(container.querySelector('.MuiAlert-root')).toBeInTheDocument()
|
|
69
|
+
expect(container.querySelector('.MuiContainer-root')).toBeInTheDocument()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('merges caller sx on top of container sx', () => {
|
|
73
|
+
const { container } = renderAlert(
|
|
74
|
+
<RcSesAlert container sx={{ mb: 0 }}>
|
|
75
|
+
text
|
|
76
|
+
</RcSesAlert>,
|
|
77
|
+
)
|
|
78
|
+
// Both container and caller sx should be applied without error
|
|
79
|
+
expect(container.querySelector('.MuiAlert-root')).toBeInTheDocument()
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
})
|
|
@@ -1,19 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Container,
|
|
3
|
+
ContainerProps,
|
|
4
|
+
Alert as MuiAlert,
|
|
5
|
+
AlertProps as MuiAlertProps,
|
|
6
|
+
} from '@mui/material'
|
|
2
7
|
import { useTranslation } from 'react-i18next'
|
|
3
8
|
|
|
9
|
+
type Props = MuiAlertProps & {
|
|
10
|
+
container?: boolean | ContainerProps
|
|
11
|
+
}
|
|
12
|
+
|
|
4
13
|
const defaultProps: Partial<MuiAlertProps> = {
|
|
5
14
|
elevation: 0,
|
|
6
15
|
variant: 'outlined',
|
|
7
16
|
}
|
|
8
17
|
|
|
9
|
-
|
|
18
|
+
const containerSx: MuiAlertProps['sx'] = {
|
|
19
|
+
borderRadius: 0,
|
|
20
|
+
px: 0,
|
|
21
|
+
'& .MuiAlert-message': { p: 0, width: '100%' },
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function RcSesAlert({ container, children, sx, ...props }: Props) {
|
|
10
25
|
const { t } = useTranslation('input', { keyPrefix: 'components.RcSesAlert' })
|
|
11
26
|
|
|
12
|
-
const
|
|
27
|
+
const containerProps: ContainerProps | undefined = (() => {
|
|
28
|
+
if (container === true) return {}
|
|
29
|
+
if (container === false || !container) return undefined
|
|
30
|
+
return container
|
|
31
|
+
})()
|
|
13
32
|
|
|
14
33
|
return (
|
|
15
|
-
<MuiAlert
|
|
16
|
-
{
|
|
34
|
+
<MuiAlert
|
|
35
|
+
{...defaultProps}
|
|
36
|
+
{...props}
|
|
37
|
+
sx={[
|
|
38
|
+
...(container ? [containerSx] : []),
|
|
39
|
+
// eslint-disable-next-line no-nested-ternary
|
|
40
|
+
...(Array.isArray(sx) ? sx : sx ? [sx] : []),
|
|
41
|
+
]}
|
|
42
|
+
closeText={t('close')}
|
|
43
|
+
>
|
|
44
|
+
{containerProps ? <Container {...containerProps}>{children}</Container> : children}
|
|
17
45
|
</MuiAlert>
|
|
18
46
|
)
|
|
19
47
|
}
|
|
@@ -10,6 +10,8 @@ import PreviewTitle from '@/components/storybook/PreviewTitle'
|
|
|
10
10
|
const lorem =
|
|
11
11
|
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard."
|
|
12
12
|
|
|
13
|
+
const severities = ['info', 'warning', 'error', 'success'] as const
|
|
14
|
+
|
|
13
15
|
const meta: Meta<typeof RcSesAlert> = {
|
|
14
16
|
title: 'components/common/Alert',
|
|
15
17
|
component: RcSesAlert,
|
|
@@ -18,6 +20,10 @@ const meta: Meta<typeof RcSesAlert> = {
|
|
|
18
20
|
|
|
19
21
|
export default meta
|
|
20
22
|
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Main (interactive / configurable via Controls panel)
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
21
27
|
const Template: StoryFn<typeof RcSesAlert> = (args) => (
|
|
22
28
|
<Fields>
|
|
23
29
|
<FieldView>
|
|
@@ -25,10 +31,11 @@ const Template: StoryFn<typeof RcSesAlert> = (args) => (
|
|
|
25
31
|
</FieldView>
|
|
26
32
|
<FieldPreview>
|
|
27
33
|
<PreviewTitle>State previews</PreviewTitle>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
{severities.map((severity) => (
|
|
35
|
+
<RcSesAlert key={severity} severity={severity}>
|
|
36
|
+
{lorem}
|
|
37
|
+
</RcSesAlert>
|
|
38
|
+
))}
|
|
32
39
|
</FieldPreview>
|
|
33
40
|
</Fields>
|
|
34
41
|
)
|
|
@@ -38,3 +45,60 @@ Main.args = {
|
|
|
38
45
|
children: lorem,
|
|
39
46
|
severity: 'info',
|
|
40
47
|
}
|
|
48
|
+
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Variants
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
|
|
53
|
+
const VariantsTemplate: StoryFn<typeof RcSesAlert> = (args) => (
|
|
54
|
+
<>
|
|
55
|
+
{severities.map((severity) => (
|
|
56
|
+
<RcSesAlert key={severity} {...args} severity={severity}>
|
|
57
|
+
{lorem}
|
|
58
|
+
</RcSesAlert>
|
|
59
|
+
))}
|
|
60
|
+
</>
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
export const Outlined = VariantsTemplate.bind({})
|
|
64
|
+
Outlined.args = { variant: 'outlined' }
|
|
65
|
+
|
|
66
|
+
export const Filled = VariantsTemplate.bind({})
|
|
67
|
+
Filled.args = { variant: 'filled' }
|
|
68
|
+
|
|
69
|
+
export const Standard = VariantsTemplate.bind({})
|
|
70
|
+
Standard.args = { variant: 'standard' }
|
|
71
|
+
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// Container — full-bleed banner keeping content width-constrained
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
export const WithContainer: StoryFn<typeof RcSesAlert> = () => (
|
|
77
|
+
<>
|
|
78
|
+
<PreviewTitle>container (default maxWidth)</PreviewTitle>
|
|
79
|
+
{severities.map((severity) => (
|
|
80
|
+
<RcSesAlert
|
|
81
|
+
key={severity}
|
|
82
|
+
severity={severity}
|
|
83
|
+
icon={false}
|
|
84
|
+
container
|
|
85
|
+
sx={{ mb: 1 }}
|
|
86
|
+
>
|
|
87
|
+
{lorem}
|
|
88
|
+
</RcSesAlert>
|
|
89
|
+
))}
|
|
90
|
+
|
|
91
|
+
<PreviewTitle>container with maxWidth="sm"</PreviewTitle>
|
|
92
|
+
{severities.map((severity) => (
|
|
93
|
+
<RcSesAlert
|
|
94
|
+
key={severity}
|
|
95
|
+
severity={severity}
|
|
96
|
+
icon={false}
|
|
97
|
+
container={{ maxWidth: 'sm' }}
|
|
98
|
+
sx={{ mb: 1 }}
|
|
99
|
+
>
|
|
100
|
+
{lorem}
|
|
101
|
+
</RcSesAlert>
|
|
102
|
+
))}
|
|
103
|
+
</>
|
|
104
|
+
)
|