Skip to content

Commit

Permalink
fix: use proper Messages section
Browse files Browse the repository at this point in the history
  • Loading branch information
raichev-dima committed Dec 26, 2024
1 parent f83d64b commit d7d753d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
4 changes: 2 additions & 2 deletions packages/formkit/src/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { token } from '@formkit/utils'
import { VaButton, VaMessageList, VaIcon } from 'vuestic-ui'
import { vuesticInputs } from './features/vuesticInputs';
import { icon, message, messages, help } from './sections'
import { icon, messages, help } from './sections'

export const buttonInput = createSection('input', () => ({
$cmp: 'VaButton',
Expand All @@ -35,7 +35,7 @@ export const button: FormKitTypeDefinition = {
* The actual schema of the input, or a function that returns the schema.
*/
schema: outer(
messages(message('$message.value')),
messages(),
wrapper(
buttonInput(
icon('prefix'),
Expand Down
7 changes: 7 additions & 0 deletions packages/formkit/src/features/vuesticInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ import type { FormKitNode } from "@formkit/core";

export function vuesticInputs(node: FormKitNode): void {
node.addProps(['loading'])

node.on('created', () => {
node.context!.fns.arrayMessages = (obj: Record<PropertyKey, any>) =>
Object.values(obj)
.filter(m => m.visible)
.map(m => m.value)
})
}
4 changes: 2 additions & 2 deletions packages/formkit/src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createSection, outer } from '@formkit/inputs'
import { token } from '@formkit/utils'
import { VaFileUpload } from 'vuestic-ui'
import { vuesticInputs } from './features/vuesticInputs';
import { help, message, messages } from './sections';
import { help, messages } from './sections';
import { createInputWrapper } from './createInputWrapper';

const FormKitInputWrapper = createInputWrapper(VaFileUpload)
Expand All @@ -27,7 +27,7 @@ export const file: FormKitTypeDefinition = {
* The actual schema of the input, or a function that returns the schema.
*/
schema: outer(
messages(message()),
messages(),
fileInput(),
help(),
),
Expand Down
10 changes: 4 additions & 6 deletions packages/formkit/src/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import {
forms,
disablesChildren,
} from '@formkit/inputs'
import { messages, message } from './sections'
import { messages } from './sections'
import { submit } from './submit'
import { vuesticInputs } from "./features/vuesticInputs";

export const formInput = createSection('form', () => ({
$cmp: 'VaForm',
bind: '$attrs',
meta: {
autoAnimate: true,
},
props: {
id: '$id',
name: '$node.name',
Expand Down Expand Up @@ -43,7 +41,7 @@ export const form: FormKitTypeDefinition = {
*/
schema: formInput(
'$slots.default',
messages(message('$message.value')),
messages(),
actions(submitInput())
),
/**
Expand All @@ -69,7 +67,7 @@ export const form: FormKitTypeDefinition = {
/**
* Additional features that should be added to your input
*/
features: [forms, disablesChildren],
features: [vuesticInputs, forms, disablesChildren],
/**
* The key used to memoize the schema.
*/
Expand Down
19 changes: 4 additions & 15 deletions packages/formkit/src/sections/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createSection, type FormKitSchemaExtendableSection } from "@formkit/inputs";

import { createSection, type FormKitSchemaExtendableSection } from '@formkit/inputs'

export const icon = (
sectionKey: string,
Expand Down Expand Up @@ -34,22 +33,12 @@ export const help = createSection('help', () => ({
}
}))

export const message = createSection('message', () => ({
$el: 'li',
for: ['message', '$messages'],
attrs: {
key: '$message.key',
id: `$id + '-' + $message.key`,
'data-message-type': '$message.type',
},
}))

export const messages = createSection('messages', () => ({
$cmp: 'VaMessageList',
if: '$defaultMessagePlacement && $fns.length($messages)',
props: {
key: '$message.key',
id: `$id + '-' + $message.key`,
'data-message-type': '$message.type',
id: '$: "errors-" + $id',
modelValue: '$fns.arrayMessages($messages)',
color: 'danger'
},
}))
2 changes: 1 addition & 1 deletion packages/ui/src/stories/formkit/Form.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const Basic: StoryFn = () => ({
v-slot="{ state: { loading } }"
v-model="formValue"
:type="types.form"
class="grid grid-cols-1 md:grid-cols-3 gap-6"
class="grid grid-cols-1 gap-6"
:submit-label="loading ? 'Submitting...' : ''"
@submit="submitApp"
>
Expand Down

0 comments on commit d7d753d

Please sign in to comment.