@councilbox/councilbox-ui 2.0.53 → 2.0.55
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/ScrollbarNew.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/overlayA11yStack.js +47 -0
- package/dist/HOCs/useA11yGuard.js +38 -0
- package/dist/HOCs/useDynamicStyles.js +41 -60
- package/dist/HOCs/useMenuNavigation.js +110 -0
- package/dist/HOCs/useOverlay.js +87 -0
- package/dist/HOCs/usePopoverPosition.js +228 -0
- package/dist/HOCs/useRipple.js +17 -35
- package/dist/HOCs/useWindowSize.js +24 -42
- package/dist/build-index.js +119 -99
- package/dist/components/1.Introduction.stories.mdx +4 -1
- package/dist/components/2.Changelog.stories.mdx +54 -0
- package/dist/components/3.Guide.stories.mdx +1 -1
- package/dist/components/Accordion/Accordion.css +7 -0
- package/dist/components/Accordion/Accordion.js +97 -102
- package/dist/components/Accordion/Accordion.stories.js +10 -12
- package/dist/components/Accordion/DesignAccordion.stories.js +10 -21
- package/dist/components/Alert/Alert.js +55 -55
- package/dist/components/Alert/Alert.stories.js +10 -11
- package/dist/components/Avatar/Avatar.js +82 -74
- package/dist/components/Avatar/Avatar.stories.js +19 -23
- package/dist/components/Avatar/DesignAvatar.stories.js +18 -26
- package/dist/components/Avatar/DesignAvatarText.stories.js +31 -40
- package/dist/components/AvatarGroup/AvatarGroup.js +7 -14
- package/dist/components/AvatarGroup/AvatarGroup.stories.js +6 -13
- package/dist/components/AvatarGroup/DesignAvatarGroup.stories.js +34 -45
- package/dist/components/Block/Block.css +3 -3
- package/dist/components/Block/Block.js +31 -45
- package/dist/components/Block/Block.stories.js +5 -12
- package/dist/components/Block/DesignBlock.stories.js +7 -13
- package/dist/components/Button/Button.js +44 -66
- package/dist/components/Button/Button.stories.js +8 -14
- package/dist/components/Button/button.css +1 -1
- package/dist/components/ButtonBasic/ButtonBasic.css +6 -1
- package/dist/components/ButtonBasic/ButtonBasic.js +96 -118
- package/dist/components/ButtonBasic/ButtonBasic.stories.js +14 -15
- package/dist/components/Checkbox/Checkbox.css +6 -0
- package/dist/components/Checkbox/Checkbox.js +81 -100
- package/dist/components/Checkbox/Checkbox.stories.js +10 -11
- package/dist/components/DatePicker/Calendar.js +243 -0
- package/dist/components/DatePicker/DatePicker.css +197 -0
- package/dist/components/DatePicker/DatePicker.js +384 -0
- package/dist/components/DatePicker/DatePicker.stories.js +180 -0
- package/dist/components/DatePicker/dateUtils.js +478 -0
- package/dist/components/DateRangePicker/DateRangePicker.css +41 -0
- package/dist/components/DateRangePicker/DateRangePicker.js +435 -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 +481 -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.css +20 -9
- package/dist/components/DragDrop/DragDrop.js +83 -76
- package/dist/components/DragDrop/DragDrop.stories.js +9 -16
- package/dist/components/DrawerPanel/DesignDrawerPanel.js +35 -53
- package/dist/components/DrawerPanel/DrawerPanel.js +157 -146
- package/dist/components/DrawerPanel/DrawerPanel.stories.js +10 -12
- package/dist/components/DropDown/DesignDropDown.stories.js +87 -97
- package/dist/components/DropDown/DropDown.js +179 -343
- package/dist/components/DropDown/DropDown.stories.js +6 -12
- package/dist/components/DropDown/PopoverPlayground.js +68 -98
- package/dist/components/EnhancedTable/DesignEnhancedTable.stories.js +26 -36
- package/dist/components/EnhancedTable/EnhancedMyTable.js +16 -19
- package/dist/components/EnhancedTable/EnhancedTable.js +77 -136
- package/dist/components/EnhancedTable/EnhancedTable.stories.js +5 -12
- package/dist/components/EnhancedTable/EnhancedTableBody.js +11 -14
- package/dist/components/EnhancedTable/EnhancedTableCell.js +25 -34
- package/dist/components/EnhancedTable/EnhancedTableContainer.js +11 -14
- package/dist/components/EnhancedTable/EnhancedTableHead.js +11 -14
- package/dist/components/EnhancedTable/EnhancedTableRow.js +15 -18
- package/dist/components/EnhancedTable/EnhancedTableSortLabel.js +15 -18
- package/dist/components/FabButton/DesignFabButton.stories.js +9 -16
- package/dist/components/FabButton/FabButton.js +51 -54
- package/dist/components/FabButton/FabButton.stories.js +10 -12
- package/dist/components/Grid/DesignGrid.stories.js +7 -14
- package/dist/components/Grid/Grid.js +38 -46
- package/dist/components/Grid/Grid.stories.js +6 -13
- package/dist/components/Grid/GridItem.js +37 -39
- package/dist/components/Header/DesignHeader.stories.js +20 -24
- package/dist/components/Header/Header.js +227 -246
- package/dist/components/Header/Header.stories.js +9 -21
- package/dist/components/Header/header.css +10 -5
- package/dist/components/IconButton/DesignIconButton.stories.js +31 -36
- package/dist/components/IconButton/IconButton.css +6 -1
- package/dist/components/IconButton/IconButton.js +135 -140
- package/dist/components/IconButton/IconButton.stories.js +12 -13
- package/dist/components/IconButtonSquare/DesignIconButtonSquare.stories.js +5 -11
- package/dist/components/IconButtonSquare/IconButtonSquare.js +14 -28
- package/dist/components/IconButtonSquare/IconButtonSquare.stories.js +7 -13
- package/dist/components/IconFont/IconFont.js +27 -48
- package/dist/components/IconFont/IconFont.stories.js +5 -11
- package/dist/components/InputAutocomplete/InputAutocomplete.css +6 -0
- package/dist/components/InputAutocomplete/InputAutocomplete.js +184 -260
- package/dist/components/InputAutocomplete/InputAutocomplete.stories.js +5 -11
- package/dist/components/InputPassword/InputPassword.css +0 -6
- package/dist/components/InputPassword/InputPassword.js +58 -73
- package/dist/components/InputPassword/InputPassword.stories.js +5 -11
- package/dist/components/InputText/InputText.css +96 -83
- package/dist/components/InputText/InputText.js +211 -215
- package/dist/components/InputText/InputText.stories.js +11 -11
- package/dist/components/InputTextArea/DesignInputTextArea.stories.js +38 -51
- package/dist/components/InputTextArea/InputTextArea.js +84 -93
- package/dist/components/InputTextArea/InputTextArea.stories.js +5 -12
- package/dist/components/LoadingSection/LoadingSection.js +44 -51
- package/dist/components/LoadingSection/LoadingSection.stories.js +5 -11
- package/dist/components/MenuItem/DesignMenuItem.stories.js +20 -34
- package/dist/components/MenuItem/MenuItem.css +7 -2
- package/dist/components/MenuItem/MenuItem.js +131 -140
- package/dist/components/MenuItem/MenuItem.stories.js +6 -15
- package/dist/components/MenuLateralLeft/MenuLateralLeft.css +24 -0
- package/dist/components/MenuLateralLeft/MenuLateralLeft.js +120 -157
- package/dist/components/MenuLateralLeft/MenuLateralLeft.stories.js +5 -12
- package/dist/components/MenuLateralRight/MenuLateralRight.css +2 -2
- package/dist/components/MenuLateralRight/MenuLateralRight.js +91 -79
- package/dist/components/MenuLateralRight/MenuLateralRight.stories.js +5 -12
- package/dist/components/Modal/DesignModal.stories.js +15 -30
- package/dist/components/Modal/Modal.css +35 -15
- package/dist/components/Modal/Modal.js +156 -145
- package/dist/components/Modal/Modal.stories.js +7 -16
- package/dist/components/PaginationFooter/DesignPaginationFooter.stories.js +4 -10
- package/dist/components/PaginationFooter/PaginationFooter.css +10 -0
- package/dist/components/PaginationFooter/PaginationFooter.js +99 -91
- package/dist/components/PaginationFooter/PaginationFooter.stories.js +5 -12
- package/dist/components/RadioButton/Radio.css +19 -18
- package/dist/components/RadioButton/Radio.js +65 -83
- package/dist/components/RadioButton/Radio.stories.js +27 -36
- package/dist/components/RichTextInput/DesignRichTextInput.stories.js +119 -0
- package/dist/components/RichTextInput/RichTextInput.css +309 -0
- package/dist/components/RichTextInput/RichTextInput.js +851 -0
- package/dist/components/RichTextInput/RichTextInput.stories.js +33 -0
- package/dist/components/Ripple/DesignRipple.js +42 -41
- package/dist/components/Ripple/Ripple.stories.js +5 -11
- package/dist/components/Scrollbar/DesignScrollbar.js +5 -10
- package/dist/components/Scrollbar/Scrollbar.js +37 -56
- package/dist/components/Scrollbar/Scrollbar.stories.js +5 -12
- package/dist/components/ScrollbarNew/DesignScrollbarNew.js +24 -0
- package/dist/components/ScrollbarNew/ScrollbarNew.css +79 -0
- package/dist/components/ScrollbarNew/ScrollbarNew.js +426 -0
- package/dist/components/ScrollbarNew/ScrollbarNew.stories.js +37 -0
- package/dist/components/SelectInput/DesignSelectInput.js +22 -45
- package/dist/components/SelectInput/SelectInput.js +171 -218
- package/dist/components/SelectInput/SelectInput.stories.js +6 -15
- package/dist/components/Slider/DesignSlider.js +8 -14
- package/dist/components/Slider/Slider.css +57 -37
- package/dist/components/Slider/Slider.js +85 -84
- package/dist/components/Slider/Slider.stories.js +5 -12
- package/dist/components/Spacing/Spacing.js +38 -45
- package/dist/components/Spacing/Spacing.stories.js +5 -11
- package/dist/components/Stars/DesignStars.js +17 -30
- package/dist/components/Stars/Stars.css +55 -104
- package/dist/components/Stars/Stars.js +89 -73
- package/dist/components/Stars/Stars.stories.js +5 -12
- package/dist/components/Stepper/DesignStepper.stories.js +16 -30
- package/dist/components/Stepper/Stepper.css +46 -10
- package/dist/components/Stepper/Stepper.js +118 -134
- package/dist/components/Stepper/Stepper.stories.js +5 -12
- package/dist/components/Table/DesignTable.stories.js +200 -211
- package/dist/components/Table/Table.css +33 -2
- package/dist/components/Table/Table.js +30 -38
- package/dist/components/Table/Table.stories.js +5 -12
- package/dist/components/Table/TableBody.js +22 -34
- package/dist/components/Table/TableCell.js +71 -61
- package/dist/components/Table/TableContainer.js +22 -34
- package/dist/components/Table/TableHead.js +22 -34
- package/dist/components/Table/TableRow.js +33 -37
- package/dist/components/Table/TableSortLabel.js +42 -52
- package/dist/components/Tabs/DesignTabs.js +14 -28
- package/dist/components/Tabs/Tabs.css +30 -11
- package/dist/components/Tabs/Tabs.js +151 -138
- package/dist/components/Tabs/Tabs.stories.js +5 -12
- package/dist/components/Tag/DesignTags.stories.js +24 -39
- package/dist/components/Tag/Tag.css +61 -42
- package/dist/components/Tag/Tag.js +93 -91
- package/dist/components/Tag/Tag.stories.js +5 -12
- package/dist/components/TextInput/TextInput.js +38 -54
- package/dist/components/TextInput/TextInput.stories.js +5 -11
- package/dist/components/ThemeProvider/Colors.js +2 -2
- package/dist/components/ThemeProvider/CouncilboxThemeContext.js +7 -10
- package/dist/components/ThemeProvider/ThemeProvider.js +34 -52
- package/dist/components/TimePicker/TimePicker.css +3 -0
- package/dist/components/TimePicker/TimePicker.js +359 -0
- package/dist/components/TimePicker/TimePicker.stories.js +132 -0
- package/dist/components/Timeline/DesignTimeline.stories.js +4 -10
- package/dist/components/Timeline/Timeline.js +66 -46
- package/dist/components/Timeline/Timeline.stories.js +5 -12
- package/dist/components/Toast/DesignToast.stories.js +174 -0
- package/dist/components/Toast/Toast.css +154 -0
- package/dist/components/Toast/Toast.js +165 -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 +127 -0
- package/dist/components/Toast/useToast.js +42 -0
- package/dist/components/Toggle/Toggle.css +10 -0
- package/dist/components/Toggle/Toggle.js +123 -100
- package/dist/components/Toggle/Toggle.stories.js +10 -11
- package/dist/components/Tooltip/DesignTooltip.stories.js +10 -16
- package/dist/components/Tooltip/Tooltip.css +17 -1
- package/dist/components/Tooltip/Tooltip.js +195 -366
- package/dist/components/Tooltip/Tooltip.stories.js +5 -12
- package/dist/components/Typography/Typography.css +57 -6
- package/dist/components/Typography/Typography.js +44 -97
- package/dist/components/Typography/Typography.stories.js +5 -11
- package/dist/index.js +2 -6
- package/dist/reportWebVitals.js +8 -14
- package/dist/storybook.test.js +2 -4
- package/dist/styles/colorConsts.css +4 -4
- package/dist/styles/main.css +16 -0
- package/dist/styles/styleFont.css +1 -1
- package/dist/styles/stylesheet.js +10 -22
- package/dist/styles/zIndexConsts.css +2 -0
- package/dist/testing/TestAutocomplete.js +74 -97
- package/dist/testing/TestComponents.js +5 -10
- package/dist/testing/TestDropdown.js +33 -41
- package/dist/utils/autoDetectScroll.js +12 -35
- package/dist/utils/index.js +37 -63
- package/dist/utils/useFallbackId.js +19 -0
- package/package.json +67 -4
- 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 -115
- package/dist/components/Avatar/AvatarOld.js +0 -138
- package/dist/components/ButtonBasic/ButtonBasicOld.css +0 -41
- package/dist/components/ButtonBasic/ButtonBasicOld.js +0 -231
- package/dist/components/Checkbox/CheckboxOld.css +0 -31
- package/dist/components/Checkbox/CheckboxOld.js +0 -112
- package/dist/components/DrawerPanel/DrawerPanelOld.css +0 -56
- package/dist/components/DrawerPanel/DrawerPanelOld.js +0 -233
- package/dist/components/DropDown/DropDownOld.css +0 -3
- package/dist/components/DropDown/DropDownOld.js +0 -186
- package/dist/components/Grid/GridItemOld.js +0 -43
- package/dist/components/Grid/GridOld.css +0 -0
- package/dist/components/Grid/GridOld.js +0 -53
- package/dist/components/IconButton/IconButtonOld.css +0 -0
- package/dist/components/IconButton/IconButtonOld.js +0 -138
- package/dist/components/IconButtonSquare/IconButtonSquareOld.css +0 -43
- package/dist/components/IconButtonSquare/IconButtonSquareOld.js +0 -133
- package/dist/components/InputAutocomplete/InputAutocompleteOld.css +0 -5
- package/dist/components/InputAutocomplete/InputAutocompleteOld.js +0 -178
- package/dist/components/InputText/InputTextOld.css +0 -10
- package/dist/components/InputText/InputTextOld.js +0 -340
- package/dist/components/MenuItem/MenuItemOld.js +0 -139
- package/dist/components/Modal/ModalOld.css +0 -3
- package/dist/components/Modal/ModalOld.js +0 -230
- package/dist/components/RadioButton/RadioOld.css +0 -31
- package/dist/components/RadioButton/RadioOld.js +0 -142
- package/dist/components/SelectInput/SelectInputOld.css +0 -17
- package/dist/components/SelectInput/SelectInputOld.js +0 -325
- package/dist/components/Table/TableOld.css +0 -79
- package/dist/components/Table/TableOld.js +0 -165
- package/dist/components/Tabs/TabsOld.js +0 -92
- package/dist/components/Typography/TypographyOld.js +0 -132
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
15
|
+
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; }
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
17
|
+
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); }
|
|
18
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
19
|
+
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."); }
|
|
20
|
+
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; } }
|
|
21
|
+
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; }
|
|
22
|
+
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; } }
|
|
23
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
24
|
+
var ENTER_DELAY_MS = 10;
|
|
25
|
+
var EXIT_DURATION_MS = 200;
|
|
26
|
+
var SEVERITY_CONFIG = {
|
|
27
|
+
success: {
|
|
28
|
+
icon: 'ri-checkbox-circle-fill',
|
|
29
|
+
label: 'Éxito'
|
|
30
|
+
},
|
|
31
|
+
error: {
|
|
32
|
+
icon: 'ri-close-circle-fill',
|
|
33
|
+
label: 'Error'
|
|
34
|
+
},
|
|
35
|
+
warning: {
|
|
36
|
+
icon: 'ri-alert-fill',
|
|
37
|
+
label: 'Aviso'
|
|
38
|
+
},
|
|
39
|
+
info: {
|
|
40
|
+
icon: 'ri-information-fill',
|
|
41
|
+
label: 'Información'
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var Toast = function Toast(_ref) {
|
|
45
|
+
var id = _ref.id,
|
|
46
|
+
message = _ref.message,
|
|
47
|
+
title = _ref.title,
|
|
48
|
+
severity = _ref.severity,
|
|
49
|
+
icon = _ref.icon,
|
|
50
|
+
color = _ref.color,
|
|
51
|
+
autoClose = _ref.autoClose,
|
|
52
|
+
horizontal = _ref.horizontal,
|
|
53
|
+
offset = _ref.offset,
|
|
54
|
+
onClose = _ref.onClose,
|
|
55
|
+
closeAriaLabel = _ref.closeAriaLabel;
|
|
56
|
+
var _React$useState = _react["default"].useState(false),
|
|
57
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
58
|
+
visible = _React$useState2[0],
|
|
59
|
+
setVisible = _React$useState2[1];
|
|
60
|
+
var _React$useState3 = _react["default"].useState(false),
|
|
61
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
62
|
+
leaving = _React$useState4[0],
|
|
63
|
+
setLeaving = _React$useState4[1];
|
|
64
|
+
var autoCloseTimeoutRef = _react["default"].useRef(null);
|
|
65
|
+
var exitTimeoutRef = _react["default"].useRef(null);
|
|
66
|
+
var config = SEVERITY_CONFIG[severity] || SEVERITY_CONFIG.success;
|
|
67
|
+
var requestClose = _react["default"].useCallback(function () {
|
|
68
|
+
setLeaving(true);
|
|
69
|
+
if (exitTimeoutRef.current) clearTimeout(exitTimeoutRef.current);
|
|
70
|
+
exitTimeoutRef.current = setTimeout(function () {
|
|
71
|
+
onClose === null || onClose === void 0 ? void 0 : onClose(id);
|
|
72
|
+
}, EXIT_DURATION_MS);
|
|
73
|
+
}, [onClose, id]);
|
|
74
|
+
_react["default"].useEffect(function () {
|
|
75
|
+
var enterTimeout = setTimeout(function () {
|
|
76
|
+
return setVisible(true);
|
|
77
|
+
}, ENTER_DELAY_MS);
|
|
78
|
+
return function () {
|
|
79
|
+
return clearTimeout(enterTimeout);
|
|
80
|
+
};
|
|
81
|
+
}, []);
|
|
82
|
+
_react["default"].useEffect(function () {
|
|
83
|
+
if (!autoClose) return undefined;
|
|
84
|
+
autoCloseTimeoutRef.current = setTimeout(requestClose, autoClose);
|
|
85
|
+
return function () {
|
|
86
|
+
return clearTimeout(autoCloseTimeoutRef.current);
|
|
87
|
+
};
|
|
88
|
+
}, [autoClose, requestClose]);
|
|
89
|
+
_react["default"].useEffect(function () {
|
|
90
|
+
return function () {
|
|
91
|
+
if (exitTimeoutRef.current) clearTimeout(exitTimeoutRef.current);
|
|
92
|
+
};
|
|
93
|
+
}, []);
|
|
94
|
+
var handleMouseEnter = function handleMouseEnter() {
|
|
95
|
+
if (autoCloseTimeoutRef.current) clearTimeout(autoCloseTimeoutRef.current);
|
|
96
|
+
};
|
|
97
|
+
var handleMouseLeave = function handleMouseLeave() {
|
|
98
|
+
if (autoClose) {
|
|
99
|
+
autoCloseTimeoutRef.current = setTimeout(requestClose, autoClose);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
103
|
+
className: "cbx-toast cbx-toast-".concat(severity, " cbx-toast-").concat(horizontal, " ").concat(visible && !leaving ? 'cbx-toast-visible' : '', " ").concat(leaving ? 'cbx-toast-leaving' : ''),
|
|
104
|
+
style: _objectSpread(_objectSpread({}, color ? {
|
|
105
|
+
backgroundColor: color
|
|
106
|
+
} : {}), offset ? {
|
|
107
|
+
marginTop: offset
|
|
108
|
+
} : {}),
|
|
109
|
+
role: severity === 'error' ? 'alert' : 'status',
|
|
110
|
+
"aria-live": severity === 'error' ? 'assertive' : 'polite',
|
|
111
|
+
onMouseEnter: handleMouseEnter,
|
|
112
|
+
onMouseLeave: handleMouseLeave
|
|
113
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
114
|
+
className: "cbx-toast-icon",
|
|
115
|
+
"aria-hidden": "true"
|
|
116
|
+
}, icon || /*#__PURE__*/_react["default"].createElement("i", {
|
|
117
|
+
className: config.icon
|
|
118
|
+
})), /*#__PURE__*/_react["default"].createElement("div", {
|
|
119
|
+
className: "cbx-toast-content"
|
|
120
|
+
}, !!title && /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
|
|
121
|
+
className: "cbx-toast-title",
|
|
122
|
+
component: "div",
|
|
123
|
+
fontWeight: "700",
|
|
124
|
+
color: "inherit"
|
|
125
|
+
}, title), /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
|
|
126
|
+
className: "cbx-toast-message",
|
|
127
|
+
component: "div",
|
|
128
|
+
color: "inherit"
|
|
129
|
+
}, message)), /*#__PURE__*/_react["default"].createElement(_IconButton["default"], {
|
|
130
|
+
className: "cbx-toast-close",
|
|
131
|
+
icon: /*#__PURE__*/_react["default"].createElement("i", {
|
|
132
|
+
className: "ri-close-line"
|
|
133
|
+
}),
|
|
134
|
+
onClick: requestClose,
|
|
135
|
+
"aria-label": closeAriaLabel
|
|
136
|
+
}));
|
|
137
|
+
};
|
|
138
|
+
Toast.displayName = "Toast";
|
|
139
|
+
Toast.propTypes = {
|
|
140
|
+
id: _propTypes["default"].string,
|
|
141
|
+
message: _propTypes["default"].node.isRequired,
|
|
142
|
+
title: _propTypes["default"].node,
|
|
143
|
+
severity: _propTypes["default"].oneOf(['success', 'error', 'warning', 'info']),
|
|
144
|
+
icon: _propTypes["default"].node,
|
|
145
|
+
color: _propTypes["default"].string,
|
|
146
|
+
autoClose: _propTypes["default"].oneOfType([_propTypes["default"].number, _propTypes["default"].bool]),
|
|
147
|
+
horizontal: _propTypes["default"].oneOf(['left', 'center', 'right']),
|
|
148
|
+
offset: _propTypes["default"].string,
|
|
149
|
+
onClose: _propTypes["default"].func,
|
|
150
|
+
closeAriaLabel: _propTypes["default"].string
|
|
151
|
+
};
|
|
152
|
+
Toast.defaultProps = {
|
|
153
|
+
id: undefined,
|
|
154
|
+
title: undefined,
|
|
155
|
+
severity: 'success',
|
|
156
|
+
icon: undefined,
|
|
157
|
+
color: undefined,
|
|
158
|
+
autoClose: 5000,
|
|
159
|
+
horizontal: 'right',
|
|
160
|
+
offset: undefined,
|
|
161
|
+
onClose: undefined,
|
|
162
|
+
closeAriaLabel: 'Cerrar notificación'
|
|
163
|
+
};
|
|
164
|
+
var _default = Toast;
|
|
165
|
+
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;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toast = exports.subscribeToasts = exports.setMaxVisible = exports.getToastsSnapshot = exports.closeToast = exports.closeAllToasts = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
9
|
+
var _ToastRoot = _interopRequireDefault(require("./ToastRoot"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
|
+
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); }
|
|
12
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
13
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
16
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
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 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; }
|
|
19
|
+
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; }
|
|
20
|
+
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; }
|
|
21
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
22
|
+
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); }
|
|
23
|
+
/**
|
|
24
|
+
* Plain-JS singleton store (no React context) so `toast()` works from anywhere -
|
|
25
|
+
* any component, any file, even outside React (a utility function, an Apollo error
|
|
26
|
+
* link) - without the host app having to mount a provider anywhere. The first call
|
|
27
|
+
* lazily mounts a self-contained React root into its own <div> on <body>, completely
|
|
28
|
+
* independent of the caller's app tree. Known trade-off: content passed as `message`/
|
|
29
|
+
* `title` therefore can't read React Context from the host app (CSS custom properties
|
|
30
|
+
* still work fine, since those flow through the DOM/CSSOM, not the React tree).
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
var DEFAULT_TOAST = {
|
|
34
|
+
severity: 'success',
|
|
35
|
+
autoClose: 5000,
|
|
36
|
+
vertical: 'top',
|
|
37
|
+
horizontal: 'right'
|
|
38
|
+
};
|
|
39
|
+
var DEFAULT_MAX_VISIBLE = 5;
|
|
40
|
+
var toasts = [];
|
|
41
|
+
var maxVisible = DEFAULT_MAX_VISIBLE;
|
|
42
|
+
var listeners = new Set();
|
|
43
|
+
var idCounter = 0;
|
|
44
|
+
var nextId = function nextId() {
|
|
45
|
+
idCounter += 1;
|
|
46
|
+
return "cbx-toast-".concat(Date.now(), "-").concat(idCounter);
|
|
47
|
+
};
|
|
48
|
+
var cornerKey = function cornerKey(vertical, horizontal) {
|
|
49
|
+
return "".concat(vertical, "-").concat(horizontal);
|
|
50
|
+
};
|
|
51
|
+
var notify = function notify() {
|
|
52
|
+
listeners.forEach(function (listener) {
|
|
53
|
+
return listener(toasts);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
var subscribeToasts = function subscribeToasts(listener) {
|
|
57
|
+
listeners.add(listener);
|
|
58
|
+
return function () {
|
|
59
|
+
return listeners["delete"](listener);
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
exports.subscribeToasts = subscribeToasts;
|
|
63
|
+
var getToastsSnapshot = function getToastsSnapshot() {
|
|
64
|
+
return toasts;
|
|
65
|
+
};
|
|
66
|
+
exports.getToastsSnapshot = getToastsSnapshot;
|
|
67
|
+
var setMaxVisible = function setMaxVisible(value) {
|
|
68
|
+
if (typeof value === 'number' && value > 0) {
|
|
69
|
+
maxVisible = value;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
exports.setMaxVisible = setMaxVisible;
|
|
73
|
+
var closeToast = function closeToast(id) {
|
|
74
|
+
toasts = toasts.filter(function (item) {
|
|
75
|
+
return item.id !== id;
|
|
76
|
+
});
|
|
77
|
+
notify();
|
|
78
|
+
};
|
|
79
|
+
exports.closeToast = closeToast;
|
|
80
|
+
var mounted = false;
|
|
81
|
+
var ensureMounted = function ensureMounted() {
|
|
82
|
+
if (mounted || typeof document === 'undefined') return;
|
|
83
|
+
mounted = true;
|
|
84
|
+
var node = document.createElement('div');
|
|
85
|
+
node.setAttribute('id', 'cbx-toast-root');
|
|
86
|
+
document.body.appendChild(node);
|
|
87
|
+
var element = /*#__PURE__*/_react["default"].createElement(_ToastRoot["default"], {
|
|
88
|
+
subscribe: subscribeToasts,
|
|
89
|
+
getSnapshot: getToastsSnapshot,
|
|
90
|
+
onCloseToast: closeToast
|
|
91
|
+
});
|
|
92
|
+
if (typeof _reactDom["default"].createRoot === 'function') {
|
|
93
|
+
_reactDom["default"].createRoot(node).render(element);
|
|
94
|
+
} else {
|
|
95
|
+
_reactDom["default"].render(element, node);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var toast = function toast(newToast) {
|
|
99
|
+
ensureMounted();
|
|
100
|
+
var id = nextId();
|
|
101
|
+
var merged = _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_TOAST), newToast), {}, {
|
|
102
|
+
id: id
|
|
103
|
+
});
|
|
104
|
+
var key = cornerKey(merged.vertical, merged.horizontal);
|
|
105
|
+
var sameCorner = toasts.filter(function (item) {
|
|
106
|
+
return cornerKey(item.vertical, item.horizontal) === key;
|
|
107
|
+
});
|
|
108
|
+
var overflow = sameCorner.length - maxVisible + 1;
|
|
109
|
+
if (overflow > 0) {
|
|
110
|
+
var toDrop = new Set(sameCorner.slice(0, overflow).map(function (item) {
|
|
111
|
+
return item.id;
|
|
112
|
+
}));
|
|
113
|
+
toasts = [].concat(_toConsumableArray(toasts.filter(function (item) {
|
|
114
|
+
return !toDrop.has(item.id);
|
|
115
|
+
})), [merged]);
|
|
116
|
+
} else {
|
|
117
|
+
toasts = [].concat(_toConsumableArray(toasts), [merged]);
|
|
118
|
+
}
|
|
119
|
+
notify();
|
|
120
|
+
return id;
|
|
121
|
+
};
|
|
122
|
+
exports.toast = toast;
|
|
123
|
+
var closeAllToasts = function closeAllToasts() {
|
|
124
|
+
toasts = [];
|
|
125
|
+
notify();
|
|
126
|
+
};
|
|
127
|
+
exports.closeAllToasts = closeAllToasts;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useToast = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _toastStore = require("./toastStore");
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
11
|
+
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."); }
|
|
12
|
+
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; } }
|
|
13
|
+
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; }
|
|
14
|
+
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; } }
|
|
15
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
16
|
+
/**
|
|
17
|
+
* const { toast } = useToast();
|
|
18
|
+
* toast({ message: '...', severity: 'error' });
|
|
19
|
+
*
|
|
20
|
+
* Works anywhere, no provider required - see toastStore.js. Need to call it outside a
|
|
21
|
+
* component (a plain util, an error handler)? Import `toast` directly instead:
|
|
22
|
+
* import { toast } from '@councilbox/councilbox-ui';
|
|
23
|
+
*/
|
|
24
|
+
var useToast = function useToast() {
|
|
25
|
+
var _React$useState = _react["default"].useState((0, _toastStore.getToastsSnapshot)()),
|
|
26
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
27
|
+
toasts = _React$useState2[0],
|
|
28
|
+
setToasts = _React$useState2[1];
|
|
29
|
+
_react["default"].useEffect(function () {
|
|
30
|
+
// Re-sync in case a toast() fired between this component's initial render and this
|
|
31
|
+
// effect actually running (same race as ToastRoot.jsx - see the comment there).
|
|
32
|
+
setToasts((0, _toastStore.getToastsSnapshot)());
|
|
33
|
+
return (0, _toastStore.subscribeToasts)(setToasts);
|
|
34
|
+
}, []);
|
|
35
|
+
return {
|
|
36
|
+
toast: _toastStore.toast,
|
|
37
|
+
closeToast: _toastStore.closeToast,
|
|
38
|
+
closeAll: _toastStore.closeAllToasts,
|
|
39
|
+
toasts: toasts
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports.useToast = useToast;
|
|
@@ -81,6 +81,16 @@
|
|
|
81
81
|
opacity: 0.12;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
.cbx-switch-label>input:focus-visible+span::after {
|
|
85
|
+
outline: 2px solid var(--primary);
|
|
86
|
+
outline-offset: 2px;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.cbx-switch-label>input:focus-visible+span::before {
|
|
90
|
+
outline: 2px solid var(--primary);
|
|
91
|
+
outline-offset: 2px;
|
|
92
|
+
}
|
|
93
|
+
|
|
84
94
|
.cbx-switch-label:hover>input:focus {
|
|
85
95
|
opacity: 0.16;
|
|
86
96
|
}
|