@re-venue/ui-core-react 0.1.3 → 0.2.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 (45) hide show
  1. package/dist/index.d.ts +409 -0
  2. package/dist/ui-core-react.css +1 -1
  3. package/dist/ui-core-react.js +10059 -210
  4. package/dist/ui-core-react.umd.cjs +47 -1
  5. package/package.json +26 -1
  6. package/src/components/common/ConfirmationModal.tsx +65 -0
  7. package/src/components/common/Container.tsx +15 -0
  8. package/src/components/common/DangerZoneSection.tsx +62 -0
  9. package/src/components/common/DetailPanel.tsx +115 -0
  10. package/src/components/common/DetailSheet.tsx +98 -0
  11. package/src/components/common/EditableTitle.tsx +119 -0
  12. package/src/components/common/EmptyState.tsx +36 -0
  13. package/src/components/common/FormModal.tsx +64 -0
  14. package/src/components/common/NavigationListItem.tsx +24 -0
  15. package/src/components/common/PanelEmptyState.tsx +17 -0
  16. package/src/components/ui/alert-dialog.tsx +104 -0
  17. package/src/components/ui/avatar.tsx +38 -0
  18. package/src/components/ui/badge.tsx +31 -0
  19. package/src/components/ui/button.tsx +47 -0
  20. package/src/components/ui/card.tsx +43 -0
  21. package/src/components/ui/checkbox.tsx +26 -0
  22. package/src/components/ui/dialog.tsx +95 -0
  23. package/src/components/ui/input.tsx +22 -0
  24. package/src/components/ui/label.tsx +17 -0
  25. package/src/components/ui/multi-select.tsx +109 -0
  26. package/src/components/ui/popover.tsx +29 -0
  27. package/src/components/ui/progress.tsx +23 -0
  28. package/src/components/ui/scroll-area.tsx +38 -0
  29. package/src/components/ui/select.tsx +143 -0
  30. package/src/components/ui/separator.tsx +20 -0
  31. package/src/components/ui/sheet.tsx +107 -0
  32. package/src/components/ui/skeleton.tsx +7 -0
  33. package/src/components/ui/sonner.tsx +27 -0
  34. package/src/components/ui/switch.tsx +27 -0
  35. package/src/components/ui/table.tsx +72 -0
  36. package/src/components/ui/toast.tsx +111 -0
  37. package/src/components/ui/toaster.tsx +24 -0
  38. package/src/components/ui/tooltip.tsx +28 -0
  39. package/src/components/ui/use-toast.ts +3 -0
  40. package/src/hooks/use-toast.ts +186 -0
  41. package/src/hooks/useDetailPanel.ts +21 -0
  42. package/src/hooks/useDetailSheetControls.ts +16 -0
  43. package/src/index.ts +48 -0
  44. package/src/lib/utils.ts +6 -0
  45. package/src/styles/utilities.css +1 -0
