@oniratec/onira-react-ui 1.1.1 → 1.1.2

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
@@ -17,40 +17,51 @@ import * as TooltipPrimitive from '@radix-ui/react-tooltip';
17
17
  import { UseFormReturn } from 'react-hook-form';
18
18
  import { z } from 'zod';
19
19
 
20
- declare type BaseField<T extends FieldValues> = {
20
+ /** =========================
21
+ * Async select field
22
+ * ========================= */
23
+ declare type AsyncSelectField<T extends FieldValues, TItem = unknown> = BaseFieldCommon<T> & {
24
+ kind: 'asyncSelect';
25
+ /** UI */
26
+ searchPlaceholder?: string;
27
+ minChars?: number;
28
+ debounceMs?: number;
29
+ emptyLabel?: string;
30
+ loadingLabel?: string;
31
+ /** Optional CTA when no results */
32
+ emptyActionLabel?: string;
33
+ onEmptyActionClick?: () => void;
34
+ /** Data */
35
+ fetcher: (query: string) => Promise<TItem[]>;
36
+ getOptionValue: (item: TItem) => string;
37
+ getOptionLabel: (item: TItem) => string;
38
+ };
39
+
40
+ declare type BaseField<T extends FieldValues> = InputField<T> | TextareaField<T> | SelectField<T> | AsyncSelectField<T, any> | ToggleField<T> | CheckboxField<T> | CustomField<T>;
41
+
42
+ /** =========================
43
+ * Common props for all fields
44
+ * ========================= */
45
+ declare type BaseFieldCommon<T extends FieldValues> = {
21
46
  name: FieldPath<T>;
22
47
  label: string;
23
- kind: FieldKind;
24
48
  placeholder?: string;
25
49
  className?: string;
26
- options?: Option_2[];
27
50
  /**
28
51
  * Zod schema for this field.
29
52
  * If not provided, it will default to optional.
30
53
  */
31
54
  schema?: z.ZodTypeAny;
32
- /**
33
- * Default value for this field.
34
- */
55
+ /** Default value for this field. */
35
56
  defaultValue?: unknown;
36
- /**
37
- * Normalize value before storing it in form state.
38
- */
57
+ /** Normalize value before storing it in form state. */
39
58
  normalize?: (value: unknown) => unknown;
40
- /**
41
- * Cross-field dependencies.
42
- */
59
+ /** Cross-field dependencies. */
43
60
  deps?: FieldDependency<T>;
44
- /**
45
- * Conditional visibility.
46
- */
61
+ /** Conditional visibility. */
47
62
  hidden?: (values: Partial<T>) => boolean;
48
63
  /** Grid layout helpers */
49
64
  colSpan?: 1 | 2 | 3 | 4;
50
- /** Personalized render for custom elements **/
51
- render?: (props: {
52
- form: UseFormReturn<T>;
53
- }) => ReactNode;
54
65
  };
55
66
 
56
67
  declare type BaseProps = {
@@ -83,6 +94,10 @@ export declare const CardHeader: ({ children, className }: BaseProps) => JSX.Ele
83
94
 
84
95
  export declare const CardTitle: ({ children, className }: BaseProps) => JSX.Element;
85
96
 
97
+ declare type CheckboxField<T extends FieldValues> = BaseFieldCommon<T> & {
98
+ kind: 'checkbox';
99
+ };
100
+
86
101
  export declare type ColorMode = 'light' | 'dark';
87
102
 
88
103
  export declare type Column<T> = {
@@ -94,6 +109,13 @@ export declare type Column<T> = {
94
109
 
95
110
  declare type CrossRule<T extends FieldValues> = (values: T, ctx: z.RefinementCtx) => void;
96
111
 
112
+ declare type CustomField<T extends FieldValues> = BaseFieldCommon<T> & {
113
+ kind: 'custom';
114
+ render: (props: {
115
+ form: UseFormReturn<T>;
116
+ }) => ReactNode;
117
+ };
118
+
97
119
  export declare const darkTheme: Theme;
98
120
 
99
121
  export declare function DataTable<T>({ columns, data }: Props<T>): JSX.Element;
@@ -146,15 +168,9 @@ declare interface FieldContextValue {
146
168
  export declare const FieldControl: ForwardRefExoticComponent<Omit<SlotProps & RefAttributes<HTMLElement>, "ref"> & RefAttributes<HTMLElement>>;
147
169
 
148
170
  declare type FieldDependency<T extends FieldValues> = {
149
- /**
150
- * Fields to revalidate when this field changes.
151
- * Required for cross-field validation (superRefine).
152
- */
153
171
  onChangeTrigger?: FieldPath<T>[];
154
172
  };
155
173
 
156
- declare type FieldKind = 'input' | 'password' | 'textarea' | 'select' | 'toggle' | 'checkbox' | 'custom';
157
-
158
174
  export declare const FieldLabel: React_2.ForwardRefExoticComponent<React_2.LabelHTMLAttributes<HTMLLabelElement> & React_2.RefAttributes<HTMLLabelElement>>;
159
175
 
160
176
  export declare const FieldMessage: React_2.ForwardRefExoticComponent<React_2.HTMLAttributes<HTMLParagraphElement> & React_2.RefAttributes<HTMLParagraphElement>>;
@@ -174,6 +190,13 @@ export declare function FormFactoryRenderer<TFormModel extends FieldValues, TEnt
174
190
 
175
191
  export declare const Input: React_2.ForwardRefExoticComponent<InputProps & React_2.RefAttributes<HTMLInputElement>>;
176
192
 
193
+ /** =========================
194
+ * Field specific types
195
+ * ========================= */
196
+ declare type InputField<T extends FieldValues> = BaseFieldCommon<T> & {
197
+ kind: 'input' | 'password';
198
+ };
199
+
177
200
  declare interface InputProps extends Omit<React_2.InputHTMLAttributes<HTMLInputElement>, 'crossOrigin' | 'dangerouslySetInnerHTML'> {
178
201
  crossOrigin?: '' | 'anonymous' | 'use-credentials';
179
202
  dangerouslySetInnerHTML?: {
@@ -283,6 +306,11 @@ export declare const Select: React_2.FC<SelectPrimitive.SelectProps>;
283
306
 
284
307
  export declare const SelectContent: React_2.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectContentProps & React_2.RefAttributes<HTMLDivElement>, "ref"> & React_2.RefAttributes<HTMLDivElement>>;
285
308
 
309
+ declare type SelectField<T extends FieldValues> = BaseFieldCommon<T> & {
310
+ kind: 'select';
311
+ options: Option_2[];
312
+ };
313
+
286
314
  export declare const SelectItem: React_2.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectItemProps & React_2.RefAttributes<HTMLDivElement>, "ref"> & React_2.RefAttributes<HTMLDivElement>>;
287
315
 
288
316
  export declare const SelectTrigger: React_2.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectTriggerProps & React_2.RefAttributes<HTMLButtonElement>, "ref"> & {
@@ -297,6 +325,10 @@ declare type SkeletonProps = {
297
325
  className?: string;
298
326
  };
299
327
 
328
+ declare type TextareaField<T extends FieldValues> = BaseFieldCommon<T> & {
329
+ kind: 'textarea';
330
+ };
331
+
300
332
  export declare interface Theme {
301
333
  mode: ColorMode;
302
334
  colors: ThemeColors;
@@ -348,6 +380,10 @@ export declare interface ThemeShadows {
348
380
 
349
381
  export declare const Toggle: ({ checked, defaultChecked, onChange, size, disabled, label, className, ariaLabel, }: ToggleProps) => JSX.Element;
350
382
 
383
+ declare type ToggleField<T extends FieldValues> = BaseFieldCommon<T> & {
384
+ kind: 'toggle';
385
+ };
386
+
351
387
  export declare interface ToggleProps {
352
388
  /** Controlled */
353
389
  checked?: boolean;