floatLabel
All checks were successful
/ test (push) Successful in 26s
/ surge (push) Successful in 40s

This commit is contained in:
严浩
2024-11-26 10:53:12 +08:00
parent 20ce563e32
commit 7d850957a6
9 changed files with 70 additions and 137 deletions

View File

@ -3,12 +3,12 @@
"source.fixAll": "explicit" "source.fixAll": "explicit"
}, },
"[vue]": { "[vue]": {
"editor.defaultFormatter": "Vue.volar", "editor.defaultFormatter": "Vue.volar"
}, },
"[typescript]": { "[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "esbenp.prettier-vscode"
}, },
"editor.formatOnSave": true, "editor.formatOnSave": true,
"editor.formatOnSaveMode": "file", "editor.formatOnSaveMode": "file",
"typescript.tsdk": "node_modules/typescript/lib", "typescript.tsdk": "node_modules/typescript/lib"
} }

7
components.d.ts vendored
View File

@ -7,14 +7,9 @@ export {}
/* prettier-ignore */ /* prettier-ignore */
declare module 'vue' { declare module 'vue' {
export interface GlobalComponents { export interface GlobalComponents {
Button: typeof import('primevue/button')['default']
BUtton: typeof import('primevue/button')['default']
Fieldset: typeof import('primevue/fieldset')['default'] Fieldset: typeof import('primevue/fieldset')['default']
Form: typeof import('@primevue/forms/form')['default'] FloatLabel: typeof import('primevue/floatlabel')['default']
FormField: typeof import('@primevue/forms/formfield')['default']
InputText: typeof import('primevue/inputtext')['default'] InputText: typeof import('primevue/inputtext')['default']
Message: typeof import('primevue/message')['default'] Message: typeof import('primevue/message')['default']
Password: typeof import('primevue/password')['default']
Toast: typeof import('primevue/toast')['default']
} }
} }

View File

@ -13,4 +13,11 @@ import ZodForm from './zod-form/index.vue';
<AllCustom /> <AllCustom />
</div> </div>
<!-- </div> --> <!-- </div> -->
<div class="p-4 w-full bg-white rounded-lg shadow-md dark:bg-gray-800 dark:text-white mt-4">
<FloatLabel>
<label for="username">用户名</label>
<InputText id="username"></InputText>
</FloatLabel>
</div>
</template> </template>

View File

