UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

60 lines (59 loc) 3.62 kB
import type { ReactElement } from "react"; import { ArraySchema } from "../../schema/ArraySchema.js"; import { BooleanSchema } from "../../schema/BooleanSchema.js"; import { ChoiceSchema } from "../../schema/ChoiceSchema.js"; import { DataSchema } from "../../schema/DataSchema.js"; import { DateSchema } from "../../schema/DateSchema.js"; import { DictionarySchema } from "../../schema/DictionarySchema.js"; import { NumberSchema } from "../../schema/NumberSchema.js"; import type { Schema } from "../../schema/Schema.js"; import { StringSchema } from "../../schema/StringSchema.js"; import { type Data } from "../../util/data.js"; import type { ValidatorType } from "../../util/validate.js"; import type { OptionalChildProps } from "../util/props.js"; import type { ValueInputProps } from "./Input.js"; /** A schema is required if it's not wrapped in an `OptionalSchema` or `NullableSchema` */ export declare function isSchemaRequired(schema: Schema): boolean; export interface SchemaInputProps<T extends Schema, I = never> extends ValueInputProps<ValidatorType<T>, I> { schema: T; } /** * Show the right control/input for a named property of a form. * * @example <FormControl name="email" /> // Outputs a `<StringInput>` for the "email" property. * @example <FormControl name="age" /> // Outputs a `<NumberInput>` for the "age" property. */ export declare function SchemaInput<T extends Schema>(props: SchemaInputProps<T>): ReactElement; export interface DateSchemaInputProps extends SchemaInputProps<DateSchema, unknown> { } export declare function DateSchemaInput({ schema, value, ...props }: DateSchemaInputProps): ReactElement; export interface NumberSchemaInputProps extends SchemaInputProps<NumberSchema, unknown> { } export declare function NumberSchemaInput({ schema, value, ...props }: NumberSchemaInputProps): ReactElement; export interface ChoiceSchemaInputProps extends SchemaInputProps<ChoiceSchema<string>, unknown> { } export declare function ChoiceSchemaInput({ schema, value, ...props }: ChoiceSchemaInputProps): ReactElement; export interface BooleanSchemaInputProps extends SchemaInputProps<BooleanSchema, unknown> { } export declare function BooleanSchemaInput({ schema, value, ...props }: BooleanSchemaInputProps): ReactElement; export interface StringSchemaInputProps extends SchemaInputProps<StringSchema, unknown> { } export declare function StringSchemaInput({ schema, value, ...props }: StringSchemaInputProps): ReactElement; export interface ArraySchemaInputProps extends SchemaInputProps<ArraySchema<unknown>, unknown> { } export declare function ArraySchemaInput({ schema, value, ...props }: ArraySchemaInputProps): ReactElement; export interface DictionarySchemaInputProps extends SchemaInputProps<DictionarySchema<unknown>, unknown> { } export declare function DictionarySchemaInput({ schema, value, ...props }: DictionarySchemaInputProps): ReactElement; export interface DataSchemaInputProps extends SchemaInputProps<DataSchema<Data>, unknown> { } export declare function DataSchemaInput({ schema, value, ...props }: DataSchemaInputProps): ReactElement; export interface SchemaFieldProps extends SchemaInputProps<Schema, unknown>, OptionalChildProps { } /** * Show the right control/input for a named property of a form, wrapped in a `<Field>` * * @example <FormControl name="email" /> // Outputs a `<Field><StringInput></Field>` for the "email" property. * @example <FormControl name="age" /> // Outputs a `<Field><NumberInput></Field>` for the "age" property. */ export declare function SchemaField({ schema, children, ...props }: SchemaFieldProps): ReactElement;