@shalomormsby/ui 0.0.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.
@@ -0,0 +1,225 @@
1
+ import { ThemeName, ColorMode } from '@sage/tokens';
2
+ import { F as FieldValidation, a as FormErrors } from './validation-Bj1ye-v_.js';
3
+
4
+ interface ThemeHook {
5
+ /**
6
+ * Current theme name
7
+ */
8
+ theme: ThemeName;
9
+ /**
10
+ * Current color mode (light/dark)
11
+ */
12
+ mode: ColorMode;
13
+ /**
14
+ * Set the theme
15
+ */
16
+ setTheme: (theme: ThemeName) => void;
17
+ /**
18
+ * Set the color mode
19
+ */
20
+ setMode: (mode: ColorMode) => void;
21
+ /**
22
+ * Toggle between light and dark mode
23
+ */
24
+ toggleMode: () => void;
25
+ /**
26
+ * Combined theme configuration
27
+ */
28
+ themeConfig: {
29
+ name: ThemeName;
30
+ mode: ColorMode;
31
+ };
32
+ }
33
+ /**
34
+ * Hook to access and control theme settings
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * function ThemeSelector() {
39
+ * const { theme, mode, setTheme, toggleMode } = useTheme();
40
+ *
41
+ * return (
42
+ * <div>
43
+ * <p>Current: {theme} - {mode}</p>
44
+ * <button onClick={() => setTheme('sage')}>Sage Theme</button>
45
+ * <button onClick={toggleMode}>Toggle Mode</button>
46
+ * </div>
47
+ * );
48
+ * }
49
+ * ```
50
+ */
51
+ declare function useTheme(): ThemeHook;
52
+
53
+ interface MotionPreference {
54
+ /**
55
+ * Motion intensity level (0-10)
56
+ * 0 = no motion, 10 = full motion
57
+ */
58
+ scale: number;
59
+ /**
60
+ * Whether animations should be displayed
61
+ * False when scale is 0 or prefersReducedMotion is true
62
+ */
63
+ shouldAnimate: boolean;
64
+ /**
65
+ * System preference for reduced motion
66
+ */
67
+ prefersReducedMotion: boolean;
68
+ }
69
+ /**
70
+ * Hook to access motion preferences
71
+ *
72
+ * Automatically syncs with system `prefers-reduced-motion` media query
73
+ * and respects user's manual motion intensity setting.
74
+ *
75
+ * @example
76
+ * ```tsx
77
+ * function AnimatedComponent() {
78
+ * const { scale, shouldAnimate } = useMotionPreference();
79
+ *
80
+ * if (!shouldAnimate) {
81
+ * return <div>Content without animation</div>;
82
+ * }
83
+ *
84
+ * return (
85
+ * <motion.div
86
+ * animate={{ opacity: 1 }}
87
+ * transition={{ duration: 0.3 * (scale / 10) }}
88
+ * >
89
+ * Content with scaled animation
90
+ * </motion.div>
91
+ * );
92
+ * }
93
+ * ```
94
+ */
95
+ declare function useMotionPreference(): MotionPreference;
96
+
97
+ interface UseFormOptions<T> {
98
+ /**
99
+ * Initial form values
100
+ */
101
+ initialValues: T;
102
+ /**
103
+ * Validation rules for each field
104
+ */
105
+ validations?: Partial<Record<keyof T, FieldValidation>>;
106
+ /**
107
+ * Callback fired when form is submitted and valid
108
+ */
109
+ onSubmit?: (values: T) => void | Promise<void>;
110
+ /**
111
+ * When to validate fields
112
+ * @default 'onBlur'
113
+ */
114
+ validateOn?: 'onChange' | 'onBlur' | 'onSubmit';
115
+ }
116
+ interface UseFormReturn<T> {
117
+ /**
118
+ * Current form values
119
+ */
120
+ values: T;
121
+ /**
122
+ * Current form errors
123
+ */
124
+ errors: FormErrors;
125
+ /**
126
+ * Whether the form is currently submitting
127
+ */
128
+ isSubmitting: boolean;
129
+ /**
130
+ * Whether the form has been touched/modified
131
+ */
132
+ isDirty: boolean;
133
+ /**
134
+ * Set value for a specific field
135
+ */
136
+ setValue: (name: keyof T, value: any) => void;
137
+ /**
138
+ * Set error for a specific field
139
+ */
140
+ setError: (name: keyof T, error: string | undefined) => void;
141
+ /**
142
+ * Handle input change event
143
+ */
144
+ handleChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
145
+ /**
146
+ * Handle input blur event
147
+ */
148
+ handleBlur: (e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
149
+ /**
150
+ * Handle form submit
151
+ */
152
+ handleSubmit: (e?: React.FormEvent<HTMLFormElement>) => Promise<void>;
153
+ /**
154
+ * Reset form to initial values
155
+ */
156
+ reset: () => void;
157
+ /**
158
+ * Manually validate all fields
159
+ */
160
+ validate: () => boolean;
161
+ /**
162
+ * Get props for a field (value, onChange, onBlur, error)
163
+ */
164
+ getFieldProps: (name: keyof T) => {
165
+ name: string;
166
+ value: any;
167
+ onChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
168
+ onBlur: (e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
169
+ error: boolean;
170
+ };
171
+ }
172
+ /**
173
+ * useForm Hook
174
+ *
175
+ * A lightweight form state management hook with built-in validation.
176
+ *
177
+ * Features:
178
+ * - Field-level validation
179
+ * - Configurable validation timing (onChange, onBlur, onSubmit)
180
+ * - Dirty state tracking
181
+ * - Submit handling with loading state
182
+ * - Helper functions for common patterns
183
+ *
184
+ * Example:
185
+ * ```tsx
186
+ * const form = useForm({
187
+ * initialValues: { email: '', password: '' },
188
+ * validations: {
189
+ * email: { required: true, pattern: patterns.email },
190
+ * password: { required: true, minLength: { value: 8, message: 'Min 8 chars' } }
191
+ * },
192
+ * onSubmit: async (values) => {
193
+ * await login(values);
194
+ * }
195
+ * });
196
+ *
197
+ * return (
198
+ * <form onSubmit={form.handleSubmit}>
199
+ * <FormField label="Email" error={form.errors.email}>
200
+ * <TextField {...form.getFieldProps('email')} />
201
+ * </FormField>
202
+ * <Button type="submit" loading={form.isSubmitting}>Submit</Button>
203
+ * </form>
204
+ * );
205
+ * ```
206
+ */
207
+ declare function useForm<T extends Record<string, any>>({ initialValues, validations, onSubmit, validateOn, }: UseFormOptions<T>): UseFormReturn<T>;
208
+
209
+ /**
210
+ * Hooks subpath export
211
+ * Allows: import { ... } from '@sage/ui/hooks'
212
+ */
213
+
214
+ type hooks_MotionPreference = MotionPreference;
215
+ type hooks_ThemeHook = ThemeHook;
216
+ type hooks_UseFormOptions<T> = UseFormOptions<T>;
217
+ type hooks_UseFormReturn<T> = UseFormReturn<T>;
218
+ declare const hooks_useForm: typeof useForm;
219
+ declare const hooks_useMotionPreference: typeof useMotionPreference;
220
+ declare const hooks_useTheme: typeof useTheme;
221
+ declare namespace hooks {
222
+ export { type hooks_MotionPreference as MotionPreference, type hooks_ThemeHook as ThemeHook, type hooks_UseFormOptions as UseFormOptions, type hooks_UseFormReturn as UseFormReturn, hooks_useForm as useForm, hooks_useMotionPreference as useMotionPreference, hooks_useTheme as useTheme };
223
+ }
224
+
225
+ export { type MotionPreference as M, type ThemeHook as T, type UseFormOptions as U, useMotionPreference as a, type UseFormReturn as b, useForm as c, hooks as h, useTheme as u };
@@ -0,0 +1,225 @@
1
+ import { ThemeName, ColorMode } from '@sage/tokens';
2
+ import { F as FieldValidation, a as FormErrors } from './validation-Bj1ye-v_.mjs';
3
+
4
+ interface ThemeHook {
5
+ /**
6
+ * Current theme name
7
+ */
8
+ theme: ThemeName;
9
+ /**
10
+ * Current color mode (light/dark)
11
+ */
12
+ mode: ColorMode;
13
+ /**
14
+ * Set the theme
15
+ */
16
+ setTheme: (theme: ThemeName) => void;
17
+ /**
18
+ * Set the color mode
19
+ */
20
+ setMode: (mode: ColorMode) => void;
21
+ /**
22
+ * Toggle between light and dark mode
23
+ */
24
+ toggleMode: () => void;
25
+ /**
26
+ * Combined theme configuration
27
+ */
28
+ themeConfig: {
29
+ name: ThemeName;
30
+ mode: ColorMode;
31
+ };
32
+ }
33
+ /**
34
+ * Hook to access and control theme settings
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * function ThemeSelector() {
39
+ * const { theme, mode, setTheme, toggleMode } = useTheme();
40
+ *
41
+ * return (
42
+ * <div>
43
+ * <p>Current: {theme} - {mode}</p>
44
+ * <button onClick={() => setTheme('sage')}>Sage Theme</button>
45
+ * <button onClick={toggleMode}>Toggle Mode</button>
46
+ * </div>
47
+ * );
48
+ * }
49
+ * ```
50
+ */
51
+ declare function useTheme(): ThemeHook;
52
+
53
+ interface MotionPreference {
54
+ /**
55
+ * Motion intensity level (0-10)
56
+ * 0 = no motion, 10 = full motion
57
+ */
58
+ scale: number;
59
+ /**
60
+ * Whether animations should be displayed
61
+ * False when scale is 0 or prefersReducedMotion is true
62
+ */
63
+ shouldAnimate: boolean;
64
+ /**
65
+ * System preference for reduced motion
66
+ */
67
+ prefersReducedMotion: boolean;
68
+ }
69
+ /**
70
+ * Hook to access motion preferences
71
+ *
72
+ * Automatically syncs with system `prefers-reduced-motion` media query
73
+ * and respects user's manual motion intensity setting.
74
+ *
75
+ * @example
76
+ * ```tsx
77
+ * function AnimatedComponent() {
78
+ * const { scale, shouldAnimate } = useMotionPreference();
79
+ *
80
+ * if (!shouldAnimate) {
81
+ * return <div>Content without animation</div>;
82
+ * }
83
+ *
84
+ * return (
85
+ * <motion.div
86
+ * animate={{ opacity: 1 }}
87
+ * transition={{ duration: 0.3 * (scale / 10) }}
88
+ * >
89
+ * Content with scaled animation
90
+ * </motion.div>
91
+ * );
92
+ * }
93
+ * ```
94
+ */
95
+ declare function useMotionPreference(): MotionPreference;
96
+
97
+ interface UseFormOptions<T> {
98
+ /**
99
+ * Initial form values
100
+ */
101
+ initialValues: T;
102
+ /**
103
+ * Validation rules for each field
104
+ */
105
+ validations?: Partial<Record<keyof T, FieldValidation>>;
106
+ /**
107
+ * Callback fired when form is submitted and valid
108
+ */
109
+ onSubmit?: (values: T) => void | Promise<void>;
110
+ /**
111
+ * When to validate fields
112
+ * @default 'onBlur'
113
+ */
114
+ validateOn?: 'onChange' | 'onBlur' | 'onSubmit';
115
+ }
116
+ interface UseFormReturn<T> {
117
+ /**
118
+ * Current form values
119
+ */
120
+ values: T;
121
+ /**
122
+ * Current form errors
123
+ */
124
+ errors: FormErrors;
125
+ /**
126
+ * Whether the form is currently submitting
127
+ */
128
+ isSubmitting: boolean;
129
+ /**
130
+ * Whether the form has been touched/modified
131
+ */
132
+ isDirty: boolean;
133
+ /**
134
+ * Set value for a specific field
135
+ */
136
+ setValue: (name: keyof T, value: any) => void;
137
+ /**
138
+ * Set error for a specific field
139
+ */
140
+ setError: (name: keyof T, error: string | undefined) => void;
141
+ /**
142
+ * Handle input change event
143
+ */
144
+ handleChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
145
+ /**
146
+ * Handle input blur event
147
+ */
148
+ handleBlur: (e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
149
+ /**
150
+ * Handle form submit
151
+ */
152
+ handleSubmit: (e?: React.FormEvent<HTMLFormElement>) => Promise<void>;
153
+ /**
154
+ * Reset form to initial values
155
+ */
156
+ reset: () => void;
157
+ /**
158
+ * Manually validate all fields
159
+ */
160
+ validate: () => boolean;
161
+ /**
162
+ * Get props for a field (value, onChange, onBlur, error)
163
+ */
164
+ getFieldProps: (name: keyof T) => {
165
+ name: string;
166
+ value: any;
167
+ onChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
168
+ onBlur: (e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
169
+ error: boolean;
170
+ };
171
+ }
172
+ /**
173
+ * useForm Hook
174
+ *
175
+ * A lightweight form state management hook with built-in validation.
176
+ *
177
+ * Features:
178
+ * - Field-level validation
179
+ * - Configurable validation timing (onChange, onBlur, onSubmit)
180
+ * - Dirty state tracking
181
+ * - Submit handling with loading state
182
+ * - Helper functions for common patterns
183
+ *
184
+ * Example:
185
+ * ```tsx
186
+ * const form = useForm({
187
+ * initialValues: { email: '', password: '' },
188
+ * validations: {
189
+ * email: { required: true, pattern: patterns.email },
190
+ * password: { required: true, minLength: { value: 8, message: 'Min 8 chars' } }
191
+ * },
192
+ * onSubmit: async (values) => {
193
+ * await login(values);
194
+ * }
195
+ * });
196
+ *
197
+ * return (
198
+ * <form onSubmit={form.handleSubmit}>
199
+ * <FormField label="Email" error={form.errors.email}>
200
+ * <TextField {...form.getFieldProps('email')} />
201
+ * </FormField>
202
+ * <Button type="submit" loading={form.isSubmitting}>Submit</Button>
203
+ * </form>
204
+ * );
205
+ * ```
206
+ */
207
+ declare function useForm<T extends Record<string, any>>({ initialValues, validations, onSubmit, validateOn, }: UseFormOptions<T>): UseFormReturn<T>;
208
+
209
+ /**
210
+ * Hooks subpath export
211
+ * Allows: import { ... } from '@sage/ui/hooks'
212
+ */
213
+
214
+ type hooks_MotionPreference = MotionPreference;
215
+ type hooks_ThemeHook = ThemeHook;
216
+ type hooks_UseFormOptions<T> = UseFormOptions<T>;
217
+ type hooks_UseFormReturn<T> = UseFormReturn<T>;
218
+ declare const hooks_useForm: typeof useForm;
219
+ declare const hooks_useMotionPreference: typeof useMotionPreference;
220
+ declare const hooks_useTheme: typeof useTheme;
221
+ declare namespace hooks {
222
+ export { type hooks_MotionPreference as MotionPreference, type hooks_ThemeHook as ThemeHook, type hooks_UseFormOptions as UseFormOptions, type hooks_UseFormReturn as UseFormReturn, hooks_useForm as useForm, hooks_useMotionPreference as useMotionPreference, hooks_useTheme as useTheme };
223
+ }
224
+
225
+ export { type MotionPreference as M, type ThemeHook as T, type UseFormOptions as U, useMotionPreference as a, type UseFormReturn as b, useForm as c, hooks as h, useTheme as u };
@@ -0,0 +1,3 @@
1
+ export { M as MotionPreference, T as ThemeHook, U as UseFormOptions, b as UseFormReturn, c as useForm, a as useMotionPreference, u as useTheme } from './hooks-JwoY_LtZ.mjs';
2
+ import '@sage/tokens';
3
+ import './validation-Bj1ye-v_.mjs';
@@ -0,0 +1,3 @@
1
+ export { M as MotionPreference, T as ThemeHook, U as UseFormOptions, b as UseFormReturn, c as useForm, a as useMotionPreference, u as useTheme } from './hooks-BQi3Ia-W.js';
2
+ import '@sage/tokens';
3
+ import './validation-Bj1ye-v_.js';