@registrucentras/rc-ses-react-components 1.3.0 → 1.3.1
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/registrucentras-rc-ses-react-components.cjs +2 -2
- package/dist/registrucentras-rc-ses-react-components.js +523 -517
- package/package.json +1 -1
- package/src/components/common/Alert/index.test.tsx +3 -10
- package/src/components/common/Alert/index.tsx +44 -16
- package/src/stories/components/Alert.stories.tsx +1 -8
package/package.json
CHANGED
|
@@ -33,7 +33,7 @@ describe('RcSesAlert', () => {
|
|
|
33
33
|
})
|
|
34
34
|
|
|
35
35
|
describe('container prop', () => {
|
|
36
|
-
test('
|
|
36
|
+
test('renders children correctly when container={true}', () => {
|
|
37
37
|
renderAlert(
|
|
38
38
|
<RcSesAlert container data-testid='alert'>
|
|
39
39
|
inside
|
|
@@ -43,7 +43,7 @@ describe('RcSesAlert', () => {
|
|
|
43
43
|
expect(screen.getByText('inside')).toBeInTheDocument()
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
-
test('
|
|
46
|
+
test('renders children correctly when container is ContainerProps object', () => {
|
|
47
47
|
renderAlert(
|
|
48
48
|
<RcSesAlert container={{ maxWidth: 'sm' }} data-testid='alert'>
|
|
49
49
|
inside sm
|
|
@@ -52,21 +52,14 @@ describe('RcSesAlert', () => {
|
|
|
52
52
|
expect(screen.getByText('inside sm')).toBeInTheDocument()
|
|
53
53
|
})
|
|
54
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
55
|
test('applies full-bleed sx overrides when container is set', () => {
|
|
62
56
|
const { container } = renderAlert(
|
|
63
57
|
<RcSesAlert container data-testid='alert'>
|
|
64
58
|
text
|
|
65
59
|
</RcSesAlert>,
|
|
66
60
|
)
|
|
67
|
-
// Verify the alert renders
|
|
61
|
+
// Verify the alert renders
|
|
68
62
|
expect(container.querySelector('.MuiAlert-root')).toBeInTheDocument()
|
|
69
|
-
expect(container.querySelector('.MuiContainer-root')).toBeInTheDocument()
|
|
70
63
|
})
|
|
71
64
|
|
|
72
65
|
test('merges caller sx on top of container sx', () => {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Container,
|
|
3
2
|
ContainerProps,
|
|
4
3
|
Alert as MuiAlert,
|
|
5
4
|
AlertProps as MuiAlertProps,
|
|
@@ -15,33 +14,62 @@ const defaultProps: Partial<MuiAlertProps> = {
|
|
|
15
14
|
variant: 'outlined',
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
const containerSx: MuiAlertProps['sx'] = {
|
|
19
|
-
borderRadius: 0,
|
|
20
|
-
px: 0,
|
|
21
|
-
'& .MuiAlert-message': { p: 0, width: '100%' },
|
|
22
|
-
}
|
|
23
|
-
|
|
24
17
|
function RcSesAlert({ container, children, sx, ...props }: Props) {
|
|
25
18
|
const { t } = useTranslation('input', { keyPrefix: 'components.RcSesAlert' })
|
|
26
19
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
const isContainer = Boolean(container)
|
|
21
|
+
const containerParams = typeof container === 'object' ? container : {}
|
|
22
|
+
const maxWidth =
|
|
23
|
+
containerParams.maxWidth === undefined ? 'lg' : containerParams.maxWidth
|
|
24
|
+
const disableGutters = containerParams.disableGutters || false
|
|
25
|
+
|
|
26
|
+
let normalizedSx: any[] = []
|
|
27
|
+
if (sx) {
|
|
28
|
+
normalizedSx = Array.isArray(sx) ? sx : [sx]
|
|
29
|
+
}
|
|
32
30
|
|
|
33
31
|
return (
|
|
34
32
|
<MuiAlert
|
|
35
33
|
{...defaultProps}
|
|
36
34
|
{...props}
|
|
37
35
|
sx={[
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
isContainer &&
|
|
37
|
+
((theme) => {
|
|
38
|
+
let maxWidthValue: string | number = 'none'
|
|
39
|
+
|
|
40
|
+
if (maxWidth !== false) {
|
|
41
|
+
if (typeof maxWidth === 'string') {
|
|
42
|
+
maxWidthValue =
|
|
43
|
+
theme.breakpoints.values[
|
|
44
|
+
maxWidth as keyof typeof theme.breakpoints.values
|
|
45
|
+
] || maxWidth
|
|
46
|
+
} else {
|
|
47
|
+
maxWidthValue = maxWidth
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const containerStyles: Record<string, any> = {
|
|
52
|
+
borderRadius: 0,
|
|
53
|
+
'& .MuiAlert-message': { p: 0, width: '100%' },
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (maxWidthValue !== 'none') {
|
|
57
|
+
const gutterXs = disableGutters ? '' : ' + 16px'
|
|
58
|
+
const gutterSm = disableGutters ? '' : ' + 24px'
|
|
59
|
+
|
|
60
|
+
containerStyles.px = `calc(max((100% - ${maxWidthValue}px) / 2, 0px)${gutterXs})`
|
|
61
|
+
containerStyles[theme.breakpoints.up('sm')] = {
|
|
62
|
+
px: `calc(max((100% - ${maxWidthValue}px) / 2, 0px)${gutterSm})`,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return containerStyles
|
|
67
|
+
}),
|
|
68
|
+
...normalizedSx,
|
|
41
69
|
]}
|
|
42
70
|
closeText={t('close')}
|
|
43
71
|
>
|
|
44
|
-
{
|
|
72
|
+
{children}
|
|
45
73
|
</MuiAlert>
|
|
46
74
|
)
|
|
47
75
|
}
|
|
@@ -77,13 +77,7 @@ export const WithContainer: StoryFn<typeof RcSesAlert> = () => (
|
|
|
77
77
|
<>
|
|
78
78
|
<PreviewTitle>container (default maxWidth)</PreviewTitle>
|
|
79
79
|
{severities.map((severity) => (
|
|
80
|
-
<RcSesAlert
|
|
81
|
-
key={severity}
|
|
82
|
-
severity={severity}
|
|
83
|
-
icon={false}
|
|
84
|
-
container
|
|
85
|
-
sx={{ mb: 1 }}
|
|
86
|
-
>
|
|
80
|
+
<RcSesAlert key={severity} severity={severity} container sx={{ mb: 1 }}>
|
|
87
81
|
{lorem}
|
|
88
82
|
</RcSesAlert>
|
|
89
83
|
))}
|
|
@@ -93,7 +87,6 @@ export const WithContainer: StoryFn<typeof RcSesAlert> = () => (
|
|
|
93
87
|
<RcSesAlert
|
|
94
88
|
key={severity}
|
|
95
89
|
severity={severity}
|
|
96
|
-
icon={false}
|
|
97
90
|
container={{ maxWidth: 'sm' }}
|
|
98
91
|
sx={{ mb: 1 }}
|
|
99
92
|
>
|