@choice-ui/react 1.6.8 → 1.7.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.
Files changed (81) hide show
  1. package/dist/components/description/dist/index.d.ts +8 -0
  2. package/dist/components/description/dist/index.js +29 -0
  3. package/dist/components/description/src/description.d.ts +6 -0
  4. package/dist/components/description/src/description.js +18 -0
  5. package/dist/components/description/src/index.d.ts +2 -0
  6. package/dist/components/description/src/tv.d.ts +13 -0
  7. package/dist/components/description/src/tv.js +15 -0
  8. package/dist/components/description/tsup.config.d.ts +2 -0
  9. package/dist/components/emoji-picker/dist/index.d.ts +1 -0
  10. package/dist/components/emoji-picker/dist/index.js +4 -2
  11. package/dist/components/emoji-picker/src/emoji-picker.d.ts +1 -0
  12. package/dist/components/emoji-picker/src/emoji-picker.js +4 -2
  13. package/dist/components/error-message/dist/index.d.ts +8 -0
  14. package/dist/components/error-message/dist/index.js +30 -0
  15. package/dist/components/error-message/src/error-message.d.ts +6 -0
  16. package/dist/components/error-message/src/error-message.js +19 -0
  17. package/dist/components/error-message/src/index.d.ts +2 -0
  18. package/dist/components/error-message/src/tv.d.ts +13 -0
  19. package/dist/components/error-message/src/tv.js +15 -0
  20. package/dist/components/error-message/tsup.config.d.ts +2 -0
  21. package/dist/components/form/src/adapters/base-adapter.js +4 -2
  22. package/dist/components/form/src/tv.d.ts +0 -12
  23. package/dist/components/form/src/tv.js +1 -13
  24. package/dist/components/index.d.ts +3 -0
  25. package/dist/components/md-render/dist/index.d.ts +2 -1
  26. package/dist/components/md-render/dist/index.js +3 -1
  27. package/dist/components/md-render/src/md-render.js +3 -1
  28. package/dist/components/md-render/src/types.d.ts +2 -1
  29. package/dist/components/notifications/dist/index.d.ts +1 -5
  30. package/dist/components/notifications/src/notifications.d.ts +0 -1
  31. package/dist/components/notifications/src/notifications.js +0 -1
  32. package/dist/components/numeric-input/dist/index.d.ts +23 -9
  33. package/dist/components/numeric-input/dist/index.js +26 -3
  34. package/dist/components/numeric-input/src/components/numeric-input-menu-trigger.js +4 -1
  35. package/dist/components/numeric-input/src/hooks/index.d.ts +1 -0
  36. package/dist/components/numeric-input/src/hooks/use-numeric-long-press.d.ts +13 -0
  37. package/dist/components/numeric-input/src/hooks/use-numeric-long-press.js +27 -0
  38. package/dist/components/numeric-input/src/index.d.ts +1 -0
  39. package/dist/components/numeric-input/src/tv.js +22 -2
  40. package/dist/components/picture-preview/dist/index.d.ts +5 -0
  41. package/dist/components/picture-preview/dist/index.js +287 -140
  42. package/dist/components/picture-preview/src/hooks/useWheelHandler.d.ts +6 -1
  43. package/dist/components/picture-preview/src/hooks/useWheelHandler.js +25 -7
  44. package/dist/components/picture-preview/src/picture-preview.d.ts +5 -0
  45. package/dist/components/picture-preview/src/picture-preview.js +214 -123
  46. package/dist/components/picture-preview/src/tv.d.ts +93 -3
  47. package/dist/components/picture-preview/src/tv.js +48 -10
  48. package/dist/components/separator/dist/index.d.ts +1 -8
  49. package/dist/components/separator/src/separator.d.ts +1 -8
  50. package/dist/components/separator/src/separator.js +33 -5
  51. package/dist/components/separator/src/tv.d.ts +39 -18
  52. package/dist/components/separator/src/tv.js +37 -7
  53. package/dist/components/text-field/dist/index.d.ts +2 -3
  54. package/dist/components/text-field/dist/index.js +4 -19
  55. package/dist/components/text-field/src/components/index.d.ts +0 -1
  56. package/dist/components/text-field/src/text-field.d.ts +3 -2
  57. package/dist/components/text-field/src/text-field.js +2 -2
  58. package/dist/components/text-field/src/tv.d.ts +3 -3
  59. package/dist/components/text-field/src/tv.js +1 -6
  60. package/dist/components/toast/dist/index.d.ts +260 -0
  61. package/dist/components/toast/src/components/index.d.ts +3 -0
  62. package/dist/components/toast/src/components/toast-progress-bar.d.ts +7 -0
  63. package/dist/components/toast/src/components/toast-progress-bar.js +53 -0
  64. package/dist/components/toast/src/components/toaster-item.d.ts +26 -0
  65. package/dist/components/toast/src/components/toaster-item.js +412 -0
  66. package/dist/components/toast/src/components/toaster-slots.d.ts +87 -0
  67. package/dist/components/toast/src/components/toaster-slots.js +38 -0
  68. package/dist/components/toast/src/index.d.ts +5 -0
  69. package/dist/components/toast/src/store.d.ts +113 -0
  70. package/dist/components/toast/src/store.js +204 -0
  71. package/dist/components/toast/src/toaster.d.ts +87 -0
  72. package/dist/components/toast/src/toaster.js +271 -0
  73. package/dist/components/toast/src/tv.d.ts +365 -0
  74. package/dist/components/toast/src/tv.js +412 -0
  75. package/dist/components/toast/src/types.d.ts +79 -0
  76. package/dist/components/toast/tsup.config.d.ts +2 -0
  77. package/dist/index.js +11 -2
  78. package/dist/styles/components.css +2 -0
  79. package/package.json +1 -1
  80. package/dist/components/text-field/src/components/field-description.d.ts +0 -2
  81. package/dist/components/text-field/src/components/field-description.js +0 -16
