UNPKG

mantine-entity

Version:

A library combining Mantine, TanStack Query, and Mantine React Table for efficient entity management

84 lines (83 loc) 3.2 kB
import { GridColProps, InputWrapperProps, NumberInputProps, ScrollAreaProps, SelectProps, StackProps, TextProps } from "@mantine/core"; import { ControllerFieldState, ControllerRenderProps, FieldValues, PathValue, UseFormReturn, UseFormStateReturn } from "react-hook-form"; import { validator } from "./utils"; export type TFieldType = "text" | "textarea" | "number" | "date" | "datetime" | "select" | "multiselect" | "file" | "radio" | "checkbox" | "label" | "panel" | "table" | "switch" | "segment" | "password" | "async-select" | "async-multi-select" | "radio-card" | "rich-text" | "custom"; export type TField<T extends FieldValues> = { id?: string; position?: number; type: TFieldType; label?: string; defaultValue?: PathValue<FieldValues, any>; name: T extends Array<infer U> ? keyof U : keyof T; placeholder?: string; description?: string; disabled?: boolean; hidden?: boolean; icon?: any; page?: number; data?: { label: string; value: string; description?: string; }[] | undefined; group?: T extends Array<infer U extends FieldValues> ? TField<U>[] : TField<T[keyof T]>[]; asyncDataSource?: { valueKey?: string; labelKey?: string | string[]; url?: string; method?: string; mapData?: (data: any) => DataItem[] | undefined; getBaseUrl?: (path: string) => string; httpGet?: (url: string) => Promise<any>; }; mapMultiSelectValue?: (data: any) => string[] | undefined; showWhen?: (props: UseFormReturn<T>) => boolean; disabledWhen?: (props: UseFormReturn<T>) => boolean; panelProps?: { root?: StackProps; label?: TextProps; description?: TextProps; wrapper?: StackProps; }; tableProps?: { root?: ScrollAreaProps; wrapper?: InputWrapperProps; }; selectProps?: SelectProps; validationRules?: ValidationRules; numberProps?: NumberInputProps; visibleRules?: { fieldName: PathValue<FieldValues, any>; comparison: ComparisonType; caseSensitivity?: boolean; fieldValue: string; whenVisibleRulesPass?: string; }; valueWithLabel?: boolean; transformValue?: (value: PathValue<FieldValues, any>, methods: UseFormReturn<T>) => void; gridColProps?: GridColProps; customComponent?: (props: CustomComponentProps<T>) => any; editableRichText?: boolean; }; export type ControllerProps<T extends FieldValues> = { field: ControllerRenderProps<T, any>; fieldState: ControllerFieldState; formState: UseFormStateReturn<T>; defaultProps: Record<string, any>; }; export type CustomComponentProps<T extends FieldValues> = { controller: ControllerProps<T>; methods: UseFormReturn<T>; }; export interface ValidationRules { required?: boolean | string; minLength?: number; maxLength?: number; pattern?: RegExp; custom?: (value: any, fun: typeof validator) => boolean | string | (boolean | string)[]; } export interface DataItem { label: string; value: any; } export type ComparisonType = "equals" | "notEquals" | "contains" | "notContains" | "startsWith" | "endsWith";