@registrucentras/rc-ses-react-components 1.6.5 → 1.7.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/assets/icons/ArrowsClockwiseIcon.d.ts +3 -0
- package/dist/assets/icons/SearchHelpIcon.d.ts +3 -0
- package/dist/assets/icons/SearchXIcon.d.ts +3 -0
- package/dist/components/common/Breadcrumbs/index.d.ts +3 -1
- package/dist/components/common/Snackbar/SnackbarProvider.d.ts +22 -0
- package/dist/components/common/Snackbar/config.d.ts +21 -0
- package/dist/components/common/Snackbar/index.d.ts +16 -0
- package/dist/components/common/Snackbar/types.d.ts +2 -0
- package/dist/components/form/inputs/CheckboxFormControl.d.ts +2 -0
- package/dist/components/form/inputs/FormControlLabel.d.ts +10 -0
- package/dist/components/form/inputs/SearchInput/index.d.ts +27 -0
- package/dist/components/form/inputs/SimpleCheckbox.d.ts +6 -0
- package/dist/components/layout/ServiceHeader.d.ts +2 -1
- package/dist/components/utils/loading.d.ts +3 -0
- package/dist/library/icons.d.ts +5 -1
- package/dist/library/index.d.ts +11 -2
- package/dist/library/types.d.ts +3 -1
- package/dist/registrucentras-rc-ses-react-components.cjs +10 -27
- package/dist/registrucentras-rc-ses-react-components.js +3484 -2897
- package/dist/stories/components/actions/Button.stories.d.ts +5 -0
- package/dist/stories/components/{SelectableCardList.stories.d.ts → display/SelectableCardList.stories.d.ts} +1 -1
- package/dist/stories/components/feedback/Snackbar.stories.d.ts +143 -0
- package/dist/stories/components/form/CheckboxFormControl.stories.d.ts +3 -0
- package/dist/stories/components/form/SimpleCheckbox.stories.d.ts +19 -0
- package/dist/stories/components/inputs/SearchInput.stories.d.ts +11 -0
- package/dist/stories/components/layout/ServiceHeader.stories.d.ts +1 -0
- package/dist/theme/light/MuiOutlinedInput.d.ts +3 -0
- package/dist/theme/light/index.d.ts +6 -0
- package/dist/theme/palette.d.ts +9 -1
- package/package.json +1 -1
- package/src/assets/icons/ArrowsClockwiseIcon.tsx +16 -0
- package/src/assets/icons/CheckIcon.tsx +1 -1
- package/src/assets/icons/SearchHelpIcon.tsx +44 -0
- package/src/assets/icons/SearchXIcon.tsx +41 -0
- package/src/components/common/Breadcrumbs/index.tsx +4 -3
- package/src/components/common/ListWithIcons/components/ListWithIconsItem.tsx +5 -3
- package/src/components/common/ListWithIcons/index.tsx +1 -1
- package/src/components/common/SelectableCardList/components/SelectableCardListItem.tsx +3 -1
- package/src/components/common/Snackbar/SnackbarProvider.tsx +78 -0
- package/src/components/common/Snackbar/config.ts +77 -0
- package/src/components/common/Snackbar/index.test.tsx +119 -0
- package/src/components/common/Snackbar/index.tsx +181 -0
- package/src/components/common/Snackbar/types.ts +2 -0
- package/src/components/form/inputs/Checkbox.tsx +2 -2
- package/src/components/form/inputs/CheckboxFormControl.test.tsx +68 -0
- package/src/components/form/inputs/CheckboxFormControl.tsx +48 -29
- package/src/components/form/inputs/FormControlLabel.tsx +36 -0
- package/src/components/form/inputs/SearchInput/index.test.tsx +203 -0
- package/src/components/form/inputs/SearchInput/index.tsx +282 -0
- package/src/components/form/inputs/SimpleCheckbox.tsx +23 -0
- package/src/components/layout/ServiceHeader.tsx +22 -8
- package/src/components/utils/loading.tsx +9 -0
- package/src/i18n/namespaces/input/en.json +11 -0
- package/src/i18n/namespaces/input/lt.json +11 -0
- package/src/library/icons.ts +8 -0
- package/src/library/index.ts +15 -1
- package/src/library/types.ts +9 -1
- package/src/stories/Colors.mdx +127 -0
- package/src/stories/components/actions/Button.stories.tsx +130 -0
- package/src/stories/components/{SelectableCardList.stories.tsx → display/SelectableCardList.stories.tsx} +36 -19
- package/src/stories/components/feedback/Snackbar.stories.tsx +504 -0
- package/src/stories/components/form/CheckboxFormControl.stories.tsx +312 -2
- package/src/stories/components/form/SimpleCheckbox.stories.tsx +52 -0
- package/src/stories/components/icons/Icons.stories.tsx +35 -0
- package/src/stories/components/inputs/SearchInput.stories.tsx +134 -0
- package/src/stories/components/layout/ServiceHeader.stories.tsx +43 -8
- package/src/theme/light/MuiButton.tsx +34 -1
- package/src/theme/light/MuiOutlinedInput.ts +15 -0
- package/src/theme/light/index.tsx +8 -0
- package/src/theme/light/themePalette.tsx +2 -0
- package/src/theme/palette.tsx +11 -1
|
@@ -73,3 +73,8 @@ export declare const WarningContained: Story;
|
|
|
73
73
|
export declare const WarningOutlined: Story;
|
|
74
74
|
export declare const ErrorContained: Story;
|
|
75
75
|
export declare const ErrorOutlined: Story;
|
|
76
|
+
export declare const LightOutlined: Story;
|
|
77
|
+
export declare const LightOutlinedWithIcon: Story;
|
|
78
|
+
export declare const LightOutlinedDisabled: Story;
|
|
79
|
+
export declare const GhostOutlinedIconOnly: Story;
|
|
80
|
+
export declare const GhostOutlinedIconOnlyDisabled: Story;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StoryObj } from '@storybook/react';
|
|
2
|
-
import { SelectableCardListItemData, SelectableCardListProps } from '
|
|
2
|
+
import { SelectableCardListItemData, SelectableCardListProps } from '../../../components/common/SelectableCardList';
|
|
3
3
|
declare const meta: {
|
|
4
4
|
title: string;
|
|
5
5
|
component: ({ items, selectedId, onSelect, error, }: SelectableCardListProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Meta } from '@storybook/react';
|
|
2
|
+
import { default as RcSesSnackbar } from '../../../components/common/Snackbar';
|
|
3
|
+
declare const meta: Meta<typeof RcSesSnackbar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
export declare const Default: {
|
|
6
|
+
render: (args: any) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
args: {
|
|
8
|
+
open: boolean;
|
|
9
|
+
state: string;
|
|
10
|
+
message: string;
|
|
11
|
+
size: string;
|
|
12
|
+
actionLabel: string;
|
|
13
|
+
duration: number;
|
|
14
|
+
persist: boolean;
|
|
15
|
+
showClose: boolean;
|
|
16
|
+
dismissOnAction: boolean;
|
|
17
|
+
};
|
|
18
|
+
argTypes: {
|
|
19
|
+
open: {
|
|
20
|
+
control: string;
|
|
21
|
+
description: string;
|
|
22
|
+
};
|
|
23
|
+
state: {
|
|
24
|
+
control: string;
|
|
25
|
+
options: string[];
|
|
26
|
+
description: string;
|
|
27
|
+
};
|
|
28
|
+
message: {
|
|
29
|
+
control: string;
|
|
30
|
+
description: string;
|
|
31
|
+
};
|
|
32
|
+
size: {
|
|
33
|
+
control: string;
|
|
34
|
+
options: string[];
|
|
35
|
+
description: string;
|
|
36
|
+
};
|
|
37
|
+
duration: {
|
|
38
|
+
control: {
|
|
39
|
+
type: string;
|
|
40
|
+
min: number;
|
|
41
|
+
max: number;
|
|
42
|
+
step: number;
|
|
43
|
+
};
|
|
44
|
+
description: string;
|
|
45
|
+
};
|
|
46
|
+
persist: {
|
|
47
|
+
control: string;
|
|
48
|
+
description: string;
|
|
49
|
+
};
|
|
50
|
+
showClose: {
|
|
51
|
+
control: string;
|
|
52
|
+
description: string;
|
|
53
|
+
};
|
|
54
|
+
dismissOnAction: {
|
|
55
|
+
control: string;
|
|
56
|
+
description: string;
|
|
57
|
+
};
|
|
58
|
+
actionLabel: {
|
|
59
|
+
control: string;
|
|
60
|
+
description: string;
|
|
61
|
+
};
|
|
62
|
+
onAction: {
|
|
63
|
+
action: string;
|
|
64
|
+
description: string;
|
|
65
|
+
};
|
|
66
|
+
onClose: {
|
|
67
|
+
action: string;
|
|
68
|
+
description: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
parameters: {
|
|
72
|
+
docs: {
|
|
73
|
+
description: {
|
|
74
|
+
story: string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export declare const CompactWithText: {
|
|
80
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
81
|
+
parameters: {
|
|
82
|
+
docs: {
|
|
83
|
+
description: {
|
|
84
|
+
story: string;
|
|
85
|
+
};
|
|
86
|
+
source: {
|
|
87
|
+
code: string;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export declare const StandardWithButtons: {
|
|
93
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
94
|
+
parameters: {
|
|
95
|
+
docs: {
|
|
96
|
+
description: {
|
|
97
|
+
story: string;
|
|
98
|
+
};
|
|
99
|
+
source: {
|
|
100
|
+
code: string;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
export declare const CustomDuration: {
|
|
106
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
107
|
+
parameters: {
|
|
108
|
+
docs: {
|
|
109
|
+
description: {
|
|
110
|
+
story: string;
|
|
111
|
+
};
|
|
112
|
+
source: {
|
|
113
|
+
code: string;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
export declare const Persistent: {
|
|
119
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
120
|
+
parameters: {
|
|
121
|
+
docs: {
|
|
122
|
+
description: {
|
|
123
|
+
story: string;
|
|
124
|
+
};
|
|
125
|
+
source: {
|
|
126
|
+
code: string;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
export declare const LongText: {
|
|
132
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
133
|
+
parameters: {
|
|
134
|
+
docs: {
|
|
135
|
+
description: {
|
|
136
|
+
story: string;
|
|
137
|
+
};
|
|
138
|
+
source: {
|
|
139
|
+
code: string;
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
};
|
|
@@ -4,3 +4,6 @@ declare const meta: Meta<typeof RcSesCheckboxFormControl>;
|
|
|
4
4
|
export default meta;
|
|
5
5
|
type Story = StoryObj<typeof RcSesCheckboxFormControl>;
|
|
6
6
|
export declare const Main: Story;
|
|
7
|
+
export declare const Loading: Story;
|
|
8
|
+
export declare const Indeterminate: Story;
|
|
9
|
+
export declare const ParentChildLogicLoading: Story;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as SimpleCheckbox } from '../../../components/form/inputs/SimpleCheckbox';
|
|
3
|
+
declare const meta: {
|
|
4
|
+
title: string;
|
|
5
|
+
component: typeof SimpleCheckbox;
|
|
6
|
+
parameters: {
|
|
7
|
+
layout: string;
|
|
8
|
+
docs: {
|
|
9
|
+
description: {
|
|
10
|
+
component: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
tags: string[];
|
|
15
|
+
};
|
|
16
|
+
export default meta;
|
|
17
|
+
type Story = StoryObj<typeof meta>;
|
|
18
|
+
export declare const Basic: Story;
|
|
19
|
+
export declare const Loading: Story;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as RcSesSearchInput } from '../../../components/form/inputs/SearchInput';
|
|
3
|
+
declare const meta: Meta<typeof RcSesSearchInput>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof RcSesSearchInput>;
|
|
6
|
+
export declare const Main: Story;
|
|
7
|
+
export declare const OnlyRequired: Story;
|
|
8
|
+
export declare const WithoutButton: Story;
|
|
9
|
+
export declare const WithoutLabel: Story;
|
|
10
|
+
export declare const SideLabel: Story;
|
|
11
|
+
export declare const OnlyNumbers: Story;
|
|
@@ -3,10 +3,14 @@ declare module '@mui/material/styles' {
|
|
|
3
3
|
interface Palette {
|
|
4
4
|
dark: Palette['grey'];
|
|
5
5
|
grey: Palette['grey'];
|
|
6
|
+
light: Palette['grey'];
|
|
7
|
+
ghost: Palette['grey'];
|
|
6
8
|
}
|
|
7
9
|
interface PaletteOptions {
|
|
8
10
|
dark?: PaletteOptions['grey'];
|
|
9
11
|
grey?: PaletteOptions['grey'];
|
|
12
|
+
light?: PaletteOptions['grey'];
|
|
13
|
+
ghost?: PaletteOptions['grey'];
|
|
10
14
|
}
|
|
11
15
|
}
|
|
12
16
|
declare module '@mui/material' {
|
|
@@ -24,6 +28,8 @@ declare module '@mui/material' {
|
|
|
24
28
|
interface ButtonPropsColorOverrides {
|
|
25
29
|
grey: any;
|
|
26
30
|
dark: any;
|
|
31
|
+
light: any;
|
|
32
|
+
ghost: any;
|
|
27
33
|
}
|
|
28
34
|
interface RadioPropsColorOverrides {
|
|
29
35
|
grey: true;
|
package/dist/theme/palette.d.ts
CHANGED
|
@@ -68,7 +68,15 @@ declare const error: {
|
|
|
68
68
|
'950': string;
|
|
69
69
|
main: string;
|
|
70
70
|
};
|
|
71
|
-
|
|
71
|
+
declare const overlays: {
|
|
72
|
+
'200': string;
|
|
73
|
+
'300': string;
|
|
74
|
+
main: string;
|
|
75
|
+
};
|
|
76
|
+
declare const common: {
|
|
77
|
+
white: string;
|
|
78
|
+
};
|
|
79
|
+
export { primary, secondary, grey, warning, error, overlays, common };
|
|
72
80
|
declare const _default: {
|
|
73
81
|
primary: {
|
|
74
82
|
'50': string;
|
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ArrowsClockwiseIcon as PhosphorArrowClockwiseIcon } from '@phosphor-icons/react'
|
|
2
|
+
|
|
3
|
+
import IconProps from '../IconProps'
|
|
4
|
+
|
|
5
|
+
function ArrowsClockwiseIcon({ className, size = 24, fillColor, ...rest }: IconProps) {
|
|
6
|
+
return (
|
|
7
|
+
<PhosphorArrowClockwiseIcon
|
|
8
|
+
{...rest}
|
|
9
|
+
className={className}
|
|
10
|
+
size={size}
|
|
11
|
+
color={fillColor}
|
|
12
|
+
/>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default ArrowsClockwiseIcon
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MagnifyingGlassIcon as MagnifyingGlass,
|
|
3
|
+
QuestionMarkIcon,
|
|
4
|
+
} from '@phosphor-icons/react'
|
|
5
|
+
|
|
6
|
+
import IconProps from '../IconProps'
|
|
7
|
+
|
|
8
|
+
function SearchHelpIcon({ className, size = 24, fillColor, ...rest }: IconProps) {
|
|
9
|
+
const innerSize = Math.round(size * 0.45)
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<span
|
|
13
|
+
className={className}
|
|
14
|
+
style={{
|
|
15
|
+
display: 'inline-flex',
|
|
16
|
+
height: size,
|
|
17
|
+
position: 'relative',
|
|
18
|
+
verticalAlign: 'middle',
|
|
19
|
+
width: size,
|
|
20
|
+
}}
|
|
21
|
+
>
|
|
22
|
+
<MagnifyingGlass
|
|
23
|
+
{...rest}
|
|
24
|
+
size={size}
|
|
25
|
+
color={fillColor}
|
|
26
|
+
style={{ position: 'absolute', inset: 0 }}
|
|
27
|
+
/>
|
|
28
|
+
<QuestionMarkIcon
|
|
29
|
+
aria-hidden='true'
|
|
30
|
+
size={innerSize}
|
|
31
|
+
weight='bold'
|
|
32
|
+
color={fillColor}
|
|
33
|
+
style={{
|
|
34
|
+
left: '44.5%',
|
|
35
|
+
position: 'absolute',
|
|
36
|
+
top: '43%',
|
|
37
|
+
transform: 'translate(-50%, -50%)',
|
|
38
|
+
}}
|
|
39
|
+
/>
|
|
40
|
+
</span>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default SearchHelpIcon
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MagnifyingGlassIcon as MagnifyingGlass, XIcon } from '@phosphor-icons/react'
|
|
2
|
+
|
|
3
|
+
import IconProps from '../IconProps'
|
|
4
|
+
|
|
5
|
+
function SearchXIcon({ className, size = 24, fillColor, ...rest }: IconProps) {
|
|
6
|
+
const innerSize = Math.round(size * 0.45)
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<span
|
|
10
|
+
className={className}
|
|
11
|
+
style={{
|
|
12
|
+
display: 'inline-flex',
|
|
13
|
+
height: size,
|
|
14
|
+
position: 'relative',
|
|
15
|
+
verticalAlign: 'middle',
|
|
16
|
+
width: size,
|
|
17
|
+
}}
|
|
18
|
+
>
|
|
19
|
+
<MagnifyingGlass
|
|
20
|
+
{...rest}
|
|
21
|
+
size={size}
|
|
22
|
+
color={fillColor}
|
|
23
|
+
style={{ position: 'absolute', inset: 0 }}
|
|
24
|
+
/>
|
|
25
|
+
<XIcon
|
|
26
|
+
aria-hidden='true'
|
|
27
|
+
size={innerSize}
|
|
28
|
+
weight='bold'
|
|
29
|
+
color={fillColor}
|
|
30
|
+
style={{
|
|
31
|
+
left: '44.5%',
|
|
32
|
+
position: 'absolute',
|
|
33
|
+
top: '43%',
|
|
34
|
+
transform: 'translate(-50%, -50%)',
|
|
35
|
+
}}
|
|
36
|
+
/>
|
|
37
|
+
</span>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default SearchXIcon
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { Link, Breadcrumbs as MuiBreadcrumbs } from '@mui/material'
|
|
1
|
+
import { Link, Breadcrumbs as MuiBreadcrumbs, SxProps, Theme } from '@mui/material'
|
|
2
2
|
|
|
3
3
|
export type BreadcrumbItem = { label: string; path: string }
|
|
4
4
|
|
|
5
5
|
type Props = {
|
|
6
6
|
path: BreadcrumbItem[]
|
|
7
|
+
sx?: SxProps<Theme>
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
function RcSesBreadcrumbs({ path }: Props) {
|
|
10
|
+
function RcSesBreadcrumbs({ path, sx }: Props) {
|
|
10
11
|
return (
|
|
11
|
-
<MuiBreadcrumbs>
|
|
12
|
+
<MuiBreadcrumbs sx={sx}>
|
|
12
13
|
{path.map((step) => (
|
|
13
14
|
<Link key={step.path} underline='hover' color='inherit' href={step.path}>
|
|
14
15
|
{step.label}
|
|
@@ -27,9 +27,11 @@ const ListWithIconsItem = ({
|
|
|
27
27
|
maxWidth: { xs: '100%', md: 'none' },
|
|
28
28
|
}}
|
|
29
29
|
>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
{Icon && (
|
|
31
|
+
<Box sx={{ display: 'flex', alignItems: 'center' }}>
|
|
32
|
+
<Icon fillColor={textColor ?? palette.grey[600]} size={16} />
|
|
33
|
+
</Box>
|
|
34
|
+
)}
|
|
33
35
|
<Typography
|
|
34
36
|
variant='body2'
|
|
35
37
|
sx={{
|
|
@@ -98,7 +98,9 @@ const SelectableCardListItem = ({
|
|
|
98
98
|
},
|
|
99
99
|
}}
|
|
100
100
|
>
|
|
101
|
-
|
|
101
|
+
{(isLoading || (!!listItems && listItems.length > 0)) && (
|
|
102
|
+
<ListWithIcons items={listItems} layout='horizontal' isLoading={isLoading} />
|
|
103
|
+
)}
|
|
102
104
|
</RcSesCard>
|
|
103
105
|
)
|
|
104
106
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ReactNode,
|
|
3
|
+
createContext,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useMemo,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react'
|
|
9
|
+
|
|
10
|
+
import RcSesSnackbar from './index'
|
|
11
|
+
import { type SnackbarSize, type SnackbarState } from './types'
|
|
12
|
+
|
|
13
|
+
export interface SnackbarConfig {
|
|
14
|
+
state: SnackbarState
|
|
15
|
+
message: string
|
|
16
|
+
size?: SnackbarSize
|
|
17
|
+
onAction?: () => void
|
|
18
|
+
actionLabel?: string
|
|
19
|
+
duration?: number
|
|
20
|
+
persist?: boolean
|
|
21
|
+
dismissOnAction?: boolean
|
|
22
|
+
showClose?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface SnackbarContextType {
|
|
26
|
+
showSnackbar: (config: SnackbarConfig) => void
|
|
27
|
+
hideSnackbar: () => void
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const SnackbarContext = createContext<SnackbarContextType | undefined>(undefined)
|
|
31
|
+
|
|
32
|
+
export function RcSesSnackbarProvider({ children }: { children: ReactNode }) {
|
|
33
|
+
const [snackbar, setSnackbar] = useState<SnackbarConfig | null>(null)
|
|
34
|
+
|
|
35
|
+
const showSnackbar = useCallback((config: SnackbarConfig) => {
|
|
36
|
+
setSnackbar(config)
|
|
37
|
+
}, [])
|
|
38
|
+
|
|
39
|
+
const hideSnackbar = useCallback(() => {
|
|
40
|
+
setSnackbar(null)
|
|
41
|
+
}, [])
|
|
42
|
+
|
|
43
|
+
const value = useMemo(
|
|
44
|
+
() => ({ showSnackbar, hideSnackbar }),
|
|
45
|
+
[showSnackbar, hideSnackbar],
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<SnackbarContext.Provider value={value}>
|
|
50
|
+
{children}
|
|
51
|
+
{snackbar && (
|
|
52
|
+
<RcSesSnackbar
|
|
53
|
+
state={snackbar.state}
|
|
54
|
+
message={snackbar.message}
|
|
55
|
+
size={snackbar.size}
|
|
56
|
+
onAction={snackbar.onAction}
|
|
57
|
+
actionLabel={snackbar.actionLabel}
|
|
58
|
+
duration={snackbar.duration}
|
|
59
|
+
persist={snackbar.persist}
|
|
60
|
+
dismissOnAction={snackbar.dismissOnAction}
|
|
61
|
+
showClose={snackbar.showClose ?? true}
|
|
62
|
+
onClose={hideSnackbar}
|
|
63
|
+
open
|
|
64
|
+
/>
|
|
65
|
+
)}
|
|
66
|
+
</SnackbarContext.Provider>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function useSnackbar() {
|
|
71
|
+
const context = useContext(SnackbarContext)
|
|
72
|
+
if (!context) {
|
|
73
|
+
throw new Error('useSnackbar must be used within RcSesSnackbarProvider')
|
|
74
|
+
}
|
|
75
|
+
return context
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default RcSesSnackbarProvider
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ComponentType } from 'react'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
CheckCircleFillIcon,
|
|
5
|
+
InfoFillIcon,
|
|
6
|
+
ScrollIcon,
|
|
7
|
+
WarningFillIcon,
|
|
8
|
+
XCircleFillIcon,
|
|
9
|
+
} from '@/library/icons'
|
|
10
|
+
import { error, primary, secondary, warning } from '@/theme/palette'
|
|
11
|
+
|
|
12
|
+
import { type SnackbarSize, type SnackbarState } from './types'
|
|
13
|
+
|
|
14
|
+
export const SNACKBAR_DURATION = 10000 // 10s
|
|
15
|
+
|
|
16
|
+
export const SNACKBAR_ICON_SIZE = { width: 18, height: 20 }
|
|
17
|
+
|
|
18
|
+
export const stateConfig: Record<
|
|
19
|
+
SnackbarState,
|
|
20
|
+
{
|
|
21
|
+
icon: ComponentType<{ fillColor?: string; 'aria-hidden'?: boolean }>
|
|
22
|
+
color: string
|
|
23
|
+
severity: 'success' | 'error' | 'warning' | 'info'
|
|
24
|
+
ariaLive: 'polite' | 'assertive'
|
|
25
|
+
}
|
|
26
|
+
> = {
|
|
27
|
+
success: {
|
|
28
|
+
icon: CheckCircleFillIcon,
|
|
29
|
+
color: secondary['400'],
|
|
30
|
+
severity: 'success',
|
|
31
|
+
ariaLive: 'polite',
|
|
32
|
+
},
|
|
33
|
+
error: {
|
|
34
|
+
icon: XCircleFillIcon,
|
|
35
|
+
color: error['400'],
|
|
36
|
+
severity: 'error',
|
|
37
|
+
ariaLive: 'assertive',
|
|
38
|
+
},
|
|
39
|
+
warning: {
|
|
40
|
+
icon: WarningFillIcon,
|
|
41
|
+
color: warning['400'],
|
|
42
|
+
severity: 'warning',
|
|
43
|
+
ariaLive: 'polite',
|
|
44
|
+
},
|
|
45
|
+
info: {
|
|
46
|
+
icon: InfoFillIcon,
|
|
47
|
+
color: primary['400'],
|
|
48
|
+
severity: 'info',
|
|
49
|
+
ariaLive: 'polite',
|
|
50
|
+
},
|
|
51
|
+
'action-needed': {
|
|
52
|
+
icon: ScrollIcon,
|
|
53
|
+
color: primary['400'],
|
|
54
|
+
severity: 'info',
|
|
55
|
+
ariaLive: 'assertive',
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const sizeConfig: Record<
|
|
60
|
+
SnackbarSize,
|
|
61
|
+
{
|
|
62
|
+
maxHeight: number
|
|
63
|
+
width: number
|
|
64
|
+
padding: string
|
|
65
|
+
}
|
|
66
|
+
> = {
|
|
67
|
+
standard: {
|
|
68
|
+
maxHeight: 120,
|
|
69
|
+
width: 400,
|
|
70
|
+
padding: '12px 16px',
|
|
71
|
+
},
|
|
72
|
+
compact: {
|
|
73
|
+
maxHeight: 96,
|
|
74
|
+
width: 320,
|
|
75
|
+
padding: '8px 12px',
|
|
76
|
+
},
|
|
77
|
+
}
|