@formkit/inputs

介绍

官方的FormKit Inputs插件。该包含有所有原生HTML输入类型的源代码。阅读inputs文档以获取使用说明。

辅助函数

$attrs()

通过应用一个高阶函数将给定的一组属性合并到节点中,将属性应用于给定的模式部分。

签名

$attrs(attrs: FormKitSchemaAttributes | (() => FormKitSchemaAttributes), section: FormKitSchemaExtendableSection): FormKitSchemaExtendableSection;

参数

返回值

FormKitSchemaExtendableSection

$extend()

使用给定的扩展来扩展模式节点。

签名

$extend(section: FormKitSchemaExtendableSection, extendWith: Partial<FormKitSchemaNode>): FormKitSchemaExtendableSection;

参数

  • section — 要应用扩展的部分。
  • extendWith — 要应用于部分的部分模式片段。

返回值

FormKitSchemaExtendableSection

$for()

将条件应用于给定的模式部分。

签名

$for(varName: string, inName: string, section: FormKitSchemaExtendableSection): (extensions: Record<string, Partial<FormKitSchemaNode>>) => FormKitSchemaNode;

参数

  • varName — 保存当前实例的变量的名称。
  • inName — 我们正在迭代的变量。
  • section — 要重复的部分。

返回值

FormKitSchemaExtendableSection

$if()

将条件应用于给定的模式部分。

签名

$if(condition: string, then: FormKitSchemaExtendableSection, otherwise?: FormKitSchemaExtendableSection): FormKitSchemaExtendableSection;

参数

  • condition — 应用于部分的模式条件。
  • then — 如果条件为真,则应用的部分。
  • otherwise 可选 —(否则)如果条件为假,则应用的部分。

返回值

FormKitSchemaExtendableSection

$root()

创建一个根模式部分。

签名

$root(section: FormKitSchemaExtendableSection): FormKitExtendableSchemaRoot;

参数

  • section — 要从中创建根的部分。

返回值

FormKitSchemaExtendableSection

特性

checkboxes()

添加复选框选择支持的特性。

签名

checkboxes(node: FormKitNode): void;

参数

defaultIcon()

添加图标属性定义的特性。

签名

defaultIcon(sectionKey: string, defaultIcon: string): (node: FormKitNode) => void;

参数

  • sectionKey — 图标应该加载的位置。
  • defaultIcon — 如果在用户的CSS中找到匹配项,则应加载的图标。

返回值

FormKitPlugin

files()

向输入添加文件处理支持的特性。

签名

files(node: FormKitNode): void;

参数

initialValue()

确保输入具有initialValue属性的特性。

签名

initialValue(node: FormKitNode): void;

参数

localize()

创建一个新的特性,为给定的组件生成类型为ui的本地化消息。

签名

localize(key: string, value?: string): (node: FormKitNode) => void;

参数

  • key — 消息的键。
  • value 可选 — 消息的值。

返回值

FormKitPlugin

normalizeBoxes()

规范化框类型(复选框,单选框)的特性。

签名

normalizeBoxes(node: FormKitNode): FormKitMiddleware<{
    prop: string | symbol;
    value: any;
}>;

参数

返回值

FormKitMiddleware

options()

将选项属性转换为可用值的特性,供特性或插件使用。

签名

options(node: FormKitNode): void;

参数

radios()

一个用于检查被检查的值是否为当前值的功能。

签名

radios(node: FormKitNode): void;

参数

函数

createLibraryPlugin()

基于一组 FormKitLibrary 创建一个插件。

签名

createLibraryPlugin(...libraries: FormKitLibrary[]): FormKitPlugin;

参数

返回值

FormKitPlugin

createSection()

创建一个新的可重用的部分。

签名

createSection(section: string, el: string | null | (() => FormKitSchemaNode), fragment: true): FormKitSection<FormKitExtendableSchemaRoot>;
createSection(section: string, el: string | null | (() => FormKitSchemaNode)): FormKitSection<FormKitSchemaExtendableSection>;
createSection(section: string, el: string | (() => FormKitSchemaNode), fragment: false): FormKitSection<FormKitSchemaExtendableSection>;

参数

  • section — 一个单独的模式部分
  • el — 元素或返回模式节点的函数。
  • fragment

返回值

返回一个 FormKitExtendableSchemaRootFormKitSchemaExtendableSection

disables()

一个允许禁用此节点的子节点的功能。

签名

disables(node: FormKitNode): void;

参数

eachSection()

在模式中的每个部分上运行回调函数。如果 stopOnCallbackReturn 为 true,并且回调函数返回一个值,则循环将停止并返回该值。

签名

eachSection<T>(schema: FormKitSchemaDefinition, callback: (section: FormKitSchemaComponent | FormKitSchemaDOMNode, schemaParent: FormKitSchemaNode[], schema: FormKitSchemaCondition) => T, stopOnCallbackReturn?: boolean, schemaParent?: FormKitSchemaNode[]): T | void;

参数

  • schema — 一个 FormKitSchemaNode 数组。
  • callback — 在每个部分上运行的回调函数。
  • stopOnCallbackReturn * 可选 * — 如果为 true,则循环将在回调函数返回一个值时停止。
  • schemaParent * 可选 * — 当前模式节点的父节点。

