-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement Textarea and Dropdown type
- Loading branch information
1 parent
d94d36b
commit 9563b12
Showing
18 changed files
with
311 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import type { FormKitTypeDefinition } from '@formkit/core' | ||
import { casts, createSection } from '@formkit/inputs' | ||
import { token } from '@formkit/utils' | ||
import { VaSelect } from 'vuestic-ui' | ||
import { createInputWrapper } from './createInputWrapper' | ||
import { vuesticInputs } from './features/vuesticInputs' | ||
|
||
const FormKitInputWrapper = createInputWrapper(VaSelect); | ||
|
||
const dropdownInput = createSection('input', () => ({ | ||
$cmp: 'FormKitInputWrapper', | ||
bind: '$attrs', | ||
props: { | ||
context: '$node.context', | ||
prefixIcon: '$prefixIcon', | ||
suffixIcon: '$suffixIcon' | ||
} | ||
})) | ||
|
||
/** | ||
* Input definition for a dropdown. | ||
* @public | ||
*/ | ||
export const dropdown: FormKitTypeDefinition = { | ||
/** | ||
* The actual schema of the input, or a function that returns the schema. | ||
*/ | ||
schema: dropdownInput(), | ||
/** | ||
* 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(), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { type FormKitTypeDefinition } from '@formkit/core' | ||
import { casts, createSection } from '@formkit/inputs' | ||
import { token } from '@formkit/utils' | ||
import { VaTextarea } from 'vuestic-ui' | ||
import { vuesticInputs } from './features/vuesticInputs' | ||
import { createInputWrapper } from './createInputWrapper' | ||
|
||
const FormKitInputWrapper = createInputWrapper(VaTextarea) | ||
|
||
const textareaInput = createSection('input', () => ({ | ||
$cmp: 'FormKitInputWrapper', | ||
bind: '$attrs', | ||
props: { | ||
context: '$node.context', | ||
prefixIcon: '$prefixIcon', | ||
suffixIcon: '$suffixIcon' | ||
} | ||
})) | ||
|
||
/** | ||
* Input definition for a textarea. | ||
* @public | ||
*/ | ||
export const textarea: FormKitTypeDefinition = { | ||
/** | ||
* The actual schema of the input, or a function that returns the schema. | ||
*/ | ||
schema: textareaInput(), | ||
/** | ||
* 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 | ||
}, | ||
/** | ||
* Forces node.props.type to be this explicit value. | ||
*/ | ||
forceTypeProp: 'text', | ||
/** | ||
* Additional features that should be added to your input | ||
*/ | ||
features: [casts, vuesticInputs], | ||
/** | ||
* The key used to memoize the schema. | ||
*/ | ||
schemaMemoKey: token(), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { StoryFn } from '@storybook/vue3' | ||
import * as types from '@vuestic/formkit' | ||
|
||
export default { | ||
title: 'Formkit Integration/Dropdown', | ||
} | ||
|
||
export const Default: StoryFn = () => ({ | ||
|
||
setup () { | ||
const frameworks = [ | ||
{ text: 'React', value: 'react' }, | ||
{ text: 'Vue', value: 'vue' }, | ||
{ text: 'Angular', value: 'angular' }, | ||
{ text: 'Svelte', value: 'svelte' }, | ||
] | ||
return { | ||
types, | ||
frameworks, | ||
} | ||
}, | ||
template: ` | ||
<FormKit | ||
:type="types.dropdown" | ||
name="framework" | ||
label="Choose your favorite frontend framework" | ||
placeholder="Backbone.js" | ||
:options="frameworks" | ||
/> | ||
`, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { StoryFn } from '@storybook/vue3' | ||
import * as types from '@vuestic/formkit' | ||
import { ref } from 'vue' | ||
import { VaCollapse } from 'vuestic-ui' | ||
|
||
export default { | ||
title: 'Formkit Integration/Form', | ||
} | ||
|
||
export const Basic: StoryFn = () => ({ | ||
components: { | ||
VaCollapse, | ||
}, | ||
setup () { | ||
// NEW: submit handler, which posts to our fake backend. | ||
const submitApp = async (_formData: any, node: any) => { | ||
await new Promise(resolve => setTimeout(resolve, 1400)) | ||
node.clearErrors() | ||
alert('Your application was submitted successfully!') | ||
} | ||
|
||
const formValue = ref({}) | ||
|
||
return { | ||
types, | ||
formValue, | ||
submitApp, | ||
} | ||
}, | ||
template: ` | ||
<h1 class="text-2xl font-bold mb-4"> | ||
Carbon Sequestration Grant | ||
</h1> | ||
<FormKit | ||
v-slot="{ state: { loading } }" | ||
v-model="formValue" | ||
:type="types.form" | ||
class="grid grid-cols-1 md:grid-cols-3 gap-6" | ||
:submit-label="loading ? 'Submitting...' : ''" | ||
@submit="submitApp" | ||
> | ||
<div> | ||
<FormKit | ||
:type="types.email" | ||
name="email" | ||
label="*Email address" | ||
validation="required|email" | ||
/> | ||
</div> | ||
<div> | ||
<FormKit | ||
:type="types.text" | ||
name="organization_name" | ||
label="*Organization name" | ||
validation="required|length:3" | ||
/> | ||
</div> | ||
<div> | ||
<FormKit | ||
:type="types.textarea" | ||
name="money_use" | ||
label="*How will you use the money?" | ||
validation="required|length:5,10" | ||
/> | ||
</div> | ||
</FormKit> | ||
<VaCollapse | ||
class="min-w-96 mt-4" | ||
header="Form data" | ||
> | ||
<pre>{{ formValue }}</pre> | ||
</VaCollapse> | ||
`, | ||
}) |
Oops, something went wrong.