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 ## Usage
::component-card Use a `v-model` to make the Input reactive.
---
baseProps: ::component-example
name: 'input' #default
--- :input-example
#code
```vue
<script setup>
const value = ref('')
</script>
<template>
<UInput v-model="value" />
</template>
```
:: ::
### Style ### Style

View File

@@ -5,11 +5,22 @@ description: Display a textarea field.
## Usage ## Usage
::component-card Use a `v-model` to make the Textarea reactive.
---
baseProps: ::component-example
name: 'textarea' #default
--- :textarea-example
#code
```vue
<script setup>
const value = ref('')
</script>
<template>
<UTextarea v-model="value" />
</template>
```
:: ::
### Style ### 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. 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 Use a `v-model` to make the Select reactive alongside the `options` prop to pass an array of strings or objects.
---
baseProps: ::component-example
name: 'select' #default
modelValue: 'United States' :select-example
props:
options: #code
- 'United States' ```vue
- 'Canada' <script setup>
- 'Mexico' const countries = ['United States', 'Canada', 'Mexico']
excludedProps:
- options const country = ref(countries[0])
--- </script>
<template>
<USelect v-model="country" :options="countries" />
</template>
```
:: ::
### Style ### 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. 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. Like the Select component, you can use the `options` prop to pass an array of strings or objects.
::component-example ::component-example

View File

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

View File

@@ -5,11 +5,36 @@ description: Display a radio field.
## Usage ## Usage
::component-card Use a `v-model` to make the Radio reactive.
---
baseProps: ::component-example
name: 'radio' #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 ### Label

View File

@@ -8,7 +8,22 @@ headlessui:
## Usage ## 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 ### Icon