UNPKG

fastapi-rtk

Version:

A React component library for FastAPI in combination with FastAPI React Toolkit backend, built with Mantine, JsonForms, and Zustand.

199 lines (198 loc) 9.14 kB
/** * @typedef {Object} CommonModalTitleOptionsProps * @property {React.ReactNode | ((props: { view: string; setView: (view: string) => void }) => React.ReactNode)} left - Content or function to render on the left side of the title. * @property {React.ReactNode | ((props: { view: string; setView: (view: string) => void }) => React.ReactNode)} right - Content or function to render on the right side of the title. * @property {boolean} [hideOverlay=false] - If true, hides the overlay toggle button. * @property {boolean} [hideFullScreen=false] - If true, hides the full screen toggle button. * @property {Record<string, any> | ((props: { view: string; setView: (view: string) => void }) => Record<string, any>)} [overlayButtonProps] - Additional props to be passed to the overlay toggle button. * @property {Record<string, any> | ((props: { view: string; setView: (view: string) => void }) => Record<string, any>)} [fullScreenButtonProps] - Additional props to be passed to the full screen toggle button. */ /** * @typedef {Object} CommonModalActionButtonsProps * @property {Record<string, any>} [groupProps] - Additional properties to be passed to the Group component wrapping the buttons. * @property {boolean} [withResetButton=true] - Flag to determine if the reset button should be displayed. * @property {boolean} [withSubmitButton=true] - Flag to determine if the submit button should be displayed. * @property {Record<string, any>} [resetButtonProps] - Additional properties to be passed to the reset Button component. * @property {Record<string, any>} [submitButtonProps] - Additional properties to be passed to the submit Button component. */ /** * @typedef {Object} CommonModalProps * @property {React.ReactNode} children - The content to be rendered inside the modal. * @property {string} view - Current view mode (e.g., VIEW_MODE.NORMAL, VIEW_MODE.FULL_SCREEN, VIEW_MODE.OVERLAY). * @property {Function} setView - Function to update the view mode. * @property {Function} onReset - Callback function triggered on form reset. * @property {Function} onSubmit - Callback function triggered on form submission. * @property {Record<string, any>} boxProps - Additional properties to be passed to the Box component wrapping the form. * @property {string} resetButtonText - Text displayed on the reset button. * @property {string} buttonText - Text displayed on the submit button. * @property {boolean} buttonLoading - Indicates whether the submit button should display a loading state. * @property {boolean} [withTitleOptions=true] - Flag to determine if title options (e.g., full screen, overlay toggles) should be displayed. * @property {boolean} [withButtons=true] - Flag to determine if action buttons (e.g., submit button) should be displayed. * @property {CommonModalTitleOptionsProps} [titleOptions] - Options for customizing the title area, such as toggles for full screen and overlay modes. * @property {CommonModalActionButtonsProps} [actionButtons] - Options for customizing the action buttons area. * @property {Record<string, any>} rest - Additional props to be passed to the Modal component. */ /** * @typedef {Object} AddDialogProps * @property {Record<string, any>} [jsonForms] - Additional JSON Forms customization options. * @property {(result: Record<string, any> | null) => void} [onSuccess] - Callback function triggered on successful form submission. * @property {(error: any) => void} [onError] - Callback function triggered on form submission error. * @property {Record<string, Record<string, string>>} [translations] - Optional translations for internationalization. * @property {boolean | string | Record<string, boolean> | string[]} [hideWarnings] - Whether to hide missing translation warnings. Can be a boolean, a specific language code, an object mapping languages to booleans, or an array of language codes. * @property {Record<string, any>} [jsonFormsProps] - Additional props to be passed to the JsonFormsWithCustomizer component. */ /** * AddDialog is a component that renders a modal dialog for adding a new entry. * * It integrates with the application's API to add entries and manages form state, * view modes, and loading state via custom hooks. The component also manages the merge * of default JSON Forms settings with any additional props provided. * * @param {AddDialogProps & CommonModalProps} props - The properties for the AddDialog component. * @returns {JSX.Element} The rendered modal dialog component for adding an entry. */ export function AddDialog({ jsonForms: __jsonForms, onSuccess, onError, translations, hideWarnings, jsonFormsProps, ...props }: AddDialogProps & CommonModalProps): JSX.Element; export type CommonModalTitleOptionsProps = { /** * - Content or function to render on the left side of the title. */ left: React.ReactNode | ((props: { view: string; setView: (view: string) => void; }) => React.ReactNode); /** * - Content or function to render on the right side of the title. */ right: React.ReactNode | ((props: { view: string; setView: (view: string) => void; }) => React.ReactNode); /** * - If true, hides the overlay toggle button. */ hideOverlay?: boolean; /** * - If true, hides the full screen toggle button. */ hideFullScreen?: boolean; /** * - Additional props to be passed to the overlay toggle button. */ overlayButtonProps?: Record<string, any> | ((props: { view: string; setView: (view: string) => void; }) => Record<string, any>); /** * - Additional props to be passed to the full screen toggle button. */ fullScreenButtonProps?: Record<string, any> | ((props: { view: string; setView: (view: string) => void; }) => Record<string, any>); }; export type CommonModalActionButtonsProps = { /** * - Additional properties to be passed to the Group component wrapping the buttons. */ groupProps?: Record<string, any>; /** * - Flag to determine if the reset button should be displayed. */ withResetButton?: boolean; /** * - Flag to determine if the submit button should be displayed. */ withSubmitButton?: boolean; /** * - Additional properties to be passed to the reset Button component. */ resetButtonProps?: Record<string, any>; /** * - Additional properties to be passed to the submit Button component. */ submitButtonProps?: Record<string, any>; }; export type CommonModalProps = { /** * - The content to be rendered inside the modal. */ children: React.ReactNode; /** * - Current view mode (e.g., VIEW_MODE.NORMAL, VIEW_MODE.FULL_SCREEN, VIEW_MODE.OVERLAY). */ view: string; /** * - Function to update the view mode. */ setView: Function; /** * - Callback function triggered on form reset. */ onReset: Function; /** * - Callback function triggered on form submission. */ onSubmit: Function; /** * - Additional properties to be passed to the Box component wrapping the form. */ boxProps: Record<string, any>; /** * - Text displayed on the reset button. */ resetButtonText: string; /** * - Text displayed on the submit button. */ buttonText: string; /** * - Indicates whether the submit button should display a loading state. */ buttonLoading: boolean; /** * - Flag to determine if title options (e.g., full screen, overlay toggles) should be displayed. */ withTitleOptions?: boolean; /** * - Flag to determine if action buttons (e.g., submit button) should be displayed. */ withButtons?: boolean; /** * - Options for customizing the title area, such as toggles for full screen and overlay modes. */ titleOptions?: CommonModalTitleOptionsProps; /** * - Options for customizing the action buttons area. */ actionButtons?: CommonModalActionButtonsProps; /** * - Additional props to be passed to the Modal component. */ rest: Record<string, any>; }; export type AddDialogProps = { /** * - Additional JSON Forms customization options. */ jsonForms?: Record<string, any>; /** * - Callback function triggered on successful form submission. */ onSuccess?: (result: Record<string, any> | null) => void; /** * - Callback function triggered on form submission error. */ onError?: (error: any) => void; /** * - Optional translations for internationalization. */ translations?: Record<string, Record<string, string>>; /** * - Whether to hide missing translation warnings. Can be a boolean, a specific language code, an object mapping languages to booleans, or an array of language codes. */ hideWarnings?: boolean | string | Record<string, boolean> | string[]; /** * - Additional props to be passed to the JsonFormsWithCustomizer component. */ jsonFormsProps?: Record<string, any>; };