diff --git a/packages/formkit/playground/src/App.vue b/packages/formkit/playground/src/App.vue index 0e958b18c1..b823378b6e 100644 --- a/packages/formkit/playground/src/App.vue +++ b/packages/formkit/playground/src/App.vue @@ -18,8 +18,18 @@ const randomColor = (e: HTMLElementEvent) => { diff --git a/packages/formkit/src/color.ts b/packages/formkit/src/color.ts new file mode 100644 index 0000000000..84dce1d3a1 --- /dev/null +++ b/packages/formkit/src/color.ts @@ -0,0 +1,79 @@ +import { type FormKitTypeDefinition } from '@formkit/core' +import { + outer, + inner, + wrapper, + label, + prefix, + suffix, + casts, + createSection +} from '@formkit/inputs' +import { icon, messages, message, help } from './sections' + + +const colorInput = createSection('input', () => ({ + $cmp: 'VaColorInput', + bind: '$attrs', + props: { + type: '$type', + disabled: '$disabled', + name: '$node.name', + onChange: '$handlers.DOMInput', + [`onUpdate:modelValue`]: '$handlers.DOMInput', + onBlur: '$handlers.blur', + modelValue: '$_value', + id: '$id', + 'aria-describedby': '$describedBy', + 'aria-required': '$state.required || undefined', + }, +})) + +/** + * Input definition for a text. + * @public + */ +export const color: FormKitTypeDefinition = { + /** + * The actual schema of the input, or a function that returns the schema. + */ + schema: outer( + wrapper( + label('$label'), + inner( + icon('prefix', 'label'), + prefix(), + colorInput(), + suffix(), + icon('suffix') + ) + ), + help('$help'), + messages(message('$message.value')) + ), + /** + * 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: [], + /** + * Forces node.props.type to be this explicit value. + */ + forceTypeProp: 'text', + /** + * Additional features that should be added to your input + */ + features: [casts], + /** + * The key used to memoize the schema. + */ + schemaMemoKey: `${Math.random()}`, +} diff --git a/packages/formkit/src/inputTypes.ts b/packages/formkit/src/inputTypes.ts index fb372ddf76..53bf3bd717 100644 --- a/packages/formkit/src/inputTypes.ts +++ b/packages/formkit/src/inputTypes.ts @@ -1,9 +1,10 @@ -import { VaInput, VaCheckbox, VaSelect, VaTextarea, VaCounter, VaTimeInput, VaColorInput, VaDateInput, VaFileUpload, VaRadio, VaSlider, VaRating, VaSwitch } from 'vuestic-ui'; +import { VaInput, VaCheckbox, VaSelect, VaTextarea, VaCounter, VaTimeInput, VaDateInput, VaFileUpload, VaRadio, VaSlider, VaRating, VaSwitch } from 'vuestic-ui'; import { createInputWrapper } from './createInputWrapper'; +export { color } from './color' export const autocomplete = createInputWrapper(VaSelect, { autocomplete: true }); export const checkbox = createInputWrapper(VaCheckbox); -export const color = createInputWrapper(VaColorInput) +// export const color = createInputWrapper(VaColorInput) export const date = createInputWrapper(VaDateInput); export const email = createInputWrapper(VaInput, { type: 'email' }); export const file = createInputWrapper(VaFileUpload);