Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 8fd9693

Browse files
committed
Docs (wip)
1 parent 0443915 commit 8fd9693

File tree

12 files changed

+1299
-0
lines changed

12 files changed

+1299
-0
lines changed

docs/components/checkbox-group.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: Checkbox Group
3+
sort: 9
4+
---
5+
6+
## Introduction
7+
8+
The checkbox group allows you to quickly group related checkboxes or radio buttons together in your forms.
9+
This is not a replacement for the form-group component, and should be used inside of the form-group component
10+
in your forms.
11+
12+
## Basic Usage
13+
14+
The most basic usage is like this:
15+
16+
```html
17+
<x-checkbox-group>
18+
checkbox 1
19+
checkbox 2
20+
</x-checkbox-group>
21+
```
22+
23+
This will output:
24+
25+
```html
26+
<div class="space-y-4">
27+
checkbox 1
28+
checkbox 2
29+
</div>
30+
```
31+
32+
## Inline Groups
33+
34+
By default, the `checkbox-group` is designed to stack your checkboxes and radio inputs, but you can display them inline
35+
with each other, by setting the `stacked` attribute to `false`. This will display the checkboxes in rows of 3 columns.
36+
37+
```html
38+
<x-checkbox-group :stacked="false">
39+
checkbox 1
40+
checkbox 2
41+
</x-checkbox-group>
42+
```
43+
44+
This will output:
45+
```html
46+
<div class="form-checkbox-group">
47+
checkbox 1
48+
checkbox 2
49+
</div>
50+
```
51+
52+
If you want a different amount of columns for your groups, you should override the `.form-checkbox-group` class in
53+
your stylesheets.

docs/components/checkbox.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
title: Checkbox
3+
sort: 8
4+
---
5+
6+
## Introduction
7+
8+
The `checkbox` component offers an easy way to set up a checkbox input field in your forms.
9+
By simple setting its `name` attribute it also automatically sets your `id` attribute and makes
10+
sure old values are respected.
11+
12+
## Basic Usage
13+
14+
The most basic usage of the component exists in setting a `name` attribute:
15+
16+
```html
17+
<x-checkbox name="remember_me" />
18+
```
19+
20+
This will output:
21+
22+
```html
23+
<div class="choice-container">
24+
<div class="choice-input">
25+
<input class="form-checkbox"
26+
name="remember_me"
27+
id="remember_me"
28+
type="checkbox"
29+
/>
30+
</div>
31+
32+
<div class="choice-label">
33+
<label for="remember_me"></label>
34+
</div>
35+
</div>
36+
```
37+
38+
## Labels
39+
40+
You can easily add a label to a checkbox by using the `label` attribute, or by using the `default slot`:
41+
42+
Via prop:
43+
```html
44+
<x-checkbox name="remember_me" label="Remember" />
45+
```
46+
47+
Via slot:
48+
```html
49+
<x-checkbox name="remember_me">
50+
Remember me
51+
</x-checkbox>
52+
```
53+
54+
Both will output:
55+
```html
56+
<div class="choice-container">
57+
<div class="choice-input">
58+
<input class="form-checkbox"
59+
name="remember_me"
60+
id="remember_me"
61+
type="checkbox"
62+
/>
63+
</div>
64+
65+
<div class="choice-label">
66+
<label for="remember_me">Remember</label>
67+
</div>
68+
</div>
69+
```
70+
71+
## Description
72+
73+
You can also add a description (help text) for a checkbox by either setting the `description` attribute or
74+
by using the `description` slot.
75+
76+
Via prop:
77+
```html
78+
<x-checkbox name="remember_me" label="Remember" description="Keep me logged in" />
79+
```
80+
81+
```html
82+
<x-checkbox name="remember_me" label="Remember">
83+
<x-slot name="description">Keep me logged in</x-slot>
84+
</x-checkbox>
85+
```
86+
87+
Both will output:
88+
```html
89+
<div class="choice-container">
90+
<div class="choice-input">
91+
<input class="form-checkbox"
92+
name="remember_me"
93+
id="remember_me"
94+
type="checkbox"
95+
/>
96+
</div>
97+
98+
<div class="choice-label">
99+
<label for="remember_me">Remember</label>
100+
101+
<p class="choice-description">Keep me logged in</p>
102+
</div>
103+
</div>
104+
```
105+
106+
## Old Values
107+
108+
The `checkbox` component also supports checked values that were set. For example,
109+
you might want to apply some validation in the backend and make sure the user
110+
doesn't lose their input data when you show them the form again with the validation errors.
111+
When re-rendering the form, the `checkbox` component will remember the checked value (when not using `wire:model`):
112+
113+
```html
114+
<input name="remember_me" id="remember_me" type="checkbox" checked />
115+
```

