Skip to content

Commit ecb8a12

Browse files
authored
Merge pull request #42 from kevinkosterr/master
Pending release
2 parents 024823b + b9e57c3 commit ecb8a12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1350
-275
lines changed

apps/docs/.vitepress/config.mts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineConfig } from 'vitepress'
22
import { groupIconMdPlugin, groupIconVitePlugin } from 'vitepress-plugin-group-icons'
3+
import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'
34
import path from 'path'
45

56
// https://vitepress.dev/reference/site-config
@@ -11,6 +12,7 @@ export default defineConfig({
1112
markdown: {
1213
config(md) {
1314
md.use(groupIconMdPlugin)
15+
md.use(tabsMarkdownPlugin)
1416
}
1517
},
1618
themeConfig: {
@@ -34,14 +36,22 @@ export default defineConfig({
3436
{ text: 'Custom validators', link: '/guide/customization/custom-validators' }
3537
]
3638
},
39+
{
40+
text: 'Components',
41+
items: [
42+
{ text: 'FormLabel', link: '/guide/components/FormLabel' },
43+
]
44+
},
3745
{
3846
text: 'Composables',
3947
items: [
4048
{ text: 'useFieldAttributes', link: '/guide/composables/useFieldAttributes' },
4149
{ text: 'useFieldEmits', link: '/guide/composables/useFieldEmits' },
4250
{ text: 'useFieldProps', link: '/guide/composables/useFieldProps' },
4351
{ text: 'useFieldValidate', link: '/guide/composables/useFieldValidate' },
44-
{ text: 'useFormModel', link: '/guide/composables/useFormModel' }
52+
{ text: 'useFormModel', link: '/guide/composables/useFormModel' },
53+
{ text: 'useLabelIcon', link: '/guide/composables/useLabelIcon' },
54+
{ text: 'useValidation', link: '/guide/composables/useValidation' }
4555
]
4656
},
4757
{

apps/docs/.vitepress/theme/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import DefaultTheme from 'vitepress/theme'
22
import VueFormGenerator from '@/index'
33

4+
import { enhanceAppWithTabs } from 'vitepress-plugin-tabs/client'
5+
46
import './index.css'
57
import '@/scss/themes/basic.scss'
68
import 'virtual:group-icons.css'
79

810
export default {
911
extends: DefaultTheme,
1012
enhanceApp({ app }) {
13+
enhanceAppWithTabs(app)
1114
app.use(VueFormGenerator, {
1215
messages: {
1316
productCodeValidator: 'Your product code is invalid'
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
outline: [2,3]
3+
---
4+
# FormLabel <Badge type="tip" text=">=2.7.0"/>
5+
> A label component that automatically handles the labelIcon property and position.
6+
7+
## Usage
8+
:::code-group
9+
```vue [template]
10+
<template>
11+
<FormLabel
12+
:label-icon="labelIcon"
13+
:label-icon-position="labelIconPosition"
14+
:label="field.label"
15+
:field-id="props.id"
16+
/>
17+
</template>
18+
```
19+
```vue [script setup]
20+
<script setup>
21+
import { toRefs } from 'vue'
22+
import { FormLabel, useLabelIcon, useFieldProps } from '@kevinkosterr/vue3-form-generator'
23+
24+
const props = defineProps(useFieldProps())
25+
26+
const { field, model } = toRefs(props)
27+
const { labelIcon, labelIconPosition } = useLabelIcon(field.value.labelIcon)
28+
</script>
29+
```
30+
:::
31+
32+
## Props
33+
### `labelIcon` <Badge type="info" text="string | ComponentPublicInstance | null" />
34+
Either a string webfont class, a component or `LabelIconDefinition`.
35+
36+
### `labelIconPosition` <Badge type="info" text="'left' | 'right' | null" />
37+
Either `'left'`, `'right'` or `null`
38+
39+
### `label` <Badge type="info" text="string" />
40+
Label as set by the field schema.
41+
42+
### `fieldId` <Badge type="info" text="string" />
43+
Computed field id, taken from props.

apps/docs/guide/composables/useFieldEmits.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ const emits = defineEmits(useFieldEmits())
1313
</script>
1414
```
1515

16+
## TypeScript alternative
17+
```vue
18+
<script setup lang="ts">
19+
import type { FieldEmits } from '@kevinkosterr/vue3-form-generator'
20+
21+
const emits = defineEmits<FieldEmits>()
22+
</script>
23+
```
24+
1625
## Emits
1726

1827
### `onInput`

apps/docs/guide/composables/useFieldProps.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ const { field, model } = toRefs(props)
1616
</script>
1717
```
1818

19+
## TypeScript alternative
20+
```vue
21+
<script setup lang="ts">
22+
import { toRefs } from 'vue'
23+
import type { FieldProps, FieldBase, FieldPropRefs } from '@kevinkosterr/vue3-form-generator'
24+
25+
type CustomField = FieldBase & {}
26+
27+
const props = defineProps<FieldProps<CustomField>>()
28+
29+
const { field, model }: FieldPropRefs<CustomField> = toRefs(props)
30+
</script>
31+
```
32+
1933
## Props
2034

2135
### `id` <Badge type="info" text="String"/>

apps/docs/guide/composables/useFieldValidate.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
---
22
outline: [2,3]
33
---
4-
# useFieldValidate <Badge type="tip" text="2.0.0+"/>
5-
> Used to validate a field against validators defined in a fields schema
4+
# useFieldValidate <Badge type="tip" text="2.0.0+"/> <Badge type="warning" text="deprecated"/>
5+
> Used to validate a field against validators defined in a field's schema
6+
::: warning
7+
This composable is deprecated, please use [`useValidation`](/guide/composables/useValidation) instead
8+
:::
69

710
## Usage
811
```vue
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
outline: [2,3]
3+
---
4+
# useLabelIcon <Badge type="tip" text=">=2.7.0" />
5+
> Determines which icon to display and the position to display it in
6+
7+
## Usage
8+
```vue
9+
<script setup>
10+
import { useLabelIcon } from '@kevinkosterr/vue3-form-generator'
11+
12+
const { labelIcon, labelIconPosition } = useLabelIcon(props.field.labelIcon)
13+
</script>
14+
```
15+
16+
## Arguments
17+
### `iconDefinition` <Badge type="info" text="string | ComponentPublicInstance | LabelIconDefinition" />
18+
::: details LabelIconDefinition type
19+
```ts
20+
type LabelIconDefinition = {
21+
icon: string | ComponentPublicInstance;
22+
position: 'left' | 'right';
23+
}
24+
```
25+
:::
26+
Either a string webfont class, a component or `LabelIconDefinition`.
27+
28+
## Returns
29+
30+
### `labelIcon` <Badge type="info" text="ComputedRef<string | ComponentPublicInstance | null>" />
31+
Either the icon class or icon component as determined by the `labelIcon` property of a field schema.
32+
33+
### `labelIconPosition` <Badge type="info" text="ComputedRef<'left' | 'right' | null>" />
34+
Position of the label, defaults to `left`.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
outline: [2,3]
3+
---
4+
# useValidation <Badge type="tip" text=">=2.7.0"/>
5+
> Used to validate a field against validators defined in a field's schema
6+
7+
## Usage
8+
::: code-group
9+
```Vue [Vue]
10+
<script setup>
11+
import { toRefs } from 'vue'
12+
import {
13+
useValidation,
14+
useFieldProps,
15+
useFormModel,
16+
useFieldEmits,
17+
useFieldAttributes
18+
} from '@kevinkosterr/vue3-form-generator'
19+
20+
const props = defineProps(useFieldProps())
21+
const emits = defineEmits(useFieldEmits())
22+
23+
const { field, model } = toRefs(props)
24+
const { isRequired, isDisabled, isReadonly } = useFieldAttributes(model.value, field.value)
25+
const { currentModelValue } = useFormModel(model.value, field.value)
26+
27+
const { validate, errors, onChanged, onBlur } = useValidation(
28+
model.value,
29+
field.value,
30+
currentModelValue,
31+
props.formOptions,
32+
emits,
33+
isDisabled.value,
34+
isRequired.value,
35+
isReadonly.value
36+
)
37+
</script>
38+
```
39+
```Vue [Vue TS]
40+
<script setup lang="ts">
41+
import { toRefs } from 'vue'
42+
import {
43+
type FieldEmits,
44+
type FieldProps,
45+
type FieldBase,
46+
type FieldPropRefs,
47+
useValidation,
48+
useFieldAttributes,
49+
useFormModel
50+
} from '@kevinkosterr/vue3-form-generator'
51+
52+
type CustomField = FieldBase & {
53+
customAttr: string
54+
}
55+
56+
const props = defineProps<FieldProps<CustomField>>()
57+
const emits = defineEmits<FieldEmits>()
58+
59+
const { field, model }: FieldPropRefs<CustomField> = toRefs(props)
60+
const { isRequired, isDisabled, isReadonly } = useFieldAttributes(model.value, field.value)
61+
const { currentModelValue } = useFormModel(model.value, field.value)
62+
63+
const { validate, errors, onChanged, onBlur } = useValidation(
64+
model.value,
65+
field.value,
66+
currentModelValue,
67+
props.formOptions,
68+
emits,
69+
isDisabled.value,
70+
isRequired.value,
71+
isReadonly.value
72+
)
73+
</script>
74+
```
75+
:::
76+
77+
## Arguments
78+
79+
### `model` <Badge type="info" text="Object"/>
80+
Model object, as returned by the props
81+
82+
### `field` <Badge type="info" text="Object"/>
83+
Field schema object, as returned by the props
84+
85+
### `currentModelValue` <Badge type="info" text="Ref<any>"/>
86+
`Ref` of the current value from the field. Returned by [`useFormModel`](/guide/composables/useFormModel).
87+
88+
### `formOptions` <Badge type="info" text="Object"/>
89+
Form options object, as returned by the props.
90+
91+
### `emits` <Badge type="info" text="EmitFn<FieldEmits>"/>
92+
Emit function as returned by `defineEmits()`
93+
94+
### `isDisabled` <Badge type="info" text="Boolean"/>
95+
Whether the field is disabled, can be obtained from [`useFieldAttributes()`](/guide/composables/useFieldAttributes)
96+
97+
### `isRequired` <Badge type="info" text="Boolean"/>
98+
Whether the field is required, can be obtained from [`useFieldAttributes()`](/guide/composables/useFieldAttributes)
99+
100+
### `isReadonly` <Badge type="info" text="Boolean"/>
101+
Whether the field is readonly, can be obtained from [`useFieldAttributes()`](/guide/composables/useFieldAttributes)
102+
103+
## Returns
104+
105+
### `errors` <Badge type="info" text="string[]"/>
106+
An array of errors for the current field. Will be auto-updated on every validation cycle. Must be cleared
107+
manually when the value of a field has changed.
108+
109+
### `validate` <Badge type="info" text="Function"/>
110+
A validation function, meant to be called when a validation has to take place. Used when a field is always validated
111+
at the same moment and isn't affected by validation triggers, such as `'onChanged'` or `'onBlur'`.
112+
113+
### `onChanged` <Badge type="info" text="Function"/>
114+
A wrapped validation function, only validates when `'onChanged'` validation is enabled. Should always be called if the value is changed, unless the field is unaffected by
115+
validation triggers.
116+
117+
### `onBlur` <Badge type="info" text="Function"/>
118+
A wrapped validation function, only validates when `'onBlur'` validation is enabled (which is the default behavior). Should always be called if the value is changed, unless the field is unaffected by
119+
validation triggers.

0 commit comments

Comments
 (0)