@@ -0,0 +1,260 @@
1
+ import { ReactNode } from 'react';
2
+ import * as react from 'react';
3
+
4
+ type ToastType = "info" | "success" | "warning" | "error" | "loading" | "default";
5
+ type ToastVariant = "default" | "accent" | "success" | "warning" | "error" | "assistive" | "reset";
6
+ type ToastPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right";
7
+
8
+ interface ToastAction {
9
+ label: ReactNode;
10
+ onClick: () => void;
11
+ }
12
+ interface ToastCancel {
13
+ label: ReactNode;
14
+ onClick?: () => void;
15
+ }
16
+ /**
17
+ * Props for Toaster.Item slot component
18
+ */
19
+ interface ToasterItemSlotProps {
20
+ className?: string;
21
+ style?: React.CSSProperties;
22
+ children?: ReactNode;
23
+ }
24
+ /**
25
+ * Slot component for customizing toast item container
26
+ */
27
+ declare const ToasterItemSlot: react.ForwardRefExoticComponent<ToasterItemSlotProps & react.RefAttributes<HTMLDivElement>>;
28
+ /**
29
+ * Props for Toaster.Icon slot component
30
+ */
31
+ interface ToasterIconSlotProps {
32
+ className?: string;
33
+ style?: React.CSSProperties;
34
+ /** Custom render function - receives type and default icon */
35
+ children?: (type: ToastType, defaultIcon: ReactNode) => ReactNode;
36
+ }
37
+ /**
38
+ * Slot component for customizing toast icon
39
+ */
40
+ declare const ToasterIconSlot: react.ForwardRefExoticComponent<ToasterIconSlotProps & react.RefAttributes<HTMLDivElement>>;
41
+ /**
42
+ * Props for Toaster.Title slot component
43
+ */
44
+ interface ToasterTitleSlotProps {
45
+ className?: string;
46
+ style?: React.CSSProperties;
47
+ }
48
+ /**
49
+ * Slot component for customizing toast title
50
+ */
51
+ declare const ToasterTitleSlot: react.ForwardRefExoticComponent<ToasterTitleSlotProps & react.RefAttributes<HTMLDivElement>>;
52
+ /**
53
+ * Props for Toaster.Description slot component
54
+ */
55
+ interface ToasterDescriptionSlotProps {
56
+ className?: string;
57
+ style?: React.CSSProperties;
58
+ }
59
+ /**
60
+ * Slot component for customizing toast description
61
+ */
62
+ declare const ToasterDescriptionSlot: react.ForwardRefExoticComponent<ToasterDescriptionSlotProps & react.RefAttributes<HTMLDivElement>>;
63
+ /**
64
+ * Props for Toaster.Actions slot component
65
+ */
66
+ interface ToasterActionsSlotProps {
67
+ className?: string;
68
+ style?: React.CSSProperties;
69
+ /** Custom render function for actions */
70
+ children?: (action: ToastAction | undefined, cancel: ToastCancel | undefined, close: () => void) => ReactNode;
71
+ }
72
+ /**
73
+ * Slot component for customizing toast actions
74
+ */
75
+ declare const ToasterActionsSlot: react.ForwardRefExoticComponent<ToasterActionsSlotProps & react.RefAttributes<HTMLDivElement>>;
76
+
77
+ interface ToastData {
78
+ id: string;
79
+ type: ToastType;
80
+ variant?: ToastVariant;
81
+ /**
82
+ * Title content. Supports:
83
+ * - Plain string: rendered as text
84
+ * - HTML string (containing tags like `<b>`, `<strong>`, etc.): rendered as HTML
85
+ * - ReactNode: rendered as React component
86
+ */
87
+ title?: React.ReactNode;
88
+ /**
89
+ * Description content. Supports:
90
+ * - Plain string: rendered as text
91
+ * - HTML string (containing tags like `<b>`, `<strong>`, etc.): rendered as HTML
92
+ * - ReactNode: rendered as React component
93
+ */
94
+ description?: React.ReactNode;
95
+ duration?: number;
96
+ icon?: React.ReactNode;
97
+ action?: {
98
+ label: React.ReactNode;
99
+ onClick: () => void;
100
+ };
101
+ cancel?: {
102
+ label: React.ReactNode;
103
+ onClick?: () => void;
104
+ };
105
+ onClose?: () => void;
106
+ onAutoClose?: () => void;
107
+ dismissible?: boolean;
108
+ createdAt: number;
109
+ height?: number;
110
+ removing?: boolean;
111
+ swipeDirection?: "left" | "right" | "up" | "down";
112
+ }
113
+ interface ToastOptions {
114
+ id?: string;
115
+ variant?: ToastVariant;
116
+ /**
117
+ * Description content. Supports:
118
+ * - Plain string: rendered as text
119
+ * - HTML string (containing tags like `<b>`, `<strong>`, etc.): rendered as HTML
120
+ * - ReactNode: rendered as React component
121
+ */
122
+ description?: React.ReactNode;
123
+ duration?: number;
124
+ icon?: React.ReactNode;
125
+ action?: {
126
+ label: React.ReactNode;
127
+ onClick: () => void;
128
+ };
129
+ cancel?: {
130
+ label: React.ReactNode;
131
+ onClick?: () => void;
132
+ };
133
+ onClose?: () => void;
134
+ onAutoClose?: () => void;
135
+ dismissible?: boolean;
136
+ }
137
+ interface PromiseOptions<T> {
138
+ loading: string | (ToastOptions & {
139
+ title: string;
140
+ });
141
+ success: string | (ToastOptions & {
142
+ title: string;
143
+ }) | ((data: T) => string | (ToastOptions & {
144
+ title: string;
145
+ }));
146
+ error: string | (ToastOptions & {
147
+ title: string;
148
+ }) | ((err: unknown) => string | (ToastOptions & {
149
+ title: string;
150
+ }));
151
+ }
152
+ type ToastFunction = {
153
+ (title: string, options?: ToastOptions): string;
154
+ success: (title: string, options?: ToastOptions) => string;
155
+ error: (title: string, options?: ToastOptions) => string;
156
+ warning: (title: string, options?: ToastOptions) => string;
157
+ info: (title: string, options?: ToastOptions) => string;
158
+ loading: (title: string, options?: ToastOptions) => string;
159
+ promise: <T>(promise: Promise<T>, options: PromiseOptions<T>) => Promise<T>;
160
+ dismiss: (id: string) => void;
161
+ dismissAll: () => void;
162
+ use: (toasterId: string) => {
163
+ (title: string, options?: ToastOptions): string;
164
+ success: (title: string, options?: ToastOptions) => string;
165
+ error: (title: string, options?: ToastOptions) => string;
166
+ warning: (title: string, options?: ToastOptions) => string;
167
+ info: (title: string, options?: ToastOptions) => string;
168
+ loading: (title: string, options?: ToastOptions) => string;
169
+ promise: <T>(promise: Promise<T>, options: PromiseOptions<T>) => Promise<T>;
170
+ dismiss: (id: string) => void;
171
+ dismissAll: () => void;
172
+ };
173
+ };
174
+ declare const toast: ToastFunction;
175
+
176
+ interface ToasterProps {
177
+ /**
178
+ * Unique ID for this Toaster instance
179
+ * Use this to have multiple Toaster instances in the same app
180
+ * @default "default"
181
+ */
182
+ id?: string;
183
+ /**
184
+ * Position of the toaster
185
+ * @default "bottom-right"
186
+ */
187
+ position?: ToastPosition;
188
+ /**
189
+ * Render toasts into a custom container
190
+ */
191
+ container?: HTMLElement | null;
192
+ /**
193
+ * Label for accessibility
194
+ * @default "Notifications"
195
+ */
196
+ label?: string;
197
+ /**
198
+ * Whether to use a portal for rendering
199
+ * @default true
200
+ */
201
+ portal?: boolean;
202
+ /**
203
+ * Offset from viewport edges in pixels
204
+ * @default 16
205
+ */
206
+ offset?: number;
207
+ /**
208
+ * Default duration for toasts in ms
209
+ * @default 5000
210
+ */
211
+ duration?: number;
212
+ /**
213
+ * Maximum number of visible toasts
214
+ * @default 3
215
+ */
216
+ visibleToasts?: number;
217
+ /**
218
+ * Additional class name
219
+ */
220
+ className?: string;
221
+ /**
222
+ * Children - use Toaster.Item to customize toast rendering
223
+ */
224
+ children?: ReactNode;
225
+ /**
226
+ * Show countdown progress bar at the bottom of each toast
227
+ * @default false
228
+ */
229
+ showProgress?: boolean;
230
+ /**
231
+ * Layout mode for toasts
232
+ * @default "default"
233
+ */
234
+ layout?: "default" | "compact";
235
+ }
236
+ interface ToasterComponent extends React.MemoExoticComponent<React.ForwardRefExoticComponent<ToasterProps & React.RefAttributes<HTMLDivElement>>> {
237
+ Item: typeof ToasterItemSlot;
238
+ Icon: typeof ToasterIconSlot;
239
+ Title: typeof ToasterTitleSlot;
240
+ Description: typeof ToasterDescriptionSlot;
241
+ Actions: typeof ToasterActionsSlot;
242
+ }
243
+ /**
244
+ * Toaster component with compound pattern
245
+ *
246
+ * @example
247
+ * ```tsx
248
+ * <Toaster id="my-toaster">
249
+ * <Toaster.Item className="custom-class">
250
+ * <Toaster.Icon>{(type, defaultIcon) => <CustomIcon type={type} />}</Toaster.Icon>
251
+ * <Toaster.Title className="font-bold uppercase" />
252
+ * <Toaster.Description className="text-sm" />
253
+ * <Toaster.Actions>{(action, cancel, close) => <CustomActions />}</Toaster.Actions>
254
+ * </Toaster.Item>
255
+ * </Toaster>
256
+ * ```
257
+ */
258
+ declare const Toaster: ToasterComponent;
259
+
260
+ export { type ToastData, type ToastOptions, type ToastPosition, type ToastType, type ToastVariant, Toaster, type ToasterProps, toast };
@@ -0,0 +1,3 @@
1
+ export * from './toast-progress-bar';
2
+ export * from './toaster-slots';
3
+ export * from './toaster-item';
@@ -0,0 +1,7 @@
1
+ import { toastRootTv } from '../tv';
2
+ export interface ToastProgressBarProps {
3
+ duration: number;
4
+ isPaused: boolean;
5
+ tv: ReturnType<typeof toastRootTv>;
6
+ }
7
+ export declare const ToastProgressBar: import('react').NamedExoticComponent<ToastProgressBarProps>;
@@ -0,0 +1,53 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useAnimationControls, motion } from "framer-motion";
3
+ import { memo, useRef, useEffect } from "react";
4
+ const ToastProgressBar = memo(function ToastProgressBar2({
5
+ duration,
6
+ isPaused,
7
+ tv
8
+ }) {
9
+ const controls = useAnimationControls();
10
+ const progressRef = useRef({ elapsed: 0, lastTime: Date.now() });
11
+ useEffect(() => {
12
+ progressRef.current = { elapsed: 0, lastTime: Date.now() };
13
+ controls.start({
14
+ x: "-100%",
15
+ transition: {
16
+ duration: duration / 1e3,
17
+ ease: "linear"
18
+ }
19
+ });
20
+ }, [controls, duration]);
21
+ useEffect(() => {
22
+ const durationSec = duration / 1e3;
23
+ if (isPaused) {
24
+ const now = Date.now();
25
+ progressRef.current.elapsed += (now - progressRef.current.lastTime) / 1e3;
26
+ controls.stop();
27
+ } else {
28
+ const remaining = Math.max(0, durationSec - progressRef.current.elapsed);
29
+ progressRef.current.lastTime = Date.now();
30
+ if (remaining > 0) {
31
+ controls.start({
32
+ x: "-100%",
33
+ transition: {
34
+ duration: remaining,
35
+ ease: "linear"
36
+ }
37
+ });
38
+ }
39
+ }
40
+ }, [isPaused, controls, duration]);
41
+ return /* @__PURE__ */ jsx("div", { className: tv.progressTrack(), children: /* @__PURE__ */ jsx(
42
+ motion.div,
43
+ {
44
+ className: tv.progressIndicator(),
45
+ initial: { x: 0 },
46
+ animate: controls
47
+ }
48
+ ) });
49
+ });
50
+ ToastProgressBar.displayName = "ToastProgressBar";
51
+ export {
52
+ ToastProgressBar
53
+ };
@@ -0,0 +1,26 @@
1
+ import { ToastData } from '../store';
2
+ import { ToastPosition } from '../types';
3
+ import { CollectedSlotProps } from './toaster-slots';
4
+ declare const GAP = 12;
5
+ declare const DEFAULT_HEIGHT = 56;
6
+ export { DEFAULT_HEIGHT, GAP };
7
+ export interface ToasterItemProps {
8
+ toast: ToastData;
9
+ index: number;
10
+ total: number;
11
+ expanded: boolean;
12
+ position: ToastPosition;
13
+ toasterId: string;
14
+ /** Heights of all visible toasts for offset calculation */
15
+ toastHeights: number[];
16
+ /** Collected slot props from Toaster.Item children */
17
+ slotProps: CollectedSlotProps;
18
+ /** Show countdown progress bar */
19
+ showProgress?: boolean;
20
+ /** Default duration from Toaster */
21
+ defaultDuration?: number;
22
+ /** Whether the timer is paused (hovering) */
23
+ isPaused?: boolean;
24
+ layout?: "default" | "compact";
25
+ }
26
+ export declare const ToasterItem: import('react').MemoExoticComponent<import('react').ForwardRefExoticComponent<ToasterItemProps & import('react').RefAttributes<HTMLDivElement>>>;