@councilbox/councilbox-ui 2.0.54 → 2.0.56
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/Accordion.js +3 -0
- package/Alert.js +3 -0
- package/Avatar.js +3 -0
- package/AvatarGroup.js +3 -0
- package/Block.js +3 -0
- package/Button.js +3 -0
- package/ButtonBasic.js +3 -0
- package/Checkbox.js +3 -0
- package/DatePicker.js +3 -0
- package/DateRangePicker.js +3 -0
- package/DateTimePicker.js +3 -0
- package/DragDrop.js +3 -0
- package/DrawerPanel.js +3 -0
- package/DropDown.js +3 -0
- package/EnhancedTable.js +3 -0
- package/FabButton.js +3 -0
- package/Grid.js +3 -0
- package/Header.js +3 -0
- package/IconButton.js +3 -0
- package/IconButtonSquare.js +3 -0
- package/IconFont.js +3 -0
- package/InputAutocomplete.js +3 -0
- package/InputPassword.js +3 -0
- package/InputText.js +3 -0
- package/InputTextArea.js +3 -0
- package/LoadingSection.js +3 -0
- package/MenuItem.js +3 -0
- package/MenuLateralLeft.js +3 -0
- package/MenuLateralRight.js +3 -0
- package/Modal.js +3 -0
- package/Radio.js +3 -0
- package/RichTextInput.js +3 -0
- package/Scrollbar.js +3 -0
- package/ScrollbarOld.js +3 -0
- package/SelectInput.js +3 -0
- package/Slider.js +3 -0
- package/Spacing.js +3 -0
- package/Stars.js +3 -0
- package/Stepper.js +3 -0
- package/Table.js +3 -0
- package/TableBody.js +3 -0
- package/TableCell.js +3 -0
- package/TableContainer.js +3 -0
- package/TableHead.js +3 -0
- package/TableRow.js +3 -0
- package/TableSortLabel.js +3 -0
- package/Tabs.js +3 -0
- package/Tag.js +3 -0
- package/TextInput.js +3 -0
- package/ThemeProvider.js +3 -0
- package/TimePicker.js +3 -0
- package/Timeline.js +3 -0
- package/ToastProvider.js +3 -0
- package/Toggle.js +3 -0
- package/Tooltip.js +3 -0
- package/Typography.js +3 -0
- package/dist/HOCs/useDynamicStyles.js +25 -24
- package/dist/HOCs/usePopoverPosition.js +2 -0
- package/dist/build-index.js +70 -0
- package/dist/components/1.Introduction.stories.mdx +4 -1
- package/dist/components/2.Changelog.stories.mdx +25 -2
- package/dist/components/Button/Button.js +15 -0
- package/dist/components/ButtonBasic/ButtonBasic.js +15 -0
- package/dist/components/Checkbox/Checkbox.js +2 -2
- package/dist/components/DatePicker/Calendar.js +243 -0
- package/dist/components/DatePicker/DatePicker.css +197 -0
- package/dist/components/DatePicker/DatePicker.js +465 -0
- package/dist/components/DatePicker/DatePicker.stories.js +180 -0
- package/dist/components/DatePicker/dateUtils.js +525 -0
- package/dist/components/DateRangePicker/DateRangePicker.css +41 -0
- package/dist/components/DateRangePicker/DateRangePicker.js +530 -0
- package/dist/components/DateRangePicker/DateRangePicker.stories.js +147 -0
- package/dist/components/DateRangePicker/RangeCalendar.js +188 -0
- package/dist/components/DateTimePicker/DateTimePicker.css +4 -0
- package/dist/components/DateTimePicker/DateTimePicker.js +541 -0
- package/dist/components/DateTimePicker/DateTimePicker.stories.js +144 -0
- package/dist/components/DateTimePicker/TimeColumns.css +46 -0
- package/dist/components/DateTimePicker/TimeColumns.js +175 -0
- package/dist/components/DragDrop/DragDrop.js +21 -5
- package/dist/components/DropDown/DesignDropDown.stories.js +8 -0
- package/dist/components/DropDown/DropDown.js +14 -4
- package/dist/components/Header/Header.js +134 -25
- package/dist/components/IconButton/IconButton.js +3 -2
- package/dist/components/IconButtonSquare/IconButtonSquare.js +3 -3
- package/dist/components/InputAutocomplete/InputAutocomplete.js +17 -2
- package/dist/components/InputPassword/InputPassword.js +14 -1
- package/dist/components/InputText/InputText.css +10 -5
- package/dist/components/InputText/InputText.js +4 -4
- package/dist/components/InputTextArea/InputTextArea.js +14 -0
- package/dist/components/LoadingSection/LoadingSection.js +16 -4
- package/dist/components/MenuItem/MenuItem.js +78 -61
- package/dist/components/MenuLateralLeft/MenuLateralLeft.js +16 -2
- package/dist/components/MenuLateralRight/MenuLateralRight.js +34 -4
- package/dist/components/Modal/Modal.js +16 -1
- package/dist/components/RadioButton/Radio.js +15 -0
- package/dist/components/RichTextInput/DesignRichTextInput.stories.js +119 -0
- package/dist/components/RichTextInput/RichTextInput.css +352 -0
- package/dist/components/RichTextInput/RichTextInput.js +1057 -0
- package/dist/components/RichTextInput/RichTextInput.stories.js +33 -0
- package/dist/components/Ripple/DesignRipple.js +17 -0
- package/dist/components/Scrollbar/Scrollbar.css +60 -19
- package/dist/components/Scrollbar/Scrollbar.js +384 -62
- package/dist/components/ScrollbarOld/DesignScrollbarOld.js +24 -0
- package/dist/components/ScrollbarOld/ScrollbarOld.css +38 -0
- package/dist/components/ScrollbarOld/ScrollbarOld.js +104 -0
- package/dist/components/ScrollbarOld/ScrollbarOld.stories.js +37 -0
- package/dist/components/SelectInput/SelectInput.js +112 -86
- package/dist/components/Slider/Slider.js +15 -0
- package/dist/components/Stars/Stars.js +13 -0
- package/dist/components/Stepper/Stepper.js +15 -2
- package/dist/components/Table/TableSortLabel.js +11 -0
- package/dist/components/Tabs/DesignTabs.js +1 -1
- package/dist/components/Tabs/Tabs.js +13 -2
- package/dist/components/Tag/Tag.js +16 -0
- package/dist/components/TextInput/TextInput.js +13 -0
- package/dist/components/TimePicker/TimePicker.css +3 -0
- package/dist/components/TimePicker/TimePicker.js +441 -0
- package/dist/components/TimePicker/TimePicker.stories.js +132 -0
- package/dist/components/Toast/DesignToast.stories.js +174 -0
- package/dist/components/Toast/Toast.css +154 -0
- package/dist/components/Toast/Toast.js +178 -0
- package/dist/components/Toast/Toast.stories.js +33 -0
- package/dist/components/Toast/ToastProvider.js +33 -0
- package/dist/components/Toast/ToastRoot.js +89 -0
- package/dist/components/Toast/toastStore.js +138 -0
- package/dist/components/Toast/useToast.js +42 -0
- package/dist/components/Toggle/Toggle.js +20 -14
- package/dist/components/Tooltip/Tooltip.js +24 -2
- package/dist/styles/styleFont.css +1 -1
- package/dist/styles/zIndexConsts.css +2 -0
- package/package.json +63 -3
- package/toast.js +7 -0
- package/useCouncilboxTheme.js +7 -0
- package/useToast.js +7 -0
- package/dist/components/Accordion/AccordionOld.css +0 -16
- package/dist/components/Accordion/AccordionOld.js +0 -91
- package/dist/components/Avatar/AvatarOld.js +0 -124
- package/dist/components/ButtonBasic/ButtonBasicOld.css +0 -41
- package/dist/components/ButtonBasic/ButtonBasicOld.js +0 -211
- package/dist/components/Checkbox/CheckboxOld.css +0 -31
- package/dist/components/Checkbox/CheckboxOld.js +0 -96
- package/dist/components/DrawerPanel/DrawerPanelOld.css +0 -56
- package/dist/components/DrawerPanel/DrawerPanelOld.js +0 -211
- package/dist/components/DropDown/DropDownOld.css +0 -3
- package/dist/components/DropDown/DropDownOld.js +0 -154
- package/dist/components/Grid/GridItemOld.js +0 -38
- package/dist/components/Grid/GridOld.css +0 -0
- package/dist/components/Grid/GridOld.js +0 -46
- package/dist/components/IconButton/IconButtonOld.css +0 -0
- package/dist/components/IconButton/IconButtonOld.js +0 -122
- package/dist/components/IconButtonSquare/IconButtonSquareOld.css +0 -43
- package/dist/components/IconButtonSquare/IconButtonSquareOld.js +0 -115
- package/dist/components/InputAutocomplete/InputAutocompleteOld.css +0 -5
- package/dist/components/InputAutocomplete/InputAutocompleteOld.js +0 -159
- package/dist/components/InputText/InputTextOld.css +0 -10
- package/dist/components/InputText/InputTextOld.js +0 -314
- package/dist/components/MenuItem/MenuItemOld.js +0 -123
- package/dist/components/Modal/ModalOld.css +0 -3
- package/dist/components/Modal/ModalOld.js +0 -213
- package/dist/components/RadioButton/RadioOld.css +0 -31
- package/dist/components/RadioButton/RadioOld.js +0 -126
- package/dist/components/SelectInput/SelectInputOld.css +0 -17
- package/dist/components/SelectInput/SelectInputOld.js +0 -296
- package/dist/components/Table/TableOld.css +0 -79
- package/dist/components/Table/TableOld.js +0 -133
- package/dist/components/Tabs/TabsOld.js +0 -78
- package/dist/components/Typography/TypographyOld.js +0 -119
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
require("../../styles/main.css");
|
|
9
|
+
var _useToast3 = require("./useToast");
|
|
10
|
+
var _ButtonBasic = _interopRequireDefault(require("../ButtonBasic/ButtonBasic"));
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
13
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
15
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) { n[e] = r[e]; } return n; }
|
|
16
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) { ; } } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
17
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
18
|
+
// No <ToastProvider> anywhere in this story on purpose - it demonstrates that
|
|
19
|
+
// useToast()/toast() work with zero setup.
|
|
20
|
+
|
|
21
|
+
// Mounts and fires a toast in the same tick, then shows the hook's own reactive `toasts.length`
|
|
22
|
+
// - exercises the exact race window between useToast()'s initial snapshot and its subscription.
|
|
23
|
+
var MountAndFireImmediately = function MountAndFireImmediately() {
|
|
24
|
+
var _useToast = (0, _useToast3.useToast)(),
|
|
25
|
+
toast = _useToast.toast,
|
|
26
|
+
toasts = _useToast.toasts;
|
|
27
|
+
var fired = _react["default"].useRef(false);
|
|
28
|
+
_react["default"].useEffect(function () {
|
|
29
|
+
if (!fired.current) {
|
|
30
|
+
fired.current = true;
|
|
31
|
+
toast({
|
|
32
|
+
message: 'Disparado en el mismo mount.',
|
|
33
|
+
severity: 'info',
|
|
34
|
+
vertical: 'bottom',
|
|
35
|
+
horizontal: 'center'
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}, [toast]);
|
|
39
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
40
|
+
id: "mount-fire-toasts-length"
|
|
41
|
+
}, "toasts.length (hook): ", toasts.length);
|
|
42
|
+
};
|
|
43
|
+
MountAndFireImmediately.displayName = "MountAndFireImmediately";
|
|
44
|
+
var DesignToastButtons = function DesignToastButtons() {
|
|
45
|
+
var _useToast2 = (0, _useToast3.useToast)(),
|
|
46
|
+
toast = _useToast2.toast,
|
|
47
|
+
closeAll = _useToast2.closeAll;
|
|
48
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
49
|
+
style: {
|
|
50
|
+
display: 'flex',
|
|
51
|
+
flexWrap: 'wrap',
|
|
52
|
+
gap: '1rem',
|
|
53
|
+
padding: '2rem',
|
|
54
|
+
maxWidth: '55%'
|
|
55
|
+
}
|
|
56
|
+
}, /*#__PURE__*/_react["default"].createElement(_ButtonBasic["default"], {
|
|
57
|
+
text: "Success",
|
|
58
|
+
onClick: function onClick() {
|
|
59
|
+
return toast({
|
|
60
|
+
message: 'Guardado correctamente.',
|
|
61
|
+
severity: 'success'
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}), /*#__PURE__*/_react["default"].createElement(_ButtonBasic["default"], {
|
|
65
|
+
text: "Error",
|
|
66
|
+
onClick: function onClick() {
|
|
67
|
+
return toast({
|
|
68
|
+
message: 'No se pudo subir el archivo.',
|
|
69
|
+
severity: 'error'
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}), /*#__PURE__*/_react["default"].createElement(_ButtonBasic["default"], {
|
|
73
|
+
text: "Warning",
|
|
74
|
+
onClick: function onClick() {
|
|
75
|
+
return toast({
|
|
76
|
+
message: 'Revisa los datos antes de continuar.',
|
|
77
|
+
severity: 'warning'
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}), /*#__PURE__*/_react["default"].createElement(_ButtonBasic["default"], {
|
|
81
|
+
text: "Info",
|
|
82
|
+
onClick: function onClick() {
|
|
83
|
+
return toast({
|
|
84
|
+
message: 'La sesión caduca en 5 minutos.',
|
|
85
|
+
severity: 'info'
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}), /*#__PURE__*/_react["default"].createElement(_ButtonBasic["default"], {
|
|
89
|
+
text: "Con t\xEDtulo",
|
|
90
|
+
onClick: function onClick() {
|
|
91
|
+
return toast({
|
|
92
|
+
title: 'Error al subir',
|
|
93
|
+
message: 'archivo.pdf supera el tamaño máximo.',
|
|
94
|
+
severity: 'error'
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}), /*#__PURE__*/_react["default"].createElement(_ButtonBasic["default"], {
|
|
98
|
+
text: "Persistente (sin autoClose)",
|
|
99
|
+
onClick: function onClick() {
|
|
100
|
+
return toast({
|
|
101
|
+
message: 'Esto no se cierra solo.',
|
|
102
|
+
severity: 'info',
|
|
103
|
+
autoClose: false
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}), /*#__PURE__*/_react["default"].createElement(_ButtonBasic["default"], {
|
|
107
|
+
id: "btn-short",
|
|
108
|
+
text: "Corto (1.5s)",
|
|
109
|
+
onClick: function onClick() {
|
|
110
|
+
return toast({
|
|
111
|
+
message: 'Se cierra en 1.5s',
|
|
112
|
+
severity: 'info',
|
|
113
|
+
autoClose: 1500
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}), /*#__PURE__*/_react["default"].createElement(_ButtonBasic["default"], {
|
|
117
|
+
id: "btn-long",
|
|
118
|
+
text: "Largo (6s)",
|
|
119
|
+
onClick: function onClick() {
|
|
120
|
+
return toast({
|
|
121
|
+
message: 'Se cierra en 6s',
|
|
122
|
+
severity: 'warning',
|
|
123
|
+
autoClose: 6000
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}), /*#__PURE__*/_react["default"].createElement(_ButtonBasic["default"], {
|
|
127
|
+
text: "Bottom-left",
|
|
128
|
+
onClick: function onClick() {
|
|
129
|
+
return toast({
|
|
130
|
+
message: 'Anclado abajo a la izquierda.',
|
|
131
|
+
severity: 'success',
|
|
132
|
+
vertical: 'bottom',
|
|
133
|
+
horizontal: 'left'
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}), /*#__PURE__*/_react["default"].createElement(_ButtonBasic["default"], {
|
|
137
|
+
text: "Disparar 8 seguidos",
|
|
138
|
+
onClick: function onClick() {
|
|
139
|
+
var severities = ['success', 'error', 'warning', 'info'];
|
|
140
|
+
for (var i = 0; i < 8; i += 1) {
|
|
141
|
+
toast({
|
|
142
|
+
message: "Notificaci\xF3n n\xFAmero ".concat(i + 1),
|
|
143
|
+
severity: severities[i % severities.length]
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}), /*#__PURE__*/_react["default"].createElement(_ButtonBasic["default"], {
|
|
148
|
+
text: "Cerrar todos",
|
|
149
|
+
variant: "secondary",
|
|
150
|
+
onClick: closeAll
|
|
151
|
+
}));
|
|
152
|
+
};
|
|
153
|
+
DesignToastButtons.displayName = "DesignToastButtons";
|
|
154
|
+
var DesignToast = function DesignToast() {
|
|
155
|
+
var _React$useState = _react["default"].useState(false),
|
|
156
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
157
|
+
showMountFire = _React$useState2[0],
|
|
158
|
+
setShowMountFire = _React$useState2[1];
|
|
159
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(DesignToastButtons, null), /*#__PURE__*/_react["default"].createElement("div", {
|
|
160
|
+
style: {
|
|
161
|
+
padding: '0 2rem'
|
|
162
|
+
}
|
|
163
|
+
}, /*#__PURE__*/_react["default"].createElement(_ButtonBasic["default"], {
|
|
164
|
+
id: "btn-mount-fire",
|
|
165
|
+
text: "Montar componente que dispara al instante",
|
|
166
|
+
onClick: function onClick() {
|
|
167
|
+
return setShowMountFire(function (v) {
|
|
168
|
+
return !v;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}), showMountFire && /*#__PURE__*/_react["default"].createElement(MountAndFireImmediately, null)));
|
|
172
|
+
};
|
|
173
|
+
var _default = DesignToast;
|
|
174
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
.cbx-toast-stack {
|
|
2
|
+
position: fixed;
|
|
3
|
+
z-index: var(--zIdxToast);
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
gap: var(--spacing8);
|
|
7
|
+
padding: var(--spacing16);
|
|
8
|
+
max-width: calc(100vw - 2 * var(--spacing16));
|
|
9
|
+
pointer-events: none;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.cbx-toast-stack-top {
|
|
13
|
+
top: 0;
|
|
14
|
+
flex-direction: column-reverse;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.cbx-toast-stack-bottom {
|
|
18
|
+
bottom: 0;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.cbx-toast-stack-right {
|
|
23
|
+
right: 0;
|
|
24
|
+
align-items: flex-end;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.cbx-toast-stack-left {
|
|
28
|
+
left: 0;
|
|
29
|
+
align-items: flex-start;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.cbx-toast-stack-center {
|
|
33
|
+
left: 50%;
|
|
34
|
+
transform: translateX(-50%);
|
|
35
|
+
align-items: center;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.cbx-toast {
|
|
39
|
+
pointer-events: auto;
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: flex-start;
|
|
42
|
+
gap: var(--spacing12);
|
|
43
|
+
min-width: 18rem;
|
|
44
|
+
max-width: 26rem;
|
|
45
|
+
padding: var(--spacing12) var(--spacing12) var(--spacing12) var(--spacing16);
|
|
46
|
+
border-radius: 0.75rem;
|
|
47
|
+
box-shadow: 0 0.375rem 1.5rem rgba(0, 0, 0, 0.18);
|
|
48
|
+
color: var(--white);
|
|
49
|
+
font-family: var(--font-primary);
|
|
50
|
+
opacity: 0;
|
|
51
|
+
transition: opacity 200ms ease, transform 200ms ease;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.cbx-toast-success {
|
|
55
|
+
background: var(--success);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.cbx-toast-error {
|
|
59
|
+
background: var(--error);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.cbx-toast-warning {
|
|
63
|
+
background: var(--warning);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.cbx-toast-info {
|
|
67
|
+
background: var(--info);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.cbx-toast-right {
|
|
71
|
+
transform: translateX(2rem);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.cbx-toast-left {
|
|
75
|
+
transform: translateX(-2rem);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.cbx-toast-center {
|
|
79
|
+
transform: translateY(-0.75rem);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.cbx-toast-visible {
|
|
83
|
+
opacity: 1;
|
|
84
|
+
transform: translate(0, 0);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.cbx-toast-leaving.cbx-toast-right {
|
|
88
|
+
opacity: 0;
|
|
89
|
+
transform: translateX(2rem);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.cbx-toast-leaving.cbx-toast-left {
|
|
93
|
+
opacity: 0;
|
|
94
|
+
transform: translateX(-2rem);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.cbx-toast-leaving.cbx-toast-center {
|
|
98
|
+
opacity: 0;
|
|
99
|
+
transform: translateY(-0.75rem);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.cbx-toast-icon {
|
|
103
|
+
display: flex;
|
|
104
|
+
align-items: center;
|
|
105
|
+
font-size: 1.375rem;
|
|
106
|
+
line-height: 1;
|
|
107
|
+
flex-shrink: 0;
|
|
108
|
+
margin-top: 0.125rem;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.cbx-toast-content {
|
|
112
|
+
flex: 1;
|
|
113
|
+
min-width: 0;
|
|
114
|
+
word-break: break-word;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.cbx-toast-title {
|
|
118
|
+
margin-bottom: var(--spacing4);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.cbx-toast-message {
|
|
122
|
+
font-size: 0.875rem;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.cbx-toast-close.cbx-IconButton {
|
|
126
|
+
flex-shrink: 0;
|
|
127
|
+
width: 1.75rem;
|
|
128
|
+
min-width: 1.75rem;
|
|
129
|
+
height: 1.75rem;
|
|
130
|
+
padding: 0.25rem;
|
|
131
|
+
font-size: 1rem;
|
|
132
|
+
color: var(--white);
|
|
133
|
+
margin: -0.25rem -0.25rem 0 0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.cbx-toast-close.cbx-IconButton:hover {
|
|
137
|
+
background-color: rgba(255, 255, 255, 0.16) !important;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@media (max-width: 480px) {
|
|
141
|
+
.cbx-toast-stack {
|
|
142
|
+
left: 0;
|
|
143
|
+
right: 0;
|
|
144
|
+
transform: none;
|
|
145
|
+
align-items: stretch;
|
|
146
|
+
padding: var(--spacing8);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.cbx-toast {
|
|
150
|
+
min-width: 0;
|
|
151
|
+
max-width: none;
|
|
152
|
+
width: 100%;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
|
+
var _IconButton = _interopRequireDefault(require("../IconButton/IconButton"));
|
|
11
|
+
var _Typography = _interopRequireDefault(require("../Typography/Typography"));
|
|
12
|
+
var _useA11yGuard2 = require("../../HOCs/useA11yGuard");
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
14
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
17
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
18
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
20
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
21
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
22
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) { n[e] = r[e]; } return n; }
|
|
23
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) { ; } } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
24
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
25
|
+
var ENTER_DELAY_MS = 10;
|
|
26
|
+
var EXIT_DURATION_MS = 200;
|
|
27
|
+
var SEVERITY_CONFIG = {
|
|
28
|
+
success: {
|
|
29
|
+
icon: 'ri-checkbox-circle-fill',
|
|
30
|
+
label: 'Éxito'
|
|
31
|
+
},
|
|
32
|
+
error: {
|
|
33
|
+
icon: 'ri-close-circle-fill',
|
|
34
|
+
label: 'Error'
|
|
35
|
+
},
|
|
36
|
+
warning: {
|
|
37
|
+
icon: 'ri-alert-fill',
|
|
38
|
+
label: 'Aviso'
|
|
39
|
+
},
|
|
40
|
+
info: {
|
|
41
|
+
icon: 'ri-information-fill',
|
|
42
|
+
label: 'Información'
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var Toast = function Toast(_ref) {
|
|
46
|
+
var id = _ref.id,
|
|
47
|
+
message = _ref.message,
|
|
48
|
+
title = _ref.title,
|
|
49
|
+
severity = _ref.severity,
|
|
50
|
+
icon = _ref.icon,
|
|
51
|
+
color = _ref.color,
|
|
52
|
+
autoClose = _ref.autoClose,
|
|
53
|
+
horizontal = _ref.horizontal,
|
|
54
|
+
offset = _ref.offset,
|
|
55
|
+
onClose = _ref.onClose,
|
|
56
|
+
closeAriaLabel = _ref.closeAriaLabel;
|
|
57
|
+
var _React$useState = _react["default"].useState(false),
|
|
58
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
59
|
+
visible = _React$useState2[0],
|
|
60
|
+
setVisible = _React$useState2[1];
|
|
61
|
+
var _React$useState3 = _react["default"].useState(false),
|
|
62
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
63
|
+
leaving = _React$useState4[0],
|
|
64
|
+
setLeaving = _React$useState4[1];
|
|
65
|
+
var autoCloseTimeoutRef = _react["default"].useRef(null);
|
|
66
|
+
var exitTimeoutRef = _react["default"].useRef(null);
|
|
67
|
+
var _useA11yGuard = (0, _useA11yGuard2.useA11yGuard)(),
|
|
68
|
+
requireAccessibleText = _useA11yGuard.requireAccessibleText;
|
|
69
|
+
requireAccessibleText(closeAriaLabel, {
|
|
70
|
+
component: 'Toast',
|
|
71
|
+
prop: '"closeAriaLabel"',
|
|
72
|
+
hint: 'El botón de cerrar la notificación (solo icono) necesita un "closeAriaLabel" para ser identificado por los lectores de pantalla.',
|
|
73
|
+
receivedProps: {
|
|
74
|
+
severity: severity,
|
|
75
|
+
id: id
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
var resolvedCloseAriaLabel = closeAriaLabel || 'Close notification';
|
|
79
|
+
var config = SEVERITY_CONFIG[severity] || SEVERITY_CONFIG.success;
|
|
80
|
+
var requestClose = _react["default"].useCallback(function () {
|
|
81
|
+
setLeaving(true);
|
|
82
|
+
if (exitTimeoutRef.current) clearTimeout(exitTimeoutRef.current);
|
|
83
|
+
exitTimeoutRef.current = setTimeout(function () {
|
|
84
|
+
onClose === null || onClose === void 0 ? void 0 : onClose(id);
|
|
85
|
+
}, EXIT_DURATION_MS);
|
|
86
|
+
}, [onClose, id]);
|
|
87
|
+
_react["default"].useEffect(function () {
|
|
88
|
+
var enterTimeout = setTimeout(function () {
|
|
89
|
+
return setVisible(true);
|
|
90
|
+
}, ENTER_DELAY_MS);
|
|
91
|
+
return function () {
|
|
92
|
+
return clearTimeout(enterTimeout);
|
|
93
|
+
};
|
|
94
|
+
}, []);
|
|
95
|
+
_react["default"].useEffect(function () {
|
|
96
|
+
if (!autoClose) return undefined;
|
|
97
|
+
autoCloseTimeoutRef.current = setTimeout(requestClose, autoClose);
|
|
98
|
+
return function () {
|
|
99
|
+
return clearTimeout(autoCloseTimeoutRef.current);
|
|
100
|
+
};
|
|
101
|
+
}, [autoClose, requestClose]);
|
|
102
|
+
_react["default"].useEffect(function () {
|
|
103
|
+
return function () {
|
|
104
|
+
if (exitTimeoutRef.current) clearTimeout(exitTimeoutRef.current);
|
|
105
|
+
};
|
|
106
|
+
}, []);
|
|
107
|
+
var handleMouseEnter = function handleMouseEnter() {
|
|
108
|
+
if (autoCloseTimeoutRef.current) clearTimeout(autoCloseTimeoutRef.current);
|
|
109
|
+
};
|
|
110
|
+
var handleMouseLeave = function handleMouseLeave() {
|
|
111
|
+
if (autoClose) {
|
|
112
|
+
autoCloseTimeoutRef.current = setTimeout(requestClose, autoClose);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
116
|
+
className: "cbx-toast cbx-toast-".concat(severity, " cbx-toast-").concat(horizontal, " ").concat(visible && !leaving ? 'cbx-toast-visible' : '', " ").concat(leaving ? 'cbx-toast-leaving' : ''),
|
|
117
|
+
style: _objectSpread(_objectSpread({}, color ? {
|
|
118
|
+
backgroundColor: color
|
|
119
|
+
} : {}), offset ? {
|
|
120
|
+
marginTop: offset
|
|
121
|
+
} : {}),
|
|
122
|
+
role: severity === 'error' ? 'alert' : 'status',
|
|
123
|
+
"aria-live": severity === 'error' ? 'assertive' : 'polite',
|
|
124
|
+
onMouseEnter: handleMouseEnter,
|
|
125
|
+
onMouseLeave: handleMouseLeave
|
|
126
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
127
|
+
className: "cbx-toast-icon",
|
|
128
|
+
"aria-hidden": "true"
|
|
129
|
+
}, icon || /*#__PURE__*/_react["default"].createElement("i", {
|
|
130
|
+
className: config.icon
|
|
131
|
+
})), /*#__PURE__*/_react["default"].createElement("div", {
|
|
132
|
+
className: "cbx-toast-content"
|
|
133
|
+
}, !!title && /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
|
|
134
|
+
className: "cbx-toast-title",
|
|
135
|
+
component: "div",
|
|
136
|
+
fontWeight: "700",
|
|
137
|
+
color: "inherit"
|
|
138
|
+
}, title), /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
|
|
139
|
+
className: "cbx-toast-message",
|
|
140
|
+
component: "div",
|
|
141
|
+
color: "inherit"
|
|
142
|
+
}, message)), /*#__PURE__*/_react["default"].createElement(_IconButton["default"], {
|
|
143
|
+
className: "cbx-toast-close",
|
|
144
|
+
icon: /*#__PURE__*/_react["default"].createElement("i", {
|
|
145
|
+
className: "ri-close-line"
|
|
146
|
+
}),
|
|
147
|
+
onClick: requestClose,
|
|
148
|
+
"aria-label": resolvedCloseAriaLabel
|
|
149
|
+
}));
|
|
150
|
+
};
|
|
151
|
+
Toast.displayName = "Toast";
|
|
152
|
+
Toast.propTypes = {
|
|
153
|
+
id: _propTypes["default"].string,
|
|
154
|
+
message: _propTypes["default"].node.isRequired,
|
|
155
|
+
title: _propTypes["default"].node,
|
|
156
|
+
severity: _propTypes["default"].oneOf(['success', 'error', 'warning', 'info']),
|
|
157
|
+
icon: _propTypes["default"].node,
|
|
158
|
+
color: _propTypes["default"].string,
|
|
159
|
+
autoClose: _propTypes["default"].oneOfType([_propTypes["default"].number, _propTypes["default"].bool]),
|
|
160
|
+
horizontal: _propTypes["default"].oneOf(['left', 'center', 'right']),
|
|
161
|
+
offset: _propTypes["default"].string,
|
|
162
|
+
onClose: _propTypes["default"].func,
|
|
163
|
+
closeAriaLabel: _propTypes["default"].string
|
|
164
|
+
};
|
|
165
|
+
Toast.defaultProps = {
|
|
166
|
+
id: undefined,
|
|
167
|
+
title: undefined,
|
|
168
|
+
severity: 'success',
|
|
169
|
+
icon: undefined,
|
|
170
|
+
color: undefined,
|
|
171
|
+
autoClose: 5000,
|
|
172
|
+
horizontal: 'right',
|
|
173
|
+
offset: undefined,
|
|
174
|
+
onClose: undefined,
|
|
175
|
+
closeAriaLabel: ''
|
|
176
|
+
};
|
|
177
|
+
var _default = Toast;
|
|
178
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = exports.DesignToastTemplate = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _ToastProvider = _interopRequireDefault(require("./ToastProvider"));
|
|
9
|
+
var _DesignToast = _interopRequireDefault(require("./DesignToast.stories"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
|
+
var _default = {
|
|
12
|
+
title: 'Components/Toast',
|
|
13
|
+
component: _ToastProvider["default"],
|
|
14
|
+
parameters: {
|
|
15
|
+
storybookCodePanel: {
|
|
16
|
+
disabled: false,
|
|
17
|
+
files: [{
|
|
18
|
+
fileName: 'Toast.jsx',
|
|
19
|
+
/* eslint-disable-next-line import/no-webpack-loader-syntax, global-require,
|
|
20
|
+
import/extensions, import/no-unresolved */
|
|
21
|
+
code: require('!!raw-loader!./Toast.jsx')
|
|
22
|
+
}]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports["default"] = _default;
|
|
27
|
+
var TemplateToast = function TemplateToast(args) {
|
|
28
|
+
return /*#__PURE__*/_react["default"].createElement(_DesignToast["default"], args);
|
|
29
|
+
};
|
|
30
|
+
TemplateToast.displayName = "TemplateToast";
|
|
31
|
+
var DesignToastTemplate = TemplateToast.bind({});
|
|
32
|
+
exports.DesignToastTemplate = DesignToastTemplate;
|
|
33
|
+
DesignToastTemplate.parameters = {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _toastStore = require("./toastStore");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
|
+
/**
|
|
12
|
+
* Optional. `useToast()`/`toast()` work anywhere without this - see toastStore.js.
|
|
13
|
+
* Mount it only if you want to set a non-default `maxVisible` (toasts stacked per
|
|
14
|
+
* corner before the oldest gets dropped); otherwise there's no need to render it at all.
|
|
15
|
+
*/
|
|
16
|
+
var ToastProvider = function ToastProvider(_ref) {
|
|
17
|
+
var children = _ref.children,
|
|
18
|
+
maxVisible = _ref.maxVisible;
|
|
19
|
+
_react["default"].useEffect(function () {
|
|
20
|
+
if (maxVisible !== undefined) {
|
|
21
|
+
(0, _toastStore.setMaxVisible)(maxVisible);
|
|
22
|
+
}
|
|
23
|
+
}, [maxVisible]);
|
|
24
|
+
return children;
|
|
25
|
+
};
|
|
26
|
+
ToastProvider.propTypes = {
|
|
27
|
+
maxVisible: _propTypes["default"].number
|
|
28
|
+
};
|
|
29
|
+
ToastProvider.defaultProps = {
|
|
30
|
+
maxVisible: undefined
|
|
31
|
+
};
|
|
32
|
+
var _default = ToastProvider;
|
|
33
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _Toast = _interopRequireDefault(require("./Toast"));
|
|
10
|
+
require("../../styles/main.css");
|
|
11
|
+
require("./Toast.css");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) { ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } } return n; }, _extends.apply(null, arguments); }
|
|
14
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
15
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
16
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
17
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) { n[e] = r[e]; } return n; }
|
|
18
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) { ; } } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
19
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
20
|
+
var cornerKey = function cornerKey(vertical, horizontal) {
|
|
21
|
+
return "".concat(vertical, "-").concat(horizontal);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Internal - mounted once by toastStore.ensureMounted() into its own detached root.
|
|
26
|
+
* Not part of the public API. Takes everything as props (instead of importing toastStore
|
|
27
|
+
* itself) so this file has no dependency back on toastStore.js - toastStore.js importing
|
|
28
|
+
* this file would otherwise be a circular import, which the bundler resolves incorrectly
|
|
29
|
+
* (ToastRoot comes back as undefined the first time it's needed).
|
|
30
|
+
*/
|
|
31
|
+
var ToastRoot = function ToastRoot(_ref) {
|
|
32
|
+
var subscribe = _ref.subscribe,
|
|
33
|
+
getSnapshot = _ref.getSnapshot,
|
|
34
|
+
onCloseToast = _ref.onCloseToast;
|
|
35
|
+
var _React$useState = _react["default"].useState(getSnapshot()),
|
|
36
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
37
|
+
toasts = _React$useState2[0],
|
|
38
|
+
setToasts = _React$useState2[1];
|
|
39
|
+
_react["default"].useEffect(function () {
|
|
40
|
+
// The very first toast is pushed (and notify()'d) synchronously as part of the same
|
|
41
|
+
// toast() call that mounts this component, which happens *before* this effect has
|
|
42
|
+
// had a chance to run and subscribe - so that first notification would otherwise be
|
|
43
|
+
// missed forever. Re-sync to the latest snapshot right here, before subscribing, to
|
|
44
|
+
// close that race window.
|
|
45
|
+
setToasts(getSnapshot());
|
|
46
|
+
return subscribe(setToasts);
|
|
47
|
+
}, [subscribe, getSnapshot]);
|
|
48
|
+
var grouped = _react["default"].useMemo(function () {
|
|
49
|
+
var groups = {};
|
|
50
|
+
toasts.forEach(function (item) {
|
|
51
|
+
var key = cornerKey(item.vertical, item.horizontal);
|
|
52
|
+
if (!groups[key]) groups[key] = [];
|
|
53
|
+
groups[key].push(item);
|
|
54
|
+
});
|
|
55
|
+
return groups;
|
|
56
|
+
}, [toasts]);
|
|
57
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, Object.entries(grouped).map(function (_ref2) {
|
|
58
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
59
|
+
key = _ref3[0],
|
|
60
|
+
group = _ref3[1];
|
|
61
|
+
var _key$split = key.split('-'),
|
|
62
|
+
_key$split2 = _slicedToArray(_key$split, 2),
|
|
63
|
+
vertical = _key$split2[0],
|
|
64
|
+
horizontal = _key$split2[1];
|
|
65
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
66
|
+
key: key,
|
|
67
|
+
className: "cbx-toast-stack cbx-toast-stack-".concat(vertical, " cbx-toast-stack-").concat(horizontal)
|
|
68
|
+
}, group.map(function (item) {
|
|
69
|
+
return (
|
|
70
|
+
/*#__PURE__*/
|
|
71
|
+
// onCloseToast is the stable store function (not a fresh arrow per render),
|
|
72
|
+
// so Toast's own autoClose timer - which depends on it - never gets reset
|
|
73
|
+
// just because a sibling toast changed.
|
|
74
|
+
_react["default"].createElement(_Toast["default"], _extends({
|
|
75
|
+
key: item.id
|
|
76
|
+
}, item, {
|
|
77
|
+
onClose: onCloseToast
|
|
78
|
+
}))
|
|
79
|
+
);
|
|
80
|
+
}));
|
|
81
|
+
}));
|
|
82
|
+
};
|
|
83
|
+
ToastRoot.propTypes = {
|
|
84
|
+
subscribe: _propTypes["default"].func.isRequired,
|
|
85
|
+
getSnapshot: _propTypes["default"].func.isRequired,
|
|
86
|
+
onCloseToast: _propTypes["default"].func.isRequired
|
|
87
|
+
};
|
|
88
|
+
var _default = ToastRoot;
|
|
89
|
+
exports["default"] = _default;
|