@factorialco/f0-react 1.361.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 +121 -0
  2. package/dist/f0.js +2015 -1952
  3. package/package.json +1 -1
package/dist/f0.d.ts CHANGED
@@ -3741,6 +3741,12 @@ declare interface F0FormDefaultSubmitConfig extends F0FormSubmitConfigBase {
3741
3741
  * @default "default"
3742
3742
  */
3743
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;
3744
3750
  }
3745
3751
 
3746
3752
  /**
@@ -3902,6 +3908,40 @@ export declare interface F0FormProps<TSchema extends z.ZodObject<ZodRawShape>> {
3902
3908
  * Controls section sidebar visibility and box wrapping.
3903
3909
  */
3904
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 */
3905
3945
  }
3906
3946
 
3907
3947
  /**
@@ -3909,6 +3949,14 @@ export declare interface F0FormProps<TSchema extends z.ZodObject<ZodRawShape>> {
3909
3949
  */
3910
3950
  export declare type F0FormSchema<T extends Record<string, ZodTypeAny>> = z.ZodObject<T>;
3911
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
+
3912
3960
  /**
3913
3961
  * Styling configuration for the form layout and appearance
3914
3962
  */
@@ -7256,6 +7304,79 @@ export declare const useEmojiConfetti: () => {
7256
7304
 
7257
7305
  export declare const useF0Dialog: () => F0DialogContextType;
7258
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
+
7259
7380
  export declare const useGroups: <R extends RecordType>(groups: GroupRecord<R>[], defaultOpenGroups?: boolean | GroupRecord<R>["key"][]) => {
7260
7381
  openGroups: Record<string, boolean>;
7261
7382
  setGroupOpen: (key: string, open: boolean) => void;