Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FormGroup): add slots #714

Merged
merged 21 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b1455db
fix(Range): add default size
Sep 17, 2023
d0afcd9
fix(Range): fix default size
Sep 19, 2023
c3c87d7
fix(Range): set default size
Sep 21, 2023
62cd82b
feat(formGroup): add slots
Sep 21, 2023
36ed0d8
fix(formGroup): revert range
Sep 21, 2023
b2b5b1f
fix(formGroup): pull dev
Sep 21, 2023
8febc84
Update docs/content/3.forms/9.form-group.md
Levy-from-Odessa Sep 22, 2023
29d286a
Update src/runtime/components/forms/FormGroup.vue
Levy-from-Odessa Sep 24, 2023
f7406db
Update docs/content/3.forms/9.form-group.md
Levy-from-Odessa Sep 24, 2023
9adfbdf
Update docs/components/content/examples/FormGroupErrorSlotExample.vue
Levy-from-Odessa Sep 24, 2023
1a3e8af
Update docs/content/3.forms/9.form-group.md
Levy-from-Odessa Sep 24, 2023
07ba274
Update docs/content/3.forms/9.form-group.md
Levy-from-Odessa Sep 24, 2023
32b96c6
Update docs/content/3.forms/9.form-group.md
Levy-from-Odessa Sep 24, 2023
542584f
Update docs/content/3.forms/9.form-group.md
Levy-from-Odessa Sep 24, 2023
a8a8baa
Update docs/content/3.forms/9.form-group.md
Levy-from-Odessa Sep 24, 2023
0a51943
Update src/runtime/components/forms/FormGroup.vue
Levy-from-Odessa Sep 26, 2023
82797a6
Update src/runtime/components/forms/FormGroup.vue
benjamincanac Sep 27, 2023
8d9250c
Update docs/content/3.forms/9.form-group.md
benjamincanac Sep 28, 2023
53dd255
Merge branch 'dev' into feat-566-form-group
benjamincanac Sep 28, 2023
5e21770
Merge branch 'dev' into feat-566-form-group
benjamincanac Sep 28, 2023
a7adcd9
up
benjamincanac Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/components/content/examples/FormGroupErrorSlotExample.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<UFormGroup label="Email" :error="!email && 'You must enter an email'" help="This is a nice email!">
<template #default="{ error }">
<UInput v-model="email" type="email" placeholder="Enter email" :trailing-icon="error ? 'i-heroicons-exclamation-triangle-20-solid' : undefined" />
</template>
<template #error="{ error }">
<UAlert icon="i-heroicons-exclamation-triangle-20-solid" :description="error" color="red" />
</template>
</UFormGroup>
</template>

<script setup lang="ts">
const email = ref('')
</script>
110 changes: 110 additions & 0 deletions docs/content/3.forms/9.form-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,116 @@ code: >-
Learn more about form validation in the `Form` component.
::


## Slots

Levy-from-Odessa marked this conversation as resolved.
Show resolved Hide resolved
### `label`
Use the `#label` slot to set the custom content for label.

::component-card
---
slots:
label: <UAvatar src="https://avatars.githubusercontent.com/u/739984?v=4" size="3xs" /> username
default: <UInput model-value="benjamincanac" placeholder="you@example.com" />
---

#label
:u-avatar{src="https://avatars.githubusercontent.com/u/739984?v=4" size="3xs" class="mr-2" }
username

#default
:u-input{model-value="benjamincanac" placeholder="you@example.com"}
::


Levy-from-Odessa marked this conversation as resolved.
Show resolved Hide resolved
### `hint`
Use the `#hint` slot to set the custom content for hint.

::component-card
---
slots:
hint: <UIcon name="i-heroicons-arrow-right-20-solid" />
default: <UInput model-value="benjamincanac" placeholder="you@example.com" />
props:
label: 'Step 1'
---

#hint
:u-icon{name="i-heroicons-arrow-right-20-solid"}

