@helpdice/ui 2.0.7 → 2.1.3

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.
Files changed (64) hide show
  1. package/dist/AutoComplete/auto-complete.d.ts +1 -1
  2. package/dist/AutoComplete/index.js +1 -1
  3. package/dist/ButtonDropdown/index.js +2 -1
  4. package/dist/Carousal/component/Indicator.d.ts +1 -0
  5. package/dist/Carousal/component/Thumbs.d.ts +1 -1
  6. package/dist/Carousal/component/index.d.ts +1 -1
  7. package/dist/Carousal/component/types.d.ts +4 -3
  8. package/dist/Carousal/index.js +88 -38
  9. package/dist/Form/types.d.ts +2 -2
  10. package/dist/Grid/grid-container.d.ts +14 -0
  11. package/dist/Grid/grid.d.ts +14 -0
  12. package/dist/Input/index.js +1 -1
  13. package/dist/Popover/index.js +1 -1
  14. package/dist/Rating/rating.d.ts +1 -1
  15. package/dist/Select/index.js +6 -4
  16. package/dist/Table/index.js +8 -6
  17. package/dist/Table/table-types.d.ts +1 -1
  18. package/dist/Text/child.d.ts +1 -1
  19. package/dist/Textarea/index.js +1 -1
  20. package/dist/Tooltip/index.js +1 -1
  21. package/dist/Tree/index.js +3 -1
  22. package/dist/Tree/tree-help.d.ts +1 -1
  23. package/dist/index.d.ts +2 -0
  24. package/dist/index.js +250 -61
  25. package/dist/use-toasts/helpers.d.ts +17 -0
  26. package/dist/use-toasts/index.d.ts +3 -0
  27. package/dist/use-toasts/index.js +204 -0
  28. package/dist/use-toasts/use-toast.d.ts +40 -0
  29. package/dist/utils/use-drag.d.ts +1 -1
  30. package/dist/utils/use-hd-ui-context.d.ts +16 -0
  31. package/esm/AutoComplete/auto-complete.d.ts +1 -1
  32. package/esm/Carousal/component/Indicator.d.ts +1 -0
  33. package/esm/Carousal/component/Indicator.js +56 -13
  34. package/esm/Carousal/component/Thumbs.d.ts +1 -1
  35. package/esm/Carousal/component/Thumbs.js +3 -3
  36. package/esm/Carousal/component/index.d.ts +1 -1
  37. package/esm/Carousal/component/index.js +29 -22
  38. package/esm/Carousal/component/types.d.ts +4 -3
  39. package/esm/Carousal/main.js +42 -59
  40. package/esm/Form/types.d.ts +2 -2
  41. package/esm/Grid/grid-container.d.ts +14 -0
  42. package/esm/Grid/grid.d.ts +14 -0
  43. package/esm/Rating/rating.d.ts +1 -1
  44. package/esm/Select/select.js +4 -3
  45. package/esm/Table/table-types.d.ts +1 -1
  46. package/esm/Text/child.d.ts +1 -1
  47. package/esm/Textarea/textarea.js +1 -1
  48. package/esm/Tooltip/tooltip.js +1 -1
  49. package/esm/Tree/tree-help.d.ts +1 -1
  50. package/esm/Tree/tree-help.js +3 -1
  51. package/esm/index.d.ts +2 -0
  52. package/esm/index.js +2 -1
  53. package/esm/use-toasts/helpers.d.ts +17 -0
  54. package/esm/use-toasts/helpers.js +69 -0
  55. package/esm/use-toasts/index.d.ts +3 -0
  56. package/esm/use-toasts/index.js +2 -0
  57. package/esm/use-toasts/toast-container.js +118 -0
  58. package/esm/use-toasts/toast-item.js +42 -0
  59. package/esm/use-toasts/use-toast.d.ts +40 -0
  60. package/esm/use-toasts/use-toast.js +103 -0
  61. package/esm/utils/collections.js +2 -1
  62. package/esm/utils/use-drag.d.ts +1 -1
  63. package/esm/utils/use-hd-ui-context.d.ts +16 -0
  64. package/package.json +188 -57
