Skip to content

Commit d7edefa

Browse files
committed
feat: implement File type
1 parent 9563b12 commit d7edefa

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

packages/formkit/src/file.ts

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { type FormKitTypeDefinition } from '@formkit/core'
2+
import { casts, createSection, outer } from '@formkit/inputs'
3+
import { token } from '@formkit/utils'
4+
import { VaFileUpload } from 'vuestic-ui'
5+
import { vuesticInputs } from './features/vuesticInputs';
6+
import { help, message, messages } from './sections';
7+
import { createInputWrapper } from './createInputWrapper';
8+
9+
const FormKitInputWrapper = createInputWrapper(VaFileUpload)
10+
11+
const fileInput = createSection('input', () => ({
12+
$cmp: 'FormKitInputWrapper',
13+
bind: '$attrs',
14+
props: {
15+
context: '$node.context',
16+
prefixIcon: '$prefixIcon',
17+
suffixIcon: '$suffixIcon'
18+
},
19+
}))
20+
21+
/**
22+
* Input definition for a file.
23+
* @public
24+
*/
25+
export const file: FormKitTypeDefinition = {
26+
/**
27+
* The actual schema of the input, or a function that returns the schema.
28+
*/
29+
schema: outer(
30+
messages(message()),
31+
fileInput(),
32+
help(),
33+
),
34+
/**
35+
* The type of node, can be a list, group, or input.
36+
*/
37+
type: 'input',
38+
/**
39+
* The family of inputs this one belongs too. For example "text" and "email"
40+
* are both part of the "text" family. This is primary used for styling.
41+
*/
42+
family: 'text',
43+
/**
44+
* An array of extra props to accept for this input.
45+
*/
46+
props: [],
47+
/**
48+
* A library of components to provide to the internal input schema
49+
*/
50+
library: {
51+
FormKitInputWrapper
52+
},
53+
/**
54+
* Additional features that should be added to your input
55+
*/
56+
features: [casts, vuesticInputs],
57+
/**
58+
* The key used to memoize the schema.
59+
*/
60+
schemaMemoKey: token(),
61+
}

packages/formkit/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export { checkbox } from './checkbox'
44
export { date } from './date'
55
export { datepicker } from './datepicker'
66
export { dropdown } from './dropdown'
7+
export { file } from './file'
78
export { email } from './email'
89
export { color } from './color'
910
export { colorpicker } from './colorpicker'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { StoryFn } from '@storybook/vue3'
2+
import * as types from '@vuestic/formkit'
3+
4+
export default {
5+
title: 'Formkit Integration/File',
6+
}
7+
8+
export const Default: StoryFn = () => ({
9+
setup () {
10+
return {
11+
types,
12+
}
13+
},
14+
template: `
15+
<div class="w-1/5 grid gap-6">
16+
<FormKit
17+
:type="types.file"
18+
label="Documents"
19+
accept=".pdf,.doc,.docx,.xml,.md,.csv"
20+
help="Select as many documents as you would like."
21+
/>
22+
</div>
23+
`,
24+
})

0 commit comments

Comments
 (0)