@zuzjs/ui 0.8.4 → 0.8.5

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 (48) hide show
  1. package/dist/cjs/comps/Crumb/index.js +2 -2
  2. package/dist/cjs/comps/Drawer/index.d.ts +1 -0
  3. package/dist/cjs/comps/Drawer/index.js +5 -2
  4. package/dist/cjs/comps/Drawer/types.d.ts +1 -0
  5. package/dist/cjs/comps/List/index.js +7 -3
  6. package/dist/cjs/comps/List/item.js +1 -1
  7. package/dist/cjs/comps/Table/index.js +9 -3
  8. package/dist/cjs/comps/Table/row.js +1 -1
  9. package/dist/cjs/comps/Toast/index.d.ts +12 -0
  10. package/dist/cjs/comps/Toast/index.js +44 -0
  11. package/dist/cjs/comps/Toast/toast.d.ts +6 -0
  12. package/dist/cjs/comps/Toast/toast.js +49 -0
  13. package/dist/cjs/comps/Toast/types.d.ts +30 -0
  14. package/dist/cjs/comps/Toast/types.js +14 -0
  15. package/dist/cjs/comps/index.d.ts +2 -0
  16. package/dist/cjs/comps/index.js +2 -0
  17. package/dist/cjs/hooks/index.d.ts +1 -0
  18. package/dist/cjs/hooks/index.js +1 -0
  19. package/dist/cjs/hooks/useBase.js +18 -1
  20. package/dist/cjs/hooks/useToast.d.ts +10 -0
  21. package/dist/cjs/hooks/useToast.js +18 -0
  22. package/dist/cjs/types/interfaces.d.ts +2 -0
  23. package/dist/css/styles.css +1 -1
  24. package/dist/esm/comps/Crumb/index.js +2 -2
  25. package/dist/esm/comps/Drawer/index.d.ts +1 -0
  26. package/dist/esm/comps/Drawer/index.js +5 -2
  27. package/dist/esm/comps/Drawer/types.d.ts +1 -0
  28. package/dist/esm/comps/List/index.js +7 -3
  29. package/dist/esm/comps/List/item.js +1 -1
  30. package/dist/esm/comps/Table/index.js +9 -3
  31. package/dist/esm/comps/Table/row.js +1 -1
  32. package/dist/esm/comps/Toast/index.d.ts +12 -0
  33. package/dist/esm/comps/Toast/index.js +44 -0
  34. package/dist/esm/comps/Toast/toast.d.ts +6 -0
  35. package/dist/esm/comps/Toast/toast.js +49 -0
  36. package/dist/esm/comps/Toast/types.d.ts +30 -0
  37. package/dist/esm/comps/Toast/types.js +14 -0
  38. package/dist/esm/comps/index.d.ts +2 -0
  39. package/dist/esm/comps/index.js +2 -0
  40. package/dist/esm/hooks/index.d.ts +1 -0
  41. package/dist/esm/hooks/index.js +1 -0
  42. package/dist/esm/hooks/useBase.js +18 -1
  43. package/dist/esm/hooks/useToast.d.ts +10 -0
  44. package/dist/esm/hooks/useToast.js +18 -0
  45. package/dist/esm/types/interfaces.d.ts +2 -0
  46. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  47. package/dist/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +2 -2
@@ -16,8 +16,8 @@ const Crumb = forwardRef((props, ref) => {
16
16
  ...crumbItems.slice(-maxItems)
17
17
  ] : crumbItems;
18
18
  return _jsx(List, { ref: ref, className: `--crumb flex aic`, direction: `rows`, seperator: _jsx(Box, { as: `--crumb-chevron`, children: SVGIcons.chevronRightOutline }), items: items.map((item, index, _items) => item.ID == `.` ?
19
- _jsx(Box, { as: `flex aic gap:3`, children: Array(3).fill(null).map(() => _jsx(Box, { as: `w:4 h:4 bg:$text r:10` })) })
20
- : _jsxs(Button, { onClick: () => item.action?.(), className: `--crumb-item`, disabled: !_items[index + 1], children: [item.icon && _jsx(Icon, { as: `--crumb-icon`, name: item.icon }), _jsx(Text, { as: `--crumb-label`, children: item.label })] })) });
19
+ _jsx(Box, { as: `flex aic gap:3`, children: Array(3).fill(null).map(() => _jsx(Box, { as: `w:4 h:4 bg:$text r:10` }, `--crumb-placeholder-${index}`)) })
20
+ : _jsxs(Button, { onClick: () => item.action?.(), className: `--crumb-item`, disabled: !_items[index + 1], children: [item.icon && _jsx(Icon, { as: `--crumb-icon`, name: item.icon }), _jsx(Text, { as: `--crumb-label`, children: item.label })] }, `${item.label.replace(/\s+/g, `-`).toLowerCase()}-${index}`)) });
21
21
  });