@@ -0,0 +1,186 @@
1
+ import * as React from "react";
2
+
3
+ import type { ToastActionElement, ToastProps } from "../components/ui/toast";
4
+
5
+ const TOAST_LIMIT = 1;
6
+ const TOAST_REMOVE_DELAY = 1000000;
7
+
8
+ type ToasterToast = ToastProps & {
9
+ id: string;
10
+ title?: React.ReactNode;
11
+ description?: React.ReactNode;
12
+ action?: ToastActionElement;
13
+ };
14
+
15
+ const actionTypes = {
16
+ ADD_TOAST: "ADD_TOAST",
17
+ UPDATE_TOAST: "UPDATE_TOAST",
18
+ DISMISS_TOAST: "DISMISS_TOAST",
19
+ REMOVE_TOAST: "REMOVE_TOAST",
20
+ } as const;
21
+
22
+ let count = 0;
23
+
24
+ function genId() {
25
+ count = (count + 1) % Number.MAX_SAFE_INTEGER;
26
+ return count.toString();
27
+ }
28
+
29
+ type ActionType = typeof actionTypes;
30
+
31
+ type Action =
32
+ | {
33
+ type: ActionType["ADD_TOAST"];
34
+ toast: ToasterToast;
35
+ }
36
+ | {
37
+ type: ActionType["UPDATE_TOAST"];
38
+ toast: Partial<ToasterToast>;
39
+ }
40
+ | {
41
+ type: ActionType["DISMISS_TOAST"];
42
+ toastId?: ToasterToast["id"];
43
+ }
44
+ | {
45
+ type: ActionType["REMOVE_TOAST"];
46
+ toastId?: ToasterToast["id"];
47
+ };
48
+
49
+ interface State {
50
+ toasts: ToasterToast[];
51
+ }
52
+
53
+ const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>();
54
+
55
+ const addToRemoveQueue = (toastId: string) => {
56
+ if (toastTimeouts.has(toastId)) {
57
+ return;
58
+ }
59
+
60
+ const timeout = setTimeout(() => {
61
+ toastTimeouts.delete(toastId);
62
+ dispatch({
63
+ type: "REMOVE_TOAST",
64
+ toastId: toastId,
65
+ });
66
+ }, TOAST_REMOVE_DELAY);
67
+
68
+ toastTimeouts.set(toastId, timeout);
69
+ };
70
+
71
+ export const reducer = (state: State, action: Action): State => {
72
+ switch (action.type) {
73
+ case "ADD_TOAST":
74
+ return {
75
+ ...state,
76
+ toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
77
+ };
78
+
79
+ case "UPDATE_TOAST":
80
+ return {
81
+ ...state,
82
+ toasts: state.toasts.map((t) => (t.id === action.toast.id ? { ...t, ...action.toast } : t)),
83
+ };
84
+
85
+ case "DISMISS_TOAST": {
86
+ const { toastId } = action;
87
+
88
+ // ! Side effects ! - This could be extracted into a dismissToast() action,
89
+ // but I'll keep it here for simplicity
90
+ if (toastId) {
91
+ addToRemoveQueue(toastId);
92
+ } else {
93
+ state.toasts.forEach((toast) => {
94
+ addToRemoveQueue(toast.id);
95
+ });
96
+ }
97
+
98
+ return {
99
+ ...state,
100
+ toasts: state.toasts.map((t) =>
101
+ t.id === toastId || toastId === undefined
102
+ ? {
103
+ ...t,
104
+ open: false,
105
+ }
106
+ : t,
107
+ ),
108
+ };
109
+ }
110
+ case "REMOVE_TOAST":
111
+ if (action.toastId === undefined) {
112
+ return {
113
+ ...state,
114
+ toasts: [],
115
+ };
116
+ }
117
+ return {
118
+ ...state,
119
+ toasts: state.toasts.filter((t) => t.id !== action.toastId),
120
+ };
121
+ }
122
+ };
123
+
124
+ const listeners: Array<(state: State) => void> = [];
125
+
126
+ let memoryState: State = { toasts: [] };
127
+
128
+ function dispatch(action: Action) {
129
+ memoryState = reducer(memoryState, action);
130
+ listeners.forEach((listener) => {
131
+ listener(memoryState);
132
+ });
133
+ }
134
+
135
+ type Toast = Omit<ToasterToast, "id">;
136
+
137
+ function toast({ ...props }: Toast) {
138
+ const id = genId();
139
+
140
+ const update = (props: ToasterToast) =>
141
+ dispatch({
142
+ type: "UPDATE_TOAST",
143
+ toast: { ...props, id },
144
+ });
145
+ const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });
146
+
147
+ dispatch({
148
+ type: "ADD_TOAST",
149
+ toast: {
150
+ ...props,
151
+ id,
152
+ open: true,
153
+ onOpenChange: (open) => {
154
+ if (!open) dismiss();
155
+ },
156
+ },
157
+ });
158
+
159
+ return {
160
+ id: id,
161
+ dismiss,
162
+ update,
163
+ };
164
+ }
165
+
166
+ function useToast() {
167
+ const [state, setState] = React.useState<State>(memoryState);
168
+
169
+ React.useEffect(() => {
170
+ listeners.push(setState);
171
+ return () => {
172
+ const index = listeners.indexOf(setState);
173
+ if (index > -1) {
174
+ listeners.splice(index, 1);
175
+ }
176
+ };
177
+ }, [state]);
178
+
179
+ return {
180
+ ...state,
181
+ toast,
182
+ dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
183
+ };
184
+ }
185
+
186
+ export { useToast, toast };
@@ -0,0 +1,21 @@
1
+ import { useContext } from "react";
2
+
3
+ import { DetailSheetContext, type DetailSheetContextType } from "../components/common/DetailSheet";
4
+
5
+ export function useDetailSheet(): DetailSheetContextType {
6
+ const context = useContext(DetailSheetContext);
7
+ if (!context) {
8
+ throw new Error("useDetailSheet must be used within a DetailSheet");
9
+ }
10
+ return context;
11
+ }
12
+
13
+ export function useDetailPanel(panelKey: string) {
14
+ const { displayStack, portalTarget, isDismissingRef } = useDetailSheet();
15
+
16
+ const isActive = displayStack.includes(panelKey);
17
+ const isTopPanel = displayStack.length > 0 && displayStack[displayStack.length - 1] === panelKey;
18
+ const depth = displayStack.indexOf(panelKey);
19
+
20
+ return { isActive, isTopPanel, depth, portalTarget, isDismissingRef };
21
+ }
@@ -0,0 +1,16 @@
1
+ import { useRef, useCallback } from "react";
2
+ import type { DetailSheetHandle } from "../components/common/DetailSheet";
3
+
4
+ export function useDetailSheetControls() {
5
+ const ref = useRef<DetailSheetHandle>(null);
6
+
7
+ const push = useCallback((panelKey: string) => {
8
+ ref.current?.push(panelKey);
9
+ }, []);
10
+
11
+ const pop = useCallback(() => {
12
+ ref.current?.pop();
13
+ }, []);
14
+
15
+ return { ref, push, pop };
16
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,53 @@
1
+ import './styles/utilities.css'
2
+
3
+ // Shell & navigation
1
4
  export { AppShell } from './components/AppShell'
2
5
  export { VenueSwitcher } from './components/VenueSwitcher'
3
6
  export { ConfirmModal } from './components/ConfirmModal'
4
7
  export { useTheme } from './hooks/useTheme'
5
8
  export type { AuthUser, Venue, SidebarNavItem } from './types'
9
+
10
+ // UI primitives
11
+ export * from './components/ui/alert-dialog'
12
+ export * from './components/ui/avatar'
13
+ export * from './components/ui/badge'
14
+ export * from './components/ui/button'
15
+ export * from './components/ui/card'
16
+ export * from './components/ui/checkbox'
17
+ export * from './components/ui/dialog'
18
+ export * from './components/ui/input'
19
+ export * from './components/ui/label'
20
+ export * from './components/ui/multi-select'
21
+ export * from './components/ui/popover'
22
+ export * from './components/ui/progress'
23
+ export * from './components/ui/scroll-area'
24
+ export * from './components/ui/select'
25
+ export * from './components/ui/separator'
26
+ export * from './components/ui/sheet'
27
+ export * from './components/ui/skeleton'
28
+ export { Toaster as SonnerToaster, toast as sonnerToast } from './components/ui/sonner'
29
+ export * from './components/ui/switch'
30
+ export * from './components/ui/table'
31
+ export * from './components/ui/toast'
32
+ export { Toaster as RadixToaster } from './components/ui/toaster'
33
+ export * from './components/ui/tooltip'
34
+ export { useToast, toast } from './hooks/use-toast'
35
+
36
+ // Common layout & UX patterns
37
+ export { Container } from './components/common/Container'
38
+ export { EmptyState } from './components/common/EmptyState'
39
+ export { FormModal } from './components/common/FormModal'
40
+ export { ConfirmationModal } from './components/common/ConfirmationModal'
41
+ export { DetailPanel } from './components/common/DetailPanel'
42
+ export { DetailSheet, DetailSheetContext } from './components/common/DetailSheet'
43
+ export type { DetailSheetHandle, DetailSheetContextType } from './components/common/DetailSheet'
44
+ export { EditableTitle } from './components/common/EditableTitle'
45
+ export { DangerZoneSection } from './components/common/DangerZoneSection'
46
+ export type { DangerAction } from './components/common/DangerZoneSection'
47
+ export { NavigationListItem } from './components/common/NavigationListItem'
48
+ export { PanelEmptyState } from './components/common/PanelEmptyState'
49
+ export { useDetailPanel, useDetailSheet } from './hooks/useDetailPanel'
50
+ export { useDetailSheetControls } from './hooks/useDetailSheetControls'
51
+
52
+ // Utility
53
+ export { cn } from './lib/utils'
@@ -0,0 +1,6 @@
1
+ import { clsx, type ClassValue } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs));
6
+ }
@@ -0,0 +1 @@
1
+ @tailwind utilities;