@moontra/moonui-pro 2.20.1 → 2.20.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 (162) hide show
  1. package/dist/index.d.ts +691 -261
  2. package/dist/index.mjs +7418 -4934
  3. package/package.json +11 -5
  4. package/plugin/index.d.ts +86 -0
  5. package/plugin/index.js +308 -0
  6. package/scripts/postbuild.js +27 -0
  7. package/scripts/postinstall.js +176 -23
  8. package/src/__tests__/use-intersection-observer.test.tsx +0 -216
  9. package/src/__tests__/use-local-storage.test.tsx +0 -174
  10. package/src/__tests__/use-pro-access.test.tsx +0 -183
  11. package/src/components/advanced-chart/advanced-chart.test.tsx +0 -281
  12. package/src/components/advanced-chart/index.tsx +0 -1242
  13. package/src/components/advanced-forms/index.tsx +0 -426
  14. package/src/components/animated-button/index.tsx +0 -385
  15. package/src/components/calendar/event-dialog.tsx +0 -372
  16. package/src/components/calendar/index.tsx +0 -1073
  17. package/src/components/calendar-pro/index.tsx +0 -1697
  18. package/src/components/color-picker/index.tsx +0 -432
  19. package/src/components/credit-card-input/index.tsx +0 -406
  20. package/src/components/dashboard/dashboard-grid.tsx +0 -462
  21. package/src/components/dashboard/demo.tsx +0 -425
  22. package/src/components/dashboard/index.tsx +0 -1046
  23. package/src/components/dashboard/time-range-picker.tsx +0 -336
  24. package/src/components/dashboard/types.ts +0 -222
  25. package/src/components/dashboard/widgets/activity-feed.tsx +0 -344
  26. package/src/components/dashboard/widgets/chart-widget.tsx +0 -418
  27. package/src/components/dashboard/widgets/metric-card.tsx +0 -343
  28. package/src/components/data-table/data-table-bulk-actions.tsx +0 -204
  29. package/src/components/data-table/data-table-column-toggle.tsx +0 -169
  30. package/src/components/data-table/data-table-export.ts +0 -156
  31. package/src/components/data-table/data-table-filter-drawer.tsx +0 -448
  32. package/src/components/data-table/data-table.test.tsx +0 -187
  33. package/src/components/data-table/index.tsx +0 -845
  34. package/src/components/draggable-list/index.tsx +0 -100
  35. package/src/components/enhanced/badge.tsx +0 -191
  36. package/src/components/enhanced/button.tsx +0 -362
  37. package/src/components/enhanced/card.tsx +0 -266
  38. package/src/components/enhanced/dialog.tsx +0 -246
  39. package/src/components/enhanced/index.ts +0 -4
  40. package/src/components/error-boundary/index.tsx +0 -109
  41. package/src/components/file-upload/file-upload.test.tsx +0 -243
  42. package/src/components/file-upload/index.tsx +0 -1660
  43. package/src/components/floating-action-button/index.tsx +0 -206
  44. package/src/components/form-wizard/form-wizard-context.tsx +0 -307
  45. package/src/components/form-wizard/form-wizard-navigation.tsx +0 -118
  46. package/src/components/form-wizard/form-wizard-progress.tsx +0 -298
  47. package/src/components/form-wizard/form-wizard-step.tsx +0 -111
  48. package/src/components/form-wizard/index.tsx +0 -102
  49. package/src/components/form-wizard/types.ts +0 -76
  50. package/src/components/gesture-drawer/index.tsx +0 -551
  51. package/src/components/github-stars/github-api.ts +0 -426
  52. package/src/components/github-stars/hooks.ts +0 -516
  53. package/src/components/github-stars/index.tsx +0 -375
  54. package/src/components/github-stars/types.ts +0 -148
  55. package/src/components/github-stars/variants.tsx +0 -513
  56. package/src/components/health-check/index.tsx +0 -439
  57. package/src/components/hover-card-3d/index.tsx +0 -530
  58. package/src/components/index.ts +0 -128
  59. package/src/components/internal/index.ts +0 -78
  60. package/src/components/kanban/add-card-modal.tsx +0 -502
  61. package/src/components/kanban/card-detail-modal.tsx +0 -761
  62. package/src/components/kanban/index.ts +0 -13
  63. package/src/components/kanban/kanban.tsx +0 -1684
  64. package/src/components/kanban/types.ts +0 -168
  65. package/src/components/lazy-component/index.tsx +0 -823
  66. package/src/components/license-error/index.tsx +0 -29
  67. package/src/components/magnetic-button/index.tsx +0 -167
  68. package/src/components/memory-efficient-data/index.tsx +0 -1016
  69. package/src/components/moonui-quiz-form/index.tsx +0 -817
  70. package/src/components/optimized-image/index.tsx +0 -425
  71. package/src/components/performance-debugger/index.tsx +0 -589
  72. package/src/components/performance-monitor/index.tsx +0 -794
  73. package/src/components/phone-number-input/index.tsx +0 -338
  74. package/src/components/pinch-zoom/index.tsx +0 -566
  75. package/src/components/quiz-form/index.tsx +0 -479
  76. package/src/components/rich-text-editor/index-old-backup.tsx +0 -437
  77. package/src/components/rich-text-editor/index.tsx +0 -2324
  78. package/src/components/rich-text-editor/slash-commands-extension.ts +0 -220
  79. package/src/components/rich-text-editor/slash-commands.css +0 -35
  80. package/src/components/rich-text-editor/table-styles.css +0 -65
  81. package/src/components/sidebar/index.tsx +0 -865
  82. package/src/components/spotlight-card/index.tsx +0 -191
  83. package/src/components/swipeable-card/index.tsx +0 -100
  84. package/src/components/timeline/index.tsx +0 -1148
  85. package/src/components/ui/accordion.tsx +0 -73
  86. package/src/components/ui/alert-dialog.tsx +0 -141
  87. package/src/components/ui/alert.tsx +0 -141
  88. package/src/components/ui/aspect-ratio.tsx +0 -245
  89. package/src/components/ui/avatar.tsx +0 -153
  90. package/src/components/ui/badge.tsx +0 -228
  91. package/src/components/ui/breadcrumb.tsx +0 -214
  92. package/src/components/ui/button.tsx +0 -222
  93. package/src/components/ui/calendar.tsx +0 -387
  94. package/src/components/ui/card.tsx +0 -214
  95. package/src/components/ui/checkbox.tsx +0 -259
  96. package/src/components/ui/collapsible.tsx +0 -135
  97. package/src/components/ui/color-picker.tsx +0 -97
  98. package/src/components/ui/command.tsx +0 -225
  99. package/src/components/ui/dialog.tsx +0 -334
  100. package/src/components/ui/dropdown-menu.tsx +0 -218
  101. package/src/components/ui/gesture-drawer.tsx +0 -11
  102. package/src/components/ui/hover-card.tsx +0 -29
  103. package/src/components/ui/index.ts +0 -190
  104. package/src/components/ui/input.tsx +0 -222
  105. package/src/components/ui/label.tsx +0 -29
  106. package/src/components/ui/lightbox.tsx +0 -606
  107. package/src/components/ui/magnetic-button.tsx +0 -129
  108. package/src/components/ui/media-gallery.tsx +0 -612
  109. package/src/components/ui/pagination.tsx +0 -123
  110. package/src/components/ui/popover.tsx +0 -185
  111. package/src/components/ui/progress.tsx +0 -30
  112. package/src/components/ui/radio-group.tsx +0 -257
  113. package/src/components/ui/scroll-area.tsx +0 -47
  114. package/src/components/ui/select.tsx +0 -374
  115. package/src/components/ui/separator.tsx +0 -145
  116. package/src/components/ui/sheet.tsx +0 -139
  117. package/src/components/ui/skeleton.tsx +0 -20
  118. package/src/components/ui/slider.tsx +0 -354
  119. package/src/components/ui/spotlight-card.tsx +0 -119
  120. package/src/components/ui/switch.tsx +0 -86
  121. package/src/components/ui/table.tsx +0 -329
  122. package/src/components/ui/tabs.tsx +0 -198
  123. package/src/components/ui/textarea.tsx +0 -28
  124. package/src/components/ui/toast.tsx +0 -317
  125. package/src/components/ui/toggle.tsx +0 -119
  126. package/src/components/ui/tooltip.tsx +0 -151
  127. package/src/components/virtual-list/index.tsx +0 -668
  128. package/src/hooks/use-chart.ts +0 -205
  129. package/src/hooks/use-data-table.ts +0 -182
  130. package/src/hooks/use-docs-pro-access.ts +0 -13
  131. package/src/hooks/use-license-check.ts +0 -65
  132. package/src/hooks/use-subscription.ts +0 -19
  133. package/src/hooks/use-toast.ts +0 -15
  134. package/src/index.ts +0 -14
  135. package/src/lib/ai-providers.ts +0 -377
  136. package/src/lib/component-metadata.ts +0 -18
  137. package/src/lib/micro-interactions.ts +0 -255
  138. package/src/lib/paddle.ts +0 -17
  139. package/src/lib/utils.ts +0 -6
  140. package/src/patterns/login-form/index.tsx +0 -276
  141. package/src/patterns/login-form/types.ts +0 -67
  142. package/src/setupTests.ts +0 -41
  143. package/src/styles/advanced-chart.css +0 -239
  144. package/src/styles/calendar.css +0 -35
  145. package/src/styles/design-system.css +0 -363
  146. package/src/styles/index.css +0 -85
  147. package/src/styles/tailwind.css +0 -7
  148. package/src/styles/tokens.css +0 -455
  149. package/src/types/moonui.d.ts +0 -22
  150. package/src/types/next-auth.d.ts +0 -21
  151. package/src/use-intersection-observer.tsx +0 -154
  152. package/src/use-local-storage.tsx +0 -71
  153. package/src/use-paddle.ts +0 -138
  154. package/src/use-performance-optimizer.ts +0 -389
  155. package/src/use-pro-access.ts +0 -141
  156. package/src/use-scroll-animation.ts +0 -219
  157. package/src/use-subscription.ts +0 -37
  158. package/src/use-toast.ts +0 -32
  159. package/src/utils/chart-helpers.ts +0 -357
  160. package/src/utils/cn.ts +0 -6
  161. package/src/utils/data-processing.ts +0 -151
  162. package/src/utils/license-validator.tsx +0 -183
