@onewelcome/react-lib-components 6.6.0 → 6.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/cjs/DataGrid/DataGrid.module.cjs.js +1 -1
- package/dist/cjs/DataGrid/DataGridBody/DataGridCell.cjs.js +1 -1
- package/dist/cjs/DataGrid/DataGridBody/DataGridCell.cjs.js.map +1 -1
- package/dist/cjs/DataGrid/DataGridBody/DataGridCell.module.cjs.js +1 -1
- package/dist/cjs/DataGrid/DataGridBody/DataGridRow.module.cjs.js +1 -1
- package/dist/cjs/DataGrid/DataGridHeader/DataGridHeader.cjs.js +1 -1
- package/dist/cjs/DataGrid/DataGridHeader/DataGridHeader.cjs.js.map +1 -1
- package/dist/cjs/DataGrid/DataGridHeader/DataGridHeader.module.cjs.js +1 -1
- package/dist/cjs/DataGrid/DataGridHeader/DataGridHeaderCell.module.cjs.js +1 -1
- package/dist/cjs/Form/FileUpload/FileItem/FileItem.cjs.js +1 -1
- package/dist/cjs/Form/FileUpload/FileItem/FileItem.cjs.js.map +1 -1
- package/dist/cjs/Form/FileUpload/FileItem/FileItem.module.cjs.js +1 -1
- package/dist/cjs/Form/FileUpload/FileUpload.cjs.js +1 -1
- package/dist/cjs/Form/FileUpload/FileUpload.cjs.js.map +1 -1
- package/dist/cjs/Form/FileUpload/FileUpload.module.cjs.js +1 -1
- package/dist/cjs/Icon/Icon.cjs.js +1 -1
- package/dist/cjs/Icon/Icon.cjs.js.map +1 -1
- package/dist/cjs/Icon/Icon.module.cjs.js +1 -1
- package/dist/cjs/Layout/ContentHeader/ContentHeader.cjs.js +2 -0
- package/dist/cjs/Layout/ContentHeader/ContentHeader.cjs.js.map +1 -0
- package/dist/cjs/Layout/ContentHeader/ContentHeader.module.cjs.js +2 -0
- package/dist/cjs/Layout/ContentHeader/ContentHeader.module.cjs.js.map +1 -0
- package/dist/cjs/Layout/FormPage/FormWithStepper/FormSection/FormSection.cjs.js +2 -0
- package/dist/cjs/Layout/FormPage/FormWithStepper/FormSection/FormSection.cjs.js.map +1 -0
- package/dist/cjs/Layout/FormPage/FormWithStepper/FormSection/FormSection.module.cjs.js +2 -0
- package/dist/cjs/Layout/FormPage/FormWithStepper/FormSection/FormSection.module.cjs.js.map +1 -0
- package/dist/cjs/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.cjs.js +2 -0
- package/dist/cjs/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.cjs.js.map +1 -0
- package/dist/cjs/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.module.cjs.js +2 -0
- package/dist/cjs/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.module.cjs.js.map +1 -0
- package/dist/cjs/Layout/FormPage/FormWithStepper/FormWithStepper.cjs.js +2 -0
- package/dist/cjs/Layout/FormPage/FormWithStepper/FormWithStepper.cjs.js.map +1 -0
- package/dist/cjs/Layout/FormPage/FormWithStepper/FormWithStepper.module.cjs.js +2 -0
- package/dist/cjs/Layout/FormPage/FormWithStepper/FormWithStepper.module.cjs.js.map +1 -0
- package/dist/cjs/Notifications/Alert/AlertContainer/AlertContainer.cjs.js +2 -0
- package/dist/cjs/Notifications/Alert/AlertContainer/AlertContainer.cjs.js.map +1 -0
- package/dist/cjs/Notifications/Alert/AlertContainer/AlertContainer.module.cjs.js +2 -0
- package/dist/cjs/Notifications/Alert/AlertContainer/AlertContainer.module.cjs.js.map +1 -0
- package/dist/cjs/Notifications/Alert/AlertContainer/useAlertContainerHeightAnimation.cjs.js +2 -0
- package/dist/cjs/Notifications/Alert/AlertContainer/useAlertContainerHeightAnimation.cjs.js.map +1 -0
- package/dist/cjs/Notifications/Alert/AlertItem/AlertItem.cjs.js +2 -0
- package/dist/cjs/Notifications/Alert/AlertItem/AlertItem.cjs.js.map +1 -0
- package/dist/cjs/Notifications/Alert/AlertItem/AlertItem.module.cjs.js +2 -0
- package/dist/cjs/Notifications/Alert/AlertItem/AlertItem.module.cjs.js.map +1 -0
- package/dist/cjs/Notifications/Alert/AlertProvider/AlertContext.cjs.js +2 -0
- package/dist/cjs/Notifications/Alert/AlertProvider/AlertContext.cjs.js.map +1 -0
- package/dist/cjs/Notifications/Alert/AlertProvider/AlertProvider.cjs.js +2 -0
- package/dist/cjs/Notifications/Alert/AlertProvider/AlertProvider.cjs.js.map +1 -0
- package/dist/cjs/Notifications/Alert/useAlert.cjs.js +2 -0
- package/dist/cjs/Notifications/Alert/useAlert.cjs.js.map +1 -0
- package/dist/cjs/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.cjs.js.map +1 -1
- package/dist/cjs/Notifications/Snackbar/SnackbarItem/SnackbarItem.cjs.js.map +1 -1
- package/dist/cjs/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.cjs.js.map +1 -1
- package/dist/cjs/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.cjs.js.map +1 -1
- package/dist/cjs/Notifications/Snackbar/interfaces.cjs.js.map +1 -1
- package/dist/cjs/Notifications/Snackbar/useSnackbar.cjs.js.map +1 -1
- package/dist/cjs/Pagination/Pagination.cjs.js +1 -1
- package/dist/cjs/Pagination/Pagination.cjs.js.map +1 -1
- package/dist/cjs/Pagination/Pagination.module.cjs.js +1 -1
- package/dist/cjs/_BaseStyling_/BaseStyling.cjs.js +1 -1
- package/dist/cjs/_BaseStyling_/BaseStyling.cjs.js.map +1 -1
- package/dist/cjs/src/components/Form/FileUpload/FileItem/FileItem.d.ts +10 -0
- package/dist/cjs/src/components/Form/FileUpload/FileUpload.d.ts +3 -0
- package/dist/cjs/src/components/Icon/Icon.d.ts +5 -1
- package/dist/cjs/src/components/Layout/ContentHeader/ContentHeader.d.ts +10 -0
- package/dist/cjs/src/components/Layout/ContentHeader/ContentHeader.test.d.ts +1 -0
- package/dist/cjs/src/components/Layout/FormPage/FormWithStepper/FormSection/FormSection.d.ts +7 -0
- package/dist/cjs/src/components/Layout/FormPage/FormWithStepper/FormSection/FormSection.test.d.ts +1 -0
- package/dist/cjs/src/components/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.d.ts +10 -0
- package/dist/cjs/src/components/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.test.d.ts +1 -0
- package/dist/cjs/src/components/Layout/FormPage/FormWithStepper/FormWithStepper.d.ts +6 -0
- package/dist/cjs/src/components/Layout/FormPage/FormWithStepper/FormWithStepper.test.d.ts +1 -0
- package/dist/cjs/src/components/Notifications/Alert/AlertContainer/AlertContainer.d.ts +12 -0
- package/dist/cjs/src/components/Notifications/Alert/AlertContainer/AlertContainer.test.d.ts +1 -0
- package/dist/cjs/src/components/Notifications/Alert/AlertContainer/useAlertContainerHeightAnimation.d.ts +4 -0
- package/dist/cjs/src/components/Notifications/Alert/AlertItem/AlertItem.d.ts +22 -0
- package/dist/cjs/src/components/Notifications/Alert/AlertItem/AlertItem.test.d.ts +1 -0
- package/dist/cjs/src/components/Notifications/Alert/AlertProvider/AlertContext.d.ts +13 -0
- package/dist/cjs/src/components/Notifications/Alert/AlertProvider/AlertProvider.d.ts +22 -0
- package/dist/cjs/src/components/Notifications/Alert/AlertProvider/AlertProvider.test.d.ts +1 -0
- package/dist/cjs/src/components/Notifications/Alert/useAlert.d.ts +7 -0
- package/dist/cjs/src/components/Notifications/Alert/useAlert.test.d.ts +1 -0
- package/dist/cjs/src/components/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.d.ts +9 -0
- package/dist/cjs/src/components/Notifications/Snackbar/SnackbarItem/SnackbarItem.d.ts +6 -0
- package/dist/cjs/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.d.ts +9 -0
- package/dist/cjs/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.d.ts +9 -0
- package/dist/cjs/src/components/Notifications/Snackbar/interfaces.d.ts +18 -0
- package/dist/cjs/src/components/Notifications/Snackbar/useSnackbar.d.ts +3 -0
- package/dist/cjs/src/components/_BaseStyling_/BaseStyling.d.ts +40 -0
- package/dist/cjs/src/components/admin/layout/MicrofrontendContainer/MicrofrontendContainer.d.ts +8 -0
- package/dist/cjs/src/index.cjs.js +1 -1
- package/dist/cjs/src/index.d.ts +15 -0
- package/dist/esm/DataGrid/DataGrid.module.esm.js +1 -1
- package/dist/esm/DataGrid/DataGridBody/DataGridCell.esm.js +1 -1
- package/dist/esm/DataGrid/DataGridBody/DataGridCell.esm.js.map +1 -1
- package/dist/esm/DataGrid/DataGridBody/DataGridCell.module.esm.js +1 -1
- package/dist/esm/DataGrid/DataGridBody/DataGridRow.module.esm.js +1 -1
- package/dist/esm/DataGrid/DataGridHeader/DataGridHeader.esm.js +1 -1
- package/dist/esm/DataGrid/DataGridHeader/DataGridHeader.esm.js.map +1 -1
- package/dist/esm/DataGrid/DataGridHeader/DataGridHeader.module.esm.js +1 -1
- package/dist/esm/DataGrid/DataGridHeader/DataGridHeaderCell.module.esm.js +1 -1
- package/dist/esm/Form/FileUpload/FileItem/FileItem.esm.js +1 -1
- package/dist/esm/Form/FileUpload/FileItem/FileItem.esm.js.map +1 -1
- package/dist/esm/Form/FileUpload/FileItem/FileItem.module.esm.js +1 -1
- package/dist/esm/Form/FileUpload/FileUpload.esm.js +1 -1
- package/dist/esm/Form/FileUpload/FileUpload.esm.js.map +1 -1
- package/dist/esm/Form/FileUpload/FileUpload.module.esm.js +1 -1
- package/dist/esm/Icon/Icon.esm.js +1 -1
- package/dist/esm/Icon/Icon.esm.js.map +1 -1
- package/dist/esm/Icon/Icon.module.esm.js +1 -1
- package/dist/esm/Layout/ContentHeader/ContentHeader.esm.js +2 -0
- package/dist/esm/Layout/ContentHeader/ContentHeader.esm.js.map +1 -0
- package/dist/esm/Layout/ContentHeader/ContentHeader.module.esm.js +2 -0
- package/dist/esm/Layout/ContentHeader/ContentHeader.module.esm.js.map +1 -0
- package/dist/esm/Layout/FormPage/FormWithStepper/FormSection/FormSection.esm.js +2 -0
- package/dist/esm/Layout/FormPage/FormWithStepper/FormSection/FormSection.esm.js.map +1 -0
- package/dist/esm/Layout/FormPage/FormWithStepper/FormSection/FormSection.module.esm.js +2 -0
- package/dist/esm/Layout/FormPage/FormWithStepper/FormSection/FormSection.module.esm.js.map +1 -0
- package/dist/esm/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.esm.js +2 -0
- package/dist/esm/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.esm.js.map +1 -0
- package/dist/esm/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.module.esm.js +2 -0
- package/dist/esm/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.module.esm.js.map +1 -0
- package/dist/esm/Layout/FormPage/FormWithStepper/FormWithStepper.esm.js +2 -0
- package/dist/esm/Layout/FormPage/FormWithStepper/FormWithStepper.esm.js.map +1 -0
- package/dist/esm/Layout/FormPage/FormWithStepper/FormWithStepper.module.esm.js +2 -0
- package/dist/esm/Layout/FormPage/FormWithStepper/FormWithStepper.module.esm.js.map +1 -0
- package/dist/esm/Notifications/Alert/AlertContainer/AlertContainer.esm.js +2 -0
- package/dist/esm/Notifications/Alert/AlertContainer/AlertContainer.esm.js.map +1 -0
- package/dist/esm/Notifications/Alert/AlertContainer/AlertContainer.module.esm.js +2 -0
- package/dist/esm/Notifications/Alert/AlertContainer/AlertContainer.module.esm.js.map +1 -0
- package/dist/esm/Notifications/Alert/AlertContainer/useAlertContainerHeightAnimation.esm.js +2 -0
- package/dist/esm/Notifications/Alert/AlertContainer/useAlertContainerHeightAnimation.esm.js.map +1 -0
- package/dist/esm/Notifications/Alert/AlertItem/AlertItem.esm.js +2 -0
- package/dist/esm/Notifications/Alert/AlertItem/AlertItem.esm.js.map +1 -0
- package/dist/esm/Notifications/Alert/AlertItem/AlertItem.module.esm.js +2 -0
- package/dist/esm/Notifications/Alert/AlertItem/AlertItem.module.esm.js.map +1 -0
- package/dist/esm/Notifications/Alert/AlertProvider/AlertContext.esm.js +2 -0
- package/dist/esm/Notifications/Alert/AlertProvider/AlertContext.esm.js.map +1 -0
- package/dist/esm/Notifications/Alert/AlertProvider/AlertProvider.esm.js +2 -0
- package/dist/esm/Notifications/Alert/AlertProvider/AlertProvider.esm.js.map +1 -0
- package/dist/esm/Notifications/Alert/useAlert.esm.js +2 -0
- package/dist/esm/Notifications/Alert/useAlert.esm.js.map +1 -0
- package/dist/esm/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.esm.js.map +1 -1
- package/dist/esm/Notifications/Snackbar/SnackbarItem/SnackbarItem.esm.js.map +1 -1
- package/dist/esm/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.esm.js.map +1 -1
- package/dist/esm/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.esm.js.map +1 -1
- package/dist/esm/Notifications/Snackbar/interfaces.esm.js.map +1 -1
- package/dist/esm/Notifications/Snackbar/useSnackbar.esm.js.map +1 -1
- package/dist/esm/Pagination/Pagination.esm.js +1 -1
- package/dist/esm/Pagination/Pagination.esm.js.map +1 -1
- package/dist/esm/Pagination/Pagination.module.esm.js +1 -1
- package/dist/esm/_BaseStyling_/BaseStyling.esm.js +1 -1
- package/dist/esm/_BaseStyling_/BaseStyling.esm.js.map +1 -1
- package/dist/esm/src/components/Form/FileUpload/FileItem/FileItem.d.ts +10 -0
- package/dist/esm/src/components/Form/FileUpload/FileUpload.d.ts +3 -0
- package/dist/esm/src/components/Icon/Icon.d.ts +5 -1
- package/dist/esm/src/components/Layout/ContentHeader/ContentHeader.d.ts +10 -0
- package/dist/esm/src/components/Layout/ContentHeader/ContentHeader.test.d.ts +1 -0
- package/dist/esm/src/components/Layout/FormPage/FormWithStepper/FormSection/FormSection.d.ts +7 -0
- package/dist/esm/src/components/Layout/FormPage/FormWithStepper/FormSection/FormSection.test.d.ts +1 -0
- package/dist/esm/src/components/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.d.ts +10 -0
- package/dist/esm/src/components/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.test.d.ts +1 -0
- package/dist/esm/src/components/Layout/FormPage/FormWithStepper/FormWithStepper.d.ts +6 -0
- package/dist/esm/src/components/Layout/FormPage/FormWithStepper/FormWithStepper.test.d.ts +1 -0
- package/dist/esm/src/components/Notifications/Alert/AlertContainer/AlertContainer.d.ts +12 -0
- package/dist/esm/src/components/Notifications/Alert/AlertContainer/AlertContainer.test.d.ts +1 -0
- package/dist/esm/src/components/Notifications/Alert/AlertContainer/useAlertContainerHeightAnimation.d.ts +4 -0
- package/dist/esm/src/components/Notifications/Alert/AlertItem/AlertItem.d.ts +22 -0
- package/dist/esm/src/components/Notifications/Alert/AlertItem/AlertItem.test.d.ts +1 -0
- package/dist/esm/src/components/Notifications/Alert/AlertProvider/AlertContext.d.ts +13 -0
- package/dist/esm/src/components/Notifications/Alert/AlertProvider/AlertProvider.d.ts +22 -0
- package/dist/esm/src/components/Notifications/Alert/AlertProvider/AlertProvider.test.d.ts +1 -0
- package/dist/esm/src/components/Notifications/Alert/useAlert.d.ts +7 -0
- package/dist/esm/src/components/Notifications/Alert/useAlert.test.d.ts +1 -0
- package/dist/esm/src/components/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.d.ts +9 -0
- package/dist/esm/src/components/Notifications/Snackbar/SnackbarItem/SnackbarItem.d.ts +6 -0
- package/dist/esm/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.d.ts +9 -0
- package/dist/esm/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.d.ts +9 -0
- package/dist/esm/src/components/Notifications/Snackbar/interfaces.d.ts +18 -0
- package/dist/esm/src/components/Notifications/Snackbar/useSnackbar.d.ts +3 -0
- package/dist/esm/src/components/_BaseStyling_/BaseStyling.d.ts +40 -0
- package/dist/esm/src/components/admin/layout/MicrofrontendContainer/MicrofrontendContainer.d.ts +8 -0
- package/dist/esm/src/index.d.ts +15 -0
- package/dist/esm/src/index.esm.js +1 -1
- package/package.json +1 -1
- package/src/components/DataGrid/DataGrid.module.scss +2 -2
- package/src/components/DataGrid/DataGridBody/DataGridCell.module.scss +7 -2
- package/src/components/DataGrid/DataGridBody/DataGridCell.tsx +1 -1
- package/src/components/DataGrid/DataGridBody/DataGridRow.module.scss +10 -0
- package/src/components/DataGrid/DataGridBody/__snapshots__/DataGridBody.test.tsx.snap +16 -16
- package/src/components/DataGrid/DataGridHeader/DataGridHeader.module.scss +0 -10
- package/src/components/DataGrid/DataGridHeader/DataGridHeader.tsx +1 -1
- package/src/components/DataGrid/DataGridHeader/DataGridHeaderCell.module.scss +3 -3
- package/src/components/Form/FileUpload/FileItem/FileItem.module.scss +114 -3
- package/src/components/Form/FileUpload/FileItem/FileItem.tsx +154 -47
- package/src/components/Form/FileUpload/FileUpload.module.scss +73 -16
- package/src/components/Form/FileUpload/FileUpload.tsx +82 -53
- package/src/components/Form/FormSection/FormSection.module.scss +12 -0
- package/src/components/Icon/Icon.module.scss +16 -1
- package/src/components/Icon/Icon.tsx +5 -1
- package/src/components/Layout/ContentHeader/ContentHeader.module.scss +44 -0
- package/src/components/Layout/ContentHeader/ContentHeader.tsx +70 -0
- package/src/components/Layout/FormPage/FormWithStepper/FormSection/FormSection.module.scss +12 -0
- package/src/components/Layout/FormPage/FormWithStepper/FormSection/FormSection.tsx +53 -0
- package/src/components/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.module.scss +25 -0
- package/src/components/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.tsx +54 -0
- package/src/components/Layout/FormPage/FormWithStepper/FormWithStepper.module.scss +39 -0
- package/src/components/Layout/FormPage/FormWithStepper/FormWithStepper.tsx +34 -0
- package/src/components/Notifications/Alert/AlertContainer/AlertContainer.module.scss +56 -0
- package/src/components/Notifications/Alert/AlertContainer/AlertContainer.tsx +52 -0
- package/src/components/Notifications/Alert/AlertContainer/useAlertContainerHeightAnimation.ts +47 -0
- package/src/components/Notifications/Alert/AlertItem/AlertItem.module.scss +277 -0
- package/src/components/Notifications/Alert/AlertItem/AlertItem.tsx +214 -0
- package/src/components/Notifications/Alert/AlertProvider/AlertContext.ts +42 -0
- package/src/components/Notifications/Alert/AlertProvider/AlertProvider.tsx +173 -0
- package/src/components/Notifications/Alert/useAlert.ts +30 -0
- package/src/components/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.tsx +9 -0
- package/src/components/Notifications/Snackbar/SnackbarItem/SnackbarItem.tsx +6 -0
- package/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.tsx +9 -0
- package/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.tsx +9 -0
- package/src/components/Notifications/Snackbar/interfaces.ts +18 -0
- package/src/components/Notifications/Snackbar/useSnackbar.ts +3 -0
- package/src/components/Pagination/Pagination.module.scss +4 -6
- package/src/components/Pagination/Pagination.tsx +3 -1
- package/src/components/_BaseStyling_/BaseStyling.tsx +78 -1
- package/src/components/admin/layout/MicrofrontendContainer/MicrofrontendContainer.module.scss +25 -0
- package/src/components/admin/layout/MicrofrontendContainer/MicrofrontendContainer.tsx +47 -0
- package/src/font/icomoon.eot +0 -0
- package/src/font/icomoon.svg +3 -0
- package/src/font/icomoon.ttf +0 -0
- package/src/font/icomoon.woff +0 -0
- package/src/font/selection.json +1 -1
- package/src/index.ts +21 -0
- package/src/mixins.module.scss +7 -0
- package/src/variables.scss +1 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright 2022 OneWelcome B.V.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
@use "../../../../mixins.module.scss";
|
|
18
|
+
|
|
19
|
+
.alert {
|
|
20
|
+
padding: 1rem 0.875rem;
|
|
21
|
+
border-radius: var(--alert-border-radius);
|
|
22
|
+
display: flex;
|
|
23
|
+
gap: 0.5rem;
|
|
24
|
+
align-items: center;
|
|
25
|
+
width: 100%;
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
flex-grow: 0;
|
|
28
|
+
|
|
29
|
+
&.neutral {
|
|
30
|
+
background-color: var(--alert-neutral-background-color);
|
|
31
|
+
border-radius: var(--alert-border-radius);
|
|
32
|
+
|
|
33
|
+
&.emph-low {
|
|
34
|
+
color: unset;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
&.emph-medium {
|
|
38
|
+
@include mixins.alertBorder(var(--alert-neutral-inverted-color));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&.emph-high {
|
|
42
|
+
background-color: var(--alert-neutral-inverted-color);
|
|
43
|
+
|
|
44
|
+
.content,
|
|
45
|
+
.title,
|
|
46
|
+
.close-btn,
|
|
47
|
+
.icon,
|
|
48
|
+
.action-button {
|
|
49
|
+
color: var(--alert-text-inverted-color);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&.informative {
|
|
55
|
+
background-color: var(--alert-info-background-color);
|
|
56
|
+
border-radius: var(--alert-border-radius);
|
|
57
|
+
|
|
58
|
+
&.emph-low {
|
|
59
|
+
color: unset;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
&.emph-medium {
|
|
63
|
+
@include mixins.alertBorder(var(--alert-info-inverted-color));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&.emph-high {
|
|
67
|
+
background-color: var(--alert-info-inverted-color);
|
|
68
|
+
|
|
69
|
+
.content,
|
|
70
|
+
.title,
|
|
71
|
+
.close-btn,
|
|
72
|
+
.icon,
|
|
73
|
+
.action-button {
|
|
74
|
+
color: var(--alert-text-inverted-color);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
&.success {
|
|
80
|
+
background-color: var(--alert-success-background-color);
|
|
81
|
+
border-radius: var(--alert-border-radius);
|
|
82
|
+
|
|
83
|
+
&.emph-low .icon {
|
|
84
|
+
color: var(--alert-success-inverted-color);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
&.emph-medium {
|
|
88
|
+
@include mixins.alertBorder(var(--alert-success-inverted-color));
|
|
89
|
+
|
|
90
|
+
.icon {
|
|
91
|
+
color: var(--alert-success-inverted-color);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&.emph-high {
|
|
96
|
+
background-color: var(--alert-success-inverted-color);
|
|
97
|
+
|
|
98
|
+
.content,
|
|
99
|
+
.title,
|
|
100
|
+
.close-btn,
|
|
101
|
+
.icon,
|
|
102
|
+
.action-button {
|
|
103
|
+
color: var(--alert-text-inverted-color);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
&.warning {
|
|
109
|
+
background-color: var(--alert-warning-background-color);
|
|
110
|
+
border-radius: var(--alert-border-radius);
|
|
111
|
+
|
|
112
|
+
&.emph-low .icon {
|
|
113
|
+
color: var(--alert-warning-inverted-color);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
&.emph-medium {
|
|
117
|
+
@include mixins.alertBorder(var(--alert-warning-inverted-color));
|
|
118
|
+
|
|
119
|
+
.icon {
|
|
120
|
+
color: var(--alert-warning-inverted-color);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
&.emph-high {
|
|
125
|
+
background-color: var(--alert-warning-inverted-color);
|
|
126
|
+
|
|
127
|
+
.content,
|
|
128
|
+
.title,
|
|
129
|
+
.close-btn,
|
|
130
|
+
.icon,
|
|
131
|
+
.action-button {
|
|
132
|
+
color: var(--alert-text-inverted-color);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
&.error {
|
|
138
|
+
background-color: var(--alert-error-background-color);
|
|
139
|
+
border-radius: var(--alert-border-radius);
|
|
140
|
+
|
|
141
|
+
&.emph-low .icon {
|
|
142
|
+
color: var(--alert-error-inverted-color);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
&.emph-medium {
|
|
146
|
+
@include mixins.alertBorder(var(--alert-error-inverted-color));
|
|
147
|
+
|
|
148
|
+
.icon {
|
|
149
|
+
color: var(--alert-error-inverted-color);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
&.emph-high {
|
|
154
|
+
background-color: var(--alert-error-inverted-color);
|
|
155
|
+
|
|
156
|
+
.content,
|
|
157
|
+
.title,
|
|
158
|
+
.close-btn,
|
|
159
|
+
.icon,
|
|
160
|
+
.action-button {
|
|
161
|
+
color: var(--alert-text-inverted-color);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
& + & {
|
|
167
|
+
margin-top: 0.5rem;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.close-btn {
|
|
171
|
+
color: var(--alert-text-color);
|
|
172
|
+
align-self: center;
|
|
173
|
+
width: 2.5rem;
|
|
174
|
+
height: 2.5rem;
|
|
175
|
+
margin: -0.5rem 0;
|
|
176
|
+
flex-shrink: 0;
|
|
177
|
+
border: 0;
|
|
178
|
+
|
|
179
|
+
span {
|
|
180
|
+
font-size: 0.875rem;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
&:not(:disabled):hover,
|
|
184
|
+
&:not(:disabled):focus {
|
|
185
|
+
background-color: var(--color-black10);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
&:not(:disabled):active {
|
|
189
|
+
background-color: var(--color-black20);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.icon {
|
|
194
|
+
color: var(--alert-text-color);
|
|
195
|
+
font-size: 1rem;
|
|
196
|
+
height: 1.25rem;
|
|
197
|
+
display: inline-flex;
|
|
198
|
+
align-items: center;
|
|
199
|
+
align-self: flex-start;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.title {
|
|
203
|
+
color: var(--alert-text-color);
|
|
204
|
+
flex: 1;
|
|
205
|
+
font-size: 0.875rem;
|
|
206
|
+
line-height: 1.25rem;
|
|
207
|
+
margin-bottom: 0.25rem;
|
|
208
|
+
display: block;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.outer-content-wrapper {
|
|
212
|
+
display: flex;
|
|
213
|
+
gap: 0.5rem;
|
|
214
|
+
flex-grow: 1;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.content-wrapper {
|
|
218
|
+
flex-grow: 1;
|
|
219
|
+
padding-left: 0.125rem;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.content {
|
|
223
|
+
color: var(--alert-text-color);
|
|
224
|
+
font-size: 0.875rem;
|
|
225
|
+
line-height: 1.25rem;
|
|
226
|
+
margin-bottom: 0;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.actions {
|
|
230
|
+
text-align: right;
|
|
231
|
+
align-self: center;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.action-button {
|
|
235
|
+
border-width: var(--button-border-width);
|
|
236
|
+
border-style: var(--button-border-style);
|
|
237
|
+
border-radius: var(--button-border-radius);
|
|
238
|
+
white-space: nowrap;
|
|
239
|
+
font-size: 0.875rem;
|
|
240
|
+
line-height: var(--button-font-size);
|
|
241
|
+
font-weight: 400;
|
|
242
|
+
margin: -0.5rem 0;
|
|
243
|
+
padding: 0.625rem 1.25rem;
|
|
244
|
+
cursor: pointer;
|
|
245
|
+
transition:
|
|
246
|
+
color,
|
|
247
|
+
background-color,
|
|
248
|
+
border-color 0.2s ease-in-out;
|
|
249
|
+
font-family: var(--font-family);
|
|
250
|
+
color: var(--alert-text-color);
|
|
251
|
+
background-color: transparent;
|
|
252
|
+
border-color: transparent;
|
|
253
|
+
|
|
254
|
+
&:disabled {
|
|
255
|
+
color: var(--greyed-out);
|
|
256
|
+
cursor: not-allowed;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
@include mixins.focusVisibleOutline();
|
|
260
|
+
|
|
261
|
+
&:not(:disabled):hover,
|
|
262
|
+
&:not(:disabled):focus {
|
|
263
|
+
background-color: var(--color-black10);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
&:not(:disabled):active {
|
|
267
|
+
background-color: var(--color-black20);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
@media only screen and (min-width: 37.5em) {
|
|
273
|
+
.alert {
|
|
274
|
+
width: min-content;
|
|
275
|
+
min-width: 25rem;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 OneWelcome B.V.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import React, { ButtonHTMLAttributes, useContext, useEffect, useRef } from "react";
|
|
18
|
+
import { IconButton } from "../../../Button/IconButton";
|
|
19
|
+
import { Icon, Icons } from "../../../Icon/Icon";
|
|
20
|
+
import classes from "./AlertItem.module.scss";
|
|
21
|
+
import readyclasses from "../../../../readyclasses.module.scss";
|
|
22
|
+
import { useAnimation } from "../../../../hooks/useAnimation";
|
|
23
|
+
import { Typography } from "../../../Typography/Typography";
|
|
24
|
+
import AlertContext from "../AlertProvider/AlertContext";
|
|
25
|
+
|
|
26
|
+
export const EMPHASES = ["low", "medium", "high"] as const;
|
|
27
|
+
export type Emphasis = (typeof EMPHASES)[keyof typeof EMPHASES];
|
|
28
|
+
|
|
29
|
+
export const VARIANTS = ["neutral", "informative", "success", "warning", "error"] as const;
|
|
30
|
+
export type Variant = (typeof VARIANTS)[keyof typeof VARIANTS];
|
|
31
|
+
|
|
32
|
+
export type Actions = (ButtonHTMLAttributes<HTMLButtonElement> & { label: string })[];
|
|
33
|
+
|
|
34
|
+
export interface Props {
|
|
35
|
+
id: string;
|
|
36
|
+
title?: string;
|
|
37
|
+
content?: string;
|
|
38
|
+
duration?: number;
|
|
39
|
+
emphasis?: Emphasis;
|
|
40
|
+
variant?: Variant;
|
|
41
|
+
className?: string;
|
|
42
|
+
onClose?: () => void;
|
|
43
|
+
closeButtonTitle?: string;
|
|
44
|
+
actions?: Actions;
|
|
45
|
+
wasShown?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const useRegisterAlertHeight = (
|
|
49
|
+
singleAlertRef: React.RefObject<HTMLDivElement>,
|
|
50
|
+
alertId: string
|
|
51
|
+
) => {
|
|
52
|
+
const ctx = useContext(AlertContext);
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (singleAlertRef.current) {
|
|
56
|
+
ctx.setAlertHeight(alertId, singleAlertRef.current.getBoundingClientRect().height);
|
|
57
|
+
}
|
|
58
|
+
}, [singleAlertRef.current]);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
let actionButtonKeyCounter = 1;
|
|
62
|
+
export const AlertItem = ({
|
|
63
|
+
id,
|
|
64
|
+
title,
|
|
65
|
+
duration,
|
|
66
|
+
variant = "neutral",
|
|
67
|
+
emphasis = "low",
|
|
68
|
+
content,
|
|
69
|
+
className,
|
|
70
|
+
actions = [],
|
|
71
|
+
onClose,
|
|
72
|
+
closeButtonTitle,
|
|
73
|
+
wasShown
|
|
74
|
+
}: Props) => {
|
|
75
|
+
const timerHandler = useRef<ReturnType<typeof setTimeout>>();
|
|
76
|
+
const onAnimationEnd = () => {
|
|
77
|
+
onClose?.();
|
|
78
|
+
};
|
|
79
|
+
const { ref, animationStarted, startAnimation } = useAnimation<HTMLDivElement>(onAnimationEnd);
|
|
80
|
+
|
|
81
|
+
useRegisterAlertHeight(ref, id);
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (duration && duration > 0) {
|
|
85
|
+
timerHandler.current = setTimeout(() => startAnimation(), duration);
|
|
86
|
+
}
|
|
87
|
+
if (ref) {
|
|
88
|
+
ref.current?.addEventListener("focus", onItemFocus);
|
|
89
|
+
ref.current?.addEventListener("blur", onItemBlur);
|
|
90
|
+
ref.current?.addEventListener("mouseenter", onItemFocus);
|
|
91
|
+
ref.current?.addEventListener("mouseleave", onItemBlur);
|
|
92
|
+
}
|
|
93
|
+
return () => {
|
|
94
|
+
timerHandler.current && clearTimeout(timerHandler.current);
|
|
95
|
+
};
|
|
96
|
+
}, []);
|
|
97
|
+
|
|
98
|
+
const onItemFocus = () => {
|
|
99
|
+
timerHandler.current && clearTimeout(timerHandler.current);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const onItemBlur = () => {
|
|
103
|
+
if (duration && duration > 0) {
|
|
104
|
+
timerHandler.current = setTimeout(() => startAnimation(), duration);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const getVariantIcon = () => {
|
|
109
|
+
if (variant === "error") {
|
|
110
|
+
return Icons.ErrorAlt;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (variant === "warning") {
|
|
114
|
+
return Icons.Warning;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return variant === "success" ? Icons.CheckmarkCircleAlt : Icons.InfoCircle;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const actionButtons = actions.map(actionProp => (
|
|
121
|
+
<button
|
|
122
|
+
key={`alert-action-button-${(actionButtonKeyCounter++).toString()}`}
|
|
123
|
+
{...actionProp}
|
|
124
|
+
onClick={e => {
|
|
125
|
+
onClose?.();
|
|
126
|
+
actionProp.onClick?.(e);
|
|
127
|
+
}}
|
|
128
|
+
className={classes["action-button"]}
|
|
129
|
+
>
|
|
130
|
+
{actionProp.label}
|
|
131
|
+
</button>
|
|
132
|
+
));
|
|
133
|
+
|
|
134
|
+
const getAlertClasses = (): string => {
|
|
135
|
+
const alertClasses = [classes["alert"], classes[`${variant}`], classes[`emph-${emphasis}`]];
|
|
136
|
+
if (animationStarted) {
|
|
137
|
+
alertClasses.push(readyclasses["slide-out"]);
|
|
138
|
+
}
|
|
139
|
+
if (!animationStarted && !wasShown) {
|
|
140
|
+
alertClasses.push(readyclasses["slide-in"]);
|
|
141
|
+
}
|
|
142
|
+
if (className) {
|
|
143
|
+
alertClasses.push(className);
|
|
144
|
+
}
|
|
145
|
+
return alertClasses.join(" ");
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const getAria = () => {
|
|
149
|
+
if (variant === "error" && (emphasis === "medium" || emphasis === "high")) {
|
|
150
|
+
return "assertive";
|
|
151
|
+
}
|
|
152
|
+
return "polite";
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const getContentOrTitle = () => {
|
|
156
|
+
if (content) {
|
|
157
|
+
return content;
|
|
158
|
+
}
|
|
159
|
+
return title;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<div
|
|
164
|
+
{...{ ["data-testid"]: "alert-container" }}
|
|
165
|
+
ref={ref}
|
|
166
|
+
aria-live={getAria()}
|
|
167
|
+
className={getAlertClasses()}
|
|
168
|
+
role="alert"
|
|
169
|
+
>
|
|
170
|
+
<div className={classes["outer-content-wrapper"]}>
|
|
171
|
+
<Icon icon={getVariantIcon()} className={classes["icon"]} />
|
|
172
|
+
<div className={classes["content-wrapper"]} role="log">
|
|
173
|
+
{!!title && !!content && (
|
|
174
|
+
<Typography
|
|
175
|
+
{...{ ["data-testid"]: "alert-title" }}
|
|
176
|
+
className={classes["title"]}
|
|
177
|
+
variant="body-bold"
|
|
178
|
+
tag="span"
|
|
179
|
+
>
|
|
180
|
+
{title}
|
|
181
|
+
</Typography>
|
|
182
|
+
)}
|
|
183
|
+
{(!!content || !!title) && (
|
|
184
|
+
<Typography
|
|
185
|
+
{...{ ["data-testid"]: "alert-content" }}
|
|
186
|
+
className={classes["content"]}
|
|
187
|
+
variant="body"
|
|
188
|
+
>
|
|
189
|
+
{getContentOrTitle()}
|
|
190
|
+
</Typography>
|
|
191
|
+
)}
|
|
192
|
+
</div>
|
|
193
|
+
</div>
|
|
194
|
+
{actionButtons.length > 0 && (
|
|
195
|
+
<div {...{ ["data-testid"]: "alert-actions" }} className={classes["actions"]}>
|
|
196
|
+
{actionButtons}
|
|
197
|
+
</div>
|
|
198
|
+
)}
|
|
199
|
+
{onClose && (
|
|
200
|
+
<IconButton
|
|
201
|
+
className={classes["close-btn"]}
|
|
202
|
+
onClick={e => {
|
|
203
|
+
e.stopPropagation();
|
|
204
|
+
startAnimation();
|
|
205
|
+
}}
|
|
206
|
+
title={closeButtonTitle}
|
|
207
|
+
{...{ ["data-testid"]: "alert-close" }}
|
|
208
|
+
>
|
|
209
|
+
<Icon icon={Icons.Times} />
|
|
210
|
+
</IconButton>
|
|
211
|
+
)}
|
|
212
|
+
</div>
|
|
213
|
+
);
|
|
214
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 OneWelcome B.V.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { AlertEntry } from "./AlertProvider";
|
|
18
|
+
import { createContext } from "react";
|
|
19
|
+
|
|
20
|
+
export type AlertQueue = Omit<AlertEntry, "id">;
|
|
21
|
+
|
|
22
|
+
export interface AlertContextValue {
|
|
23
|
+
enqueueAlert: (entry: AlertQueue) => void;
|
|
24
|
+
enqueueInfoAlert: (entry: AlertQueue) => void;
|
|
25
|
+
enqueueSuccessAlert: (entry: AlertQueue) => void;
|
|
26
|
+
enqueueWarningAlert: (entry: AlertQueue) => void;
|
|
27
|
+
enqueueErrorAlert: (entry: AlertQueue) => void;
|
|
28
|
+
setAlertHeight: (id: string, height: number) => void;
|
|
29
|
+
alerts: AlertEntry[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const AlertContext = createContext<AlertContextValue>({
|
|
33
|
+
enqueueAlert: entry => null,
|
|
34
|
+
enqueueInfoAlert: entry => null,
|
|
35
|
+
enqueueSuccessAlert: entry => null,
|
|
36
|
+
enqueueErrorAlert: entry => null,
|
|
37
|
+
enqueueWarningAlert: entry => null,
|
|
38
|
+
setAlertHeight: (id, height) => null,
|
|
39
|
+
alerts: []
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export default AlertContext;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 OneWelcome B.V.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import React, { ReactNode, useRef, useState, useMemo } from "react";
|
|
18
|
+
import { createPortal } from "react-dom";
|
|
19
|
+
import { Placement, AlertContainer } from "../AlertContainer/AlertContainer";
|
|
20
|
+
import { generateID } from "../../../../util/helper";
|
|
21
|
+
import { AlertItem, Props as AlertComponentProps, Variant } from "../AlertItem/AlertItem";
|
|
22
|
+
import { useGetDomRoot } from "../../../../hooks/useGetDomRoot";
|
|
23
|
+
import AlertContext, { AlertContextValue } from "./AlertContext";
|
|
24
|
+
|
|
25
|
+
/** Short msg is when only title is provided. Long one when content or/and actions are provided (or type is error). */
|
|
26
|
+
interface Duration {
|
|
27
|
+
long: number;
|
|
28
|
+
short: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface Props {
|
|
32
|
+
closeButtonTitle: string;
|
|
33
|
+
children?: ReactNode;
|
|
34
|
+
placement?: Placement;
|
|
35
|
+
stackSize?: number;
|
|
36
|
+
domRoot?: HTMLElement;
|
|
37
|
+
autoHideDuration?: Duration;
|
|
38
|
+
className?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type AlertEntry = AlertComponentProps & { height?: number };
|
|
42
|
+
|
|
43
|
+
export const AlertProvider = ({
|
|
44
|
+
closeButtonTitle,
|
|
45
|
+
placement = { vertical: "bottom", horizontal: "center" },
|
|
46
|
+
autoHideDuration = { long: 8000, short: 4000 },
|
|
47
|
+
stackSize = 3,
|
|
48
|
+
domRoot,
|
|
49
|
+
children,
|
|
50
|
+
className
|
|
51
|
+
}: Props) => {
|
|
52
|
+
const [alertEntries, setAlertEntries] = useState<AlertEntry[]>([]);
|
|
53
|
+
const wrappingDivRef = useRef(null);
|
|
54
|
+
const { root } = useGetDomRoot(domRoot, wrappingDivRef);
|
|
55
|
+
|
|
56
|
+
const getDuration = (entry: Omit<AlertEntry, "id">) => {
|
|
57
|
+
if (entry.variant === "error") {
|
|
58
|
+
return autoHideDuration.long;
|
|
59
|
+
}
|
|
60
|
+
if (entry.actions?.length) {
|
|
61
|
+
return autoHideDuration.long;
|
|
62
|
+
}
|
|
63
|
+
return autoHideDuration.short;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const buildEntryWithVariant = (arg: Omit<AlertEntry, "id">, variant?: Variant): AlertEntry => {
|
|
67
|
+
let closeTitle = closeButtonTitle;
|
|
68
|
+
if (arg.closeButtonTitle) {
|
|
69
|
+
closeTitle = arg.closeButtonTitle;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
...arg,
|
|
73
|
+
variant: variant ?? arg.variant,
|
|
74
|
+
id: generateID(15, arg.content ?? arg.title),
|
|
75
|
+
duration: arg.duration ?? getDuration(arg),
|
|
76
|
+
closeButtonTitle: closeTitle
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const enqueueAlert = (arg: Omit<AlertEntry, "id">) => {
|
|
81
|
+
const newEntry = buildEntryWithVariant(arg);
|
|
82
|
+
setAlertEntries(entries => [...entries, newEntry]);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const enqueueInfoAlert: AlertContextValue["enqueueInfoAlert"] = arg => {
|
|
86
|
+
const newEntry: AlertEntry = buildEntryWithVariant(arg, "informative");
|
|
87
|
+
setAlertEntries(entries => [...entries, newEntry]);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const enqueueSuccessAlert: AlertContextValue["enqueueSuccessAlert"] = arg => {
|
|
91
|
+
const newEntry: AlertEntry = buildEntryWithVariant(arg, "success");
|
|
92
|
+
setAlertEntries(entries => [...entries, newEntry]);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const enqueueWarningAlert: AlertContextValue["enqueueWarningAlert"] = arg => {
|
|
96
|
+
const newEntry: AlertEntry = buildEntryWithVariant(arg, "warning");
|
|
97
|
+
setAlertEntries(entries => [...entries, newEntry]);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const enqueueErrorAlert: AlertContextValue["enqueueErrorAlert"] = arg => {
|
|
101
|
+
const newEntry: AlertEntry = buildEntryWithVariant(arg, "error");
|
|
102
|
+
setAlertEntries(entries => [...entries, newEntry]);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const setAlertHeight = (id: string, height: number) => {
|
|
106
|
+
const newAlertsState = alertEntries.map(alertEntry => {
|
|
107
|
+
if (alertEntry.id !== id) {
|
|
108
|
+
return alertEntry;
|
|
109
|
+
}
|
|
110
|
+
return { ...alertEntry, height };
|
|
111
|
+
});
|
|
112
|
+
setAlertEntries(newAlertsState);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const removeEntry = (entryId: string) => {
|
|
116
|
+
setAlertEntries(entries => {
|
|
117
|
+
return entries.filter((entry, idx) => {
|
|
118
|
+
if (idx < stackSize) {
|
|
119
|
+
entries[idx] = { ...entries[idx], wasShown: true };
|
|
120
|
+
}
|
|
121
|
+
return entry.id !== entryId;
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const renderAlertList = (): ReactNode => {
|
|
127
|
+
return alertEntries.slice(0, stackSize).map(entry => (
|
|
128
|
+
<AlertItem
|
|
129
|
+
{...entry}
|
|
130
|
+
key={`${entry.id}`}
|
|
131
|
+
onClose={() => {
|
|
132
|
+
removeEntry(entry.id);
|
|
133
|
+
entry.onClose?.();
|
|
134
|
+
}}
|
|
135
|
+
/>
|
|
136
|
+
));
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const contextValue = useMemo(
|
|
140
|
+
() => ({
|
|
141
|
+
enqueueAlert,
|
|
142
|
+
enqueueInfoAlert,
|
|
143
|
+
enqueueSuccessAlert,
|
|
144
|
+
enqueueErrorAlert,
|
|
145
|
+
enqueueWarningAlert,
|
|
146
|
+
setAlertHeight,
|
|
147
|
+
alerts: alertEntries
|
|
148
|
+
}),
|
|
149
|
+
[
|
|
150
|
+
enqueueAlert,
|
|
151
|
+
enqueueInfoAlert,
|
|
152
|
+
enqueueSuccessAlert,
|
|
153
|
+
enqueueErrorAlert,
|
|
154
|
+
enqueueWarningAlert,
|
|
155
|
+
setAlertHeight,
|
|
156
|
+
alertEntries
|
|
157
|
+
]
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<AlertContext.Provider value={contextValue}>
|
|
162
|
+
{children}
|
|
163
|
+
<div ref={wrappingDivRef}>
|
|
164
|
+
{createPortal(
|
|
165
|
+
<AlertContainer placement={placement} className={className}>
|
|
166
|
+
{renderAlertList()}
|
|
167
|
+
</AlertContainer>,
|
|
168
|
+
root
|
|
169
|
+
)}
|
|
170
|
+
</div>
|
|
171
|
+
</AlertContext.Provider>
|
|
172
|
+
);
|
|
173
|
+
};
|