@mateosuarezdev/react-ui 1.0.5 → 1.0.7

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.
package/dist/index.d.ts CHANGED
@@ -2,10 +2,20 @@ import { ButtonHTMLAttributes } from 'react';
2
2
  import { ClassValue } from 'clsx';
3
3
  import { ComponentPropsWithoutRef } from 'react';
4
4
  import { CSSProperties } from 'react';
5
+ import { default as default_2 } from 'react';
6
+ import { FieldErrors } from 'react-hook-form';
7
+ import { FieldValues } from 'react-hook-form';
5
8
  import { ForwardRefExoticComponent } from 'react';
9
+ import { InputHTMLAttributes } from 'react';
6
10
  import { JSX } from 'react/jsx-runtime';
11
+ import { ReactPortal } from 'react';
7
12
  import { RefAttributes } from 'react';
8
13
  import { RefObject } from 'react';
14
+ import { SubmitHandler as RHFSubmitHandler } from 'react-hook-form';
15
+ import { TextareaHTMLAttributes } from 'react';
16
+ import { UseFormReturn } from 'react-hook-form';
17
+ import { z } from 'zod';
18
+ import { ZodTypeAny } from 'zod';
9
19
 
10
20
  export declare const AliveScope: React.FC<AliveScopeProps>;
11
21
 
@@ -73,6 +83,28 @@ export declare type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement>
73
83
  children?: React.ReactNode;
74
84
  };
75
85
 
86
+ export declare const calculatePopoverPosition: ({ triggerRect, popoverWidth, popoverHeight, align, side, offset, collisionPadding, avoidCollisions, }: PositionOptions_2) => {
87
+ x: number;
88
+ top: number | undefined;
89
+ bottom: number | undefined;
90
+ };
91
+
92
+ export declare const Checkbox: default_2.ForwardRefExoticComponent<CheckboxProps & default_2.RefAttributes<HTMLButtonElement>>;
93
+
94
+ declare interface CheckboxProps {
95
+ checked?: boolean | "indeterminate";
96
+ onCheckedChange?: (checked: boolean | "indeterminate") => void;
97
+ disabled?: boolean;
98
+ required?: boolean;
99
+ name?: string;
100
+ value?: string;
101
+ id?: string;
102
+ className?: string | ((checked: boolean | "indeterminate") => string);
103
+ size?: "xs" | "sm" | "md" | "lg";
104
+ }
105
+
106
+ export declare const checkOverflow: (element: HTMLElement) => OverflowInfo;
107
+
76
108
  export { ClassValue }
77
109
 
78
110
  /**Tailwind Merge + Clsx */
