@factorialco/f0-react 1.360.0 → 1.362.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 (3) hide show
  1. package/dist/f0.d.ts +203 -19
  2. package/dist/f0.js +2789 -2693
  3. package/package.json +1 -1
package/dist/f0.d.ts CHANGED
@@ -1263,7 +1263,7 @@ export declare const ChatSpinner: ForwardRefExoticComponent<Omit<SVGProps<SVGSVG
1263
1263
  /**
1264
1264
  * All valid renderIf conditions for checkbox fields
1265
1265
  */
1266
- declare type CheckboxFieldRenderIf = BooleanRenderIfCondition | CommonRenderIfCondition;
1266
+ declare type CheckboxFieldRenderIf = BooleanRenderIfCondition | CommonRenderIfCondition | F0BaseFieldRenderIfFunction;
1267
1267
 
1268
1268
  declare interface CheckboxProps extends DataAttributes_2 {
1269
1269
  /**
@@ -1520,7 +1520,7 @@ export declare type CurrentFilters<F extends FilterOptions<string>> = F extends
1520
1520
  /**
1521
1521
  * All valid renderIf conditions for custom fields
1522
1522
  */
1523
- declare type CustomFieldRenderIf = CommonRenderIfCondition;
1523
+ declare type CustomFieldRenderIf = CommonRenderIfCondition | F0BaseFieldRenderIfFunction;
1524
1524
 
1525
1525
  /**
1526
1526
  * Props passed to the custom field render function
@@ -1840,7 +1840,7 @@ export declare type DataSourceDefinition<R extends RecordType = RecordType, Filt
1840
1840
  /**
1841
1841
  * All valid renderIf conditions for date fields
1842
1842
  */
1843
- declare type DateFieldRenderIf = DateRenderIfCondition | CommonRenderIfCondition;
1843
+ declare type DateFieldRenderIf = DateRenderIfCondition | CommonRenderIfCondition | F0BaseFieldRenderIfFunction;
1844
1844
 
1845
1845
  export declare type DateFilterDefinition = BaseFilterDefinition<"date"> & {
1846
1846
  options?: DateFilterOptions_2;
@@ -1925,7 +1925,7 @@ declare type DateRangeComplete = Required<DateRange>;
1925
1925
  /**
1926
1926
  * All valid renderIf conditions for date range fields
1927
1927
  */
1928
- declare type DateRangeFieldRenderIf = DateRangeRenderIfCondition | CommonRenderIfCondition;
1928
+ declare type DateRangeFieldRenderIf = DateRangeRenderIfCondition | CommonRenderIfCondition | F0BaseFieldRenderIfFunction;
1929
1929
 
1930
1930
  /**
1931
1931
  * Base for date range-specific conditions
@@ -2674,9 +2674,9 @@ export declare interface ErrorMessageProps {
2674
2674
  }
2675
2675
 
2676
2676
  /**
2677
- * Evaluate a renderIf condition against the current form values
2677
+ * Evaluate a renderIf property which can be a condition object or a function
2678
2678
  */
2679
- export declare function evaluateRenderIf(condition: RenderIfCondition, values: Record<string, unknown>): boolean;
2679
+ export declare function evaluateRenderIf(renderIf: F0BaseFieldRenderIfProp, values: Record<string, unknown>): boolean;
2680
2680
 
2681
2681
  declare type EventCatcherFunction = (eventName: EventName, params: EventParams) => void;
2682
2682
 
@@ -3040,12 +3040,36 @@ export declare interface F0BaseConfig {
3040
3040
  placeholder?: string;
3041
3041
  /** Helper text displayed below the field */
3042
3042
  helpText?: string;
3043
- /** Whether the field is disabled */
3044
- disabled?: boolean;
3043
+ /**
3044
+ * Whether the field is disabled.
3045
+ * Can be a boolean or a function that receives form values.
3046
+ * @example
3047
+ * // Static disabled
3048
+ * disabled: true
3049
+ *
3050
+ * // Dynamic disabled based on other field values
3051
+ * disabled: ({ values }) => values.status === 'readonly'
3052
+ */
3053
+ disabled?: F0BaseFieldDisabledProp;
3054
+ /**
3055
+ * When true, resets the field to its default value when it becomes disabled.
3056
+ * Useful for clearing dependent fields when their controlling field changes.
3057
+ * @default false
3058
+ */
3059
+ resetOnDisable?: boolean;
3045
3060
  /** Row ID for horizontal grouping with other fields */
3046
3061
  row?: string;
3047
- /** Conditional rendering based on another field's value */
3048
- renderIf?: RenderIfCondition;
3062
+ /**
3063
+ * Conditional rendering based on another field's value.
3064
+ * Can be a condition object or a function that receives form values.
3065
+ * @example
3066
+ * // Condition object
3067
+ * renderIf: { fieldId: 'status', equalsTo: 'active' }
3068
+ *
3069
+ * // Dynamic renderIf based on form values
3070
+ * renderIf: ({ values }) => values.status === 'active'
3071
+ */
3072
+ renderIf?: F0BaseFieldRenderIfProp;
3049
3073
  }
3050
3074
 
3051
3075
  /**
@@ -3062,10 +3086,49 @@ export declare interface F0BaseField {
3062
3086
  helpText?: string;
3063
3087
  /** Placeholder text for the input */
3064
3088
  placeholder?: string;
3065
- /** Whether the field is disabled */
3066
- disabled?: boolean;
3089
+ /**
3090
+ * Whether the field is disabled.
3091
+ * Can be a boolean or a function that receives form values.
3092
+ * @example
3093
+ * // Static disabled
3094
+ * disabled: true
3095
+ *
3096
+ * // Dynamic disabled based on other field values
3097
+ * disabled: ({ values }) => values.status === 'readonly'
3098
+ */
3099
+ disabled?: F0BaseFieldDisabledProp;
3100
+ /**
3101
+ * When true, resets the field to its default value when it becomes disabled.
3102
+ * Useful for clearing dependent fields when their controlling field changes.
3103
+ * @default false
3104
+ */
3105
+ resetOnDisable?: boolean;
3067
3106
  }
3068
3107
 
3108
+ /**
3109
+ * Function type for dynamic disabled evaluation based on form values
3110
+ */
3111
+ declare type F0BaseFieldDisabledFunction = (context: {
3112
+ values: Record<string, unknown>;
3113
+ }) => boolean;
3114
+
3115
+ /**
3116
+ * Disabled property can be a boolean or a function that receives form values
3117
+ */
3118
+ declare type F0BaseFieldDisabledProp = boolean | F0BaseFieldDisabledFunction;
3119
+
3120
+ /**
3121
+ * Function type for dynamic renderIf evaluation based on form values
3122
+ */
3123
+ declare type F0BaseFieldRenderIfFunction = (context: {
3124
+ values: Record<string, unknown>;
3125
+ }) => boolean;
3126
+
3127
+ /**
3128
+ * RenderIf property can be a condition object or a function that receives form values
3129
+ */
3130
+ declare type F0BaseFieldRenderIfProp = RenderIfCondition | F0BaseFieldRenderIfFunction;
3131
+
3069
3132
  export declare const F0BigNumber: {
3070
3133
  ({ label, ...props }: BigNumberProps_2): JSX_2.Element;
3071
3134
  displayName: string;
@@ -3678,6 +3741,12 @@ declare interface F0FormDefaultSubmitConfig extends F0FormSubmitConfigBase {
3678
3741
  * @default "default"
3679
3742
  */
3680
3743
  type?: "default";
3744
+ /**
3745
+ * When true, hides the submit button.
3746
+ * Useful when using `useF0Form` hook to submit from outside the form.
3747
+ * @default false
3748
+ */
3749
+ hideSubmitButton?: boolean;
3681
3750
  }
3682
3751
 
3683
3752
  /**
@@ -3839,6 +3908,40 @@ export declare interface F0FormProps<TSchema extends z.ZodObject<ZodRawShape>> {
3839
3908
  * Controls section sidebar visibility and box wrapping.
3840
3909
  */
3841
3910
  styling?: F0FormStylingConfig;
3911
+ /**
3912
+ * Ref to control the form programmatically from outside.
3913
+ * Use with the `useF0Form` hook to get a ref and submit/reset functions.
3914
+ *
3915
+ * @example
3916
+ * ```tsx
3917
+ * const { formRef, submit } = useF0Form()
3918
+ *
3919
+ * <F0Form formRef={formRef} ... />
3920
+ * <Button onClick={submit}>Submit</Button>
3921
+ * ```
3922
+ */
3923
+ formRef?: React.MutableRefObject<F0FormRef | null>;
3924
+ }
3925
+
3926
+ /**
3927
+ * Interface for the F0Form ref methods
3928
+ */
3929
+ export declare interface F0FormRef {
3930
+ /**
3931
+ * Programmatically submit the form.
3932
+ * Will only call onSubmit if validation passes.
3933
+ * @returns Promise that resolves when submission completes (or rejects on validation failure)
3934
+ */
3935
+ submit: () => Promise<void>;
3936
+ /**
3937
+ * Reset the form to its default values
3938
+ */
3939
+ reset: () => void;
3940
+ /**
3941
+ * Check if the form has unsaved changes
3942
+ */
3943
+ isDirty: () => boolean;
3944
+ /* Excluded from this release type: _setStateCallback */
3842
3945
  }
3843
3946
 
3844
3947
  /**
@@ -3846,6 +3949,14 @@ export declare interface F0FormProps<TSchema extends z.ZodObject<ZodRawShape>> {
3846
3949
  */
3847
3950
  export declare type F0FormSchema<T extends Record<string, ZodTypeAny>> = z.ZodObject<T>;
3848
3951
 
3952
+ /**
3953
+ * Callback to update form state in the hook
3954
+ */
3955
+ declare type F0FormStateCallback = (state: {
3956
+ isSubmitting: boolean;
3957
+ hasErrors: boolean;
3958
+ }) => void;
3959
+
3849
3960
  /**
3850
3961
  * Styling configuration for the form layout and appearance
3851
3962
  */
@@ -5512,7 +5623,7 @@ export declare interface NextStepsProps {
5512
5623
  /**
5513
5624
  * All valid renderIf conditions for number fields
5514
5625
  */
5515
- declare type NumberFieldRenderIf = NumberRenderIfCondition | CommonRenderIfCondition;
5626
+ declare type NumberFieldRenderIf = NumberRenderIfCondition | CommonRenderIfCondition | F0BaseFieldRenderIfFunction;
5516
5627
 
5517
5628
  export declare type NumberFilterDefinition = BaseFilterDefinition<"number"> & {
5518
5629
  options?: NumberFilterOptions_2;
@@ -6212,7 +6323,7 @@ export declare interface ResponsiveStyleProps {
6212
6323
  /**
6213
6324
  * All valid renderIf conditions for richtext fields
6214
6325
  */
6215
- declare type RichTextFieldRenderIf = CommonRenderIfCondition;
6326
+ declare type RichTextFieldRenderIf = CommonRenderIfCondition | F0BaseFieldRenderIfFunction;
6216
6327
 
6217
6328
  /**
6218
6329
  * Rich text editor result value type
@@ -6272,7 +6383,7 @@ declare type SecondaryActionsItems = SecondaryActionItem[] | SecondaryActionItem
6272
6383
  /**
6273
6384
  * Conditional rendering for sections - can be a condition object or a function
6274
6385
  */
6275
- export declare type SectionRenderIf = RenderIfCondition | ((values: Record<string, unknown>) => boolean);
6386
+ export declare type SectionRenderIf = RenderIfCondition | F0BaseFieldRenderIfFunction;
6276
6387
 
6277
6388
  /**
6278
6389
  * Represents a collection of selected items.
@@ -6315,7 +6426,7 @@ export declare type SelectedState = {
6315
6426
  /**
6316
6427
  * All valid renderIf conditions for select fields
6317
6428
  */
6318
- declare type SelectFieldRenderIf = SelectRenderIfCondition | CommonRenderIfCondition;
6429
+ declare type SelectFieldRenderIf = SelectRenderIfCondition | CommonRenderIfCondition | F0BaseFieldRenderIfFunction;
6319
6430
 
6320
6431
  export declare type SelectionId = number | string;
6321
6432
 
@@ -6471,7 +6582,7 @@ declare type SummaryType = "sum";
6471
6582
  /**
6472
6583
  * All valid renderIf conditions for switch fields
6473
6584
  */
6474
- declare type SwitchFieldRenderIf = BooleanRenderIfCondition | CommonRenderIfCondition;
6585
+ declare type SwitchFieldRenderIf = BooleanRenderIfCondition | CommonRenderIfCondition | F0BaseFieldRenderIfFunction;
6475
6586
 
6476
6587
  export declare function Table({ children, ...props }: React.HTMLAttributes<HTMLTableElement>): JSX_2.Element;
6477
6588
 
@@ -6745,12 +6856,12 @@ declare type TeamTagProps = ComponentProps<typeof F0TagTeam>;
6745
6856
  /**
6746
6857
  * All valid renderIf conditions for textarea fields
6747
6858
  */
6748
- declare type TextareaFieldRenderIf = TextRenderIfCondition | CommonRenderIfCondition;
6859
+ declare type TextareaFieldRenderIf = TextRenderIfCondition | CommonRenderIfCondition | F0BaseFieldRenderIfFunction;
6749
6860
 
6750
6861
  /**
6751
6862
  * All valid renderIf conditions for text fields
6752
6863
  */
6753
- declare type TextFieldRenderIf = TextRenderIfCondition | CommonRenderIfCondition;
6864
+ declare type TextFieldRenderIf = TextRenderIfCondition | CommonRenderIfCondition | F0BaseFieldRenderIfFunction;
6754
6865
 
6755
6866
  declare interface TextProps extends Omit<default_2.HTMLAttributes<HTMLElement>, "className">, default_2.RefAttributes<HTMLElement> {
6756
6867
  /**
@@ -7193,6 +7304,79 @@ export declare const useEmojiConfetti: () => {
7193
7304
 
7194
7305
  export declare const useF0Dialog: () => F0DialogContextType;
7195
7306
 
7307
+ /**
7308
+ * Hook to control F0Form programmatically.
7309
+ *
7310
+ * Useful when you need to submit the form from outside the component,
7311
+ * such as when the form is inside a dialog and the submit button is
7312
+ * in the dialog's footer.
7313
+ *
7314
+ * @example
7315
+ * ```tsx
7316
+ * import { useF0Form, F0Form } from "@factorialco/factorial-one/experimental"
7317
+ *
7318
+ * function FormInDialog() {
7319
+ * const { formRef, submit } = useF0Form()
7320
+ * const [open, setOpen] = useState(false)
7321
+ *
7322
+ * return (
7323
+ * <Dialog open={open} onOpenChange={setOpen}>
7324
+ * <DialogContent>
7325
+ * <F0Form
7326
+ * formRef={formRef}
7327
+ * name="my-form"
7328
+ * schema={schema}
7329
+ * defaultValues={defaultValues}
7330
+ * onSubmit={async (data) => {
7331
+ * // Handle submission
7332
+ * setOpen(false)
7333
+ * return { success: true }
7334
+ * }}
7335
+ * />
7336
+ * <DialogFooter>
7337
+ * <Button onClick={() => setOpen(false)}>Cancel</Button>
7338
+ * <Button onClick={submit}>Save</Button>
7339
+ * </DialogFooter>
7340
+ * </DialogContent>
7341
+ * </Dialog>
7342
+ * )
7343
+ * }
7344
+ * ```
7345
+ */
7346
+ export declare function useF0Form(): UseF0FormReturn;
7347
+
7348
+ /**
7349
+ * Return type for the useF0Form hook
7350
+ */
7351
+ export declare interface UseF0FormReturn {
7352
+ /**
7353
+ * Ref to pass to the F0Form component's `formRef` prop
7354
+ */
7355
+ formRef: React.MutableRefObject<F0FormRef | null>;
7356
+ /**
7357
+ * Programmatically submit the form.
7358
+ * Will only trigger onSubmit if all validations pass.
7359
+ * @returns Promise that resolves when submission completes
7360
+ */
7361
+ submit: () => Promise<void>;
7362
+ /**
7363
+ * Reset the form to its default values
7364
+ */
7365
+ reset: () => void;
7366
+ /**
7367
+ * Check if the form has unsaved changes
7368
+ */
7369
+ isDirty: () => boolean;
7370
+ /**
7371
+ * Whether the form is currently submitting
7372
+ */
7373
+ isSubmitting: boolean;
7374
+ /**
7375
+ * Whether the form has validation errors
7376
+ */
7377
+ hasErrors: boolean;
7378
+ }
7379
+
7196
7380
  export declare const useGroups: <R extends RecordType>(groups: GroupRecord<R>[], defaultOpenGroups?: boolean | GroupRecord<R>["key"][]) => {
7197
7381
  openGroups: Record<string, boolean>;
7198
7382
  setGroupOpen: (key: string, open: boolean) => void;