Skip to content

Commit

Permalink
feat: implement File type
Browse files Browse the repository at this point in the history
  • Loading branch information
raichev-dima committed Dec 17, 2024
1 parent 5436d37 commit 5840311
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
61 changes: 61 additions & 0 deletions packages/formkit/src/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { type FormKitTypeDefinition } from '@formkit/core'
import { casts, 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 { createInputWrapper } from './createInputWrapper';

const FormKitInputWrapper = createInputWrapper(VaFileUpload)

const fileInput = createSection('input', () => ({
$cmp: 'FormKitInputWrapper',
bind: '$attrs',
props: {
context: '$node.context',
prefixIcon: '$prefixIcon',
suffixIcon: '$suffixIcon'
},
}))

/**
* Input definition for a file.
* @public
*/
export const file: FormKitTypeDefinition = {
/**
* The actual schema of the input, or a function that returns the schema.
*/
schema: outer(
messages(message()),
fileInput(),
help(),
),
/**
* 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: [],
/**
* A library of components to provide to the internal input schema
*/
library: {
FormKitInputWrapper
},
/**
* Additional features that should be added to your input
*/
features: [casts, vuesticInputs],
/**
* The key used to memoize the schema.
*/
schemaMemoKey: token(),
}
1 change: 1 addition & 0 deletions packages/formkit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { checkbox } from './checkbox'
export { date } from './date'
export { datepicker } from './datepicker'
export { dropdown } from './dropdown'
export { file } from './file'
export { email } from './email'
export { color } from './color'
export { colorpicker } from './colorpicker'
Expand Down
24 changes: 24 additions & 0 deletions packages/ui/src/stories/formkit/File.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { StoryFn } from '@storybook/vue3'
import * as types from '@vuestic/formkit'

export default {
title: 'Formkit Integration/File',
}

export const Default: StoryFn = () => ({
setup () {
return {
types,
}
},
template: `
<div class="w-1/5 grid gap-6">
<FormKit
:type="types.file"
label="Documents"
accept=".pdf,.doc,.docx,.xml,.md,.csv"
help="Select as many documents as you would like."
/>
</div>
`,
})

0 comments on commit 5840311

Please sign in to comment.