@@ -113,6 +145,26 @@ declare const colorStyles: {
113
145
  */
114
146
  export declare function debounce<T extends (...args: any[]) => any>(func: T, delay?: number): (...args: Parameters<T>) => void;
115
147
 
148
+ /**
149
+ * Extracts only the dirty fields from form data
150
+ * @param data The complete form data
151
+ * @param dirtyFields The dirtyFields object from form.formState
152
+ * @param staticFields An object containing fields to always include (like ID)
153
+ * @returns A new object containing only dirty fields and the static fields
154
+ */
155
+ export declare function extractDirtyData<T extends Record<string, any>>(data: T, dirtyFields: any, staticFields?: Partial<T>): Partial<T>;
156
+
157
+ export declare class FocusTrap {
158
+ private container;
159
+ private previouslyFocusedElement;
160
+ constructor();
161
+ enable(): void;
162
+ disable(): void;
163
+ setContainer(container: HTMLElement): void;
164
+ private trapFocus;
165
+ private handleClickOutside;
166
+ }
167
+
116
168
  declare const fontWeightStyles: {
117
169
  light: string;
118
170
  normal: string;
@@ -121,6 +173,55 @@ declare const fontWeightStyles: {
121
173
  bold: string;
122
174
  };
123
175
 
176
+ export declare function Form<T extends FieldValues>({ methods, onSubmit, onError, children, logErrors, className, }: FormWrapperProps<T>): JSX.Element;
177
+
178
+ export declare const FormInput: ({ name, customRead, customSet, withNullSet, ...others }: {
179
+ name: string;
180
+ customRead?: (value: string | null) => string;
181
+ customSet?: (value: string) => string | number | null | undefined;
182
+ withNullSet?: boolean;
183
+ } & InputProps) => JSX.Element;
184
+
185
+ export declare const FormMultiSelect: <T>({ name, ...others }: FormMultiSelectProps<T>) => JSX.Element;
186
+
187
+ declare type FormMultiSelectProps<T> = Omit<MultiSelectProps<T>, "selectedValues" | "onChange"> & {
188
+ name: string;
189
+ };
190
+
191
+ export declare const FormSubmit: ({ isEditable, isDeletable, createUpdateLoading, deleteLoading, onDelete, onDeleteConfirm, addText, updateText, deleteText, className, }: {
192
+ isEditable?: boolean;
193
+ isDeletable?: boolean;
194
+ createUpdateLoading: boolean;
195
+ deleteLoading?: boolean;
196
+ onDelete?: () => void;
197
+ onDeleteConfirm?: boolean;
198
+ addText?: string;
199
+ updateText?: string;
200
+ deleteText?: string;
201
+ className?: string;
202
+ }) => JSX.Element;
203
+
204
+ export declare const FormTags: ({ name, ...others }: FormTagsProps) => JSX.Element;
205
+
206
+ declare type FormTagsProps = Omit<TagsProps, "tags" | "onChange"> & {
207
+ name: string;
208
+ };
209
+
210
+ export declare const FormTextArea: ({ name, customRead, customSet, ...others }: {
211
+ name: string;
212
+ customRead?: (value: string | null) => string;
213
+ customSet?: (value: string) => string | null | undefined;
214
+ } & TextAreaProps) => JSX.Element;
215
+
216
+ declare type FormWrapperProps<T extends FieldValues> = {
217
+ methods: UseFormReturn<T>;
218
+ onSubmit: RHFSubmitHandler<T>;
219
+ onError?: (errors: FieldErrors<T>) => void;
220
+ children: default_2.ReactNode;
221
+ logErrors?: boolean;
222
+ className?: string;
223
+ };
224
+
124
225
  export declare function generateInitials(name: string): string;
125
226
 
126
227
  /**
@@ -169,6 +270,23 @@ declare interface IconProps extends React.SVGProps<SVGSVGElement> {
169
270
 
170
271
  export declare type IndividualIconProps = Omit<IconProps, "children">;
171
272
 
273
+ export declare const Input: ForwardRefExoticComponent<InputProps & RefAttributes<HTMLInputElement>>;
274
+
275
+ export declare interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
276
+ label?: string;
277
+ description?: string;
278
+ labelPosition?: "default" | "floating";
279
+ color?: "solid" | "outline";
280
+ focusColor?: "solid" | "brand";
281
+ valid?: boolean;
282
+ error?: boolean;
283
+ errorMessage?: string;
284
+ isPrice?: boolean;
285
+ prefix?: string;
286
+ wrapperClassName?: string;
287
+ containerClassName?: string;
288
+ }
289
+
172
290
  export declare const KeepAlive: React.FC<KeepAliveProps>;
173
291
 
174
292
  declare type KeepAliveContextType = {
@@ -185,10 +303,83 @@ declare type KeepAliveProps = React.HTMLAttributes<HTMLDivElement> & {
185
303
  enabled?: boolean;
186
304
  };
187
305
 
306
+ export declare const MultiSelect: <T>({ label, labelPosition, options, selectedValues, onChange, idExtractor, labelExtractor, customSetter, valid, error, placeholder, maxSelections, searchable, disabled, className, }: MultiSelectProps<T>) => JSX.Element;
307
+
308
+ declare interface MultiSelectProps<T> {
309
+ label: string;
310
+ labelPosition?: "default" | "floating";
311
+ options: T[];
312
+ selectedValues: T[];
313
+ onChange: (values: T[]) => void;
314
+ idExtractor: (item: T) => string | number;
315
+ labelExtractor: (item: T) => string;
316
+ customSetter?: (item: T) => any;
317
+ valid?: boolean;
318
+ error?: string;
319
+ placeholder?: string;
320
+ maxSelections?: number;
321
+ searchable?: boolean;
322
+ disabled?: boolean;
323
+ className?: string;
324
+ }
325
+
326
+ /**
327
+ * helper to set an input to empty string
328
+ * if the value is null
329
+ */
330
+ export declare function nullRead(e: string | null): string;
331
+
332
+ /**
333
+ * helper to set an input
334
+ * back to null if the value is empty
335
+ */
336
+ export declare function nullSet(e: string): string | null;
337
+
338
+ declare type OverflowInfo = {
339
+ horizontal: boolean;
340
+ vertical: boolean;
341
+ scrollWidth: number;
342
+ clientWidth: number;
343
+ scrollHeight: number;
344
+ clientHeight: number;
345
+ canScrollLeft: boolean;
346
+ canScrollRight: boolean;
347
+ canScrollUp: boolean;
348
+ canScrollDown: boolean;
349
+ scrollPercentageX: number;
350
+ scrollPercentageY: number;
351
+ scrollLeft: number;
352
+ scrollTop: number;
353
+ };
354
+
355
+ export declare const Portal: ({ children, node }: PortalProps) => ReactPortal;
356
+
357
+ declare type PortalProps = {
358
+ children: React.ReactNode;
359
+ node?: HTMLElement | null;
360
+ };
361
+
362
+ declare type PositionOptions_2 = {
363
+ triggerRect: DOMRect;
364
+ popoverWidth: number;
365
+ popoverHeight: number;
366
+ align?: "start" | "center" | "end";
367
+ side?: "top" | "bottom" | "left" | "right";
368
+ offset?: number;
369
+ collisionPadding?: number;
370
+ avoidCollisions?: boolean;
371
+ };
372
+
373
+ export declare function removeWhitespaces(text: string): string;
374
+
375
+ export { RHFSubmitHandler }
376
+
188
377
  export declare const Separator: ({ className }: {
189
378
  className?: string;
190
379
  }) => JSX.Element;
191
380
 
381
+ export declare function setFocusEnd(element: HTMLInputElement): void;
382
+
192
383
  declare const sizes: {
193
384
  xs: string;
194
385
  sm: string;
@@ -210,6 +401,51 @@ declare const sizeStyles: {
210
401
  iconLg: string;
211
402
  };
212
403
 
404
+ export declare const Spinner: React.FC<SpinnerProps>;
405
+
406
+ declare type SpinnerProps = {
407
+ loading?: boolean;
408
+ wrapperClassName?: string;
409
+ spinnerClassName?: string;
410
+ };
411
+
412
+ export declare type SubmitHandler<T extends FieldValues> = (data: T, form: UseFormReturn<T>) => Promise<void> | void;
413
+
414
+ export declare function Switch({ checked, onCheckedChange, disabled, name, required, className, }: SwitchProps): JSX.Element;
415
+
416
+ declare interface SwitchProps {
417
+ checked: boolean;
418
+ onCheckedChange: (checked: boolean) => void;
419
+ disabled?: boolean;
420
+ name?: string;
421
+ required?: boolean;
422
+ className?: string;
423
+ }
424
+
425
+ export declare const Tags: ({ label, variant, color, tags, onChange, valid, error, placeholder, maxTags, validateTag, }: TagsProps) => JSX.Element;
426
+
427
+ declare interface TagsProps {
428
+ label: string;
429
+ variant?: "default" | "floating";
430
+ color?: "solid" | "translucent" | "outline";
431
+ tags: string[];
432
+ onChange: (tags: string[]) => void;
433
+ valid?: boolean;
434
+ error?: string;
435
+ placeholder?: string;
436
+ maxTags?: number;
437
+ validateTag?: (tag: string) => boolean | string;
438
+ }
439
+
440
+ export declare const TextArea: ForwardRefExoticComponent<TextAreaProps & RefAttributes<HTMLTextAreaElement>>;
441
+
442
+ declare interface TextAreaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
443
+ label: string;
444
+ labelPosition?: "default" | "floating";
445
+ error?: boolean;
446
+ focusColor?: "solid" | "brand";
447
+ }
448
+
213
449
  /**
214
450
  * Creates a throttled function that only invokes func at most once per every limit milliseconds.
215
451
  * The first call executes immediately, subsequent calls are rate-limited, and the last call
@@ -228,6 +464,20 @@ declare const sizeStyles: {
228
464
  */
229
465
  export declare function throttle<T extends (...args: any[]) => any>(func: T, limit?: number): (...args: Parameters<T>) => void;
230
466
 
467
+ export declare function toTitleCase(str: string): string;
468
+
469
+ export declare function useClickAway<T extends HTMLElement = HTMLElement>(callback: () => void): RefObject<T | null>;
470
+
471
+ export declare function useClickAwayAdvanced<T extends HTMLElement = HTMLElement>(callback: () => void, options?: UseClickOutsideOptions): RefObject<T | null>;
472
+
473
+ export declare function useClickAwayWithRef<T extends HTMLElement | null = HTMLElement>(ref: React.RefObject<T>, callback: (event: MouseEvent) => void, enabled?: boolean): void;
474
+
475
+ declare interface UseClickOutsideOptions {
476
+ enabled?: boolean;
477
+ events?: string[];
478
+ excludeRefs?: React.RefObject<HTMLElement>[];
479
+ }
480
+
231
481
  export declare const useKeepAlive: () => KeepAliveContextType;
232
482
 
233
483
  /**
@@ -253,6 +503,71 @@ export declare const useLargeScreen: () => boolean;
253
503
 
254
504
  export declare function useMergedRef<T>(...refs: React.Ref<T>[]): React.RefCallback<T>;
255
505
 
506
+ /**
507
+ * Hook to create react-hook-form methods based on a zod schema and default values.
508
+ *
509
+ * @param schema Zod schema to validate form data
510
+ * @param defaultValues Optional default form values (partial)
511
+ * @returns UseFormReturn with typed form methods
512
+ */
513
+ export declare function useMethods<TSchema extends ZodTypeAny>(schema: TSchema, defaultValues?: Partial<z.infer<TSchema>>): UseFormReturn<z.infer<TSchema>>;
514
+
515
+ export declare const useOverflow: <T extends HTMLElement>({ onOverflow, trackScroll, withObserver, enabled, deps, }?: {
516
+ onOverflow?: (info: OverflowInfo) => void;
517
+ trackScroll?: boolean;
518
+ withObserver?: boolean;
519
+ enabled?: boolean;
520
+ deps?: any[];
521
+ }) => {
522
+ ref: RefObject<T | null>;
523
+ };
524
+
525
+ export declare const useOverflowState: <T extends HTMLElement>({ trackScroll, withObserver, enabled, deps, }?: {
526
+ trackScroll?: boolean;
527
+ withObserver?: boolean;
528
+ enabled?: boolean;
529
+ deps?: any[];
530
+ }) => {
531
+ ref: RefObject<T | null>;
532
+ overflowInfo: OverflowInfo | null;
533
+ };
534
+
535
+ export declare const usePopover: <T extends HTMLElement, P extends HTMLElement>({ scrollerId, align, side, offset, collisionPadding, avoidCollisions, closeOnScroll, onOpen, onClose, }?: UsePopoverProps) => {
536
+ triggerRef: RefObject<T | null>;
537
+ triggerProps: {
538
+ id: string;
539
+ "aria-expanded": boolean;
540
+ "aria-haspopup": boolean;
541
+ };
542
+ popoverRef: RefObject<P | null>;
543
+ /**
544
+ * Call this sync before rendering the popover
545
+ */
546
+ getPopoverPosition: (customRect?: DOMRect) => {
547
+ x: number;
548
+ top: number | undefined;
549
+ bottom: number | undefined;
550
+ };
551
+ open: boolean;
552
+ toggle: () => void;
553
+ close: () => void;
554
+ };
555
+
556
+ declare type UsePopoverProps = {
557
+ scrollerId?: string;
558
+ /**
559
+ * To point scroller id to route id-content instead of id
560
+ */
561
+ align?: "start" | "center" | "end";
562
+ side?: "top" | "bottom" | "left" | "right";
563
+ offset?: number;
564
+ collisionPadding?: number;
565
+ avoidCollisions?: boolean;
566
+ closeOnScroll?: boolean;
567
+ onOpen?: VoidFunction;
568
+ onClose?: VoidFunction;
569
+ };
570
+
256
571
  export declare const useRipple: <T extends HTMLElement>(enabled?: boolean, contrastRipple?: boolean) => {
257
572
  ref: RefObject<T | null>;
258
573
  ripple: (event: React.MouseEvent<T>) => void;