@ -1,77 +0,0 @@
import { FormKitTypeDefinition, type FormKitFrameworkContext } from '@formkit/core';
import {
casts,
createSection,
help,
icon,
inner,
label,
outer,
prefix,
suffix,
textInput,
wrapper,
} from '@formkit/inputs';
import { messages } from '../sections/messages';
import { h, markRaw } from 'vue';
// https://github.com/formkit/formkit/blob/e57ad1632b95d34d9e6cf046a4802f7ae389700e/packages/vue/src/composables/createInput.ts
/**
* 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(),
),
/**
* 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',
};
// @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 }>),
};

View File

@ -11,9 +11,9 @@ const formInput = createSection('form', () => ({
autoAnimate: true, autoAnimate: true,
}, },
attrs: { attrs: {
id: '$id', 'id': '$id',
name: '$node.name', 'name': '$node.name',
onSubmit: '$handlers.submit', 'onSubmit': '$handlers.submit',
'data-loading': '$state.loading || undefined', 'data-loading': '$state.loading || undefined',
}, },
})); }));
@ -33,13 +33,13 @@ const button = createSection(
); );
export const form: FormKitTypeDefinition = { export const form: FormKitTypeDefinition = {
type: 'group',
schema: formInput( schema: formInput(
'$slots.default', '$slots.default',
messages(), messages(),
actions(submitInput()), actions(submitInput()),
button(), // button(), //
), ),
type: 'group',
props: [ props: [
'submitLabel', 'submitLabel',
'submitAttrs', 'submitAttrs',

View File

@ -4,29 +4,35 @@ import { casts, createSection, label, outer } from '@formkit/inputs';
import SchemaComponent from 'primevue/password'; import SchemaComponent from 'primevue/password';
import { markRaw } from 'vue'; import { markRaw } from 'vue';
import { messages } from '../sections/messages'; import { messages } from '../sections/messages';
import { floatLabel } from '../sections/floatLabel';
const input = createSection('input', () => ({
$cmp: markRaw(SchemaComponent) as never,
bind: '$attrs',
props: {
invalid: '$state.invalid',
disabled: '$disabled',
// name: '$node.name',
// inputProps: {}
onInput: '$handlers.DOMInput',
onBlur: '$handlers.blur',
modelValue: '$_value',
inputId: '$id',
fluid: true,
},
}));
export const PInputPassword: FormKitTypeDefinition = { export const PInputPassword: FormKitTypeDefinition = {
type: 'input', type: 'input',
schema: outer( schema: outer(
label('$label'), floatLabel(
createSection('input', () => ({ input(), //
$cmp: markRaw(SchemaComponent) as never, label('$label'),
bind: '$attrs', ),
props: {
invalid: '$state.invalid',
disabled: '$disabled',
// name: '$node.name',
// inputProps: {}
onInput: '$handlers.DOMInput',
onBlur: '$handlers.blur',
modelValue: '$_value',
inputId: '$id',
},
}))(),
messages(), messages(),
), ),
features: [casts], features: [casts],
// schemaMemoKey: 'g2f31c24kjh', // schemaMemoKey: 'g2f31c24kjh', // Math.random().toString(36).substring(2, 15)
}; };
declare module '@formkit/inputs' { declare module '@formkit/inputs' {

View File

@ -3,35 +3,36 @@ import type { FormKitInputs } from '@formkit/inputs';
import { casts, createSection, label, outer } from '@formkit/inputs'; import { casts, createSection, label, outer } from '@formkit/inputs';
import SchemaComponent from 'primevue/inputtext'; import SchemaComponent from 'primevue/inputtext';
import { markRaw } from 'vue'; import { markRaw } from 'vue';
import { floatLabel } from '../sections/floatLabel';
import { messages } from '../sections/messages'; import { messages } from '../sections/messages';
const cmpName = `SchemaComponent${SchemaComponent.name}`; const input = createSection('input', () => ({
$cmp: markRaw(SchemaComponent) as never,
bind: '$attrs',
props: {
invalid: '$state.invalid',
type: '$type',
disabled: '$disabled',
name: '$node.name',
onInput: '$handlers.DOMInput',
onBlur: '$handlers.blur',
modelValue: '$_value',
id: '$id',
fluid: true,
},
}));
export const PInputText: FormKitTypeDefinition = { export const PInputText: FormKitTypeDefinition = {
type: 'input', type: 'input',
schema: outer( schema: outer(
label('$label'), floatLabel(
createSection('input', () => ({ input(), //
$cmp: cmpName, label('$label'),
bind: '$attrs', ),
props: {
invalid: '$state.invalid',
type: '$type',
disabled: '$disabled',
name: '$node.name',
onInput: '$handlers.DOMInput',
onBlur: '$handlers.blur',
modelValue: '$_value',
id: '$id',
},
}))(),
messages(), messages(),
), ),
library: {
[cmpName]: markRaw(SchemaComponent),
},
features: [casts], features: [casts],
// schemaMemoKey: 'g2f31c24kjh', // schemaMemoKey: 'g2f31c24kjh', // Math.random().toString(36).substring(2, 15)
}; };
declare module '@formkit/inputs' { declare module '@formkit/inputs' {

View File

@ -0,0 +1,8 @@
import { createSection } from '@formkit/inputs';
import FloatLabel from 'primevue/floatlabel';
import { markRaw } from 'vue';
export const floatLabel = createSection('floatLabel', () => ({
$cmp: markRaw(FloatLabel) as never,
bind: '$attrs',
}));

View File

@ -1,10 +1,8 @@
<script setup lang="ts"> <script setup lang="ts">
import { text } from '@/__fk-inputs__/inputs/_demo_text';
import { FormKitNode } from '@formkit/core'; import { FormKitNode } from '@formkit/core';
import { text } from '@formkit/inputs';
import Swal from 'sweetalert2'; import Swal from 'sweetalert2';
async function submit(formData: Record<string, any>, formNode: FormKitNode) { async function submit(formData: Record<string, any>, formNode: FormKitNode) {
console.group('submit'); console.group('submit');
console.log('formData :>> ', formData); console.log('formData :>> ', formData);
@ -19,8 +17,6 @@ async function submit(formData: Record<string, any>, formNode: FormKitNode) {
timer: 1500 timer: 1500
}) })
} }
</script> </script>
<template> <template>
@ -33,10 +29,10 @@ async function submit(formData: Record<string, any>, formNode: FormKitNode) {
<FormKit <FormKit
:config="{ :config="{
classes: { classes: {
form: 'flex flex-col gap-4 w-full', form: 'flex flex-col w-full py-8 gap-8',
outer: 'flex flex-col gap-2', outer: 'flex flex-col gap-2',
label: 'font-medium block' /* label: 'font-medium block' */
} },
}" }"
type="form" type="form"
#default="{ value }" #default="{ value }"
@ -51,7 +47,6 @@ async function submit(formData: Record<string, any>, formNode: FormKitNode) {
name="PInputText" name="PInputText"
label="输入框" label="输入框"
:value="`default value`.repeat(5)" :value="`default value`.repeat(5)"
placeholder="请输入"
some="prop" some="prop"
some-boolean-prop some-boolean-prop
validation="required" validation="required"
@ -61,10 +56,8 @@ async function submit(formData: Record<string, any>, formNode: FormKitNode) {
type="PInputPassword" type="PInputPassword"
name="PInputPassword" name="PInputPassword"
label="密码" label="密码"
placeholder="输入一个密码"
validation="required" validation="required"
toggleMask toggleMask
fluid
:feedback="false" :feedback="false"
/> />
<FormKit <FormKit