feat: 重构表单输入组件,添加文本输入类型,优化配置和样式
This commit is contained in:
14
src/__fk-inputs__/components/input-text.vue
Normal file
14
src/__fk-inputs__/components/input-text.vue
Normal 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>
|
48
src/__fk-inputs__/inputs/inputs/form.ts
Normal file
48
src/__fk-inputs__/inputs/inputs/form.ts
Normal 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',
|
||||
}
|
68
src/__fk-inputs__/inputs/inputs/text.ts
Normal file
68
src/__fk-inputs__/inputs/inputs/text.ts
Normal 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',
|
||||
}
|
20
src/__fk-inputs__/inputs/sections/formInput.ts
Normal file
20
src/__fk-inputs__/inputs/sections/formInput.ts
Normal 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',
|
||||
},
|
||||
}))
|
Reference in New Issue
Block a user