docs: improve forms usage with examples

This commit is contained in:
Benjamin Canac
2023-06-12 14:34:12 +02:00
parent 429791dab0
commit bc81d45b2b
13 changed files with 172 additions and 36 deletions

View File

@@ -0,0 +1,7 @@
<script setup>
const selected = ref(false)
</script>
<template>
<UCheckbox v-model="selected" name="notifications" label="Notifications" />
</template>

View File

@@ -0,0 +1,7 @@
<script setup>
const value = ref('')
</script>
<template>
<UInput v-model="value" />
</template>

View File

@@ -0,0 +1,23 @@
<script setup>
const methods = [{
name: 'email',
value: 'email',
label: 'Email'
}, {
name: 'sms',
value: 'sms',
label: 'Phone (SMS)'
}, {
name: 'push',
value: 'push',
label: 'Push notification'
}]
const selected = ref('sms')
</script>
<template>
<div class="space-y-1">
<URadio v-for="method of methods" :key="method.name" v-model="selected" v-bind="method" />
</div>
</template>

View File

@@ -0,0 +1,9 @@
<script setup>
const countries = ['United States', 'Canada', 'Mexico']
const country = ref(countries[0])
</script>
<template>
<USelect v-model="country" :options="countries" />
</template>

View File

@@ -0,0 +1,7 @@
<script setup>
const value = ref('')
</script>
<template>
<UTextarea v-model="value" />
</template>

View File

@@ -0,0 +1,7 @@
<script setup>
const selected = ref(false)
</script>
<template>
<UToggle v-model="selected" />
</template>

View File

@@ -5,11 +5,22 @@ description: Display an input field.
## Usage
::component-card
---
baseProps:
name: 'input'
---
Use a `v-model` to make the Input reactive.
::component-example
#default
:input-example
#code
```vue
<script setup>
const value = ref('')
</script>
<template>
<UInput v-model="value" />
</template>
```
::
### Style

View File

@@ -5,11 +5,22 @@ description: Display a textarea field.
## Usage
::component-card
---
baseProps:
name: 'textarea'
---
Use a `v-model` to make the Textarea reactive.
::component-example
#default
:textarea-example
#code
```vue
<script setup>
const value = ref('')
</script>
<template>
<UTextarea v-model="value" />
</template>
```
::
### Style

View File

@@ -7,19 +7,24 @@ description: Display a select field.
The Select component is a wrapper around the native `<select>` HTML element. For more advanced use cases like searching or multiple selection, consider using the [SelectMenu](/forms/select-menu) component.
::component-card
---
baseProps:
name: 'select'
modelValue: 'United States'
props:
options:
- 'United States'
- 'Canada'
- 'Mexico'
excludedProps:
- options
---
Use a `v-model` to make the Select reactive alongside the `options` prop to pass an array of strings or objects.
::component-example
#default
:select-example
#code
```vue
<script setup>
const countries = ['United States', 'Canada', 'Mexico']
const country = ref(countries[0])
</script>
<template>
<USelect v-model="country" :options="countries" />
</template>
```
::
### Style

View File

@@ -10,8 +10,6 @@ headlessui:
The SelectMenu component renders by default a [Select](/forms/select) component and is based on the `ui.select` preset. You can use most of the Select props to configure the display if you don't want to override the default slot such as [color](/forms/select#style), [variant](/forms/select#style), [size](/forms/select#size), [placeholder](/forms/select#placeholder), [icon](/forms/select#icon), [disabled](/forms/select#disabled), etc.
### Options
Like the Select component, you can use the `options` prop to pass an array of strings or objects.
::component-example

View File

@@ -5,11 +5,22 @@ description: Display a checkbox field.
## Usage
::component-card
---
baseProps:
name: 'checkbox'
---
Use a `v-model` to make the Checkbox reactive.
::component-example
#default
:checkbox-example
#code
```vue
<script setup>
const selected = ref(false)
</script>
<template>
<UCheckbox v-model="selected" name="notifications" label="Notifications" />
</template>
```
::
### Label

View File

@@ -5,11 +5,36 @@ description: Display a radio field.
## Usage
::component-card
---
baseProps:
name: 'radio'
---
Use a `v-model` to make the Radio reactive.
::component-example
#default
:radio-example
#code
```vue
<script setup>
const methods = [{
name: 'email',
value: 'email',
label: 'Email'
}, {
name: 'sms',
value: 'sms',
label: 'Phone (SMS)'
}, {
name: 'push',
value: 'push',
label: 'Push notification'
}]
const selected = ref('sms')
</script>
<template>
<URadio v-for="method of methods" :key="method.name" v-model="selected" v-bind="method" />
</template>
```
::
### Label

View File

@@ -8,7 +8,22 @@ headlessui:
## Usage
::component-card
Use a `v-model` to make the Toggle reactive.
::component-example
#default
:toggle-example
#code
```vue
<script setup>
const selected = ref(false)
</script>
<template>
<UToggle v-model="selected" />
</template>
```
::
### Icon