Skip to content

Commit

Permalink
feat(FormKit): work on Text component
Browse files Browse the repository at this point in the history
  • Loading branch information
raichev-dima committed Dec 5, 2024
1 parent fec6bf9 commit d24ac8e
Show file tree
Hide file tree
Showing 9 changed files with 952 additions and 82 deletions.
1 change: 1 addition & 0 deletions packages/formkit/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@formkit/vue": "^1.6.7",
"unocss": "^0.65.1",
"vue": "^3.5.12",
"vuestic-ui": "*"
},
Expand Down
45 changes: 24 additions & 21 deletions packages/formkit/playground/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,32 @@ const randomColor = (e: HTMLElementEvent) => {
</script>

<template>
<div class="d-flex flex-direction-column pa-4" style="gap: 1.5rem">
<FormKit
:type="types.button"
color="danger"
label="Checkout my label"
help="You can use the label prop."
/>
<div class="p-5">
<h2 class="my-2">Button</h2>
<div class="flex flex-direction-column gap-row-6">
<FormKit
:type="types.button"
color="danger"
label="Checkout my label"
help="You can use the label prop."
/>

<FormKit
:type="types.button"
help="You can use the default slot."
prefix-icon="check"
>
I have slot content
</FormKit>
<FormKit
:type="types.button"
help="You can use the default slot."
prefix-icon="check"
>
I have slot content
</FormKit>

<FormKit
:type="types.button"
help="You can bind event listeners."
@click="randomColor"
>
Click me!
</FormKit>
<FormKit
:type="types.button"
help="You can bind event listeners."
@click="randomColor"
>
Click me!
</FormKit>
</div>
</div>
</template>

1 change: 1 addition & 0 deletions packages/formkit/playground/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { plugin, defaultConfig } from '@formkit/vue'
// @ts-ignore
import 'vuestic-ui/css'
import { createVuestic } from 'vuestic-ui'
import 'virtual:uno.css'

// @ts-ignore
createApp(App).use(plugin, defaultConfig).use(createVuestic()).mount('#app')
3 changes: 2 additions & 1 deletion packages/formkit/playground/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import UnoCSS from 'unocss/vite'

// https://vite.dev/config/
export default defineConfig({
plugins: [vue()],
plugins: [UnoCSS(), vue()],
})
811 changes: 807 additions & 4 deletions packages/formkit/playground/yarn.lock

Large diffs are not rendered by default.

33 changes: 1 addition & 32 deletions packages/formkit/src/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,7 @@ import {
ignores,
} from '@formkit/inputs'
import { VaButton, VaMessageList, VaIcon } from 'vuestic-ui'
import { icon } from './icon'


export const help = createSection('help', () => ({
$cmp: 'VaMessageList',
if: '$help',
props: {
id: '$: "help-" + $id',
modelValue: '$help'
}
}))


export const message = createSection('message', () => ({
$el: 'li',
for: ['message', '$messages'],
attrs: {
key: '$message.key',
id: `$id + '-' + $message.key`,
'data-message-type': '$message.type',
},
}))

export const messages = createSection('messages', () => ({
$cmp: 'VaMessageList',
if: '$defaultMessagePlacement && $fns.length($messages)',
props: {
key: '$message.key',
id: `$id + '-' + $message.key`,
'data-message-type': '$message.type',
},
}))
import { icon, message, messages, help } from './sections'

export const buttonInput = createSection('input', () => ({
$cmp: 'VaButton',
Expand Down
24 changes: 0 additions & 24 deletions packages/formkit/src/icon.ts

This file was deleted.

55 changes: 55 additions & 0 deletions packages/formkit/src/sections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { createSection, type FormKitSchemaExtendableSection } from "@formkit/inputs";


export const icon = (
sectionKey: string,
el?: string
): FormKitSchemaExtendableSection => {
return createSection(`${sectionKey}Icon`, () => {
return {
if: `$${sectionKey}Icon`,
$cmp: 'VaIcon',
props: {
tag: el,
for: {
if: `${el === 'label'}`,
then: '$id',
},
class: 'material-icons',
onClick: `$handlers.iconClick(${sectionKey})`,
role: `$fns.iconRole(${sectionKey})`,
tabindex: `$fns.iconRole(${sectionKey}) === "button" && "0" || undefined`,
},
children: '$prefixIcon'
}
})()
}

export const help = createSection('help', () => ({
$cmp: 'VaMessageList',
if: '$help',
props: {
id: '$: "help-" + $id',
modelValue: '$help'
}
}))

export const message = createSection('message', () => ({
$el: 'li',
for: ['message', '$messages'],
attrs: {
key: '$message.key',
id: `$id + '-' + $message.key`,
'data-message-type': '$message.type',
},
}))

export const messages = createSection('messages', () => ({
$cmp: 'VaMessageList',
if: '$defaultMessagePlacement && $fns.length($messages)',
props: {
key: '$message.key',
id: `$id + '-' + $message.key`,
'data-message-type': '$message.type',
},
}))
61 changes: 61 additions & 0 deletions packages/formkit/src/text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { type FormKitTypeDefinition } from '@formkit/core'
import {
outer,
inner,
wrapper,
label,
prefix,
suffix,
textInput,
casts,
} from '@formkit/inputs'
import { icon, messages, message, help } from './sections'

/**
* Input definition for a text.
* @public
*/
export const text: FormKitTypeDefinition = {
/**
* The actual schema of the input, or a function that returns the schema.
*/
schema: outer(
wrapper(
label('$label'),
inner(
icon('prefix', 'label'),
prefix(),
textInput(),
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()}`,
}

0 comments on commit d24ac8e

Please sign in to comment.