@bolio-ui/core 1.0.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/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/avatar/index.js +901 -0
- package/dist/badge/index.js +899 -0
- package/dist/bolio-ui-provider/index.js +1883 -0
- package/dist/breadcrumbs/index.js +985 -0
- package/dist/button/index.js +1358 -0
- package/dist/button-dropdown/index.js +1111 -0
- package/dist/button-group/index.js +782 -0
- package/dist/capacity/index.js +780 -0
- package/dist/card/index.js +1275 -0
- package/dist/checkbox/index.js +1042 -0
- package/dist/code/index.js +803 -0
- package/dist/col/index.js +90 -0
- package/dist/collapse/index.js +1158 -0
- package/dist/container/index.js +444 -0
- package/dist/css-baseline/index.js +348 -0
- package/dist/description/index.js +741 -0
- package/dist/display/index.js +745 -0
- package/dist/divider/index.js +767 -0
- package/dist/dot/index.js +755 -0
- package/dist/drawer/index.js +1513 -0
- package/dist/fieldset/index.js +1089 -0
- package/dist/grid/index.js +870 -0
- package/dist/image/index.js +1094 -0
- package/dist/index.js +9970 -0
- package/dist/input/index.js +1275 -0
- package/dist/keyboard/index.js +711 -0
- package/dist/link/index.js +863 -0
- package/dist/loading/index.js +765 -0
- package/dist/mdx-widgets/index.js +438 -0
- package/dist/modal/index.js +2220 -0
- package/dist/note/index.js +773 -0
- package/dist/page/index.js +928 -0
- package/dist/pagination/index.js +1201 -0
- package/dist/popover/index.js +1502 -0
- package/dist/progress/index.js +804 -0
- package/dist/radio/index.js +1028 -0
- package/dist/rating/index.js +912 -0
- package/dist/row/index.js +442 -0
- package/dist/section/index.js +733 -0
- package/dist/select/index.js +1865 -0
- package/dist/slider/index.js +1097 -0
- package/dist/snippet/index.js +1207 -0
- package/dist/spacer/index.js +692 -0
- package/dist/spinner/index.js +763 -0
- package/dist/styled-jsx.cjs.js +766 -0
- package/dist/tabs/index.js +1125 -0
- package/dist/tag/index.js +749 -0
- package/dist/text/index.js +830 -0
- package/dist/textarea/index.js +915 -0
- package/dist/themes/index.js +319 -0
- package/dist/toggle/index.js +852 -0
- package/dist/tooltip/index.js +1353 -0
- package/dist/use-all-themes/index.js +335 -0
- package/dist/use-body-scroll/index.js +173 -0
- package/dist/use-classes/index.js +55 -0
- package/dist/use-click-away/index.js +28 -0
- package/dist/use-clipboard/index.js +188 -0
- package/dist/use-current-state/index.js +90 -0
- package/dist/use-input/index.js +129 -0
- package/dist/use-keyboard/index.js +214 -0
- package/dist/use-media-query/index.js +495 -0
- package/dist/use-modal/index.js +114 -0
- package/dist/use-scale/index.js +673 -0
- package/dist/use-tabs/index.js +112 -0
- package/dist/use-theme/index.js +333 -0
- package/dist/use-toasts/index.js +236 -0
- package/esm/avatar/avatar-group.js +29 -0
- package/esm/avatar/avatar.js +107 -0
- package/esm/avatar/avatar.skeleton.js +21 -0
- package/esm/avatar/helpers.js +16 -0
- package/esm/avatar/index.js +4 -0
- package/esm/avatar/stories.js +113 -0
- package/esm/badge/badge-anchor.js +70 -0
- package/esm/badge/badge.js +58 -0
- package/esm/badge/index.js +4 -0
- package/esm/badge/stories.js +92 -0
- package/esm/bolio-ui-provider/bolio-ui-provider.js +62 -0
- package/esm/bolio-ui-provider/index.js +2 -0
- package/esm/bolio-ui-provider/theme-provider.js +47 -0
- package/esm/breadcrumbs/breadcrumbs-item.js +49 -0
- package/esm/breadcrumbs/breadcrumbs-separator.js +25 -0
- package/esm/breadcrumbs/breadcrumbs.js +47 -0
- package/esm/breadcrumbs/index.js +6 -0
- package/esm/breadcrumbs/stories.js +51 -0
- package/esm/button/button-icon.js +29 -0
- package/esm/button/button-loading.js +17 -0
- package/esm/button/button.drip.js +57 -0
- package/esm/button/button.js +146 -0
- package/esm/button/index.js +2 -0
- package/esm/button/stories.js +221 -0
- package/esm/button/styles.js +232 -0
- package/esm/button/utils.js +46 -0
- package/esm/button-dropdown/button-dropdown-context.js +11 -0
- package/esm/button-dropdown/button-dropdown-item.js +52 -0
- package/esm/button-dropdown/button-dropdown.js +111 -0
- package/esm/button-dropdown/icon.js +30 -0
- package/esm/button-dropdown/index.js +4 -0
- package/esm/button-dropdown/stories.js +92 -0
- package/esm/button-dropdown/styles.js +60 -0
- package/esm/button-group/button-group-context.js +9 -0
- package/esm/button-group/button-group.js +75 -0
- package/esm/button-group/index.js +2 -0
- package/esm/button-group/stories.js +66 -0
- package/esm/capacity/capacity.js +52 -0
- package/esm/capacity/index.js +2 -0
- package/esm/capacity/stories.js +55 -0
- package/esm/card/card-content.js +28 -0
- package/esm/card/card-footer.js +36 -0
- package/esm/card/card.js +68 -0
- package/esm/card/index.js +8 -0
- package/esm/card/stories.js +126 -0
- package/esm/card/styles.js +45 -0
- package/esm/checkbox/checkbox-context.js +10 -0
- package/esm/checkbox/checkbox-group.js +70 -0
- package/esm/checkbox/checkbox.icon.js +50 -0
- package/esm/checkbox/checkbox.js +114 -0
- package/esm/checkbox/index.js +4 -0
- package/esm/checkbox/stories.js +84 -0
- package/esm/checkbox/styles.js +34 -0
- package/esm/code/code.js +57 -0
- package/esm/code/index.js +2 -0
- package/esm/code/stories.js +53 -0
- package/esm/col/col.js +29 -0
- package/esm/col/index.js +2 -0
- package/esm/collapse/collapse-context.js +8 -0
- package/esm/collapse/collapse-group.js +75 -0
- package/esm/collapse/collapse-icon.js +28 -0
- package/esm/collapse/collapse.js +93 -0
- package/esm/collapse/index.js +4 -0
- package/esm/collapse/stories.js +48 -0
- package/esm/container/container.js +62 -0
- package/esm/container/index.js +2 -0
- package/esm/css-baseline/css-baseline.js +18 -0
- package/esm/css-baseline/index.js +1 -0
- package/esm/description/description.js +39 -0
- package/esm/description/index.js +2 -0
- package/esm/description/stories.js +23 -0
- package/esm/display/display.js +43 -0
- package/esm/display/index.js +2 -0
- package/esm/divider/divider.js +65 -0
- package/esm/divider/index.js +2 -0
- package/esm/divider/stories.js +41 -0
- package/esm/dot/dot.js +53 -0
- package/esm/dot/index.js +2 -0
- package/esm/dot/stories.js +40 -0
- package/esm/drawer/drawer-wrapper.js +86 -0
- package/esm/drawer/drawer.js +77 -0
- package/esm/drawer/helper.js +27 -0
- package/esm/drawer/index.js +8 -0
- package/esm/drawer/stories.js +79 -0
- package/esm/fieldset/fieldset-content.js +29 -0
- package/esm/fieldset/fieldset-context.js +9 -0
- package/esm/fieldset/fieldset-footer.js +30 -0
- package/esm/fieldset/fieldset-group.js +88 -0
- package/esm/fieldset/fieldset-subtitle.js +21 -0
- package/esm/fieldset/fieldset-title.js +23 -0
- package/esm/fieldset/fieldset.js +96 -0
- package/esm/fieldset/index.js +13 -0
- package/esm/fieldset/stories.js +72 -0
- package/esm/grid/basic-item.js +96 -0
- package/esm/grid/grid-container.js +46 -0
- package/esm/grid/grid-types.js +6 -0
- package/esm/grid/grid.js +37 -0
- package/esm/grid/index.js +4 -0
- package/esm/grid/stories.js +212 -0
- package/esm/icon/stories.js +36 -0
- package/esm/image/helpers.js +16 -0
- package/esm/image/image-browser-https-icon.js +23 -0
- package/esm/image/image-browser.js +86 -0
- package/esm/image/image.js +91 -0
- package/esm/image/image.skeleton.js +21 -0
- package/esm/image/index.js +4 -0
- package/esm/image/stories.js +73 -0
- package/esm/image/styles.js +15 -0
- package/esm/index.js +69 -0
- package/esm/input/index.js +6 -0
- package/esm/input/input-block-label.js +18 -0
- package/esm/input/input-icon-clear.js +47 -0
- package/esm/input/input-icon.js +19 -0
- package/esm/input/input-label.js +18 -0
- package/esm/input/input-props.js +12 -0
- package/esm/input/input.js +179 -0
- package/esm/input/password-icon.js +30 -0
- package/esm/input/password.js +66 -0
- package/esm/input/stories.js +113 -0
- package/esm/input/styles.js +41 -0
- package/esm/keyboard/index.js +2 -0
- package/esm/keyboard/keyboard.js +48 -0
- package/esm/keyboard/stories.js +43 -0
- package/esm/link/icon.js +30 -0
- package/esm/link/index.js +2 -0
- package/esm/link/link.js +50 -0
- package/esm/link/stories.js +59 -0
- package/esm/loading/index.js +2 -0
- package/esm/loading/loading.js +63 -0
- package/esm/loading/stories.js +75 -0
- package/esm/mdx-widgets/index.js +2 -0
- package/esm/mdx-widgets/mock-page.js +37 -0
- package/esm/mdx-widgets/parsed-codes/index.js +1 -0
- package/esm/mdx-widgets/parsed-codes/wait-time.js +13 -0
- package/esm/modal/index.js +10 -0
- package/esm/modal/modal-action.js +76 -0
- package/esm/modal/modal-actions.js +39 -0
- package/esm/modal/modal-content.js +28 -0
- package/esm/modal/modal-context.js +6 -0
- package/esm/modal/modal-subtitle.js +30 -0
- package/esm/modal/modal-title.js +30 -0
- package/esm/modal/modal-wrapper.js +80 -0
- package/esm/modal/modal.js +104 -0
- package/esm/modal/stories.js +165 -0
- package/esm/note/index.js +2 -0
- package/esm/note/note.js +71 -0
- package/esm/note/stories.js +68 -0
- package/esm/page/index.js +9 -0
- package/esm/page/page-content.js +26 -0
- package/esm/page/page-footer.js +25 -0
- package/esm/page/page-header.js +33 -0
- package/esm/page/page.js +88 -0
- package/esm/page/stories.js +54 -0
- package/esm/pagination/index.js +6 -0
- package/esm/pagination/pagination-context.js +8 -0
- package/esm/pagination/pagination-ellipsis.js +73 -0
- package/esm/pagination/pagination-item.js +50 -0
- package/esm/pagination/pagination-next.js +25 -0
- package/esm/pagination/pagination-pages.js +90 -0
- package/esm/pagination/pagination-previous.js +25 -0
- package/esm/pagination/pagination.js +105 -0
- package/esm/pagination/stories.js +49 -0
- package/esm/popover/index.js +5 -0
- package/esm/popover/popover-context.js +9 -0
- package/esm/popover/popover-item.js +65 -0
- package/esm/popover/popover.js +83 -0
- package/esm/popover/stories.js +84 -0
- package/esm/progress/index.js +2 -0
- package/esm/progress/progress.js +76 -0
- package/esm/progress/stories.js +114 -0
- package/esm/radio/index.js +7 -0
- package/esm/radio/radio-context.js +9 -0
- package/esm/radio/radio-description.js +30 -0
- package/esm/radio/radio-group.js +61 -0
- package/esm/radio/radio.js +123 -0
- package/esm/radio/stories.js +98 -0
- package/esm/radio/styles.js +41 -0
- package/esm/rating/index.js +2 -0
- package/esm/rating/rating-icon.js +20 -0
- package/esm/rating/rating.js +115 -0
- package/esm/rating/stories.js +72 -0
- package/esm/row/index.js +2 -0
- package/esm/row/row.js +60 -0
- package/esm/section/index.js +2 -0
- package/esm/section/section.js +30 -0
- package/esm/select/index.js +4 -0
- package/esm/select/select-context.js +9 -0
- package/esm/select/select-dropdown.js +41 -0
- package/esm/select/select-icon-clear.js +41 -0
- package/esm/select/select-icon.js +23 -0
- package/esm/select/select-input.js +34 -0
- package/esm/select/select-multiple-value.js +23 -0
- package/esm/select/select-option.js +100 -0
- package/esm/select/select.js +244 -0
- package/esm/select/stories.js +239 -0
- package/esm/select/styles.js +48 -0
- package/esm/shared/backdrop.js +77 -0
- package/esm/shared/css-transition.js +71 -0
- package/esm/shared/dropdown.js +109 -0
- package/esm/shared/ellipsis.js +15 -0
- package/esm/shared/expand.js +95 -0
- package/esm/shared/highlight.js +47 -0
- package/esm/slider/index.js +2 -0
- package/esm/slider/slider-dot.js +27 -0
- package/esm/slider/slider-mark.js +38 -0
- package/esm/slider/slider.js +163 -0
- package/esm/slider/stories.js +134 -0
- package/esm/slider/styles.js +27 -0
- package/esm/snippet/index.js +2 -0
- package/esm/snippet/snippet-icon.js +27 -0
- package/esm/snippet/snippet.js +100 -0
- package/esm/snippet/stories.js +133 -0
- package/esm/snippet/styles.js +58 -0
- package/esm/spacer/index.js +2 -0
- package/esm/spacer/spacer.js +28 -0
- package/esm/spacer/stories.js +54 -0
- package/esm/spinner/index.js +2 -0
- package/esm/spinner/spinner.js +46 -0
- package/esm/spinner/stories.js +13 -0
- package/esm/styled-jsx-server.es.js +5 -0
- package/esm/styled-jsx.es.js +757 -0
- package/esm/tabs/index.js +5 -0
- package/esm/tabs/stories.js +92 -0
- package/esm/tabs/tabs-context.js +8 -0
- package/esm/tabs/tabs-item.js +80 -0
- package/esm/tabs/tabs.js +151 -0
- package/esm/tag/index.js +2 -0
- package/esm/tag/stories.js +58 -0
- package/esm/tag/tag.js +86 -0
- package/esm/text/child.js +78 -0
- package/esm/text/index.js +2 -0
- package/esm/text/stories.js +104 -0
- package/esm/text/text.js +94 -0
- package/esm/textarea/index.js +2 -0
- package/esm/textarea/stories.js +104 -0
- package/esm/textarea/textarea.js +116 -0
- package/esm/themes/index.js +2 -0
- package/esm/themes/presets/dark.js +67 -0
- package/esm/themes/presets/default.js +67 -0
- package/esm/themes/presets/index.js +1 -0
- package/esm/themes/presets/shared.js +42 -0
- package/esm/themes/themes.js +89 -0
- package/esm/toggle/index.js +2 -0
- package/esm/toggle/stories.js +55 -0
- package/esm/toggle/styles.js +27 -0
- package/esm/toggle/toggle.js +82 -0
- package/esm/tooltip/helper.js +21 -0
- package/esm/tooltip/index.js +2 -0
- package/esm/tooltip/placement.js +160 -0
- package/esm/tooltip/stories.js +183 -0
- package/esm/tooltip/styles.js +18 -0
- package/esm/tooltip/tooltip-content.js +83 -0
- package/esm/tooltip/tooltip-icon.js +32 -0
- package/esm/tooltip/tooltip.js +132 -0
- package/esm/use-all-themes/all-themes-context.js +9 -0
- package/esm/use-all-themes/index.js +2 -0
- package/esm/use-body-scroll/index.js +2 -0
- package/esm/use-body-scroll/use-body-scroll.js +70 -0
- package/esm/use-classes/index.js +2 -0
- package/esm/use-classes/use-classes.js +41 -0
- package/esm/use-click-away/index.js +2 -0
- package/esm/use-click-away/use-click-away.js +22 -0
- package/esm/use-clipboard/index.js +2 -0
- package/esm/use-clipboard/use-clipboard.js +46 -0
- package/esm/use-current-state/index.js +2 -0
- package/esm/use-current-state/use-current-state.js +26 -0
- package/esm/use-input/index.js +2 -0
- package/esm/use-input/use-input.js +32 -0
- package/esm/use-keyboard/codes.js +97 -0
- package/esm/use-keyboard/helper.js +26 -0
- package/esm/use-keyboard/index.js +4 -0
- package/esm/use-keyboard/use-keyboard.js +79 -0
- package/esm/use-media-query/index.js +2 -0
- package/esm/use-media-query/use-media-query.js +90 -0
- package/esm/use-modal/index.js +2 -0
- package/esm/use-modal/use-modal.js +26 -0
- package/esm/use-scale/index.js +6 -0
- package/esm/use-scale/scale-context.js +37 -0
- package/esm/use-scale/utils.js +62 -0
- package/esm/use-scale/with-scale.js +114 -0
- package/esm/use-tabs/index.js +2 -0
- package/esm/use-tabs/use-tabs.js +24 -0
- package/esm/use-theme/index.js +2 -0
- package/esm/use-theme/theme-context.js +7 -0
- package/esm/use-toasts/helpers.js +72 -0
- package/esm/use-toasts/index.js +2 -0
- package/esm/use-toasts/toast-container.js +127 -0
- package/esm/use-toasts/toast-item.js +48 -0
- package/esm/use-toasts/use-toast.js +124 -0
- package/esm/utils/calculations.js +27 -0
- package/esm/utils/collections.js +138 -0
- package/esm/utils/color.js +43 -0
- package/esm/utils/layouts.js +82 -0
- package/esm/utils/prop-types.js +22 -0
- package/esm/utils/types.js +1 -0
- package/esm/utils/use-body-scroll.js +2 -0
- package/esm/utils/use-bolio-ui-context.js +27 -0
- package/esm/utils/use-click-anywhere.js +16 -0
- package/esm/utils/use-click-away.js +2 -0
- package/esm/utils/use-clipboard.js +2 -0
- package/esm/utils/use-context-state/create-bolio-ui-context.js +57 -0
- package/esm/utils/use-context-state/use-context-state.js +44 -0
- package/esm/utils/use-current-state.js +2 -0
- package/esm/utils/use-default-props.js +22 -0
- package/esm/utils/use-dom-observer.js +28 -0
- package/esm/utils/use-drag.js +75 -0
- package/esm/utils/use-portal.js +40 -0
- package/esm/utils/use-previous.js +11 -0
- package/esm/utils/use-real-shape.js +53 -0
- package/esm/utils/use-resize.js +21 -0
- package/esm/utils/use-ssr.js +20 -0
- package/esm/utils/use-warning.js +17 -0
- package/package.json +140 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { KeyMod } from './codes';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { getActiveModMap, getCtrlKeysByPlatform } from './helper';
|
|
4
|
+
|
|
5
|
+
var useKeyboard = function useKeyboard(handler, keyBindings) {
|
|
6
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
7
|
+
var bindings = Array.isArray(keyBindings) ? keyBindings : [keyBindings];
|
|
8
|
+
var _options$disableGloba = options.disableGlobalEvent,
|
|
9
|
+
disableGlobalEvent = _options$disableGloba === void 0 ? false : _options$disableGloba,
|
|
10
|
+
_options$capture = options.capture,
|
|
11
|
+
capture = _options$capture === void 0 ? false : _options$capture,
|
|
12
|
+
_options$stopPropagat = options.stopPropagation,
|
|
13
|
+
stopPropagation = _options$stopPropagat === void 0 ? false : _options$stopPropagat,
|
|
14
|
+
_options$preventDefau = options.preventDefault,
|
|
15
|
+
preventDefault = _options$preventDefau === void 0 ? true : _options$preventDefau,
|
|
16
|
+
_options$event = options.event,
|
|
17
|
+
event = _options$event === void 0 ? 'keydown' : _options$event;
|
|
18
|
+
var activeModMap = getActiveModMap(bindings);
|
|
19
|
+
var keyCode = bindings.filter(function (item) {
|
|
20
|
+
return !KeyMod[item];
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
var _getCtrlKeysByPlatfor = getCtrlKeysByPlatform(),
|
|
24
|
+
CtrlCmd = _getCtrlKeysByPlatfor.CtrlCmd,
|
|
25
|
+
WinCtrl = _getCtrlKeysByPlatfor.WinCtrl;
|
|
26
|
+
|
|
27
|
+
var eventHandler = function eventHandler(event) {
|
|
28
|
+
if (activeModMap.Shift && !event.shiftKey) return;
|
|
29
|
+
if (activeModMap.Alt && !event.altKey) return;
|
|
30
|
+
if (activeModMap.CtrlCmd && !event[CtrlCmd]) return;
|
|
31
|
+
if (activeModMap.WinCtrl && !event[WinCtrl]) return;
|
|
32
|
+
var hitOne = keyCode.find(function (k) {
|
|
33
|
+
return k === event.keyCode;
|
|
34
|
+
});
|
|
35
|
+
if (keyCode && !hitOne) return;
|
|
36
|
+
|
|
37
|
+
if (stopPropagation) {
|
|
38
|
+
event.stopPropagation();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (preventDefault) {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
handler && handler(event);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
useEffect(function () {
|
|
49
|
+
if (!disableGlobalEvent) {
|
|
50
|
+
document.addEventListener(event, eventHandler);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return function () {
|
|
54
|
+
document.removeEventListener(event, eventHandler);
|
|
55
|
+
};
|
|
56
|
+
}, [disableGlobalEvent]);
|
|
57
|
+
|
|
58
|
+
var elementBindingHandler = function elementBindingHandler(elementEventType) {
|
|
59
|
+
var isCapture = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
60
|
+
if (elementEventType !== event) return function () {};
|
|
61
|
+
if (isCapture !== capture) return function () {};
|
|
62
|
+
return function (e) {
|
|
63
|
+
return eventHandler(e);
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
bindings: {
|
|
69
|
+
onKeyDown: elementBindingHandler('keydown'),
|
|
70
|
+
onKeyDownCapture: elementBindingHandler('keydown', true),
|
|
71
|
+
onKeyPress: elementBindingHandler('keypress'),
|
|
72
|
+
onKeyPressCapture: elementBindingHandler('keypress', true),
|
|
73
|
+
onKeyUp: elementBindingHandler('keyup'),
|
|
74
|
+
onKeyUpCapture: elementBindingHandler('keyup', true)
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default useKeyboard;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import useTheme from '../use-theme';
|
|
4
|
+
import { tuple } from '../utils/prop-types';
|
|
5
|
+
var breakpoints = tuple('xs', 'sm', 'md', 'lg', 'xl', 'mobile');
|
|
6
|
+
var matchType = tuple('up', 'down', 'default');
|
|
7
|
+
var defaultResponsiveOptions = {
|
|
8
|
+
match: 'default'
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
var makeQueries = function makeQueries(bp, up, down) {
|
|
12
|
+
var queryString = function queryString(item) {
|
|
13
|
+
var upQuery = "(min-width: ".concat(item.min, ")");
|
|
14
|
+
var downQuery = "(max-width: ".concat(item.max, ")");
|
|
15
|
+
return up ? upQuery : down ? downQuery : "".concat(upQuery, " and ").concat(downQuery);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
var xs = queryString(bp.xs);
|
|
19
|
+
return {
|
|
20
|
+
xs: xs,
|
|
21
|
+
mobile: xs,
|
|
22
|
+
sm: queryString(bp.sm),
|
|
23
|
+
md: queryString(bp.md),
|
|
24
|
+
lg: queryString(bp.lg),
|
|
25
|
+
xl: queryString(bp.xl)
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
var useMediaQuery = function useMediaQuery(breakpoint) {
|
|
30
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultResponsiveOptions;
|
|
31
|
+
var _options$match = options.match,
|
|
32
|
+
matchType = _options$match === void 0 ? 'default' : _options$match,
|
|
33
|
+
_options$ssrMatchMedi = options.ssrMatchMedia,
|
|
34
|
+
ssrMatchMedia = _options$ssrMatchMedi === void 0 ? null : _options$ssrMatchMedi;
|
|
35
|
+
var supportMedia = typeof window !== 'undefined' && typeof window.matchMedia !== 'undefined';
|
|
36
|
+
var theme = useTheme();
|
|
37
|
+
var mediaQueries = useMemo(function () {
|
|
38
|
+
var up = matchType === 'up';
|
|
39
|
+
var down = matchType === 'down';
|
|
40
|
+
return makeQueries(theme.breakpoints, up, down);
|
|
41
|
+
}, [matchType, theme.breakpoints]);
|
|
42
|
+
var query = useMemo(function () {
|
|
43
|
+
return mediaQueries[breakpoint];
|
|
44
|
+
}, [mediaQueries, breakpoint]);
|
|
45
|
+
|
|
46
|
+
var matchQuery = function matchQuery(q) {
|
|
47
|
+
return window.matchMedia(q);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Do nothing in the server-side rendering.
|
|
51
|
+
* If server match query fucntion is simulated, return user-defined value first.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
var _useState = useState(function () {
|
|
56
|
+
if (supportMedia) return matchQuery(query).matches;
|
|
57
|
+
|
|
58
|
+
if (ssrMatchMedia && typeof ssrMatchMedia === 'function') {
|
|
59
|
+
return ssrMatchMedia(query).matches;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return false;
|
|
63
|
+
}),
|
|
64
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
65
|
+
state = _useState2[0],
|
|
66
|
+
setState = _useState2[1];
|
|
67
|
+
|
|
68
|
+
useEffect(function () {
|
|
69
|
+
if (!supportMedia) return;
|
|
70
|
+
var queryList = matchQuery(query);
|
|
71
|
+
|
|
72
|
+
var update = function update() {
|
|
73
|
+
return setState(matchQuery(query).matches);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
update();
|
|
77
|
+
/**
|
|
78
|
+
* addListener is deprecated. EventTarget.addEventListener is recommended.
|
|
79
|
+
* But in some old browsers, MediaQueryList does not inherit from EventTarget.
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
queryList.addListener(update);
|
|
83
|
+
return function () {
|
|
84
|
+
queryList.removeListener(update);
|
|
85
|
+
};
|
|
86
|
+
}, [query, supportMedia]);
|
|
87
|
+
return state;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default useMediaQuery;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import useCurrentState from '../utils/use-current-state';
|
|
3
|
+
|
|
4
|
+
var useModal = function useModal() {
|
|
5
|
+
var initialVisible = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
6
|
+
|
|
7
|
+
var _useCurrentState = useCurrentState(initialVisible),
|
|
8
|
+
_useCurrentState2 = _slicedToArray(_useCurrentState, 3),
|
|
9
|
+
visible = _useCurrentState2[0],
|
|
10
|
+
setVisible = _useCurrentState2[1],
|
|
11
|
+
currentRef = _useCurrentState2[2];
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
visible: visible,
|
|
15
|
+
setVisible: setVisible,
|
|
16
|
+
currentRef: currentRef,
|
|
17
|
+
bindings: {
|
|
18
|
+
visible: visible,
|
|
19
|
+
onClose: function onClose() {
|
|
20
|
+
return setVisible(false);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default useModal;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export var ScalePropKeys = ['width', 'height', 'padding', 'margin', 'w', 'h', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'pl', 'pr', 'pt', 'pb', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom', 'ml', 'mr', 'mt', 'mb', 'px', 'py', 'mx', 'my', 'font', 'unit', 'scale'];
|
|
3
|
+
|
|
4
|
+
var defaultDynamicLayoutPipe = function defaultDynamicLayoutPipe(scale1x) {
|
|
5
|
+
return "".concat(scale1x);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
var defaultContext = {
|
|
9
|
+
getScaleProps: function getScaleProps() {
|
|
10
|
+
return undefined;
|
|
11
|
+
},
|
|
12
|
+
getAllScaleProps: function getAllScaleProps() {
|
|
13
|
+
return {};
|
|
14
|
+
},
|
|
15
|
+
SCALES: {
|
|
16
|
+
pl: defaultDynamicLayoutPipe,
|
|
17
|
+
pr: defaultDynamicLayoutPipe,
|
|
18
|
+
pb: defaultDynamicLayoutPipe,
|
|
19
|
+
pt: defaultDynamicLayoutPipe,
|
|
20
|
+
px: defaultDynamicLayoutPipe,
|
|
21
|
+
py: defaultDynamicLayoutPipe,
|
|
22
|
+
mb: defaultDynamicLayoutPipe,
|
|
23
|
+
ml: defaultDynamicLayoutPipe,
|
|
24
|
+
mr: defaultDynamicLayoutPipe,
|
|
25
|
+
mt: defaultDynamicLayoutPipe,
|
|
26
|
+
mx: defaultDynamicLayoutPipe,
|
|
27
|
+
my: defaultDynamicLayoutPipe,
|
|
28
|
+
width: defaultDynamicLayoutPipe,
|
|
29
|
+
height: defaultDynamicLayoutPipe,
|
|
30
|
+
font: defaultDynamicLayoutPipe
|
|
31
|
+
},
|
|
32
|
+
unit: '16px'
|
|
33
|
+
};
|
|
34
|
+
export var ScaleContext = /*#__PURE__*/React.createContext(defaultContext);
|
|
35
|
+
export var useScale = function useScale() {
|
|
36
|
+
return React.useContext(ScaleContext);
|
|
37
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
|
|
5
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
6
|
+
|
|
7
|
+
import { ScalePropKeys } from './scale-context';
|
|
8
|
+
export var generateGetScaleProps = function generateGetScaleProps(props) {
|
|
9
|
+
var getScaleProps = function getScaleProps(keyOrKeys) {
|
|
10
|
+
if (!Array.isArray(keyOrKeys)) return props[keyOrKeys];
|
|
11
|
+
var value = undefined;
|
|
12
|
+
|
|
13
|
+
var _iterator = _createForOfIteratorHelper(keyOrKeys),
|
|
14
|
+
_step;
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
18
|
+
var key = _step.value;
|
|
19
|
+
var currentValue = props[key];
|
|
20
|
+
|
|
21
|
+
if (typeof currentValue !== 'undefined') {
|
|
22
|
+
value = currentValue;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
} catch (err) {
|
|
26
|
+
_iterator.e(err);
|
|
27
|
+
} finally {
|
|
28
|
+
_iterator.f();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return value;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return getScaleProps;
|
|
35
|
+
};
|
|
36
|
+
export var generateGetAllScaleProps = function generateGetAllScaleProps(props) {
|
|
37
|
+
var getAllScaleProps = function getAllScaleProps() {
|
|
38
|
+
var scaleProps = {};
|
|
39
|
+
|
|
40
|
+
var _iterator2 = _createForOfIteratorHelper(ScalePropKeys),
|
|
41
|
+
_step2;
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
45
|
+
var key = _step2.value;
|
|
46
|
+
var value = props[key];
|
|
47
|
+
|
|
48
|
+
if (typeof value !== 'undefined') {
|
|
49
|
+
scaleProps[key] = value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
_iterator2.e(err);
|
|
54
|
+
} finally {
|
|
55
|
+
_iterator2.f();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return scaleProps;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return getAllScaleProps;
|
|
62
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["children"],
|
|
4
|
+
_excluded2 = ["paddingLeft", "pl", "paddingRight", "pr", "paddingTop", "pt", "paddingBottom", "pb", "marginTop", "mt", "marginRight", "mr", "marginBottom", "mb", "marginLeft", "ml", "px", "py", "mx", "my", "width", "height", "font", "w", "h", "margin", "padding", "unit", "scale"];
|
|
5
|
+
import React, { forwardRef } from 'react';
|
|
6
|
+
import { ScaleContext } from './scale-context';
|
|
7
|
+
import useTheme from '../use-theme';
|
|
8
|
+
import { isCSSNumberValue } from '../utils/collections';
|
|
9
|
+
import { generateGetAllScaleProps, generateGetScaleProps } from './utils';
|
|
10
|
+
|
|
11
|
+
var reduceScaleCoefficient = function reduceScaleCoefficient(scale) {
|
|
12
|
+
if (scale === 1) return scale;
|
|
13
|
+
var diff = Math.abs((scale - 1) / 2);
|
|
14
|
+
return scale > 1 ? 1 + diff : 1 - diff;
|
|
15
|
+
}; // eslint-disable-next-line @typescript-eslint/ban-types
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var withScale = function withScale(Render) {
|
|
19
|
+
var ScaleFC = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
20
|
+
var _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _ref10, _ref11, _ref12, _ref13, _ref14, _ref15, _ref16, _ref17, _ref18, _ref19, _ref20, _ref21, _ref22, _ref23, _ref24, _ref25, _ref26, _ref27, _ref28, _ref29, _ref30, _ref31, _ref32, _ref33;
|
|
21
|
+
|
|
22
|
+
var children = _ref.children,
|
|
23
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
24
|
+
|
|
25
|
+
var _useTheme = useTheme(),
|
|
26
|
+
layout = _useTheme.layout;
|
|
27
|
+
|
|
28
|
+
var paddingLeft = props.paddingLeft,
|
|
29
|
+
pl = props.pl,
|
|
30
|
+
paddingRight = props.paddingRight,
|
|
31
|
+
pr = props.pr,
|
|
32
|
+
paddingTop = props.paddingTop,
|
|
33
|
+
pt = props.pt,
|
|
34
|
+
paddingBottom = props.paddingBottom,
|
|
35
|
+
pb = props.pb,
|
|
36
|
+
marginTop = props.marginTop,
|
|
37
|
+
mt = props.mt,
|
|
38
|
+
marginRight = props.marginRight,
|
|
39
|
+
mr = props.mr,
|
|
40
|
+
marginBottom = props.marginBottom,
|
|
41
|
+
mb = props.mb,
|
|
42
|
+
marginLeft = props.marginLeft,
|
|
43
|
+
ml = props.ml,
|
|
44
|
+
px = props.px,
|
|
45
|
+
py = props.py,
|
|
46
|
+
mx = props.mx,
|
|
47
|
+
my = props.my,
|
|
48
|
+
width = props.width,
|
|
49
|
+
height = props.height,
|
|
50
|
+
font = props.font,
|
|
51
|
+
w = props.w,
|
|
52
|
+
h = props.h,
|
|
53
|
+
margin = props.margin,
|
|
54
|
+
padding = props.padding,
|
|
55
|
+
_props$unit = props.unit,
|
|
56
|
+
unit = _props$unit === void 0 ? layout.unit : _props$unit,
|
|
57
|
+
_props$scale = props.scale,
|
|
58
|
+
scale = _props$scale === void 0 ? 1 : _props$scale,
|
|
59
|
+
innerProps = _objectWithoutProperties(props, _excluded2);
|
|
60
|
+
|
|
61
|
+
var makeScaleHandler = function makeScaleHandler(attrValue) {
|
|
62
|
+
return function (scale1x, defaultValue) {
|
|
63
|
+
// 0 means disable scale and the default value is 0
|
|
64
|
+
if (scale1x === 0) {
|
|
65
|
+
scale1x = 1;
|
|
66
|
+
defaultValue = defaultValue || 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var factor = reduceScaleCoefficient(scale) * scale1x;
|
|
70
|
+
|
|
71
|
+
if (typeof attrValue === 'undefined') {
|
|
72
|
+
if (typeof defaultValue !== 'undefined') return "".concat(defaultValue);
|
|
73
|
+
return "calc(".concat(factor, " * ").concat(unit, ")");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!isCSSNumberValue(attrValue)) return "".concat(attrValue);
|
|
77
|
+
var customFactor = factor * Number(attrValue);
|
|
78
|
+
return "calc(".concat(customFactor, " * ").concat(unit, ")");
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
var value = {
|
|
83
|
+
unit: unit,
|
|
84
|
+
SCALES: {
|
|
85
|
+
pt: makeScaleHandler((_ref2 = (_ref3 = paddingTop !== null && paddingTop !== void 0 ? paddingTop : pt) !== null && _ref3 !== void 0 ? _ref3 : py) !== null && _ref2 !== void 0 ? _ref2 : padding),
|
|
86
|
+
pr: makeScaleHandler((_ref4 = (_ref5 = paddingRight !== null && paddingRight !== void 0 ? paddingRight : pr) !== null && _ref5 !== void 0 ? _ref5 : px) !== null && _ref4 !== void 0 ? _ref4 : padding),
|
|
87
|
+
pb: makeScaleHandler((_ref6 = (_ref7 = paddingBottom !== null && paddingBottom !== void 0 ? paddingBottom : pb) !== null && _ref7 !== void 0 ? _ref7 : py) !== null && _ref6 !== void 0 ? _ref6 : padding),
|
|
88
|
+
pl: makeScaleHandler((_ref8 = (_ref9 = paddingLeft !== null && paddingLeft !== void 0 ? paddingLeft : pl) !== null && _ref9 !== void 0 ? _ref9 : px) !== null && _ref8 !== void 0 ? _ref8 : padding),
|
|
89
|
+
px: makeScaleHandler((_ref10 = (_ref11 = (_ref12 = (_ref13 = px !== null && px !== void 0 ? px : paddingLeft) !== null && _ref13 !== void 0 ? _ref13 : paddingRight) !== null && _ref12 !== void 0 ? _ref12 : pl) !== null && _ref11 !== void 0 ? _ref11 : pr) !== null && _ref10 !== void 0 ? _ref10 : padding),
|
|
90
|
+
py: makeScaleHandler((_ref14 = (_ref15 = (_ref16 = (_ref17 = py !== null && py !== void 0 ? py : paddingTop) !== null && _ref17 !== void 0 ? _ref17 : paddingBottom) !== null && _ref16 !== void 0 ? _ref16 : pt) !== null && _ref15 !== void 0 ? _ref15 : pb) !== null && _ref14 !== void 0 ? _ref14 : padding),
|
|
91
|
+
mt: makeScaleHandler((_ref18 = (_ref19 = marginTop !== null && marginTop !== void 0 ? marginTop : mt) !== null && _ref19 !== void 0 ? _ref19 : my) !== null && _ref18 !== void 0 ? _ref18 : margin),
|
|
92
|
+
mr: makeScaleHandler((_ref20 = (_ref21 = marginRight !== null && marginRight !== void 0 ? marginRight : mr) !== null && _ref21 !== void 0 ? _ref21 : mx) !== null && _ref20 !== void 0 ? _ref20 : margin),
|
|
93
|
+
mb: makeScaleHandler((_ref22 = (_ref23 = marginBottom !== null && marginBottom !== void 0 ? marginBottom : mb) !== null && _ref23 !== void 0 ? _ref23 : my) !== null && _ref22 !== void 0 ? _ref22 : margin),
|
|
94
|
+
ml: makeScaleHandler((_ref24 = (_ref25 = marginLeft !== null && marginLeft !== void 0 ? marginLeft : ml) !== null && _ref25 !== void 0 ? _ref25 : mx) !== null && _ref24 !== void 0 ? _ref24 : margin),
|
|
95
|
+
mx: makeScaleHandler((_ref26 = (_ref27 = (_ref28 = (_ref29 = mx !== null && mx !== void 0 ? mx : marginLeft) !== null && _ref29 !== void 0 ? _ref29 : marginRight) !== null && _ref28 !== void 0 ? _ref28 : ml) !== null && _ref27 !== void 0 ? _ref27 : mr) !== null && _ref26 !== void 0 ? _ref26 : margin),
|
|
96
|
+
my: makeScaleHandler((_ref30 = (_ref31 = (_ref32 = (_ref33 = my !== null && my !== void 0 ? my : marginTop) !== null && _ref33 !== void 0 ? _ref33 : marginBottom) !== null && _ref32 !== void 0 ? _ref32 : mt) !== null && _ref31 !== void 0 ? _ref31 : mb) !== null && _ref30 !== void 0 ? _ref30 : margin),
|
|
97
|
+
width: makeScaleHandler(width !== null && width !== void 0 ? width : w),
|
|
98
|
+
height: makeScaleHandler(height !== null && height !== void 0 ? height : h),
|
|
99
|
+
font: makeScaleHandler(font)
|
|
100
|
+
},
|
|
101
|
+
getScaleProps: generateGetScaleProps(props),
|
|
102
|
+
getAllScaleProps: generateGetAllScaleProps(props)
|
|
103
|
+
};
|
|
104
|
+
return /*#__PURE__*/React.createElement(ScaleContext.Provider, {
|
|
105
|
+
value: value
|
|
106
|
+
}, /*#__PURE__*/React.createElement(Render, _extends({}, innerProps, {
|
|
107
|
+
ref: ref
|
|
108
|
+
}), children));
|
|
109
|
+
});
|
|
110
|
+
ScaleFC.displayName = "Scale".concat(Render.displayName || 'Wrapper');
|
|
111
|
+
return ScaleFC;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export default withScale;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import useCurrentState from '../utils/use-current-state';
|
|
3
|
+
|
|
4
|
+
var useTabs = function useTabs(initialValue) {
|
|
5
|
+
var _useCurrentState = useCurrentState(initialValue),
|
|
6
|
+
_useCurrentState2 = _slicedToArray(_useCurrentState, 3),
|
|
7
|
+
state = _useCurrentState2[0],
|
|
8
|
+
setState = _useCurrentState2[1],
|
|
9
|
+
currentRef = _useCurrentState2[2];
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
state: state,
|
|
13
|
+
setState: setState,
|
|
14
|
+
currentRef: currentRef,
|
|
15
|
+
bindings: {
|
|
16
|
+
value: state,
|
|
17
|
+
onChange: function onChange(val) {
|
|
18
|
+
setState(val);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default useTabs;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Themes from '../themes';
|
|
3
|
+
var defaultTheme = Themes.getPresetStaticTheme();
|
|
4
|
+
export var ThemeContext = /*#__PURE__*/React.createContext(defaultTheme);
|
|
5
|
+
export var useTheme = function useTheme() {
|
|
6
|
+
return React.useContext(ThemeContext);
|
|
7
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Button from '../button';
|
|
3
|
+
import { tuple } from '../utils/prop-types';
|
|
4
|
+
export var makeToastActions = function makeToastActions(actions, cancelHandle) {
|
|
5
|
+
var handler = function handler(event, userHandler) {
|
|
6
|
+
userHandler && userHandler(event, cancelHandle);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
if (!actions || !actions.length) return null;
|
|
10
|
+
return actions.map(function (action, index) {
|
|
11
|
+
return /*#__PURE__*/React.createElement(Button, {
|
|
12
|
+
auto: true,
|
|
13
|
+
scale: 1 / 3,
|
|
14
|
+
font: "13px",
|
|
15
|
+
type: action.passive ? 'default' : 'primary',
|
|
16
|
+
key: "action-".concat(index),
|
|
17
|
+
onClick: function onClick(event) {
|
|
18
|
+
return handler(event, action.handler);
|
|
19
|
+
}
|
|
20
|
+
}, action.name);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
export var getColors = function getColors(palette, type) {
|
|
24
|
+
var colors = {
|
|
25
|
+
"default": palette.background,
|
|
26
|
+
primary: palette.primary,
|
|
27
|
+
secondary: palette.secondary,
|
|
28
|
+
success: palette.success,
|
|
29
|
+
warning: palette.warning,
|
|
30
|
+
error: palette.error,
|
|
31
|
+
info: palette.info
|
|
32
|
+
};
|
|
33
|
+
var isDefault = !type || type === 'default';
|
|
34
|
+
if (isDefault) return {
|
|
35
|
+
bgColor: colors["default"],
|
|
36
|
+
color: palette.foreground
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Prevent main color change in special types.
|
|
40
|
+
* The color will only follow the theme when it is in the default type.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
bgColor: colors[type],
|
|
45
|
+
color: 'white'
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
var toastPlacement = tuple('topLeft', 'topRight', 'bottomLeft', 'bottomRight');
|
|
49
|
+
export var isTopPlacement = function isTopPlacement(placement) {
|
|
50
|
+
return "".concat(placement).toLowerCase().startsWith('top');
|
|
51
|
+
};
|
|
52
|
+
export var isLeftPlacement = function isLeftPlacement(placement) {
|
|
53
|
+
return "".concat(placement).toLowerCase().endsWith('left');
|
|
54
|
+
};
|
|
55
|
+
export var getTranslateByPlacement = function getTranslateByPlacement(placement) {
|
|
56
|
+
var translateInByPlacement = {
|
|
57
|
+
topLeft: 'translate(-60px, -60px)',
|
|
58
|
+
topRight: 'translate(60px, -60px)',
|
|
59
|
+
bottomLeft: 'translate(-60px, 60px)',
|
|
60
|
+
bottomRight: 'translate(60px, 60px)'
|
|
61
|
+
};
|
|
62
|
+
var translateOutByPlacement = {
|
|
63
|
+
topLeft: 'translate(-50px, 15px) scale(0.85)',
|
|
64
|
+
topRight: 'translate(50px, 15px) scale(0.85)',
|
|
65
|
+
bottomLeft: 'translate(-50px, -15px) scale(0.85)',
|
|
66
|
+
bottomRight: 'translate(50px, -15px) scale(0.85)'
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
enter: translateInByPlacement[placement],
|
|
70
|
+
leave: translateOutByPlacement[placement]
|
|
71
|
+
};
|
|
72
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _JSXStyle from "../styled-jsx.es.js";
|
|
4
|
+
import React, { useEffect, useMemo } from 'react';
|
|
5
|
+
import { createPortal } from 'react-dom';
|
|
6
|
+
import usePortal from '../utils/use-portal';
|
|
7
|
+
import useTheme from '../use-theme';
|
|
8
|
+
import { useBolioUIContext } from '../utils/use-bolio-ui-context';
|
|
9
|
+
import ToastItem from './toast-item';
|
|
10
|
+
import useClasses from '../use-classes';
|
|
11
|
+
import { isLeftPlacement, isTopPlacement } from './helpers';
|
|
12
|
+
import useCurrentState from '../utils/use-current-state';
|
|
13
|
+
|
|
14
|
+
var ToastContainer = function ToastContainer() {
|
|
15
|
+
var theme = useTheme();
|
|
16
|
+
var portal = usePortal('toast');
|
|
17
|
+
|
|
18
|
+
var _useCurrentState = useCurrentState(false),
|
|
19
|
+
_useCurrentState2 = _slicedToArray(_useCurrentState, 3),
|
|
20
|
+
setHovering = _useCurrentState2[1],
|
|
21
|
+
hoveringRef = _useCurrentState2[2];
|
|
22
|
+
|
|
23
|
+
var _useBolioUIContext = useBolioUIContext(),
|
|
24
|
+
toasts = _useBolioUIContext.toasts,
|
|
25
|
+
updateToasts = _useBolioUIContext.updateToasts,
|
|
26
|
+
toastLayout = _useBolioUIContext.toastLayout,
|
|
27
|
+
lastUpdateToastId = _useBolioUIContext.lastUpdateToastId;
|
|
28
|
+
|
|
29
|
+
var memoizedLayout = useMemo(function () {
|
|
30
|
+
return toastLayout;
|
|
31
|
+
}, [toastLayout]);
|
|
32
|
+
var toastElements = useMemo(function () {
|
|
33
|
+
return toasts.map(function (toast) {
|
|
34
|
+
return /*#__PURE__*/React.createElement(ToastItem, {
|
|
35
|
+
toast: toast,
|
|
36
|
+
layout: memoizedLayout,
|
|
37
|
+
key: toast._internalIdent
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}, [toasts, memoizedLayout]);
|
|
41
|
+
var classNames = useMemo(function () {
|
|
42
|
+
return useClasses('toasts', {
|
|
43
|
+
top: isTopPlacement(toastLayout.placement),
|
|
44
|
+
left: isLeftPlacement(toastLayout.placement)
|
|
45
|
+
});
|
|
46
|
+
}, [memoizedLayout]);
|
|
47
|
+
|
|
48
|
+
var hoverHandler = function hoverHandler(isHovering) {
|
|
49
|
+
setHovering(isHovering);
|
|
50
|
+
|
|
51
|
+
if (isHovering) {
|
|
52
|
+
return updateToasts(function (last) {
|
|
53
|
+
return last.map(function (toast) {
|
|
54
|
+
if (!toast.visible) return toast;
|
|
55
|
+
toast._timeout && window.clearTimeout(toast._timeout);
|
|
56
|
+
return _extends({}, toast, {
|
|
57
|
+
timeout: null
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
updateToasts(function (last) {
|
|
64
|
+
return last.map(function (toast, index) {
|
|
65
|
+
if (!toast.visible) return toast;
|
|
66
|
+
toast._timeout && window.clearTimeout(toast._timeout);
|
|
67
|
+
return _extends({}, toast, {
|
|
68
|
+
_timeout: function () {
|
|
69
|
+
var timer = window.setTimeout(function () {
|
|
70
|
+
toast.cancel();
|
|
71
|
+
window.clearTimeout(timer);
|
|
72
|
+
}, toast.delay + index * 100);
|
|
73
|
+
return timer;
|
|
74
|
+
}()
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
useEffect(function () {
|
|
81
|
+
var index = toasts.findIndex(function (r) {
|
|
82
|
+
return r._internalIdent === lastUpdateToastId;
|
|
83
|
+
});
|
|
84
|
+
var toast = toasts[index];
|
|
85
|
+
if (!toast || toast.visible || !hoveringRef.current) return;
|
|
86
|
+
var hasVisible = toasts.find(function (r, i) {
|
|
87
|
+
return i < index && r.visible;
|
|
88
|
+
});
|
|
89
|
+
if (hasVisible || !hoveringRef.current) return;
|
|
90
|
+
hoverHandler(false);
|
|
91
|
+
}, [toasts, lastUpdateToastId]);
|
|
92
|
+
useEffect(function () {
|
|
93
|
+
var timeout = null;
|
|
94
|
+
var timer = window.setInterval(function () {
|
|
95
|
+
if (toasts.length === 0) return;
|
|
96
|
+
timeout = window.setTimeout(function () {
|
|
97
|
+
var allInvisible = !toasts.find(function (r) {
|
|
98
|
+
return r.visible;
|
|
99
|
+
});
|
|
100
|
+
allInvisible && updateToasts(function () {
|
|
101
|
+
return [];
|
|
102
|
+
});
|
|
103
|
+
timeout && clearTimeout(timeout);
|
|
104
|
+
}, 350);
|
|
105
|
+
}, 5000);
|
|
106
|
+
return function () {
|
|
107
|
+
timer && clearInterval(timer);
|
|
108
|
+
timeout && clearTimeout(timeout);
|
|
109
|
+
};
|
|
110
|
+
}, [toasts]);
|
|
111
|
+
if (!portal) return null;
|
|
112
|
+
if (!toasts || toasts.length === 0) return null;
|
|
113
|
+
return /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement("div", {
|
|
114
|
+
onMouseEnter: function onMouseEnter() {
|
|
115
|
+
return hoverHandler(true);
|
|
116
|
+
},
|
|
117
|
+
onMouseLeave: function onMouseLeave() {
|
|
118
|
+
return hoverHandler(false);
|
|
119
|
+
},
|
|
120
|
+
className: _JSXStyle.dynamic([["622610754", [theme.layout.gap, theme.layout.gap, theme.layout.gap, theme.layout.gap]]]) + " " + (classNames || "")
|
|
121
|
+
}, toastElements, /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
122
|
+
id: "622610754",
|
|
123
|
+
dynamic: [theme.layout.gap, theme.layout.gap, theme.layout.gap, theme.layout.gap]
|
|
124
|
+
}, ".toasts.__jsx-style-dynamic-selector{position:fixed;width:auto;max-width:100%;right:".concat(theme.layout.gap, ";bottom:").concat(theme.layout.gap, ";z-index:2000;-webkit-transition:all 400ms ease;transition:all 400ms ease;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}.top.__jsx-style-dynamic-selector{bottom:unset;-webkit-flex-direction:column-reverse;-ms-flex-direction:column-reverse;flex-direction:column-reverse;top:").concat(theme.layout.gap, ";}.left.__jsx-style-dynamic-selector{right:unset;left:").concat(theme.layout.gap, ";}"))), portal);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export default ToastContainer;
|