22
22
  Crumb.displayName = `Zuz.Crumb`;
23
23
  export default Crumb;
@@ -8,6 +8,7 @@ declare const Drawer: import("react").ForwardRefExoticComponent<BoxProps & {
8
8
  from?: DRAWER_SIDE;
9
9
  children?: string | ReactNode | ReactNode[];
10
10
  prerender?: boolean;
11
+ margin?: number;
11
12
  onClose?: () => void;
12
13
  } & import("react").RefAttributes<DrawerHandler>>;
13
14
  export default Drawer;
@@ -6,7 +6,7 @@ import { DRAWER_SIDE, KeyCode, TRANSITION_CURVES } from "../../types/enums";
6
6
  import Box from "../Box";
7
7
  import Overlay from "../Overlay";
8
8
  const Drawer = forwardRef((props, ref) => {
9
- const { from, speed, children, prerender, onClose, ...pops } = props;
9
+ const { from, speed, children, margin, prerender, onClose, ...pops } = props;
10
10
  const [render, setRender] = useState(undefined == prerender ? true : prerender);
11
11
  const [visible, setVisible] = useState(false);
12
12
  const divRef = useRef(null);
@@ -53,7 +53,10 @@ const Drawer = forwardRef((props, ref) => {
53
53
  onClose?.();
54
54
  setVisible(false);
55
55
  }
56
- }, when: visible }), _jsxs(Box, { ref: divRef, style: style, className: `--drawer flex cols ${className} --${from ? from.toLowerCase() : `left`} fixed`, fx: {
56
+ }, when: visible }), _jsxs(Box, { ref: divRef, style: {
57
+ ...style,
58
+ ...{ "--m": `${margin || 0}px` }
59
+ }, "aria-hidden": !visible, className: `--drawer flex cols ${className} --${from ? from.toLowerCase() : `left`} fixed`, fx: {
57
60
  from: { ..._style.from, opacity: 0 },
58
61
  to: { ..._style.to, opacity: 1 },
59
62
  when: visible,
@@ -7,6 +7,7 @@ export type DrawerProps = BoxProps & {
7
7
  from?: DRAWER_SIDE;
8
8
  children?: string | ReactNode | ReactNode[];
9
9
  prerender?: boolean;
10
+ margin?: number;
10
11
  onClose?: () => void;
11
12
  };
12
13
  export interface DrawerHandler {
@@ -1,5 +1,6 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { createElement, forwardRef } from "react";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { MD5 } from "@zuzjs/core";
3
+ import { createElement, forwardRef, Fragment, isValidElement } from "react";
3
4
  import { useBase } from "../../hooks";
4
5
  import { Size } from "../../types/enums";
5
6
  import Item from "./item";
@@ -11,7 +12,10 @@ const List = forwardRef((props, ref) => {
11
12
  className: `--list --${size || Size.Small} flex ${direction ?? `cols`} ${className}`.trim(),
12
13
  style, ref,
13
14
  ...rest,
14
- children: items.map((item, index, _items) => _jsxs(_Fragment, { children: [_jsx(Item, { meta: item }, `list-item-${typeof item == `string` ? String(item) : item.label}-${index}`), seperator && _items[index + 1] ? _jsx("li", { className: `--list-seperator`, children: seperator }) : null] }))
15
+ children: items.map((item, index, _items) => {
16
+ const _key = `${typeof item == `string` ? `li-${String(item)}` : isValidElement(item) ? `li-${item.key}` || `${index}-${MD5(item.toString())}` : item.label}-${index}`;
17
+ return _jsxs(Fragment, { children: [_jsx(Item, { meta: item }), seperator && _items[index + 1] ? _jsx("li", { className: `--list-seperator`, children: seperator }, `spt-${index + 1}-${_key}`) : null] }, _key);
18
+ })
15
19
  });
16
20
  });
17
21
  List.displayName = `Zuz.List`;
@@ -17,5 +17,5 @@ const Item = (props) => {
17
17
  }
18
18
  return _jsx("li", { style: style, className: className, ...rest, children: typeof meta == `string` ? meta : label });
19
19
  };
20
- Item.displayName = `ListItem`;
20
+ Item.displayName = `Zuz.ListItem`;
21
21
  export default Item;
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { forwardRef, useEffect, useMemo, useRef, useState } from "react";
4
- import { PubSub, SPINNER, Spinner, Text, uuid } from "../..";
4
+ import { PubSub, SPINNER, Spinner, Text, TRANSITION_CURVES, TRANSITIONS, uuid } from "../..";
5
5
  import { useBase } from "../../hooks";
6
6
  import Box from "../Box";
7
7
  import Pagination from "../Pagination";
@@ -94,8 +94,14 @@ const Table = (props, ref) => {
94
94
  setSortBy(col);
95
95
  onSort?.(col, dir);
96
96
  };
97
- const _paginated = useMemo(() => _jsx(Pagination, { hash: paginationHash, ref: _pagination, renderOnZeroPageCount: showPaginationOnZeroPageCount, onPageChange: onPageChange, paginationStyle: PaginationStyle.Table, startPage: currentPage, itemCount: rowCount || (rows ? rows.length : 0), itemsPerPage: rowsPerPage || 10 }), []);
98
- return _jsxs(Box, { as: `--table ${(hoverable ?? true) ? `--hoverable` : ``} flex cols rel ${className}`, ref: _tableRef, children: [_header == true && _jsx(TRow, { sortBy: _sortBy, onSort: handleSort, tableRef: _tableRef, pubsub: pubsub, selectable: selectableRows, index: -1, schema: schema, loading: true, styles: _schemaParsed }), loading && _jsxs(Box, { as: `abs center-x flex aic --table-spinner`, children: [_jsx(Spinner, { type: spinner || SPINNER.Simple }), loadingMessage && _jsx(Text, { as: `--table-loading-message`, children: loadingMessage })] }), loading && Array(loadingRowCount || 5).fill({}).map((row, index) => _jsx(TRow, { tableRef: _tableRef, index: index, pubsub: pubsub, schema: schema, styles: _schemaParsed, loading: true, animate: animateRows }, `--trow-loading-${index}-${schema[0].id}`)), !loading && rows && rows.map((row, index) => _jsx(TRow, { tableRef: _tableRef, pubsub: pubsub, loading: false, index: index, schema: schema, ids: _cols, styles: _schemaParsed, animate: animateRows, data: row, rowClassName: rowClassName, selectable: selectableRows, onSelect: onRowSelectToggle, onContextMenu: onRowContextMenu }, `--trow-${rowKeys.current[index] || index}-${schema[0].id}`)), pagination && _pagination.current != null && _jsx(Box, { as: `--row flex aic --row-footer`, children: _paginated })] });
97
+ const possiblePage = (rowCount || (rows ? rows.length : 0)) / (rowsPerPage || 10);
98
+ const _paginated = useMemo(() => (showPaginationOnZeroPageCount || (possiblePage > 1)) ? _jsx(Pagination, { hash: paginationHash, ref: _pagination, renderOnZeroPageCount: showPaginationOnZeroPageCount, onPageChange: onPageChange, paginationStyle: PaginationStyle.Table, startPage: currentPage, itemCount: rowCount || (rows ? rows.length : 0), itemsPerPage: rowsPerPage || 10 }) : null, [currentPage, rowCount]);
99
+ return _jsxs(Box, { as: `--table ${(hoverable ?? true) ? `--hoverable` : ``} flex cols rel ${className}`, ref: _tableRef, children: [_header == true && _jsx(TRow, { sortBy: _sortBy, onSort: handleSort, tableRef: _tableRef, pubsub: pubsub, selectable: selectableRows, index: -1, schema: schema, loading: true, styles: _schemaParsed }), loading && _jsxs(Box, { as: `abs center-x flex aic --table-spinner`, children: [_jsx(Spinner, { type: spinner || SPINNER.Simple }), loadingMessage && _jsx(Text, { as: `--table-loading-message`, children: loadingMessage })] }), loading && Array(loadingRowCount || 5).fill({}).map((row, index) => _jsx(TRow, { tableRef: _tableRef, index: index, pubsub: pubsub, schema: schema, styles: _schemaParsed, loading: true, animate: animateRows }, `--trow-loading-${index}-${schema[0].id}`)), !loading && rows && rows.map((row, index) => _jsx(TRow, { tableRef: _tableRef, pubsub: pubsub, loading: false, index: index, schema: schema, ids: _cols, styles: _schemaParsed, animate: animateRows, data: row, rowClassName: rowClassName, selectable: selectableRows, onSelect: onRowSelectToggle, onContextMenu: onRowContextMenu }, `--trow-${rowKeys.current[index] || index}-${schema[0].id}`)), _jsx(Box, { "aria-hidden": !pagination || !_paginated, ...(animateRows ? { fx: {
100
+ transition: TRANSITIONS.SlideInBottom,
101
+ curve: TRANSITION_CURVES.EaseInOut,
102
+ delay: .02 * (rows.length + 1),
103
+ when: !loading && rows && pagination && _paginated != null
104
+ } } : {}), as: `--row flex aic --row-footer`, children: pagination && _paginated ? _paginated : null })] });
99
105
  };
