feat: 重构表单输入组件,添加文本输入类型,优化配置和样式

This commit is contained in:
严浩
2024-11-24 17:47:02 +08:00
parent 798954d6f3
commit 2aa80123b8
11 changed files with 257 additions and 40 deletions

View File

@@ -0,0 +1,14 @@
<template>
<div>
input-text.vue
</div>
</template>
<script setup lang="ts">
import { FormKitFrameworkContext } from '@formkit/core';
const props = defineProps<{
context: FormKitFrameworkContext & { 'some': string };
}>();
console.debug(`props.context.some :>> `, props.context.some);
</script>

View File

@@ -0,0 +1,48 @@
import { FormKitTypeDefinition } from '@formkit/core'
import {
messages,
message,
actions,
submitInput,
forms,
disablesChildren,
} from '@formkit/inputs'
import { formInput } from '../sections/formInput'
/**
* Input definition for a form.
* @public
*/
export const form: FormKitTypeDefinition = {
/**
* The actual schema of the input, or a function that returns the schema.
*/
schema: formInput(
'$slots.default',
messages(message('$message.value')),
actions(submitInput())
),
/**
* The type of node, can be a list, group, or input.
*/
type: 'group',
/**
* An array of extra props to accept for this input.
*/
props: [
'actions',
'submit',
'submitLabel',
'submitAttrs',
'submitBehavior',
'incompleteMessage',
],
/**
* Additional features that should be added to your input
*/
features: [forms, disablesChildren],
/**
* The key used to memoize the schema.
*/
// schemaMemoKey: 'rorzq1rsrf',
}

View File

@@ -0,0 +1,68 @@
import { FormKitTypeDefinition } from '@formkit/core'
import {
outer,
inner,
wrapper,
label,
help,
messages,
message,
icon,
prefix,
suffix,
textInput,
casts,
createSection,
} from '@formkit/inputs'
/**
* Input definition for a text.
* @public
*/
export const text: FormKitTypeDefinition = {
/**
* The actual schema of the input, or a function that returns the schema.
*/
schema: outer(
wrapper(
label('$label'),
inner(
icon('prefix', 'label'),
prefix(),
textInput(),
suffix(),
icon('suffix')
)
),
help('$help'),
messages(message('$message.value'))
),
/**
* The type of node, can be a list, group, or input.
*/
type: 'input',
/**
* The family of inputs this one belongs too. For example "text" and "email"
* are both part of the "text" family. This is primary used for styling.
*/
family: 'text',
/**
* An array of extra props to accept for this input.
*/
props: [
// 'label2',
],
/**
* Forces node.props.type to be this explicit value.
*/
forceTypeProp: 'text',
/**
* Additional features that should be added to your input
*/
features: [casts],
/**
* The key used to memoize the schema.
*/
// schemaMemoKey: 'g2f31c24kjh',
}

View File

@@ -0,0 +1,20 @@
import { createSection } from '@formkit/inputs'
/**
* Form section
*
* @public
*/
export const formInput = createSection('form', () => ({
$el: 'form',
bind: '$attrs',
meta: {
autoAnimate: true,
},
attrs: {
id: '$id',
name: '$node.name',
onSubmit: '$handlers.submit',
'data-loading': '$state.loading || undefined',
},
}))