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

Commit

Permalink
Added support for Tailwind v2.0 with Tailwind Forms (#26)
Browse files Browse the repository at this point in the history
* Added support for Tailwind v2.0 with Tailwind Forms
* Move to GA
  • Loading branch information
pascalbaljet authored Nov 25, 2020
1 parent c7292e8 commit b642e4d
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 42 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: run-tests

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [7.4]
laravel: [8.*, 7.*]
framework: [tailwind, tailwind-2, bootstrap-4]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: 6.*
livewire: ^2.0
- laravel: 7.*
testbench: 5.*
livewire: ^1.3.2

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.framework }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-livewire-${{ matrix.livewire }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, mysql, mysqli, pdo_mysql
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "livewire/livewire:${{ matrix.livewire }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Execute tests
env:
FORM_COMPONENTS_FRAMEWORK: ${{ matrix.framework }}
run: vendor/bin/phpunit
4 changes: 0 additions & 4 deletions .styleci.yml

This file was deleted.

36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ A set of Blade components to rapidly build forms with [Tailwind CSS Custom Forms
## Features

* Components for input, textarea, select, multi-select, checkbox and radio elements.
* Support for [Tailwind CSS Custom Forms](https://tailwindcss-custom-forms.netlify.app) and [Bootstrap 4 Forms](https://getbootstrap.com/docs/4.0/components/forms/).
* Support for Tailwind v1 with [Tailwind CSS Custom Forms](https://tailwindcss-custom-forms.netlify.app) and
* Support for Tailwind v2 with [Tailwind Forms](https://tailwindcss-forms.vercel.app/) and
* Support for [Bootstrap 4 Forms](https://getbootstrap.com/docs/4.0/components/forms/).
* Component logic independent from Blade views, the Tailwind and Bootstrap views use the same logic.
* Bind a target to a form (or a set of elements) to provide default values.
* Support for [Laravel Livewire](https://laravel-livewire.com).
Expand Down Expand Up @@ -89,7 +91,15 @@ The `action` attribute is optional, but you can pass a hard-coded, primitive val

## Configuration

There is no configuration needed unless you want to [customize the Blade views and components](#customize-the-blade-views).
You can switch frameworks by updating the `framework` setting in the `form-components.php` configuration file. Use the `artisan vendor:publish` command to publish the configuration file.

```php
return [
'framework' => 'bootstrap-4',
];
```

No further configuration is needed unless you want to [customize the Blade views and components](#customize-the-blade-views).

## Usage

Expand Down
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
return [
'prefix' => '',

/** tailwind | tailwind-2 | bootstrap-4 */
'framework' => 'tailwind',

'components' => [
Expand Down
24 changes: 24 additions & 0 deletions resources/views/tailwind-2/form-checkbox.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="flex flex-col">
<label class="flex items-center">
<input {!! $attributes !!}
type="checkbox"
value="{{ $value }}"

@if($isWired())
wire:model="{{ $name }}"
@else
name="{{ $name }}"
@endif

@if($checked)
checked="checked"
@endif
/>

<span class="ml-2">{{ $label }}</span>
</label>

@if($hasErrorAndShow($name))
<x-form-errors :name="$name" />
@endif
</div>
5 changes: 5 additions & 0 deletions resources/views/tailwind-2/form-errors.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@error($name, $bag)
<p {!! $attributes->merge(['class' => 'text-red-500 text-xs italic']) !!}>
{{ $message }}
</p>
@enderror
11 changes: 11 additions & 0 deletions resources/views/tailwind-2/form-group.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div {!! $attributes->merge(['class' => 'mt-4']) !!}>
<x-form-label :label="$label" />

<div class="@if($label) mt-2 @endif @if($inline) flex flex-wrap space-x-6 @endif">
{!! $slot !!}
</div>

@if($hasErrorAndShow($name))
<x-form-errors :name="$name" />
@endif
</div>
21 changes: 21 additions & 0 deletions resources/views/tailwind-2/form-input.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="@if($type === 'hidden') hidden @else mt-4 @endif">
<label class="block">
<x-form-label :label="$label" />

<input {!! $attributes->merge([
'class' => 'block w-full ' . ($label ? 'mt-1' : '')
]) !!}
@if($isWired())
wire:model="{{ $name }}"
@else
name="{{ $name }}"
value="{{ $value }}"
@endif

type="{{ $type }}" />
</label>

@if($hasErrorAndShow($name))
<x-form-errors :name="$name" />
@endif
</div>
3 changes: 3 additions & 0 deletions resources/views/tailwind-2/form-label.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@if($label)
<span {!! $attributes->merge(['class' => 'text-gray-700']) !!}>{{ $label }}</span>
@endif
25 changes: 25 additions & 0 deletions resources/views/tailwind-2/form-radio.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div>
<label class="inline-flex items-center">
<input {!! $attributes !!}
type="radio"

@if($isWired())
wire:model="{{ $name }}"
@else
name="{{ $name }}"
@endif

value="{{ $value }}"

@if($checked)
checked="checked"
@endif
/>

<span class="ml-2">{{ $label }}</span>
</label>

@if($hasErrorAndShow($name))
<x-form-errors :name="$name" />
@endif
</div>
32 changes: 32 additions & 0 deletions resources/views/tailwind-2/form-select.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="mt-4">
<label class="block">
<x-form-label :label="$label" />

<select
@if($isWired())
wire:model="{{ $name }}"
@else
name="{{ $name }}"
@endif

@if($multiple)
multiple
@endif

{!! $attributes->merge([
'class' => ($label ? 'mt-1' : '') . ' block w-full'
]) !!}>
@forelse($options as $key => $option)
<option value="{{ $key }}" @if($isSelected($key)) selected="selected" @endif>
{{ $option }}
</option>
@empty
{!! $slot !!}
@endforelse
</select>
</label>

@if($hasErrorAndShow($name))
<x-form-errors :name="$name" />
@endif
</div>
8 changes: 8 additions & 0 deletions resources/views/tailwind-2/form-submit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="mt-6 flex items-center justify-between">
<button {!! $attributes->merge([
'class' => 'bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 focus:outline-none focus:shadow-outline',
'type' => 'submit'
]) !!}>
{!! trim($slot) ?: __('Submit') !!}
</button>
</div>
19 changes: 19 additions & 0 deletions resources/views/tailwind-2/form-textarea.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="mt-4">
<label class="block">
<x-form-label :label="$label" />

<textarea
@if($isWired())
wire:model="{{ $name }}"
@else
name="{{ $name }}"
@endif

{!! $attributes->merge(['class' => 'block w-full ' . ($label ? 'mt-1' : '')]) !!}
>@unless($isWired()){!! $value !!}@endunless</textarea>
</label>

@if($hasErrorAndShow($name))
<x-form-errors :name="$name" />
@endif
</div>
11 changes: 11 additions & 0 deletions resources/views/tailwind-2/form.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<form method="{{ $spoofMethod ? 'POST' : $method }}" {!! $attributes !!}>
@unless(in_array($method, ['HEAD', 'GET', 'OPTIONS']))
@csrf
@endunless

@if($spoofMethod)
@method($method)
@endif

{!! $slot !!}
</form>

0 comments on commit b642e4d

Please sign in to comment.