100
106
  Table.displayName = `Zuz.Table`;
101
107
  const ForwardedTable = forwardRef(Table);
@@ -74,7 +74,7 @@ const TRow = (props) => {
74
74
  };
75
75
  }
76
76
  }, []);
77
- return _jsxs(Box, { onContextMenu: e => onContextMenu ? onContextMenu(e, data) : null, ...(animate ? { animate: { ..._animation, when: mounted } } : {}), as: `--row flex aic ${index == -1 ? `--row-head` : ``} ${rowClassName || ``}`, children: [index == -1 && schema.map((c, i) => {
77
+ return _jsxs(Box, { onContextMenu: e => onContextMenu ? onContextMenu(e, data) : null, ...(animate ? { fx: { ..._animation, when: mounted } } : {}), as: `--row flex aic ${index == -1 ? `--row-head` : ``} ${rowClassName || ``}`, children: [index == -1 && schema.map((c, i) => {
78
78
  const { renderWhenHeader, render, value, ...cc } = c;
79
79
  return _jsxs(Fragment, { children: [selectable && i == 0 && Selector(-1, `--selector-${c.id}`, `all`), _jsx(TColumn, { idx: -1, onSort: onSort, sortBy: sortBy,
80
80
  // value={renderWhenHeader && render ? render!(index == -1 ? c as dynamicObject : data as T, index) : value as string}
@@ -0,0 +1,12 @@
1
+ import { FC, ReactNode } from "react";
2
+ import { TRANSITION_CURVES } from "../../types/enums";
3
+ import { ToastContextType } from "./types";
4
+ export declare const ToastContext: import("react").Context<ToastContextType | null>;
5
+ declare const ToastProvider: FC<{
6
+ children: ReactNode;
7
+ fx?: {
8
+ curve: TRANSITION_CURVES;
9
+ duration: number;
10
+ };
11
+ }>;
12
+ export default ToastProvider;
@@ -0,0 +1,44 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, forwardRef, useImperativeHandle, useMemo, useRef, useState } from "react";
3
+ import { TRANSITION_CURVES } from "../../types/enums";
4
+ import Box from "../Box";
5
+ import Toast from "./toast";
6
+ import { ToastType } from "./types";
7
+ export const ToastContext = createContext(null);
8
+ const ToastRenderer = forwardRef((props, ref) => {
9
+ const [toasts, setToasts] = useState([]);
10
+ const id = useRef(0);
11
+ const nextId = () => ++id.current;
12
+ useImperativeHandle(ref, () => ({
13
+ add(toast) {
14
+ const toastId = nextId();
15
+ const fullToast = { id: toastId, ...toast };
16
+ setToasts(prev => [fullToast, ...prev.slice(0, 4)]); // max 5
17
+ if (toast.duration !== Infinity && toast.type != ToastType.Promise) {
18
+ setTimeout(() => this.remove(toastId), ((toast.duration ?? 4) + 1) * 1000);
19
+ }
20
+ return toastId;
21
+ },
22
+ remove(id) {
23
+ setToasts(t => t.filter(toast => toast.id !== id));
24
+ },
25
+ clear() {
26
+ setToasts([]);
27
+ }
28
+ }));
29
+ return _jsx(Box, { as: `--toast-wrapper rel`, children: toasts.map((toast, i) => _jsx(Toast, { index: i, ...toast }, `toast-${toast.id}`)) });
30
+ });
31
+ const ToastProvider = forwardRef(({ children, fx }, ref) => {
32
+ const toastController = useRef(null);
33
+ const contextValue = useMemo(() => ({
34
+ add: (toast) => toastController.current?.add(toast),
35
+ remove: (id) => toastController.current?.remove(id),
36
+ clear: () => toastController.current?.clear(),
37
+ fx: fx || {
38
+ curve: TRANSITION_CURVES.EaseInOut,
39
+ duration: 0.4
40
+ }
41
+ }), [toastController.current]);
42
+ return _jsxs(ToastContext.Provider, { value: contextValue, children: [children, _jsx(ToastRenderer, { ref: toastController })] });
43
+ });
44
+ export default ToastProvider;
@@ -0,0 +1,6 @@
1
+ import { FC } from "react";
2
+ import { ToastData } from "./types";
3
+ declare const Toast: FC<ToastData & {
4
+ index: number;
5
+ }>;
6
+ export default Toast;
@@ -0,0 +1,49 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useContext } from "react";
3
+ import { ToastContext } from ".";
4
+ import { ToastDefaultTitle, TRANSITION_CURVES, TRANSITIONS, useDelayed } from "../..";
5
+ import Box from "../Box";
6
+ import Icon from "../Icon";
7
+ import Text from "../Text";
8
+ const Toast = ({ index, id, type, icon, title, message, duration }) => {
9
+ const mounted = useDelayed();
10
+ const expired = useDelayed(((duration || 4) - 1) * 1000);
11
+ const ctx = useContext(ToastContext);
12
+ return _jsxs(Box, { as: `--snack --${type} --snack-${id} ${index > 2 ? `--snacked` : ``} flex aic`, fx: {
13
+ from: { left: `50%`, x: `-50%`, top: -100, scale: 1, opacity: 0.5 },
14
+ to: { left: `50%`, x: `-50%`, top: 25, scale: 1, opacity: 1 },
15
+ // exit: { left: `50%`, x: `-50%`, top: 25, scale: 0, opacity: 0 },
16
+ curve: ctx?.fx.curve,
17
+ duration: ctx?.fx.duration,
18
+ when: mounted && !expired
19
+ }, children: [_jsx(Box, { as: `--ico flex aic jcc`, fx: {
20
+ transition: TRANSITIONS.ScaleIn,
21
+ curve: TRANSITION_CURVES.Spring,
22
+ delay: 0.2,
23
+ when: mounted && !expired
24
+ }, children: icon ? _jsx(Icon, { name: icon, fx: {
25
+ transition: TRANSITIONS.ScaleIn,
26
+ curve: TRANSITION_CURVES.Spring,
27
+ delay: 0.4,
28
+ duration: 0.5,
29
+ when: mounted && !expired
30
+ } }) : _jsx(Box, { as: `--no-icon`, fx: {
31
+ transition: TRANSITIONS.ScaleIn,
32
+ curve: TRANSITION_CURVES.Spring,
33
+ delay: 0.4,
34
+ duration: 0.5,
35
+ when: mounted && !expired
36
+ } }) }), _jsxs(Box, { as: `--meta`, children: [_jsx(Text, { as: `--tt`, fx: {
37
+ transition: TRANSITIONS.SlideInTop,
38
+ curve: TRANSITION_CURVES.Spring,
39
+ delay: 0.3,
40
+ when: mounted
41
+ }, children: title || ToastDefaultTitle[type] }), _jsx(Text, { as: `--tm`, fx: {
42
+ transition: TRANSITIONS.SlideInTop,
43
+ curve: TRANSITION_CURVES.Spring,
44
+ delay: 0.4,
45
+ duration: 0.5,
46
+ when: mounted
47
+ }, children: message })] })] });
48
+ };
49
+ export default Toast;
@@ -0,0 +1,30 @@
1
+ import { dynamic } from "../..";
2
+ import { TRANSITION_CURVES } from "../../types/enums";
3
+ export declare enum ToastType {
4
+ Default = "default",
5
+ Success = "success",
6
+ Error = "error",
7
+ Warn = "warn",
8
+ Promise = "promise"
9
+ }
10
+ export declare const ToastDefaultTitle: dynamic;
11
+ export interface ToastData {
12
+ id: number;
13
+ type: ToastType;
14
+ icon?: string;
15
+ title?: string;
16
+ message?: string;
17
+ duration?: number;
18
+ onClick?: () => void;
19
+ }
20
+ export interface ToastController {
21
+ add: (toast: Omit<ToastData, 'id'>) => number;
22
+ remove: (id: number) => void;
23
+ clear: () => void;
24
+ }
25
+ export interface ToastContextType extends ToastController {
26
+ fx: {
27
+ curve: TRANSITION_CURVES;
28
+ duration: number;
29
+ };
30
+ }
@@ -0,0 +1,14 @@
1
+ export var ToastType;
2
+ (function (ToastType) {
3
+ ToastType["Default"] = "default";
4
+ ToastType["Success"] = "success";
5
+ ToastType["Error"] = "error";
6
+ ToastType["Warn"] = "warn";
7
+ ToastType["Promise"] = "promise";
8
+ })(ToastType || (ToastType = {}));
9
+ export const ToastDefaultTitle = {
10
+ success: "Action Successful",
11
+ error: "Something Went Wrong",
12
+ warn: "Heads Up",
13
+ default: "Notice"
14
+ };
@@ -78,6 +78,8 @@ export { default as Text, type TextProps } from './Text';
78
78
  export { default as Textarea, type TextAreaProps } from './TextArea';
79
79
  export { default as TextWheel } from './TextWheel';
80
80
  export * from './TextWheel/types';
81
+ export { default as ToastProvider } from './Toast';
82
+ export * from './Toast/types';
81
83
  export { default as ToolTip } from './Tooltip';
82
84
  export * from './Tooltip/types';
83
85
  export { default as TreeView } from './Treeview';
@@ -78,6 +78,8 @@ export { default as Text } from './Text';
78
78
  export { default as Textarea } from './TextArea';
79
79
  export { default as TextWheel } from './TextWheel';
80
80
  export * from './TextWheel/types';
81
+ export { default as ToastProvider } from './Toast';
82
+ export * from './Toast/types';
81
83
  export { default as ToolTip } from './Tooltip';
82
84
  export * from './Tooltip/types';
83
85
  export { default as TreeView } from './Treeview';
@@ -27,6 +27,7 @@ export { default as useShortcuts } from './useShortcuts';
27
27
  export { default as useNetworkStatus } from './useNetworkStatus';
28
28
  export { default as useResizeObserver } from './useResizeObserver';
29
29
  export { default as useSlider } from './useSlider';
30
+ export { default as useToast } from './useToast';
30
31
  export { default as useTruncateText } from './useTruncateText';
31
32
  export { default as useUploader } from './useUploader';
32
33
  export { default as useViewTransition } from './useViewTransition';
@@ -28,6 +28,7 @@ export { default as useShortcuts } from './useShortcuts';
28
28
  export { default as useNetworkStatus } from './useNetworkStatus';
29
29
  export { default as useResizeObserver } from './useResizeObserver';
30
30
  export { default as useSlider } from './useSlider';
31
+ export { default as useToast } from './useToast';
31
32
  export { default as useTruncateText } from './useTruncateText';
32
33
  export { default as useUploader } from './useUploader';
33
34
  export { default as useViewTransition } from './useViewTransition';
@@ -34,7 +34,7 @@ const useBase = (props) => {
34
34
  if (as) {
35
35
  cx = css().Build(`string` == typeof as ? as : as.join(` `)).cx;
36
36
  }
37
- const { transition, from, to, when, duration, delay, curve } = autoTransition ? {
37
+ const { transition, from, to, exit, when, duration, delay, curve } = autoTransition ? {
38
38
  transition: autoTransition,
39
39
  duration: 0.3
40
40
  } : fx || animate || {};
@@ -48,6 +48,23 @@ const useBase = (props) => {
48
48
  else {
49
49
  _style = transition ? getAnimationTransition(transition, false, true) : from || {};
50
50
  }
51
+ // Track previous value of 'when'
52
+ // const prevWhenRef = useRef<boolean | undefined>(when);
53
+ // if (undefined === when) {
54
+ // _style = transition ? getAnimationTransition(transition, true) : { ...from, ...to };
55
+ // } else if (true === when) {
56
+ // _style = transition ? getAnimationTransition(transition, false) : { ...(to || {}) };
57
+ // } else {
58
+ // // Check if exit style should be applied
59
+ // const wasTrue = prevWhenRef.current === true;
60
+ // if (wasTrue && exit) {
61
+ // _style = { ...(exit || {}) };
62
+ // } else {
63
+ // _style = transition ? getAnimationTransition(transition, false, true) : from || {};
64
+ // }
65
+ // }
66
+ // // Update previous value for next render
67
+ // prevWhenRef.current = when;
51
68
  const _transition = {};
52
69
  if (transition || (from && to)) {
53
70
  // { transition: `all ${duration || `0.2`}s ${getAnimationCurve(curve)} ${delay || 0}s` }
@@ -0,0 +1,10 @@
1
+ declare const useToast: () => {
2
+ show: (title: string, message?: string, icon?: string, duration?: number) => number;
3
+ hide: (id: number) => void;
4
+ success: (title: string, message?: string, icon?: string, duration?: number) => number;
5
+ error: (title: string, message?: string, icon?: string, duration?: number) => number;
6
+ warn: (title: string, message?: string, icon?: string, duration?: number) => number;
7
+ promise: (title: string, message?: string, icon?: string, duration?: number) => number;
8
+ clearAll: () => void;
9
+ };
10
+ export default useToast;
@@ -0,0 +1,18 @@
1
+ import { useContext } from "react";
2
+ import { ToastContext } from "../comps/Toast";
3
+ import { ToastType } from "../comps/Toast/types";
4
+ const useToast = () => {
5
+ const ctx = useContext(ToastContext);
6
+ if (!ctx)
7
+ throw new Error('useToast must be used inside <ToastProvider>');
8
+ const base = (type, data) => ctx.add({ ...data, type });
9
+ const clearAll = () => ctx.clear();
10
+ const hide = (id) => ctx.remove(id);
11
+ const show = (title, message, icon, duration) => base(ToastType.Default, { title, message, icon, duration });
12
+ const success = (title, message, icon, duration) => base(ToastType.Success, { title, message, icon, duration });
13
+ const error = (title, message, icon, duration) => base(ToastType.Error, { title, message, icon, duration });
14
+ const warn = (title, message, icon, duration) => base(ToastType.Warn, { title, message, icon, duration });
15
+ const promise = (title, message, icon, duration) => base(ToastType.Promise, { title, message, icon, duration });
16
+ return { show, hide, success, error, warn, promise, clearAll };
17
+ };
18
+ export default useToast;
@@ -16,6 +16,8 @@ export interface animationProps {
16
16
  from?: dynamicObject;
17
17
  /** Target style properties after the animation completes */
18
18
  to?: dynamicObject;
19
+ /** Target style properties for exit animation */
20
+ exit?: dynamicObject;
19
21
  /** Condition that determines when the animation should trigger */
20
22
  when?: boolean;
21
23
  /** Duration of the animation in milliseconds */