From d7edefac05592754acd8d540a7e52be754258138 Mon Sep 17 00:00:00 2001 From: raichev-dima Date: Tue, 17 Dec 2024 16:37:40 +0300 Subject: [PATCH] feat: implement File type --- packages/formkit/src/file.ts | 61 +++++++++++++++++++ packages/formkit/src/index.ts | 1 + .../ui/src/stories/formkit/File.stories.ts | 24 ++++++++ 3 files changed, 86 insertions(+) create mode 100644 packages/formkit/src/file.ts create mode 100644 packages/ui/src/stories/formkit/File.stories.ts diff --git a/packages/formkit/src/file.ts b/packages/formkit/src/file.ts new file mode 100644 index 0000000000..78aefa7c08 --- /dev/null +++ b/packages/formkit/src/file.ts @@ -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(), +} diff --git a/packages/formkit/src/index.ts b/packages/formkit/src/index.ts index 43fd483b0e..cb7a62a9ed 100644 --- a/packages/formkit/src/index.ts +++ b/packages/formkit/src/index.ts @@ -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' diff --git a/packages/ui/src/stories/formkit/File.stories.ts b/packages/ui/src/stories/formkit/File.stories.ts new file mode 100644 index 0000000000..797d7592c0 --- /dev/null +++ b/packages/ui/src/stories/formkit/File.stories.ts @@ -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: ` +
+ +
+ `, +})