@@ -1,206 +0,0 @@
1
- "use client"
2
-
3
- import React, { useState } from "react"
4
- import { motion, AnimatePresence } from "framer-motion"
5
- import { Plus, X, Lock, Sparkles } from "lucide-react"
6
- import { cn } from "../../lib/utils"
7
- import { Card, CardContent } from "../ui/card"
8
- import { Button } from "../ui/button"
9
- import { useSubscription } from "../../hooks/use-subscription"
10
-
11
- export interface FloatingActionButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
12
- actions?: Array<{
13
- icon: React.ReactNode
14
- label: string
15
- onClick: () => void
16
- }>
17
- position?: "bottom-right" | "bottom-left" | "top-right" | "top-left"
18
- size?: "sm" | "default" | "lg"
19
- }
20
-
21
- const FloatingActionButtonInternal = React.forwardRef<HTMLButtonElement, FloatingActionButtonProps>(
22
- ({
23
- actions = [],
24
- position = "bottom-right",
25
- size = "default",
26
- className,
27
- children,
28
- onClick,
29
- ...props
30
- }, ref) => {
31
- const [isOpen, setIsOpen] = useState(false)
32
-
33
- const sizeClasses = {
34
- sm: "h-10 w-10",
35
- default: "h-12 w-12",
36
- lg: "h-14 w-14"
37
- }
38
-
39
- const positionClasses = {
40
- "bottom-right": "bottom-4 right-4",
41
- "bottom-left": "bottom-4 left-4",
42
- "top-right": "top-4 right-4",
43
- "top-left": "top-4 left-4"
44
- }
45
-
46
- const actionPositions = {
47
- "bottom-right": { x: -60, y: 0 },
48
- "bottom-left": { x: 60, y: 0 },
49
- "top-right": { x: -60, y: 0 },
50
- "top-left": { x: 60, y: 0 }
51
- }
52
-
53
- const handleMainClick = (e: React.MouseEvent<HTMLButtonElement>) => {
54
- if (actions.length > 0) {
55
- setIsOpen(!isOpen)
56
- } else if (onClick) {
57
- onClick(e)
58
- }
59
- }
60
-
61
- return (
62
- <div className={cn("fixed z-50", positionClasses[position])}>
63
- {/* Action buttons */}
64
- <AnimatePresence>
65
- {isOpen && actions.length > 0 && (
66
- <div className="absolute">
67
- {actions.map((action, index) => (
68
- <motion.div
69
- key={index}
70
- initial={{
71
- scale: 0,
72
- opacity: 0,
73
- x: 0,
74
- y: 0
75
- }}
76
- animate={{
77
- scale: 1,
78
- opacity: 1,
79
- x: actionPositions[position].x,
80
- y: actionPositions[position].y * (index + 1) - 10
81
- }}
82
- exit={{
83
- scale: 0,
84
- opacity: 0,
85
- x: 0,
86
- y: 0
87
- }}
88
- transition={{
89
- delay: index * 0.05,
90
- type: "spring",
91
- stiffness: 200,
92
- damping: 15
93
- }}
94
- className="absolute flex items-center gap-2"
95
- style={{
96
- transform: `translate(${position.includes('right') ? '0' : '0'}, ${position.includes('bottom') ? '0' : '0'})`
97
- }}
98
- >
99
- {/* Label */}
100
- <motion.div
101
- initial={{ opacity: 0, scale: 0.8 }}
102
- animate={{ opacity: 1, scale: 1 }}
103
- exit={{ opacity: 0, scale: 0.8 }}
104
- transition={{ delay: (index + 1) * 0.05 }}
105
- className={cn(
106
- "px-2 py-1 bg-background/90 backdrop-blur-sm text-sm font-medium rounded-md shadow-sm border whitespace-nowrap",
107
- position.includes('right') ? 'mr-2' : 'ml-2'
108
- )}
109
- >
110
- {action.label}
111
- </motion.div>
112
-
113
- {/* Action button */}
114
- <button
115
- onClick={() => {
116
- action.onClick()
117
- setIsOpen(false)
118
- }}
119
- className={cn(
120
- "inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground shadow-lg hover:bg-primary/90 transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
121
- sizeClasses[size]
122
- )}
123
- >
124
- {action.icon}
125
- </button>
126
- </motion.div>
127
- ))}
128
- </div>
129
- )}
130
- </AnimatePresence>
131
-
132
- {/* Main FAB */}
133
- <motion.button
134
- ref={ref}
135
- className={cn(
136
- "inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground shadow-lg hover:bg-primary/90 transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
137
- sizeClasses[size],
138
- className
139
- )}
140
- onClick={handleMainClick}
141
- whileHover={{ scale: 1.1 }}
142
- whileTap={{ scale: 0.9 }}
143
- animate={{ rotate: isOpen ? 45 : 0 }}
144
- transition={{ duration: 0.2 }}
145
- >
146
- {children || (actions.length > 0 ? <Plus className="h-5 w-5" /> : <Plus className="h-5 w-5" />)}
147
- </motion.button>
148
-
149
- {/* Backdrop */}
150
- <AnimatePresence>
151
- {isOpen && (
152
- <motion.div
153
- initial={{ opacity: 0 }}
154
- animate={{ opacity: 1 }}
155
- exit={{ opacity: 0 }}
156
- className="fixed inset-0 z-[-1]"
157
- onClick={() => setIsOpen(false)}
158
- />
159
- )}
160
- </AnimatePresence>
161
- </div>
162
- )
163
- }
164
- )
165
-
166
- FloatingActionButtonInternal.displayName = "FloatingActionButtonInternal"
167
-
168
- export const FloatingActionButton = React.forwardRef<HTMLButtonElement, FloatingActionButtonProps>(
169
- ({ className, ...props }, ref) => {
170
- // Check if we're in docs mode or have pro access
171
- const { hasProAccess, isLoading } = useSubscription()
172
-
173
- // In docs mode, always show the component
174
-
175
- // If not in docs mode and no pro access, show upgrade prompt
176
- if (!isLoading && !hasProAccess) {
177
- return (
178
- <Card className={cn("w-fit", className)}>
179
- <CardContent className="py-6 text-center">
180
- <div className="space-y-4">
181
- <div className="rounded-full bg-purple-100 dark:bg-purple-900/30 p-3 w-fit mx-auto">
182
- <Lock className="h-6 w-6 text-purple-600 dark:text-purple-400" />
183
- </div>
184
- <div>
185
- <h3 className="font-semibold text-sm mb-2">Pro Feature</h3>
186
- <p className="text-muted-foreground text-xs mb-4">
187
- Floating Action Button is available exclusively to MoonUI Pro subscribers.
188
- </p>
189
- <a href="/pricing">
190
- <Button size="sm">
191
- <Sparkles className="mr-2 h-4 w-4" />
192
- Upgrade to Pro
193
- </Button>
194
- </a>
195
- </div>
196
- </div>
197
- </CardContent>
198
- </Card>
199
- )
200
- }
201
-
202
- return <FloatingActionButtonInternal className={className} ref={ref} {...props} />
203
- }
204
- )
205
-
206
- FloatingActionButton.displayName = "FloatingActionButton"
@@ -1,307 +0,0 @@
1
- "use client"
2
-
3
- import React, { createContext, useContext, useState, useCallback, useEffect } from "react"
4
- import { WizardContextValue, WizardStep, FormWizardProps } from "./types"
5
-
6
- const FormWizardContext = createContext<WizardContextValue | null>(null)
7
-
8
- export const useFormWizard = () => {
9
- const context = useContext(FormWizardContext)
10
- if (!context) {
11
- throw new Error("useFormWizard must be used within a FormWizardProvider")
12
- }
13
- return context
14
- }
15
-
16
- interface FormWizardProviderProps {
17
- children: React.ReactNode
18
- steps: WizardStep[]
19
- initialStep?: number
20
- onStepChange?: FormWizardProps['onStepChange']
21
- onComplete?: FormWizardProps['onComplete']
22
- validateOnStepChange?: boolean
23
- allowBackNavigation?: boolean
24
- allowStepSkip?: boolean
25
- autoSave?: boolean
26
- autoSaveDelay?: number
27
- onAutoSave?: FormWizardProps['onAutoSave']
28
- persistData?: boolean
29
- storageKey?: string
30
- }
31
-
32
- export const FormWizardProvider: React.FC<FormWizardProviderProps> = ({
33
- children,
34
- steps,
35
- initialStep = 0,
36
- onStepChange,
37
- onComplete,
38
- validateOnStepChange = true,
39
- allowBackNavigation = true,
40
- allowStepSkip = false,
41
- autoSave = false,
42
- autoSaveDelay = 2000,
43
- onAutoSave,
44
- persistData = false,
45
- storageKey = "form-wizard-data"
46
- }) => {
47
- const [currentStep, setCurrentStep] = useState(initialStep)
48
- const [stepData, setStepData] = useState<Record<string, any>>({})
49
- const [completedSteps, setCompletedSteps] = useState<Set<number>>(new Set())
50
- const [isLoading, setIsLoading] = useState(false)
51
- const [error, setError] = useState<string | null>(null)
52
-
53
- // Load persisted data on mount
54
- useEffect(() => {
55
- if (persistData && typeof window !== 'undefined') {
56
- const savedData = localStorage.getItem(storageKey)
57
- if (savedData) {
58
- try {
59
- const parsed = JSON.parse(savedData)
60
- setStepData(parsed.stepData || {})
61
- setCurrentStep(parsed.currentStep || 0)
62
- setCompletedSteps(new Set(parsed.completedSteps || []))
63
- } catch (e) {
64
- console.error("Failed to load persisted wizard data:", e)
65
- }
66
- }
67
- }
68
- }, [persistData, storageKey])
69
-
70
- // Auto-save functionality
71
- useEffect(() => {
72
- if (!autoSave || !onAutoSave) return
73
-
74
- const timeoutId = setTimeout(() => {
75
- const currentStepData = stepData[steps[currentStep].id]
76
- if (currentStepData) {
77
- onAutoSave(steps[currentStep].id, currentStepData)
78
- }
79
- }, autoSaveDelay)
80
-
81
- return () => clearTimeout(timeoutId)
82
- }, [stepData, currentStep, autoSave, autoSaveDelay, onAutoSave, steps])
83
-
84
- // Persist data when it changes
85
- useEffect(() => {
86
- if (persistData && typeof window !== 'undefined') {
87
- const dataToSave = {
88
- stepData,
89
- currentStep,
90
- completedSteps: Array.from(completedSteps)
91
- }
92
- localStorage.setItem(storageKey, JSON.stringify(dataToSave))
93
- }
94
- }, [stepData, currentStep, completedSteps, persistData, storageKey])
95
-
96
- const validateCurrentStep = useCallback(async (): Promise<boolean> => {
97
- const step = steps[currentStep]
98
-
99
- // First check HTML5 validation for required fields
100
- if (typeof window !== 'undefined') {
101
- const stepElement = document.querySelector('[data-wizard-step-content]')
102
- if (stepElement) {
103
- const requiredInputs = stepElement.querySelectorAll('input[required], select[required], textarea[required]')
104
- const emptyFields: string[] = []
105
-
106
- requiredInputs.forEach((input: Element) => {
107
- const htmlInput = input as HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement
108
- if (!htmlInput.value || htmlInput.value.trim() === '') {
109
- const label = document.querySelector(`label[for="${htmlInput.id}"]`)
110
- const fieldName = label ? (label.textContent?.replace(' *', '') || 'Field') : htmlInput.name || htmlInput.id || 'Field'
111
- emptyFields.push(fieldName)
112
- }
113
- })
114
-
115
- // Check for required checkboxes
116
- const requiredCheckboxes = stepElement.querySelectorAll('input[type="checkbox"][required]')
117
- requiredCheckboxes.forEach((checkbox: Element) => {
118
- const htmlCheckbox = checkbox as HTMLInputElement
119
- if (!htmlCheckbox.checked) {
120
- const label = document.querySelector(`label[for="${htmlCheckbox.id}"]`)
121
- const fieldName = label ? (label.textContent?.replace(' *', '') || 'Checkbox') : htmlCheckbox.name || htmlCheckbox.id || 'Checkbox'
122
- emptyFields.push(fieldName)
123
- }
124
- })
125
-
126
- if (emptyFields.length > 0) {
127
- setError(`Please fill in the following required fields: ${emptyFields.join(', ')}`)
128
- return false
129
- }
130
- }
131
- }
132
-
133
- // Then run custom validation if provided
134
- if (!step.validation) return true
135
-
136
- setIsLoading(true)
137
- setError(null)
138
-
139
- try {
140
- const result = await step.validation()
141
-
142
- // Handle boolean return
143
- if (typeof result === 'boolean') {
144
- if (!result) {
145
- setError("Please complete all required fields before proceeding")
146
- }
147
- return result
148
- }
149
-
150
- // Handle object return {isValid: boolean, error?: string, errors?: string[]}
151
- if (typeof result === 'object' && result !== null && 'isValid' in result) {
152
- const validationResult = result as { isValid: boolean; error?: string; errors?: string[] }
153
- if (!validationResult.isValid) {
154
- if (validationResult.error) {
155
- setError(validationResult.error)
156
- } else if (validationResult.errors && Array.isArray(validationResult.errors)) {
157
- setError(validationResult.errors.join(', '))
158
- } else {
159
- setError("Please complete all required fields before proceeding")
160
- }
161
- }
162
- return validationResult.isValid
163
- }
164
-
165
- // Invalid return type
166
- setError("Invalid validation response")
167
- return false
168
- } catch (err) {
169
- setError(err instanceof Error ? err.message : "Validation failed")
170
- return false
171
- } finally {
172
- setIsLoading(false)
173
- }
174
- }, [currentStep, steps])
175
-
176
- const updateStepData = useCallback((stepId: string, data: any) => {
177
- setStepData(prev => ({
178
- ...prev,
179
- [stepId]: { ...prev[stepId], ...data }
180
- }))
181
- setError(null)
182
- }, [])
183
-
184
- const goToStep = useCallback(async (stepIndex: number) => {
185
- if (stepIndex < 0 || stepIndex >= steps.length) return
186
- if (stepIndex === currentStep) return
187
-
188
- const targetStep = steps[stepIndex]
189
- const isDisabled = typeof targetStep.isDisabled === 'function'
190
- ? targetStep.isDisabled(currentStep, steps)
191
- : targetStep.isDisabled
192
-
193
- if (isDisabled) return
194
-
195
- // Validate current step if moving forward
196
- if (validateOnStepChange && stepIndex > currentStep) {
197
- const isValid = await validateCurrentStep()
198
- if (!isValid) return
199
- }
200
-
201
- // Call exit handler for current step
202
- const currentStepObj = steps[currentStep]
203
- if (currentStepObj.onExit) {
204
- await currentStepObj.onExit()
205
- }
206
-
207
- // Update completed steps
208
- if (stepIndex > currentStep) {
209
- setCompletedSteps(prev => new Set([...prev, currentStep]))
210
- }
211
-
212
- // Call enter handler for new step
213
- if (targetStep.onEnter) {
214
- await targetStep.onEnter()
215
- }
216
-
217
- const previousStep = currentStep
218
- setCurrentStep(stepIndex)
219
- onStepChange?.(stepIndex, previousStep)
220
- }, [currentStep, steps, validateOnStepChange, validateCurrentStep, onStepChange])
221
-
222
- const goToNext = useCallback(() => {
223
- goToStep(currentStep + 1)
224
- }, [currentStep, goToStep])
225
-
226
- const goToPrevious = useCallback(() => {
227
- if (!allowBackNavigation) return
228
- goToStep(currentStep - 1)
229
- }, [currentStep, goToStep, allowBackNavigation])
230
-
231
- const completeWizard = useCallback(async () => {
232
- const isValid = await validateCurrentStep()
233
- if (!isValid) return
234
-
235
- setCompletedSteps(prev => new Set([...prev, currentStep]))
236
-
237
- if (onComplete) {
238
- setIsLoading(true)
239
- try {
240
- await onComplete(stepData)
241
-
242
- // Clear persisted data after successful completion
243
- if (persistData && typeof window !== 'undefined') {
244
- localStorage.removeItem(storageKey)
245
- }
246
- } catch (err) {
247
- setError(err instanceof Error ? err.message : "Failed to complete wizard")
248
- } finally {
249
- setIsLoading(false)
250
- }
251
- }
252
- }, [currentStep, stepData, validateCurrentStep, onComplete, persistData, storageKey])
253
-
254
- const resetWizard = useCallback(() => {
255
- setCurrentStep(0)
256
- setStepData({})
257
- setCompletedSteps(new Set())
258
- setError(null)
259
-
260
- if (persistData && typeof window !== 'undefined') {
261
- localStorage.removeItem(storageKey)
262
- }
263
- }, [persistData, storageKey])
264
-
265
- const isStepCompleted = useCallback((stepIndex: number) => {
266
- return completedSteps.has(stepIndex)
267
- }, [completedSteps])
268
-
269
- const isStepAccessible = useCallback((stepIndex: number) => {
270
- if (stepIndex === 0) return true
271
- if (allowStepSkip) return true
272
-
273
- // Check if all previous steps are completed
274
- for (let i = 0; i < stepIndex; i++) {
275
- if (!completedSteps.has(i) && !steps[i].isOptional) {
276
- return false
277
- }
278
- }
279
-
280
- return true
281
- }, [completedSteps, allowStepSkip, steps])
282
-
283
- const value: WizardContextValue = {
284
- steps,
285
- currentStep,
286
- stepData,
287
- isLoading,
288
- error,
289
- goToNext,
290
- goToPrevious,
291
- goToStep,
292
- updateStepData: (data: any) => updateStepData(steps[currentStep].id, data),
293
- validateCurrentStep,
294
- completeWizard,
295
- resetWizard,
296
- isStepCompleted,
297
- isStepAccessible,
298
- canGoNext: currentStep < steps.length - 1,
299
- canGoPrevious: allowBackNavigation && currentStep > 0
300
- }
301
-
302
- return (
303
- <FormWizardContext.Provider value={value}>
304
- {children}
305
- </FormWizardContext.Provider>
306
- )
307
- }
@@ -1,118 +0,0 @@
1
- "use client"
2
-
3
- import React from "react"
4
- import { motion } from "framer-motion"
5
- import { ChevronLeft, ChevronRight, Check, Loader2 } from "lucide-react"
6
- import { Button } from "../ui/button"
7
- import { cn } from "../../lib/utils"
8
- import { useFormWizard } from "./form-wizard-context"
9
-
10
- interface FormWizardNavigationProps {
11
- className?: string
12
- showStepIndicator?: boolean
13
- previousText?: string
14
- nextText?: string
15
- completeText?: string
16
- loadingText?: string
17
- onPreviousClick?: () => void
18
- onNextClick?: () => void
19
- onCompleteClick?: () => void
20
- }
21
-
22
- export const FormWizardNavigation: React.FC<FormWizardNavigationProps> = ({
23
- className,
24
- showStepIndicator = true,
25
- previousText = "Previous",
26
- nextText = "Next",
27
- completeText = "Complete",
28
- loadingText = "Processing...",
29
- onPreviousClick,
30
- onNextClick,
31
- onCompleteClick
32
- }) => {
33
- const {
34
- steps,
35
- currentStep,
36
- isLoading,
37
- canGoNext,
38
- canGoPrevious,
39
- goToNext,
40
- goToPrevious,
41
- completeWizard
42
- } = useFormWizard()
43
-
44
- const isLastStep = currentStep === steps.length - 1
45
- const currentStepObj = steps[currentStep]
46
-
47
- const handlePrevious = () => {
48
- onPreviousClick?.()
49
- goToPrevious()
50
- }
51
-
52
- const handleNext = () => {
53
- if (isLastStep) {
54
- onCompleteClick?.()
55
- completeWizard()
56
- } else {
57
- onNextClick?.()
58
- goToNext()
59
- }
60
- }
61
-
62
- return (
63
- <div className={cn("flex items-center justify-between", className)}>
64
- <div className="flex items-center gap-2">
65
- <Button
66
- type="button"
67
- variant="outline"
68
- onClick={handlePrevious}
69
- disabled={!canGoPrevious || isLoading}
70
- className={cn(
71
- "transition-all duration-200",
72
- !canGoPrevious && "invisible"
73
- )}
74
- >
75
- <ChevronLeft className="w-4 h-4 mr-1" />
76
- {previousText}
77
- </Button>
78
-
79
- {showStepIndicator && (
80
- <motion.div
81
- initial={{ opacity: 0, scale: 0.9 }}
82
- animate={{ opacity: 1, scale: 1 }}
83
- className="px-3 py-1 text-sm text-muted-foreground"
84
- >
85
- Step {currentStep + 1} of {steps.length}
86
- {currentStepObj.isOptional && (
87
- <span className="ml-1 text-xs">(Optional)</span>
88
- )}
89
- </motion.div>
90
- )}
91
- </div>
92
-
93
- <Button
94
- type="button"
95
- onClick={handleNext}
96
- disabled={isLoading || (!canGoNext && !isLastStep)}
97
- className="min-w-[120px]"
98
- >
99
- {isLoading ? (
100
- <>
101
- <Loader2 className="w-4 h-4 mr-2 animate-spin" />
102
- {loadingText}
103
- </>
104
- ) : isLastStep ? (
105
- <>
106
- <Check className="w-4 h-4 mr-2" />
107
- {completeText}
108
- </>
109
- ) : (
110
- <>
111
- {nextText}
112
- <ChevronRight className="w-4 h-4 ml-1" />
113
- </>
114
- )}
115
- </Button>
116
- </div>
117
- )
118
- }