docs/components/email.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: Email
3+
sort: 4
4+
---
5+
6+
## Introduction
7+
8+
The `email` component offers an easy way to set up an email input field for your
9+
forms. By simply setting its `name` attribute it also automatically sets your `id`
10+
and makes sure old values are respected.
11+
12+
## Basic Usage
13+
14+
The most basic usage of the component is like this:
15+
16+
```html
17+
<x-email name="email" />
18+
```
19+
20+
This will output:
21+
22+
```html
23+
<div class="form-text-container">
24+
<input class="form-input form-text" name="email" id="email" type="email" />
25+
</div>
26+
```
27+
28+
By default an `email` type will be set for the input field as well as an `id` that allows it to be
29+
easily referenced by a `label` element.
30+
31+
Besides this, the email element behaves exactly the same as the [input component](/docs/laravel-form-components/v1/components/input).

docs/components/form-error.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
title: Form Error
3+
sort: 11
4+
---
5+
6+
## Introduction
7+
8+
The `form-error` component provides an easy way to work with Laravel's `$error` message bag
9+
in its Blade views. You can use it to display error messages for form fields.
10+
11+
This isn't a component you will usually reach for, as in most cases you will probably
12+
want to use the `form-group` component to render the label and errors automatically
13+
for you, but this component is available to use for other use cases you may have.
14+
15+
## Basic Usage
16+
17+
Imagine we have the following validation error:
18+
19+
```php
20+
['first_name' => 'Incorrect first name.']
21+
```
22+
23+
The most basic usage of the `form-error` component exists in using it as a self-closing component
24+
using a `name` attribute:
25+
26+
```html
27+
<x-form-error name="first_name" />
28+
```
29+
30+
This will output:
31+
32+
```html
33+
<p class="form-error" id="first_name-error">
34+
Incorrect first name.
35+
</p>
36+
```
37+
38+
As you can see it'll pick the error message from the `$error` message bag and
39+
render it in the view. If the message isn't set, the HTML isn't rendered.
40+
41+
It also sets the input id automatically from the `name` attribute, but you can easily override it by
42+
setting the `input-id` attribute to the relevant input's id. The input id is used in the `id` attribute,
43+
which can be referenced by an `aria-describedby` attribute on your input element.
44+
45+
## Composing The Content
46+
47+
You can also opt to composing how the rendered content looks too. This allows you to make use of hte component's
48+
`messages()` method to render multiple validation errors at the same time.
49+
50+
Let's assume we have the following validation errors:
51+
52+
```php
53+
[
54+
'first_name' => [
55+
'Incorrect first name.',
56+
'Needs at least 5 characters.',
57+
]
58+
]
59+
```
60+
61+
Now we'll use the component's slot and its `messages()` method to render an unordered list of the errors:
62+
63+
```html
64+
<x-form-error tag="ul" name="first_name">
65+
@foreach ($component->messages($errors) as $error)
66+
<li>{{ $error }}</li>
67+
@endforeach
68+
</x-form-error>
69+
```
70+
71+
We also specified the `tag` attribute to change the element tag from the default `p` tag to a `ul` tag.
72+
73+
This will output:
74+
75+
```html
76+
<ul class="form-error" id="first_name-error">
77+
<li>Incorrect first name.</li>
78+
<li>Needs at least 5 characters.</li>
79+
</ul>
80+
```
81+
82+
As you can see we need to pass in the `$errors` message bag to the `messages()`
83+
method of the component to grab all the messages for our field. Then we loop over
84+
them and render them.

0 commit comments

Comments
 (0)