@@ -196,7 +196,7 @@ export interface SharedRenderProps<T> {
196
196
  /**
197
197
  * Field component to render. Can either be a string like 'select' or a component.
198
198
  */
199
- component?: keyof JSX.IntrinsicElements | React.ComponentType<T | void>;
199
+ component?: keyof React.JSX.IntrinsicElements | React.ComponentType<T | void>;
200
200
  /**
201
201
  * Render prop (works like React router's <Route render={props =>} />)
202
202
  */
@@ -206,7 +206,7 @@ export interface SharedRenderProps<T> {
206
206
  */
207
207
  children?: (props: T) => React.ReactNode;
208
208
  }
209
- export type GenericFieldHTMLAttributes = JSX.IntrinsicElements['input'] | JSX.IntrinsicElements['select'] | JSX.IntrinsicElements['textarea'];
209
+ export type GenericFieldHTMLAttributes = React.JSX.IntrinsicElements['input'] | React.JSX.IntrinsicElements['select'] | React.JSX.IntrinsicElements['textarea'];
210
210
  /** Field metadata */
211
211
  export interface FieldMetaProps<Value> {
212
212
  /** Value of the field */
@@ -57,6 +57,10 @@ declare const GridContainer: React.ForwardRefExoticComponent<Props & import("./b
57
57
  results?: number | undefined | undefined;
58
58
  security?: string | undefined | undefined;
59
59
  unselectable?: "on" | "off" | undefined | undefined;
60
+ popover?: "" | "auto" | "manual" | "hint" | undefined | undefined;
61
+ popoverTargetAction?: "toggle" | "show" | "hide" | undefined | undefined;
62
+ popoverTarget?: string | undefined | undefined;
63
+ inert?: boolean | undefined | undefined;
60
64
  inputMode?: "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search" | undefined | undefined;
61
65
  is?: string | undefined | undefined;
62
66
  exportparts?: string | undefined | undefined;
@@ -263,6 +267,8 @@ declare const GridContainer: React.ForwardRefExoticComponent<Props & import("./b
263
267
  onLostPointerCaptureCapture?: React.PointerEventHandler<any> | undefined;
264
268
  onScroll?: React.UIEventHandler<any> | undefined;
265
269
  onScrollCapture?: React.UIEventHandler<any> | undefined;
270
+ onScrollEnd?: React.UIEventHandler<any> | undefined;
271
+ onScrollEndCapture?: React.UIEventHandler<any> | undefined;
266
272
  onWheel?: React.WheelEventHandler<any> | undefined;
267
273
  onWheelCapture?: React.WheelEventHandler<any> | undefined;
268
274
  onAnimationStart?: React.AnimationEventHandler<any> | undefined;
@@ -271,8 +277,16 @@ declare const GridContainer: React.ForwardRefExoticComponent<Props & import("./b
271
277
  onAnimationEndCapture?: React.AnimationEventHandler<any> | undefined;
272
278
  onAnimationIteration?: React.AnimationEventHandler<any> | undefined;
273
279
  onAnimationIterationCapture?: React.AnimationEventHandler<any> | undefined;
280
+ onToggle?: React.ToggleEventHandler<any> | undefined;
281
+ onBeforeToggle?: React.ToggleEventHandler<any> | undefined;
282
+ onTransitionCancel?: React.TransitionEventHandler<any> | undefined;
283
+ onTransitionCancelCapture?: React.TransitionEventHandler<any> | undefined;
274
284
  onTransitionEnd?: React.TransitionEventHandler<any> | undefined;
275
285
  onTransitionEndCapture?: React.TransitionEventHandler<any> | undefined;
286
+ onTransitionRun?: React.TransitionEventHandler<any> | undefined;
287
+ onTransitionRunCapture?: React.TransitionEventHandler<any> | undefined;
288
+ onTransitionStart?: React.TransitionEventHandler<any> | undefined;
289
+ onTransitionStartCapture?: React.TransitionEventHandler<any> | undefined;
276
290
  } & {
277
291
  width?: string | number;
278
292
  height?: string | number;
@@ -54,6 +54,10 @@ declare const Grid: React.ForwardRefExoticComponent<Props & import("./basic-item
54
54
  results?: number | undefined | undefined;
55
55
  security?: string | undefined | undefined;
56
56
  unselectable?: "on" | "off" | undefined | undefined;
57
+ popover?: "" | "auto" | "manual" | "hint" | undefined | undefined;
58
+ popoverTargetAction?: "toggle" | "show" | "hide" | undefined | undefined;
59
+ popoverTarget?: string | undefined | undefined;
60
+ inert?: boolean | undefined | undefined;
57
61
  inputMode?: "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search" | undefined | undefined;
58
62
  is?: string | undefined | undefined;
59
63
  exportparts?: string | undefined | undefined;
@@ -260,6 +264,8 @@ declare const Grid: React.ForwardRefExoticComponent<Props & import("./basic-item
260
264
  onLostPointerCaptureCapture?: React.PointerEventHandler<any> | undefined;
261
265
  onScroll?: React.UIEventHandler<any> | undefined;
262
266
  onScrollCapture?: React.UIEventHandler<any> | undefined;
267
+ onScrollEnd?: React.UIEventHandler<any> | undefined;
268
+ onScrollEndCapture?: React.UIEventHandler<any> | undefined;
263
269
  onWheel?: React.WheelEventHandler<any> | undefined;
264
270
  onWheelCapture?: React.WheelEventHandler<any> | undefined;
265
271
  onAnimationStart?: React.AnimationEventHandler<any> | undefined;
@@ -268,8 +274,16 @@ declare const Grid: React.ForwardRefExoticComponent<Props & import("./basic-item
268
274
  onAnimationEndCapture?: React.AnimationEventHandler<any> | undefined;
269
275
  onAnimationIteration?: React.AnimationEventHandler<any> | undefined;
270
276
  onAnimationIterationCapture?: React.AnimationEventHandler<any> | undefined;
277
+ onToggle?: React.ToggleEventHandler<any> | undefined;
278
+ onBeforeToggle?: React.ToggleEventHandler<any> | undefined;
279
+ onTransitionCancel?: React.TransitionEventHandler<any> | undefined;
280
+ onTransitionCancelCapture?: React.TransitionEventHandler<any> | undefined;
271
281
  onTransitionEnd?: React.TransitionEventHandler<any> | undefined;
272
282
  onTransitionEndCapture?: React.TransitionEventHandler<any> | undefined;
283
+ onTransitionRun?: React.TransitionEventHandler<any> | undefined;
284
+ onTransitionRunCapture?: React.TransitionEventHandler<any> | undefined;
285
+ onTransitionStart?: React.TransitionEventHandler<any> | undefined;
286
+ onTransitionStartCapture?: React.TransitionEventHandler<any> | undefined;
273
287
  } & {
274
288
  width?: string | number;
275
289
  height?: string | number;
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { JSX } from 'react';
2
2
  import { NormalTypes } from '../utils/prop-types';
3
3
  export type RatingTypes = NormalTypes;
4
4
  declare const ratingCountTuple: [2, 3, 4, 5, 6, 7, 8, 9, 10];
@@ -146,13 +146,14 @@ var SelectComponent = /*#__PURE__*/React.forwardRef(function (_ref, selectRef) {
146
146
  _pickChildByProps2 = _slicedToArray(_pickChildByProps, 2),
147
147
  optionChildren = _pickChildByProps2[1];
148
148
  return React.Children.map(optionChildren, function (child) {
149
- if (! /*#__PURE__*/React.isValidElement(child)) return null;
150
- var el = /*#__PURE__*/React.cloneElement(child); // { preventAllEvents: true }
149
+ var _child = child;
150
+ if (! /*#__PURE__*/React.isValidElement(_child)) return null;
151
+ var el = /*#__PURE__*/React.cloneElement(_child); // { preventAllEvents: true }
151
152
  if (!multiple) return el;
152
153
  return /*#__PURE__*/React.createElement(SelectMultipleValue, {
153
154
  disabled: disabled,
154
155
  onClear: clearable ? function () {
155
- return updateValue(child.props.value);
156
+ return updateValue(_child.props.value);
156
157
  } : null
157
158
  }, el);
158
159
  });
@@ -1,4 +1,4 @@
1
- import React, { CSSProperties } from 'react';
1
+ import React, { CSSProperties, JSX } from 'react';
2
2
  export type TableDataItemBase = Record<string, any>;
3
3
  export type TableColumnRender<Item extends TableDataItemBase> = (value: Item[keyof Item], rowData: Item, rowIndex: number) => JSX.Element | void;
4
4
  export type TableAbstractColumn<TableDataItem> = {
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { JSX } from 'react';
2
2
  import { NormalTypes } from '../utils/prop-types';
3
3
  export interface Props {
4
4
  tag: keyof JSX.IntrinsicElements;
@@ -36,7 +36,7 @@ var TextareaComponent = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
36
36
  var textareaRef = useRef(null);
37
37
  useImperativeHandle(ref, function () {
38
38
  return textareaRef.current;
39
- });
39
+ }); // added not null
40
40
  var isControlledComponent = useMemo(function () {
41
41
  return value !== undefined;
42
42
  }, [value]);
@@ -38,7 +38,7 @@ var TooltipComponent = function TooltipComponent(_ref) {
38
38
  hideArrow = _ref$hideArrow === void 0 ? false : _ref$hideArrow,
39
39
  customVisible = _ref.visible,
40
40
  props = _objectWithoutProperties(_ref, _excluded);
41
- var timer = useRef();
41
+ var timer = useRef(undefined);
42
42
  var ref = useRef(null);
43
43
  var _useState = useState(initialVisible),
44
44
  _useState2 = _slicedToArray(_useState, 2),
@@ -1,4 +1,4 @@
1
1
  import React, { ReactNode } from 'react';
2
- export declare const sortChildren: (children: ReactNode | undefined, folderComponentType: React.ElementType) => (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal)[];
2
+ export declare const sortChildren: (children: ReactNode | undefined, folderComponentType: React.ElementType) => (string | number | bigint | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined>)[];
3
3
  export declare const makeChildPath: (name: string, parentPath?: string) => string;
4
4
  export declare const stopPropagation: (event: React.MouseEvent) => void;
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
2
  export var sortChildren = function sortChildren(children, folderComponentType) {
3
- return React.Children.toArray(children).sort(function (a, b) {
3
+ return React.Children.toArray(children).sort(function (_a, _b) {
4
+ var a = _a;
5
+ var b = _b;
4
6
  if (! /*#__PURE__*/React.isValidElement(a) || ! /*#__PURE__*/React.isValidElement(b)) return 0;
5
7
  if (a.type !== b.type) return a.type !== folderComponentType ? 1 : -1;
6
8
  return "".concat(a.props.name).charCodeAt(0) - "".concat(b.props.name).charCodeAt(0);
package/esm/index.d.ts CHANGED
@@ -128,3 +128,5 @@ export { Carousel } from './Carousal';
128
128
  export type { CarouselProps } from './Carousal';
129
129
  export { default as CurrencyInput } from './CurrencyInput';
130
130
  export type { CurrencyInputProps, CurrencyInputOnChangeValues } from './CurrencyInput';
131
+ export { default as useToasts } from './use-toasts';
132
+ export type { Toast, ToastInput, ToastAction, ToastLayout } from './use-toasts';
package/esm/index.js CHANGED
@@ -86,4 +86,5 @@ export { default as Swipe } from './Swipe';
86
86
  // Carousel
87
87
  export { Carousel } from './Carousal';
88
88
  // Currency Input
89
- export { default as CurrencyInput } from './CurrencyInput';
89
+ export { default as CurrencyInput } from './CurrencyInput';
90
+ export { default as useToasts } from './use-toasts';
@@ -0,0 +1,17 @@
1
+ import { Toast } from './use-toast';
2
+ import React from 'react';
3
+ import { NormalTypes } from '../utils/prop-types';
4
+ export declare const makeToastActions: (actions: Toast["actions"], cancelHandle: () => void) => React.JSX.Element[] | null;
5
+ export declare const getColors: (palette: any, type?: NormalTypes) => {
6
+ bgColor: string;
7
+ color: any;
8
+ };
9
+ declare const toastPlacement: ["topLeft", "topRight", "bottomLeft", "bottomRight"];
10
+ export type ToastPlacement = typeof toastPlacement[number];
11
+ export declare const isTopPlacement: (placement: ToastPlacement) => boolean;
12
+ export declare const isLeftPlacement: (placement: ToastPlacement) => boolean;
13
+ export declare const getTranslateByPlacement: (placement: ToastPlacement) => {
14
+ enter: string;
15
+ leave: string;
16
+ };
17
+ export {};
@@ -0,0 +1,69 @@
1
+ import React from 'react';
2
+ import Button from '../Button';
3
+ // import { } from '@helpdice/theme'
4
+ import { tuple } from '../utils/prop-types';
5
+ export var makeToastActions = function makeToastActions(actions, cancelHandle) {
6
+ var handler = function handler(event, userHandler) {
7
+ userHandler && userHandler(event, cancelHandle);
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
+ color: action.passive ? 'default' : 'secondary',
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
+ secondary: palette.secondary,
27
+ success: palette.success,
28
+ warning: palette.warning,
29
+ error: palette.error
30
+ };
31
+ var isDefault = !type || type === 'default';
32
+ if (isDefault) return {
33
+ bgColor: colors["default"],
34
+ color: palette.foreground
35
+ };
36
+ /**
37
+ * Prevent main color change in special types.
38
+ * The color will only follow the theme when it is in the default type.
39
+ */
40
+ return {
41
+ bgColor: colors[type],
42
+ color: 'white'
43
+ };
44
+ };
45
+ var toastPlacement = tuple('topLeft', 'topRight', 'bottomLeft', 'bottomRight');
46
+ export var isTopPlacement = function isTopPlacement(placement) {
47
+ return "".concat(placement).toLowerCase().startsWith('top');
48
+ };
49
+ export var isLeftPlacement = function isLeftPlacement(placement) {
50
+ return "".concat(placement).toLowerCase().endsWith('left');
51
+ };
52
+ export var getTranslateByPlacement = function getTranslateByPlacement(placement) {
53
+ var translateInByPlacement = {
54
+ topLeft: 'translate(-60px, -60px)',
55
+ topRight: 'translate(60px, -60px)',
56
+ bottomLeft: 'translate(-60px, 60px)',
57
+ bottomRight: 'translate(60px, 60px)'
58
+ };
59
+ var translateOutByPlacement = {
60
+ topLeft: 'translate(-50px, 15px) scale(0.85)',
61
+ topRight: 'translate(50px, 15px) scale(0.85)',
62
+ bottomLeft: 'translate(-50px, -15px) scale(0.85)',
63
+ bottomRight: 'translate(50px, -15px) scale(0.85)'
64
+ };
65
+ return {
66
+ enter: translateInByPlacement[placement],
67
+ leave: translateOutByPlacement[placement]
68
+ };
69
+ };
@@ -0,0 +1,3 @@
1
+ import useToasts from './use-toast';
2
+ export type { ToastAction, Toast, ToastTypes, ToastInput, ToastLayout } from './use-toast';
3
+ export default useToasts;
@@ -0,0 +1,2 @@
1
+ import useToasts from './use-toast';
2
+ export default useToasts;
@@ -0,0 +1,118 @@
1
+ "use client";
2
+
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
+ import _JSXStyle from "../styled-jsx.es.js";
6
+ import React, { useEffect, useMemo } from 'react';
7
+ import { createPortal } from 'react-dom';
8
+ import usePortal from '../utils/use-portal';
9
+ import { useTheme, useClasses, useCurrentState } from '@helpdice/theme';
10
+ import { useHUIContext } from '../utils/use-hd-ui-context';
11
+ import ToastItem from './toast-item';
12
+ import { isLeftPlacement, isTopPlacement } from './helpers';
13
+ var ToastContainer = function ToastContainer() {
14
+ var theme = useTheme();
15
+ var portal = usePortal('toast');
16
+ var _useCurrentState = useCurrentState(false),
17
+ _useCurrentState2 = _slicedToArray(_useCurrentState, 3),
18
+ setHovering = _useCurrentState2[1],
19
+ hoveringRef = _useCurrentState2[2];
20
+ var _useHUIContext = useHUIContext(),
21
+ toasts = _useHUIContext.toasts,
22
+ updateToasts = _useHUIContext.updateToasts,
23
+ toastLayout = _useHUIContext.toastLayout,
24
+ lastUpdateToastId = _useHUIContext.lastUpdateToastId;
25
+ var memoizedLayout = useMemo(function () {
26
+ return toastLayout;
27
+ }, [toastLayout]);
28
+ var toastElements = useMemo(function () {
29
+ return toasts.map(function (toast) {
30
+ return /*#__PURE__*/React.createElement(ToastItem, {
31
+ toast: toast,
32
+ layout: memoizedLayout,
33
+ key: toast._internalIdent
34
+ });
35
+ });
36
+ }, [toasts, memoizedLayout]);
37
+ var classNames = useMemo(function () {
38
+ return useClasses('toasts', {
39
+ top: isTopPlacement(toastLayout.placement),
40
+ left: isLeftPlacement(toastLayout.placement)
41
+ });
42
+ }, [memoizedLayout]);
43
+ var hoverHandler = function hoverHandler(isHovering) {
44
+ setHovering(isHovering);
45
+ if (isHovering) {
46
+ return updateToasts(function (last) {
47
+ return last.map(function (toast) {
48
+ if (!toast.visible) return toast;
49
+ toast._timeout && window.clearTimeout(toast._timeout);
50
+ return _extends({}, toast, {
51
+ timeout: null
52
+ });
53
+ });
54
+ });
55
+ }
56
+ updateToasts(function (last) {
57
+ return last.map(function (toast, index) {
58
+ if (!toast.visible) return toast;
59
+ toast._timeout && window.clearTimeout(toast._timeout);
60
+ return _extends({}, toast, {
61
+ _timeout: function () {
62
+ var timer = window.setTimeout(function () {
63
+ toast.cancel();
64
+ window.clearTimeout(timer);
65
+ }, toast.delay + index * 100);
66
+ return timer;
67
+ }()
68
+ });
69
+ });
70
+ });
71
+ };
72
+ useEffect(function () {
73
+ var index = toasts.findIndex(function (r) {
74
+ return r._internalIdent === lastUpdateToastId;
75
+ });
76
+ var toast = toasts[index];
77
+ if (!toast || toast.visible || !hoveringRef.current) return;
78
+ var hasVisible = toasts.find(function (r, i) {
79
+ return i < index && r.visible;
80
+ });
81
+ if (hasVisible || !hoveringRef.current) return;
82
+ hoverHandler(false);
83
+ }, [toasts, lastUpdateToastId]);
84
+ useEffect(function () {
85
+ var timeout = null;
86
+ var timer = window.setInterval(function () {
87
+ if (toasts.length === 0) return;
88
+ timeout = window.setTimeout(function () {
89
+ var allInvisible = !toasts.find(function (r) {
90
+ return r.visible;
91
+ });
92
+ allInvisible && updateToasts(function () {
93
+ return [];
94
+ });
95
+ timeout && clearTimeout(timeout);
96
+ }, 350);
97
+ }, 5000);
98
+ return function () {
99
+ timer && clearInterval(timer);
100
+ timeout && clearTimeout(timeout);
101
+ };
102
+ }, [toasts]);
103
+ if (!portal) return null;
104
+ if (!toasts || toasts.length === 0) return null;
105
+ return /*#__PURE__*/createPortal(/*#__PURE__*/React.createElement("div", {
106
+ onMouseEnter: function onMouseEnter() {
107
+ return hoverHandler(true);
108
+ },
109
+ onMouseLeave: function onMouseLeave() {
110
+ return hoverHandler(false);
111
+ },
112
+ className: _JSXStyle.dynamic([["622610754", [theme.layout.gap, theme.layout.gap, theme.layout.gap, theme.layout.gap]]]) + " " + (classNames || "")
113
+ }, toastElements, /*#__PURE__*/React.createElement(_JSXStyle, {
114
+ id: "622610754",
115
+ dynamic: [theme.layout.gap, theme.layout.gap, theme.layout.gap, theme.layout.gap]
116
+ }, ".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);
117
+ };
118
+ export default ToastContainer;
@@ -0,0 +1,42 @@
1
+ import _JSXStyle from "../styled-jsx.es.js";
2
+ import React, { useMemo } from 'react';
3
+ import { useTheme, CssTransition } from '@helpdice/theme';
4
+ import { makeToastActions, getColors, getTranslateByPlacement } from './helpers';
5
+ var ToastItem = /*#__PURE__*/React.memo(function (_ref) {
6
+ var toast = _ref.toast,
7
+ layout = _ref.layout;
8
+ var theme = useTheme();
9
+ var _useMemo = useMemo(function () {
10
+ return getColors(theme.palette, toast.type);
11
+ }, [theme.palette, toast.type]),
12
+ color = _useMemo.color,
13
+ bgColor = _useMemo.bgColor;
14
+ var isReactNode = typeof toast.text !== 'string';
15
+ var padding = layout.padding,
16
+ margin = layout.margin,
17
+ maxHeight = layout.maxHeight,
18
+ maxWidth = layout.maxWidth,
19
+ width = layout.width,
20
+ placement = layout.placement;
21
+ var _useMemo2 = useMemo(function () {
22
+ return getTranslateByPlacement(placement);
23
+ }, [placement]),
24
+ enter = _useMemo2.enter,
25
+ leave = _useMemo2.leave;
26
+ return /*#__PURE__*/React.createElement(CssTransition, {
27
+ name: "toast",
28
+ visible: toast.visible,
29
+ clearTime: 350
30
+ }, /*#__PURE__*/React.createElement("div", {
31
+ key: toast.id,
32
+ className: _JSXStyle.dynamic([["1407001838", [width, maxWidth, maxHeight, theme.palette.foreground, bgColor, color, theme.layout.radius, theme.expressiveness.shadowSmall, theme.layout.gapHalf, enter, margin, padding, margin, padding, leave]]]) + " " + "toast"
33
+ }, isReactNode ? toast.text : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
34
+ className: _JSXStyle.dynamic([["1407001838", [width, maxWidth, maxHeight, theme.palette.foreground, bgColor, color, theme.layout.radius, theme.expressiveness.shadowSmall, theme.layout.gapHalf, enter, margin, padding, margin, padding, leave]]]) + " " + "message"
35
+ }, toast.text), /*#__PURE__*/React.createElement("div", {
36
+ className: _JSXStyle.dynamic([["1407001838", [width, maxWidth, maxHeight, theme.palette.foreground, bgColor, color, theme.layout.radius, theme.expressiveness.shadowSmall, theme.layout.gapHalf, enter, margin, padding, margin, padding, leave]]]) + " " + "action"
37
+ }, makeToastActions(toast.actions, toast.cancel))), /*#__PURE__*/React.createElement(_JSXStyle, {
38
+ id: "1407001838",
39
+ dynamic: [width, maxWidth, maxHeight, theme.palette.foreground, bgColor, color, theme.layout.radius, theme.expressiveness.shadowSmall, theme.layout.gapHalf, enter, margin, padding, margin, padding, leave]
40
+ }, ".toast.__jsx-style-dynamic-selector{width:".concat(width, ";max-width:").concat(maxWidth, ";max-height:").concat(maxHeight, ";display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;color:").concat(theme.palette.foreground, ";background-color:").concat(bgColor, ";color:").concat(color, ";border:0;border-radius:").concat(theme.layout.radius, ";opacity:1;box-shadow:").concat(theme.expressiveness.shadowSmall, ";-webkit-transition:all 350ms cubic-bezier(0.1,0.2,0.1,1);transition:all 350ms cubic-bezier(0.1,0.2,0.1,1);overflow:hidden;}.message.__jsx-style-dynamic-selector{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;height:100%;font-size:0.875em;display:-webkit-box;word-break:break-all;padding-right:").concat(theme.layout.gapHalf, ";overflow:hidden;max-height:100%;text-overflow:ellipsis;-webkit-box-orient:vertical;-webkit-line-clamp:2;line-height:1.1rem;}.toast-enter.__jsx-style-dynamic-selector{opacity:0;height:0;padding:0;margin:0;-webkit-transform:").concat(enter, ";-ms-transform:").concat(enter, ";transform:").concat(enter, ";}.toast-enter-active.__jsx-style-dynamic-selector{opacity:1;height:auto;margin:").concat(margin, ";padding:").concat(padding, ";-webkit-transform:translate(0,0);-ms-transform:translate(0,0);transform:translate(0,0);}.toast-leave.__jsx-style-dynamic-selector{opacity:1;-webkit-transform:translate(0,0);-ms-transform:translate(0,0);transform:translate(0,0);height:auto;margin:").concat(margin, ";padding:").concat(padding, ";}.toast-leave-active.__jsx-style-dynamic-selector{opacity:0;-webkit-transform:").concat(leave, ";-ms-transform:").concat(leave, ";transform:").concat(leave, ";}"))));
41
+ });
42
+ export default ToastItem;
@@ -0,0 +1,40 @@
1
+ import React, { CSSProperties } from 'react';
2
+ import type { NormalTypes } from '../utils/prop-types';
3
+ import { ToastPlacement } from '../use-toasts/helpers';
4
+ export interface ToastAction {
5
+ name: string;
6
+ handler: (event: React.MouseEvent<HTMLButtonElement>, cancel: () => void) => void;
7
+ passive?: boolean;
8
+ }
9
+ export type ToastTypes = NormalTypes;
10
+ export type ToastLayout = {
11
+ padding?: CSSProperties['padding'];
12
+ margin?: CSSProperties['margin'];
13
+ width?: CSSProperties['width'];
14
+ maxWidth?: CSSProperties['maxWidth'];
15
+ maxHeight?: CSSProperties['maxHeight'];
16
+ placement?: ToastPlacement;
17
+ };
18
+ export interface ToastInput {
19
+ text: string | React.ReactNode;
20
+ type?: ToastTypes;
21
+ id?: string;
22
+ delay?: number;
23
+ actions?: Array<ToastAction>;
24
+ }
25
+ export type ToastInstance = {
26
+ visible: boolean;
27
+ cancel: () => void;
28
+ _timeout: null | number;
29
+ _internalIdent: string;
30
+ };
31
+ export type Toast = Required<ToastInput> & ToastInstance;
32
+ export type ToastHooksResult = {
33
+ toasts: Array<Toast>;
34
+ setToast: (toast: ToastInput) => void;
35
+ removeAll: () => void;
36
+ findToastOneByID: (ident: string) => Toast | undefined;
37
+ removeToastOneByID: (ident: string) => void;
38
+ };
39
+ declare const useToasts: (layout?: ToastLayout) => ToastHooksResult;
40
+ export default useToasts;
@@ -0,0 +1,103 @@
1
+ "use client";
2
+
3
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
+ import _extends from "@babel/runtime/helpers/esm/extends";
5
+ import { useEffect } from 'react';
6
+ import { defaultToastLayout, useHUIContext } from '../utils/use-hd-ui-context';
7
+ import { getId } from '../utils/collections';
8
+ var defaultToast = {
9
+ delay: 2000,
10
+ type: 'default'
11
+ };
12
+ var useToasts = function useToasts(layout) {
13
+ var _useHUIContext = useHUIContext(),
14
+ updateToasts = _useHUIContext.updateToasts,
15
+ toasts = _useHUIContext.toasts,
16
+ updateToastLayout = _useHUIContext.updateToastLayout,
17
+ updateLastToastId = _useHUIContext.updateLastToastId;
18
+ useEffect(function () {
19
+ if (!layout) return;
20
+ updateToastLayout(function () {
21
+ return layout ? _extends({}, defaultToastLayout, layout) : defaultToastLayout;
22
+ });
23
+ }, []);
24
+ var _cancel = function cancel(internalId) {
25
+ updateToasts(function (currentToasts) {
26
+ return currentToasts.map(function (item) {
27
+ if (item._internalIdent !== internalId) return item;
28
+ return _extends({}, item, {
29
+ visible: false
30
+ });
31
+ });
32
+ });
33
+ updateLastToastId(function () {
34
+ return internalId;
35
+ });
36
+ };
37
+ var removeAll = function removeAll() {
38
+ updateToasts(function (last) {
39
+ return last.map(function (toast) {
40
+ return _extends({}, toast, {
41
+ visible: false
42
+ });
43
+ });
44
+ });
45
+ };
46
+ var findToastOneByID = function findToastOneByID(id) {
47
+ return toasts.find(function (t) {
48
+ return t.id === id;
49
+ });
50
+ };
51
+ var removeToastOneByID = function removeToastOneByID(id) {
52
+ updateToasts(function (last) {
53
+ return last.map(function (toast) {
54
+ if (toast.id !== id) return toast;
55
+ return _extends({}, toast, {
56
+ visible: false
57
+ });
58
+ });
59
+ });
60
+ };
61
+ var setToast = function setToast(toast) {
62
+ var internalIdent = "toast-".concat(getId());
63
+ var delay = toast.delay || defaultToast.delay;
64
+ if (toast.id) {
65
+ var hasIdent = toasts.find(function (t) {
66
+ return t.id === toast.id;
67
+ });
68
+ if (hasIdent) {
69
+ throw new Error('Toast: Already have the same key: "ident"');
70
+ }
71
+ }
72
+ updateToasts(function (last) {
73
+ var newToast = {
74
+ delay: delay,
75
+ text: toast.text,
76
+ visible: true,
77
+ type: toast.type || defaultToast.type,
78
+ id: toast.id || internalIdent,
79
+ actions: toast.actions || [],
80
+ _internalIdent: internalIdent,
81
+ _timeout: window.setTimeout(function () {
82
+ _cancel(internalIdent);
83
+ if (newToast._timeout) {
84
+ window.clearTimeout(newToast._timeout);
85
+ newToast._timeout = null;
86
+ }
87
+ }, delay),
88
+ cancel: function cancel() {
89
+ return _cancel(internalIdent);
90
+ }
91
+ };
92
+ return [].concat(_toConsumableArray(last), [newToast]);
93
+ });
94
+ };
95
+ return {
96
+ toasts: toasts,
97
+ setToast: setToast,
98
+ removeAll: removeAll,
99
+ findToastOneByID: findToastOneByID,
100
+ removeToastOneByID: removeToastOneByID
101
+ };
102
+ };
103
+ export default useToasts;
@@ -31,7 +31,8 @@ export var pickChild = function pickChild(children, targetChild) {
31
31
  export var pickChildByProps = function pickChildByProps(children, key, value) {
32
32
  var target = [];
33
33
  var isArray = Array.isArray(value);
34
- var withoutPropChildren = React.Children.map(children, function (item) {
34
+ var withoutPropChildren = React.Children.map(children, function (_item) {
35
+ var item = _item;
35
36
  if (! /*#__PURE__*/React.isValidElement(item)) return null;
36
37
  if (!item.props) return item;
37
38
  if (isArray) {
@@ -4,5 +4,5 @@ export type DraggingEvent = {
4
4
  currentX: number;
5
5
  };
6
6
  export type DraggingHandler = (event: DraggingEvent) => void;
7
- declare const useDrag: (elementRef: RefObject<HTMLElement> | null, draggingHandler?: DraggingHandler, dragStartHandler?: DraggingHandler, dragEndHandler?: DraggingHandler) => void;
7
+ declare const useDrag: (elementRef: RefObject<HTMLElement | null>, draggingHandler?: DraggingHandler, dragStartHandler?: DraggingHandler, dragEndHandler?: DraggingHandler) => void;
8
8
  export default useDrag;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import type { ToastLayout, Toast } from '@helpdice/theme';
3
+ export declare const defaultToastLayout: Required<ToastLayout>;
4
+ export type UpdateToastsFunction = (fn: (toasts: Array<Toast>) => Array<Toast>) => any;
5
+ export type UpdateToastsLayoutFunction = (fn: (layout: Required<ToastLayout>) => Required<ToastLayout>) => any;
6
+ export type UpdateToastsIDFunction = (fn: () => string | null) => any;
7
+ export interface HUIContextParams {
8
+ toasts: Array<Toast>;
9
+ updateToasts: UpdateToastsFunction;
10
+ toastLayout: Required<ToastLayout>;
11
+ updateToastLayout: UpdateToastsLayoutFunction;
12
+ lastUpdateToastId: string | null;
13
+ updateLastToastId: UpdateToastsIDFunction;
14
+ }
15
+ export declare const HUIContent: React.Context<HUIContextParams>;
16
+ export declare const useHUIContext: () => HUIContextParams;