Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

Commit 88e5735

Browse files
authored
Support for Bootstrap v5 (#55)
1 parent c0eb477 commit 88e5735

30 files changed

+547
-36
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
matrix:
1111
php: [8.0, 7.4]
1212
laravel: [8.*, 7.*]
13-
framework: [tailwind, tailwind-2, bootstrap-4]
13+
framework: [tailwind, tailwind-2, bootstrap-4, bootstrap-5]
1414
dependency-version: [prefer-lowest, prefer-stable]
1515
include:
1616
- laravel: 8.*

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `laravel-form-components` will be documented in this file
44

5+
## 3.0.0 - 2021-09-08
6+
7+
- Support for Bootstrap 5
8+
59
## 2.5.4 - 2020-02-15
610

711
- Bugfix for old nested data

README.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
[![Total Downloads](https://img.shields.io/packagist/dt/protonemedia/laravel-form-components.svg?style=flat-square)](https://packagist.org/packages/protonemedia/laravel-form-components)
77
[![Buy us a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen)](https://plant.treeware.earth/protonemedia/laravel-form-components)
88

9-
A set of Blade components to rapidly build forms with [Tailwind CSS v1](https://tailwindcss-custom-forms.netlify.app), [Tailwind CSS v2](https://tailwindcss-forms.vercel.app) and [Bootstrap 4](https://getbootstrap.com/docs/4.0/components/forms/). Supports validation, model binding, default values, translations, includes default vendor styling and fully customizable!
9+
A set of Blade components to rapidly build forms with [Tailwind CSS v1](https://tailwindcss-custom-forms.netlify.app), [Tailwind CSS v2](https://tailwindcss-forms.vercel.app), [Bootstrap 4](https://getbootstrap.com/docs/4.0/components/forms/) and [Bootstrap 5 Forms](https://getbootstrap.com/docs/5.1/forms/overview/). Supports validation, model binding, default values, translations, includes default vendor styling and fully customizable!
1010

11-
#### ... 👀 There's a Pro version of this package in development: check out [formcomponents.pro](https://formcomponents.pro)!
11+
Looking for Inertia/Vue.js support? Check out [formcomponents.pro](https://formcomponents.pro)!
1212

1313
### 📺 Want to see this package in action? Join the live stream on November 19 at 14:00 CET: [https://youtu.be/7eNZS4U7xyM](https://youtu.be/7eNZS4U7xyM)
1414

@@ -17,7 +17,8 @@ A set of Blade components to rapidly build forms with [Tailwind CSS v1](https://
1717
* Components for input, textarea, select, multi-select, checkbox and radio elements.
1818
* Support for Tailwind v1 with [Tailwind CSS Custom Forms](https://tailwindcss-custom-forms.netlify.app).
1919
* Support for Tailwind v2 with [Tailwind Forms](https://tailwindcss-forms.vercel.app/).
20-
* Support for [Bootstrap 4 Forms](https://getbootstrap.com/docs/4.0/components/forms/).
20+
* Support for [Bootstrap 4 Forms](https://getbootstrap.com/docs/4.6/components/forms/).
21+
* Support for [Bootstrap 5 Forms](https://getbootstrap.com/docs/5.1/forms/overview/).
2122
* Component logic independent from Blade views, the Tailwind and Bootstrap views use the same logic.
2223
* Bind a target to a form (or a set of elements) to provide default values (model binding).
2324
* Support for [Laravel Livewire](https://laravel-livewire.com) v2.
@@ -75,7 +76,7 @@ If you're using Tailwind, make sure the right plugin ([v1](https://github.com/ta
7576
</x-form>
7677
```
7778

78-
<img src="https://github.com/pascalbaljetmedia/laravel-form-components/blob/master/quick-example-form.png?raw=true" width="450" />
79+
<img src="https://github.com/protonemedia/laravel-form-components/blob/master/quick-example-form.png?raw=true" width="450" alt="Quick example form"/>
7980

8081
## Preface
8182

@@ -130,7 +131,7 @@ You can also choose to use a `placeholder` instead of a label, and of course you
130131
<x-form-input type="email" name="current_email" placeholder="Current email address" />
131132
```
132133

133-
By default every element shows validation errors but you can hide them if you want.
134+
By default, every element shows validation errors, but you can hide them if you want.
134135

135136
```blade
136137
<x-form-textarea name="description" :show-errors="false" />
@@ -406,29 +407,31 @@ By the default, the errors messages are positioned under the element. To show th
406407

407408
### Submit button
408409

409-
The label defaults to *Submit* but you can use the slot to provide your own content.
410+
The label defaults to *Submit*, but you can use the slot to provide your own content.
410411

411412
```blade
412413
<x-form-submit>
413414
<span class="text-green-500">Send</span>
414415
</x-form-submit>
415416
```
416417

417-
### Bootstrap 4
418+
### Bootstrap
418419

419-
You can switch to [Bootstrap 4](https://getbootstrap.com/docs/4.0/components/forms/) by updating the `framework` setting in the `form-components.php` configuration file.
420+
You can switch to [Bootstrap 4](https://getbootstrap.com/docs/4.0/components/forms/) or [Bootstrap 5](https://getbootstrap.com/docs/5.0/forms/overview/) by updating the `framework` setting in the `form-components.php` configuration file.
420421

421422
```php
422423
return [
423-
'framework' => 'bootstrap-4',
424+
'framework' => 'bootstrap-5',
424425
];
425426
```
426427

427-
There is a little bit of styling added to the `form.blade.php` view to add support for inline form groups. If you want to change it or remove it, [publish the assets](#customize-the-blade-views) and update the view file.
428+
There is a little of styling added to the `form.blade.php` view to add support for inline form groups. If you want to change it or remove it, [publish the assets](#customize-the-blade-views) and update the view file.
429+
430+
Bootstrap 5 changes a lot regarding forms. If you migrate from 4 to 5, make sure to read the migration logs about [forms](https://getbootstrap.com/docs/5.0/migration/#forms).
428431

429-
#### Input prepend and append
432+
#### Input group / prepend and append
430433

431-
In addition to the Tailwind features, there is also support for [input groups](https://getbootstrap.com/docs/4.1/components/forms/#auto-sizing). Use the `prepend` and `append` slots to provide the contents.
434+
In addition to the Tailwind features, with Bootstrap 4, there is also support for [input groups](https://getbootstrap.com/docs/4.6/components/forms/). Use the `prepend` and `append` slots to provide the contents.
432435

433436
```blade
434437
<x-form-input name="username" label="Username">
@@ -444,9 +447,28 @@ In addition to the Tailwind features, there is also support for [input groups](h
444447
</x-form-input>
445448
```
446449

450+
With Bootstrap 5, the [input groups](https://getbootstrap.com/docs/5.0/forms/input-group/) have been simplified. You can add as many items as you would like in any order you would like. Use the `form-input-group-text` component to add text or [checkboxes](https://getbootstrap.com/docs/5.0/forms/input-group/#checkboxes-and-radios).
451+
452+
```blade
453+
<x-form-input-group label="Profile" >
454+
<x-form-input name="name" placeholder="Name" id="name" />
455+
<x-form-input-group-text>@</x-form-input-group-text>
456+
<x-form-input name="nickname" placeholder="Nickname" id="nickname" />
457+
<x-form-submit />
458+
</x-form-input-group>
459+
```
460+
461+
#### Floating labels
462+
463+
As of Bootstrap 5, you can add [floating labels](https://getbootstrap.com/docs/5.0/forms/floating-labels/) by adding the `floating` attribute to inputs, selects (excluding `multiple`), and textareas.
464+
465+
```blade
466+
<x-form-input label="Floating Label" name="float_me" id="float_me" floating />
467+
```
468+
447469
#### Help text
448470

449-
You can add [block-level help text](https://getbootstrap.com/docs/4.1/components/forms/#help-text) to any element by using the `help` slot.
471+
You can add [block-level help text](https://getbootstrap.com/docs/4.6/components/forms/#help-text) to any element by using the `help` slot.
450472

451473
```blade
452474
<x-form-input name="username" label="Username">

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"tailwindcss",
88
"bootstrap",
99
"bootstrap4",
10+
"bootstrap5",
11+
"bootstrap-4",
12+
"bootstrap-5",
1013
"laravel",
1114
"form",
1215
"forms",

config/config.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
return [
66
'prefix' => '',
77

8-
/** tailwind | tailwind-2 | bootstrap-4 */
8+
/** tailwind | tailwind-2 | bootstrap-4 | bootstrap-5 */
99
'framework' => 'tailwind',
1010

1111
'components' => [
@@ -34,6 +34,16 @@
3434
'class' => Components\FormInput::class,
3535
],
3636

37+
'form-input-group' => [
38+
'view' => 'form-components::{framework}.form-input-group',
39+
'class' => Components\FormInputGroup::class,
40+
],
41+
42+
'form-input-group-text' => [
43+
'view' => 'form-components::{framework}.form-input-group-text',
44+
'class' => Components\FormInputGroupText::class,
45+
],
46+
3747
'form-label' => [
3848
'view' => 'form-components::{framework}.form-label',
3949
'class' => Components\FormLabel::class,
@@ -44,6 +54,11 @@
4454
'class' => Components\FormRadio::class,
4555
],
4656

57+
'form-range' => [
58+
'view' => 'form-components::{framework}.form-range',
59+
'class' => Components\FormRange::class,
60+
],
61+
4762
'form-select' => [
4863
'view' => 'form-components::{framework}.form-select',
4964
'class' => Components\FormSelect::class,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<div class="form-group">
2+
<x-form-label :label="$label" :for="$attributes->get('id') ?: $id()" />
3+
4+
<input
5+
{!! $attributes->merge(['class' => 'form-control-range' . ($hasError($name) ? ' is-invalid' : '')]) !!}
6+
7+
type="range"
8+
9+
@if($isWired())
10+
wire:model{!! $wireModifier() !!}="{{ $name }}"
11+
@else
12+
name="{{ $name }}"
13+
value="{{ $value }}"
14+
@endif
15+
16+
@if($label && !$attributes->get('id'))
17+
id="{{ $id() }}"
18+
@endif
19+
/>
20+
21+
{!! $help ?? null !!}
22+
23+
@if($hasErrorAndShow($name))
24+
<x-form-errors :name="$name" />
25+
@endif
26+
</div>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<div class="form-check @if(null !== $attributes->get('switch')) form-switch @endif @if(null !== $attributes->get('inline')) form-check-inline @endif">
2+
<input
3+
{!! $attributes->merge(['class' => 'form-check-input' . ($hasError($name) ? ' is-invalid' : '')]) !!}
4+
5+
type="checkbox"
6+
7+
value="{{ $value }}"
8+
9+
@if($isWired())
10+
wire:model{!! $wireModifier() !!}="{{ $name }}"
11+
@else
12+
name="{{ $name }}"
13+
@endif
14+
15+
@if($label && !$attributes->get('id'))
16+
id="{{ $id() }}"
17+
@endif
18+
19+
@if($checked)
20+
checked="checked"
21+
@endif
22+
/>
23+
24+
<x-form-label :label="$label" :for="$attributes->get('id') ?: $id()" class="form-check-label" />
25+
26+
{!! $help ?? null !!}
27+
28+
@if($hasErrorAndShow($name))
29+
<x-form-errors :name="$name" />
30+
@endif
31+
</div>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@error($name, $bag)
2+
<div {!! $attributes->merge(['class' => 'invalid-feedback']) !!}>
3+
{{ $message }}
4+
</div>
5+
@enderror
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<div {!! $attributes->merge(['class' => ($hasError($name) ? 'is-invalid' : '')]) !!}>
2+
<x-form-label :label="$label" />
3+
4+
<div class="@if($inline) d-flex flex-row flex-wrap inline-space @endif">
5+
{!! $slot !!}
6+
</div>
7+
8+
{!! $help ?? null !!}
9+
10+
@if($hasErrorAndShow($name))
11+
<x-form-errors :name="$name" class="d-block" />
12+
@endif
13+
</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<span {!! $attributes->merge(['class' => 'input-group-text']) !!}>{!! $slot !!}</span>

0 commit comments

Comments
 (0)