Skip to content

Commit

Permalink
Merge branch 'dev' into docs/ui-pro
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Oct 10, 2023
2 parents 64953ff + 94cabca commit a54a5ce
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 77 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
ci:
Expand Down
10 changes: 3 additions & 7 deletions docs/components/content/examples/FormExampleBasic.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { FormError, FormSubmitEvent } from '@nuxt/ui/dist/runtime/types'
import type { FormError, FormSubmitEvent } from '#ui/types'
const state = reactive({
email: undefined,
Expand All @@ -13,18 +13,14 @@ const validate = (state: any): FormError[] => {
return errors
}
async function submit (event: FormSubmitEvent<any>) {
async function onSubmit (event: FormSubmitEvent<any>) {
// Do something with data
console.log(event.data)
}
</script>

<template>
<UForm
:validate="validate"
:state="state"
@submit="submit"
>
<UForm :validate="validate" :state="state" @submit="onSubmit">
<UFormGroup label="Email" name="email">
<UInput v-model="state.email" />
</UFormGroup>
Expand Down
11 changes: 3 additions & 8 deletions docs/components/content/examples/FormExampleElements.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { z } from 'zod'
import type { FormSubmitEvent } from '@nuxt/ui/dist/runtime/types'
import type { FormSubmitEvent } from '#ui/types'
const options = [
{ label: 'Option 1', value: 'option-1' },
Expand Down Expand Up @@ -45,19 +45,14 @@ type Schema = z.infer<typeof schema>
const form = ref()
async function submit (event: FormSubmitEvent<Schema>) {
async function onSubmit (event: FormSubmitEvent<Schema>) {
// Do something with event.data
console.log(event.data)
}
</script>

<template>
<UForm
ref="form"
:schema="schema"
:state="state"
@submit="submit"
>
<UForm ref="form" :schema="schema" :state="state" @submit="onSubmit">
<UFormGroup name="input" label="Input">
<UInput v-model="state.input" />
</UFormGroup>
Expand Down
10 changes: 3 additions & 7 deletions docs/components/content/examples/FormExampleJoi.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import Joi from 'joi'
import type { FormSubmitEvent } from '@nuxt/ui/dist/runtime/types'
import type { FormSubmitEvent } from '#ui/types'
const schema = Joi.object({
email: Joi.string().required(),
Expand All @@ -14,18 +14,14 @@ const state = reactive({
password: undefined
})
async function submit (event: FormSubmitEvent<any>) {
async function onSubmit (event: FormSubmitEvent<any>) {
// Do something with event.data
console.log(event.data)
}
</script>

<template>
<UForm
:schema="schema"
:state="state"
@submit="submit"
>
<UForm :schema="schema" :state="state" @submit="onSubmit">
<UFormGroup label="Email" name="email">
<UInput v-model="state.email" />
</UFormGroup>
Expand Down
42 changes: 42 additions & 0 deletions docs/components/content/examples/FormExampleOnError.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script setup lang="ts">
import type { FormError, FormErrorEvent, FormSubmitEvent } from '#ui/types'
const state = reactive({
email: undefined,
password: undefined
})
const validate = (state: any): FormError[] => {
const errors = []
if (!state.email) errors.push({ path: 'email', message: 'Required' })
if (!state.password) errors.push({ path: 'password', message: 'Required' })
return errors
}
async function onSubmit (event: FormSubmitEvent<any>) {
// Do something with data
console.log(event.data)
}
async function onError (event: FormErrorEvent) {
const element = document.getElementById(event.errors[0].id)
element?.focus()
element?.scrollIntoView({ behavior: 'smooth', block: 'center' })
}
</script>

<template>
<UForm :validate="validate" :state="state" @submit="onSubmit" @error="onError">
<UFormGroup label="Email" name="email">
<UInput v-model="state.email" />
</UFormGroup>

<UFormGroup label="Password" name="password">
<UInput v-model="state.password" type="password" />
</UFormGroup>

<UButton type="submit">
Submit
</UButton>
</UForm>
</template>
10 changes: 3 additions & 7 deletions docs/components/content/examples/FormExampleValibot.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { string, objectAsync, email, minLength, Input } from 'valibot'
import type { FormSubmitEvent } from '@nuxt/ui/dist/runtime/types'
import type { FormSubmitEvent } from '#ui/types'
const schema = objectAsync({
email: string([email('Invalid email')]),
Expand All @@ -14,18 +14,14 @@ const state = reactive({
password: undefined
})
async function submit (event: FormSubmitEvent<Schema>) {
async function onSubmit (event: FormSubmitEvent<Schema>) {
// Do something with event.data
console.log(event.data)
}
</script>

<template>
<UForm
:schema="schema"
:state="state"
@submit="submit"
>
<UForm :schema="schema" :state="state" @submit="onSubmit">
<UFormGroup label="Email" name="email">
<UInput v-model="state.email" />
</UFormGroup>
Expand Down
10 changes: 3 additions & 7 deletions docs/components/content/examples/FormExampleYup.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { object, string, InferType } from 'yup'
import type { FormSubmitEvent } from '@nuxt/ui/dist/runtime/types'
import type { FormSubmitEvent } from '#ui/types'
const schema = object({
email: string().email('Invalid email').required('Required'),
Expand All @@ -16,18 +16,14 @@ const state = reactive({
password: undefined
})
async function submit (event: FormSubmitEvent<Schema>) {
async function onSubmit (event: FormSubmitEvent<Schema>) {
// Do something with event.data
console.log(event.data)
}
</script>

<template>
<UForm
:schema="schema"
:state="state"
@submit="submit"
>
<UForm :schema="schema" :state="state" @submit="onSubmit">
<UFormGroup label="Email" name="email">
<UInput v-model="state.email" />
</UFormGroup>
Expand Down
10 changes: 3 additions & 7 deletions docs/components/content/examples/FormExampleZod.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { z } from 'zod'
import type { FormSubmitEvent } from '@nuxt/ui/dist/runtime/types'
import type { FormSubmitEvent } from '#ui/types'
const schema = z.object({
email: z.string().email('Invalid email'),
Expand All @@ -14,18 +14,14 @@ const state = reactive({
password: undefined
})
async function submit (event: FormSubmitEvent<Schema>) {
async function onSubmit (event: FormSubmitEvent<Schema>) {
// Do something with data
console.log(event.data)
}
</script>

<template>
<UForm
:schema="schema"
:state="state"
@submit="submit"
>
<UForm :schema="schema" :state="state" @submit="onSubmit">
<UFormGroup label="Email" name="email">
<UInput v-model="state.email" />
</UFormGroup>
Expand Down
9 changes: 5 additions & 4 deletions docs/content/1.getting-started/5.examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Here is an example of a Table component with all its features implemented.

:component-example{component="table-example-advanced" hiddenCode :padding="false" }

::callout{icon="i-simple-icons-github" to="https://github.com/nuxt/ui/blob/dev/docs/components/content/examples/TableExampleAdvanced.vue"}
::callout{icon="i-simple-icons-github" to="https://github.com/nuxt/ui/blob/dev/docs/components/content/examples/TableExampleAdvanced.vue" target="_blank"}
Take a look at the component!
::

Expand All @@ -130,6 +130,7 @@ Our theming system provides a lot of flexibility to customize the components.
Here is some examples of what you can do with the [CommandPalette](/navigation/command-palette).

#### Algolia

::component-example
---
padding: false
Expand All @@ -140,7 +141,7 @@ hiddenCode: true
---
::

::callout{icon="i-simple-icons-github" to="https://github.com/nuxt/ui/blob/dev/docs/components/content/examples/CommandPaletteExampleThemeAlgolia.vue#L23"}
::callout{icon="i-simple-icons-github" to="https://github.com/nuxt/ui/blob/dev/docs/components/content/examples/CommandPaletteExampleThemeAlgolia.vue#L23" target="_blank"}
Take a look at the component!
::

Expand All @@ -156,7 +157,7 @@ hiddenCode: true
---
::

::callout{icon="i-simple-icons-github" to="https://github.com/nuxt/ui/blob/dev/docs/components/content/examples/CommandPaletteExampleThemeRaycast.vue#L30"}
::callout{icon="i-simple-icons-github" to="https://github.com/nuxt/ui/blob/dev/docs/components/content/examples/CommandPaletteExampleThemeRaycast.vue#L30" target="_blank"}
Take a look at the component!
::

Expand All @@ -176,6 +177,6 @@ Here are some examples of how components look like in RTL mode.

:component-example{component="pagination-example-r-t-l" hiddenCode}

::callout{icon="i-simple-icons-github" to="https://github.com/nuxt/ui/blob/dev/docs/components/content/examples/PaginationExampleRTL.vue"}
::callout{icon="i-simple-icons-github" to="https://github.com/nuxt/ui/blob/dev/docs/components/content/examples/PaginationExampleRTL.vue" target="_blank"}
Take a look at the component!
::
21 changes: 16 additions & 5 deletions docs/content/3.forms/10.form.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ You can provide a schema from [Yup](#yup), [Zod](#zod) or [Joi](#joi), [Valibot]

:component-example{component="form-example-joi" :componentProps='{"class": "space-y-4 w-60"}'}


### Valibot

:component-example{component="form-example-valibot" :componentProps='{"class": "space-y-4 w-60"}'}
Expand Down Expand Up @@ -87,7 +86,7 @@ You can manually set errors after form submission if required. To do this, simpl

```vue
<script setup lang="ts">
import type { FormError, FormSubmitEvent } from '@nuxt/ui/dist/runtime/types'
import type { FormError, FormSubmitEvent } from '#ui/types'
const state = reactive({
email: undefined,
Expand All @@ -96,7 +95,7 @@ const state = reactive({
const form = ref()
async function submit (event: FormSubmitEvent<any>) {
async function onSubmit (event: FormSubmitEvent<any>) {
form.value.clear()
try {
const response = await $fetch('...')
Expand All @@ -112,7 +111,7 @@ async function submit (event: FormSubmitEvent<any>) {
</script>
<template>
<UForm ref="form" :state="state" @submit="submit">
<UForm ref="form" :state="state" @submit="onSubmit">
<UFormGroup label="Email" name="email">
<UInput v-model="state.email" />
</UFormGroup>
Expand All @@ -134,10 +133,22 @@ The Form component automatically triggers validation upon `submit`, `input`, `bl

:component-example{component="form-example-elements" :componentProps='{"class": "space-y-4 w-60"}' hiddenCode }

::callout{icon="i-simple-icons-github" to="https://github.com/nuxt/ui/blob/dev/docs/components/content/examples/FormExampleElements.vue"}
::callout{icon="i-simple-icons-github" to="https://github.com/nuxt/ui/blob/dev/docs/components/content/examples/FormExampleElements.vue" target="_blank"}
Take a look at the component!
::

## Error event :u-badge{label="New" class="align-middle ml-2 !rounded-full" variant="subtle"}

You can listen to the `@error` event to handle errors. This event is triggered when the form is validated and contains an array of `FormError` objects with the following fields:

- `id` - the identifier of the form element.
- `path` - the path to the form element matching the `name`.
- `message` - the error message to display.

Here is an example of how to focus the first form element with an error:

:component-example{component="form-example-on-error" :componentProps='{"class": "space-y-4 w-60"}'}

## Props

:component-props
Expand Down
Loading

0 comments on commit a54a5ce

Please sign in to comment.