feat: 更新 README 和配置文件,添加 PInputText 组件并优化输入文本组件
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { FormKitTypeDefinition } from '@formkit/core'
|
||||
import { FormKitTypeDefinition, type FormKitFrameworkContext } from '@formkit/core';
|
||||
import {
|
||||
casts,
|
||||
createSection,
|
||||
help,
|
||||
icon,
|
||||
inner,
|
||||
@@ -9,10 +10,10 @@ import {
|
||||
prefix,
|
||||
suffix,
|
||||
textInput,
|
||||
wrapper
|
||||
} from '@formkit/inputs'
|
||||
import { messages } from '../sections/messages'
|
||||
|
||||
wrapper,
|
||||
} from '@formkit/inputs';
|
||||
import { messages } from '../sections/messages';
|
||||
import { h, markRaw } from 'vue';
|
||||
|
||||
/**
|
||||
* Input definition for a text.
|
||||
@@ -23,16 +24,7 @@ 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')
|
||||
)
|
||||
),
|
||||
wrapper(label('$label'), inner(icon('prefix', 'label'), prefix(), textInput(), suffix(), icon('suffix'))),
|
||||
help('$help'),
|
||||
messages(),
|
||||
),
|
||||
@@ -54,7 +46,7 @@ export const text: FormKitTypeDefinition = {
|
||||
/**
|
||||
* Forces node.props.type to be this explicit value.
|
||||
*/
|
||||
forceTypeProp: 'text',
|
||||
// forceTypeProp: 'text',
|
||||
/**
|
||||
* Additional features that should be added to your input
|
||||
*/
|
||||
@@ -63,4 +55,21 @@ export const text: FormKitTypeDefinition = {
|
||||
* The key used to memoize the schema.
|
||||
*/
|
||||
// schemaMemoKey: 'g2f31c24kjh',
|
||||
}
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
const custom_FComponent = {
|
||||
schema: createSection('input', () => ({
|
||||
$cmp: 'FComponent',
|
||||
props: { context: '$node.context' },
|
||||
}))(),
|
||||
library: markRaw(((props: { context: FormKitFrameworkContext } /* context */) => {
|
||||
return h('XxxxCmp', {
|
||||
id: props.context.id,
|
||||
value: props.context._value,
|
||||
...props.context.attrs,
|
||||
onInput: props.context.handlers.DOMInput,
|
||||
onBlur: props.context.handlers.blur,
|
||||
});
|
||||
}) satisfies import('vue').FunctionalComponent<{ context: FormKitFrameworkContext }>),
|
||||
};
|
||||
|
@@ -1,30 +1,36 @@
|
||||
import { FormKitTypeDefinition, type FormKitFrameworkContext } from '@formkit/core';
|
||||
import {
|
||||
casts,
|
||||
createSection,
|
||||
label,
|
||||
outer
|
||||
} from '@formkit/inputs';
|
||||
import PInputText from 'primevue/inputtext';
|
||||
import { h, markRaw } from 'vue';
|
||||
import { FormKitTypeDefinition } from '@formkit/core';
|
||||
import type { FormKitInputs } from '@formkit/inputs';
|
||||
import { casts, createSection, label, outer } from '@formkit/inputs';
|
||||
import InputTextCmp from 'primevue/inputtext';
|
||||
import { markRaw } from 'vue';
|
||||
import { messages } from '../sections/messages';
|
||||
|
||||
export const InputText: FormKitTypeDefinition = {
|
||||
declare module '@formkit/inputs' {
|
||||
// https://formkit.com/essentials/custom-inputs#typescript-support
|
||||
interface FormKitInputProps<Props extends FormKitInputs<Props>> {
|
||||
PInputText: {
|
||||
type: 'PInputText';
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const PInputText: FormKitTypeDefinition = {
|
||||
type: 'input',
|
||||
schema: outer(
|
||||
label('$label'),
|
||||
// custom_FComponent.schema,
|
||||
createSection('input', () => ({
|
||||
$cmp: 'PInputText',
|
||||
$cmp: 'InputTextCmp',
|
||||
bind: '$attrs',
|
||||
props: {
|
||||
invalid: '$state.invalid',
|
||||
// 'type': '$type',
|
||||
type: '$type',
|
||||
'a-typeeeee': '$type',
|
||||
'b-typeeeee': 'bbb',
|
||||
disabled: '$disabled',
|
||||
name: '$node.name',
|
||||
onInput: '$handlers.DOMInput',
|
||||
onBlur: '$handlers.blur',
|
||||
// value: '$_value',
|
||||
modelValue: '$_value',
|
||||
id: '$id',
|
||||
'aria-describedby': '$describedBy',
|
||||
@@ -35,30 +41,8 @@ export const InputText: FormKitTypeDefinition = {
|
||||
),
|
||||
library: {
|
||||
// 'FComponent': custom_FComponent.library,
|
||||
'PInputText': markRaw(PInputText),
|
||||
InputTextCmp: markRaw(InputTextCmp),
|
||||
},
|
||||
features: [casts],
|
||||
// family: 'text',
|
||||
// forceTypeProp: 'text',
|
||||
// schemaMemoKey: 'g2f31c24kjh',
|
||||
}
|
||||
|
||||
|
||||
// @ts-ignore
|
||||
const custom_FComponent = {
|
||||
schema: createSection('input', () => ({
|
||||
$cmp: 'FComponent',
|
||||
props: { context: '$node.context', },
|
||||
}))(),
|
||||
library: markRaw(
|
||||
((props: { context: FormKitFrameworkContext; }, /* context */) => {
|
||||
return h(PInputText, {
|
||||
id: props.context.id,
|
||||
value: props.context._value,
|
||||
...props.context.attrs,
|
||||
onInput: props.context.handlers.DOMInput,
|
||||
onBlur: props.context.handlers.blur,
|
||||
})
|
||||
}) satisfies import('vue').FunctionalComponent<{ context: FormKitFrameworkContext }>
|
||||
)
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user