#default
:u-input{model-value="benjamincanac" placeholder="you@example.com"}
::


Use the `#description` slot to set the custom content for description.

::component-card
---
slots:
description: Write only valid email address <UIcon name="i-heroicons-arrow-right-20-solid" />
default: <UInput model-value="benjamincanac" placeholder="you@example.com" />
props:
label: 'E-mail'
---

#description
Write only valid email address
:u-icon{name="i-heroicons-information-circle"}

#default
:u-input{model-value="benjamincanac" placeholder="you@example.com"}
::


Levy-from-Odessa marked this conversation as resolved.
Show resolved Hide resolved
### `help`
Use the `#help` slot to set the custom content for help.

::component-card
---
slots:
help: Here are some examples <UIcon name="i-heroicons-arrow-right-20-solid" />
default: <UInput model-value="benjamincanac" placeholder="you@example.com" />
props:
label: 'E-mail'
---

#help
Here are some examples
:u-icon{name="i-heroicons-information-circle"}

#default
:u-input{model-value="benjamincanac" placeholder="you@example.com"}
::


Levy-from-Odessa marked this conversation as resolved.
Show resolved Hide resolved
### `error`
Use the `#error` slot to set the custom content for error.

::component-example
#default
:form-group-error-slot-example

#code
```vue
<template>
<UFormGroup label="Email" :error="You must enter an email">
<template #default="{ error }">
<UInput v-model="email" type="email" placeholder="Enter email" />
</template>
<template #error="{ error }">
<UAlert icon="i-heroicons-exclamation-triangle-20-solid" :description="error" color="red" />
</template>
</UFormGroup>
</template>

<script setup lang="ts">
const email = ref('')
</script>

benjamincanac marked this conversation as resolved.
Show resolved Hide resolved
```
::

### Size

Use the `size` prop to change the size of the label and the form element.
Expand Down
36 changes: 27 additions & 9 deletions src/runtime/components/forms/FormGroup.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
<template>
<div :class="ui.wrapper" v-bind="attrs">
<div v-if="label" :class="[ui.label.wrapper, size]">
<label :for="inputId" :class="[ui.label.base, required ? ui.label.required : '']">{{ label }}</label>
<span v-if="hint" :class="[ui.hint]">{{ hint }}</span>
<div v-if="label || $slots.label" :class="[ui.label.wrapper, size]">
<label :for="inputId" :class="[ui.label.base, required ? ui.label.required : '']">
<slot v-if="$slots.label" name="label" v-bind="{ error, label, name, hint, description, help }" />
<template v-else>{{ label }}</template>
</label>
<span v-if="hint || $slots.hint" :class="[ui.hint]">
<slot v-if="$slots.hint" name="hint" v-bind="{ error, label, name, hint, description, help }" />
<template v-else>{{ hint }}</template>
</span>
</div>
<p v-if="description" :class="[ui.description, size]">
{{ description }}

<p v-if="description || $slots.description" :class="[ui.description, size]">
<slot v-if="$slots.description" name="description" v-bind="{ error, label, name, hint, description, help }" />
<template v-else>
{{ description }}
</template>
</p>

<div :class="[label ? ui.container : '']">
<slot v-bind="{ error }" />
<p v-if="typeof error === 'string' && error" :class="[ui.error, size]">
{{ error }}

<p v-if="(typeof error === 'string' && error`) || $slots.error`" :class="[ui.error, size]">
benjamincanac marked this conversation as resolved.
Show resolved Hide resolved
<slot v-if="$slots.error" name="error" v-bind="{ error, label, name, hint, description, help }" />
<template v-else>
{{ error }}
</template>
</p>
<p v-else-if="help" :class="[ui.help, size]">
{{ help }}
<p v-else-if="help || $slots.help" :class="[ui.help, size]">
<slot v-if="$slots.help" name="help" v-bind="{ error, label, name, hint, description, help }" />
<template v-else>
{{ help }}
</template>
</p>
</div>
</div>
Expand Down