feat: 更新自定义切换组件,添加 TypeScript 支持并调整属性定义
This commit is contained in:
@ -15,7 +15,6 @@ import FormKitToggle from "./src/headlessui-switch.vue";
|
|||||||
|
|
||||||
const library = createLibraryPlugin({
|
const library = createLibraryPlugin({
|
||||||
text, form, submit, group, checkbox, range, list, number, textarea,
|
text, form, submit, group, checkbox, range, list, number, textarea,
|
||||||
|
|
||||||
mytoggle: createInput(FormKitToggle)
|
mytoggle: createInput(FormKitToggle)
|
||||||
})
|
})
|
||||||
const validation = createValidationPlugin(defaultRules)
|
const validation = createValidationPlugin(defaultRules)
|
||||||
|
@ -1,12 +1,30 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { FormKitFrameworkContext } from '@formkit/core';
|
||||||
|
import type { FormKitInputs } from '@formkit/inputs';
|
||||||
|
|
||||||
|
declare module '@formkit/inputs' {
|
||||||
|
// https://formkit.com/essentials/custom-inputs#typescript-support
|
||||||
|
interface FormKitInputProps<Props extends FormKitInputs<Props>> {
|
||||||
|
// This key and the `type` should match:
|
||||||
|
'mytoggle': {
|
||||||
|
// Define your input `type`:
|
||||||
|
type: 'mytoggle',
|
||||||
|
someProp: string,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
// https://www.ajahandideh.com/articles/formkit-custom-toggle
|
// https://www.ajahandideh.com/articles/formkit-custom-toggle
|
||||||
// https://headlessui.com/v1/vue
|
// https://headlessui.com/v1/vue
|
||||||
import { Switch, SwitchGroup, SwitchLabel } from '@headlessui/vue';
|
import { Switch, SwitchGroup, SwitchLabel } from '@headlessui/vue';
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps<{
|
||||||
context: Object,
|
context: FormKitFrameworkContext;
|
||||||
});
|
}>();
|
||||||
|
|
||||||
|
|
||||||
const value = computed({
|
const value = computed({
|
||||||
get: () => {
|
get: () => {
|
||||||
@ -17,15 +35,12 @@ const value = computed({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const label = props.context?.label;
|
|
||||||
const name = props.context?.name;
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<SwitchGroup>
|
<SwitchGroup data-switch-group-template-root>
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<SwitchLabel class="mr-4">{{ label }}</SwitchLabel>
|
<SwitchLabel class="mr-4">{{ context?.label }}</SwitchLabel>
|
||||||
<Switch
|
<Switch
|
||||||
v-model="value"
|
v-model="value"
|
||||||
:class='value ? "bg-blue-600" : "bg-gray-200"'
|
:class='value ? "bg-blue-600" : "bg-gray-200"'
|
||||||
|
Reference in New Issue
Block a user