返回值

extendSchema()

使用扩展来扩展单个模式节点。扩展可以是任何部分节点,包括字符串。

签名

extendSchema(schema: FormKitSchemaNode, extension?: Partial<FormKitSchemaNode>): FormKitSchemaNode;

参数

  • schema — 基本模式节点。
  • extension * 可选 * — 要扩展到基本模式节点上的值。

返回值

FormKitSchemaNode

findSection()

在模式中按名称查找部分。

签名

findSection(schema: FormKitSchemaDefinition, target: string): [false, false] | [FormKitSchemaNode[] | false, FormKitSchemaCondition];

参数

返回值

模式和部分的元组,如果未找到则为 falsefalse 的元组。

form()

一个添加提交处理程序和操作部分的功能。

签名

form(node: FormKitNode): void;

参数

ignore()

一个默认应用 ignore="true" 的功能。

签名

ignore(node: FormKitNode): void;

参数

isSchemaObject()

用于模式对象的类型保护。

签名

isSchemaObject(schema: Partial<FormKitSchemaNode>): schema is FormKitSchemaDOMNode | FormKitSchemaComponent | FormKitSchemaFormKit;

参数

  • schema — 如果节点是模式节点但不是字符串或条件,则返回 true

返回值

boolean

isSlotCondition()

检查当前模式节点是否为插槽条件。

签名

isSlotCondition(node: FormKitSchemaNode): node is {
    if: string;
    then: string;
    else: FormKitSchemaNode | FormKitSchemaNode[];
};

参数

返回值

boolean

示例

{
 if: '$slot.name',
 then: '$slot.name',
 else: []
} // 这个模式节点将返回true。

normalizeOptions()

一个函数,用于将对象数组、字符串数组或键值对对象规范化为使用具有value和label属性的对象数组。

签名

normalizeOptions(options: FormKitOptionsProp): FormKitOptionsList;

参数

返回值

FormKitOptionsList的列表。

select()

将选项属性转换为可用的值。

签名

select(node: FormKitNode): void;

参数

  • node — 一个formkit节点。

useSchema()

创建一个包含所有包装基本模式的输入模式。

签名

useSchema(inputSection: FormKitSection): FormKitSchemaExtendableSection;

参数

  • inputSection — 要存储在输入部分键位置的内容。

返回值

FormKitExtendableSchemaRoot

TypeScript

FormKitFile

FormKit合成的“FileList”中的单个文件对象。

interface FormKitFile {
    file?: File;
    name: string;
}

FormKitOptionsItem

选项应始终格式化为具有label和value属性的对象数组。

interface FormKitOptionsItem {
    __original?: any;
    [index: string]: any;
    attrs?:{
        disabled?: boolean;
    }&Record<string, any>;
    label: string;
    value: unknown;
}

FormKitOptionsPropExtensions

允许通过使用键被忽略但值应用于联合类型的接口来定义prop扩展。这允许任何第三方代码通过使用模块扩展来向联合类型添加新值来扩展选项prop。

interface FormKitOptionsPropExtensions {
    arrayOfNumbers: number[];
    arrayOfStrings: string[];
    optionsList: FormKitOptionsList;
    valueLabelPojo: Record<string | number, string>;
}

FormKitSchemaExtendableSection

一个使用扩展参数调用的函数,并返回一个有效的模式节点。

interface FormKitSchemaExtendableSection {
    _s?: string;
    (extensions: Record<string, Partial<FormKitSchemaNode>>): FormKitSchemaNode;
}

FormKitSection

一个函数,当调用时,返回一个可以再次使用扩展参数调用的函数。

interface FormKitSection<T = FormKitSchemaExtendableSection> {
    (...children: Array<FormKitSchemaExtendableSection | string>): T;
}

FormKitSyntheticPropsExtensions

合成props是不明确声明为props,但应被视为对外界的props。

interface FormKitSyntheticPropsExtensions {
    accept: string;
    action: string;
    actions: boolean;
    dirtyBehavior:'touched' | 'compare';
    disabled: string | boolean;
    enctype: string;
    help: string;
    ignore: string | boolean;
    label: string;
    max: string | number;
    method: string;
    min: string | number;
    multiple: string | boolean;
    options: FormKitOptionsProp;
    preserve: string | boolean;
    preserveErrors: string | boolean;
    step: string | number;
}

FormKitFileValue

基于数组的合成“FileList”。

type FormKitFileValue = FormKitFile[];

FormKitInputSchema

模式节点或返回模式节点的函数。

type FormKitInputSchema = ((children?: FormKitSchemaDefinition) => FormKitSchemaNode) | FormKitSchemaNode;

FormKitOptionsList

选项项的数组。

type FormKitOptionsList = FormKitOptionsItem[];

FormKitOptionsProp

可以传递给选项prop的选项类型。

type FormKitOptionsProp = FormKitOptionsPropExtensions[keyof FormKitOptionsPropExtensions];

FormKitSyntheticProps

合成prop类型。

type FormKitSyntheticProps = {
    [Property in keyof FormKitSyntheticPropsExtensions]: FormKitSyntheticPropsExtensions[Property];
};