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

Card Component #9

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ php artisan laravel-template-components:install

### Input Component
```html
<x-template-components::input />
<x-template-components-input />
```
He accept all normal attributes of input tag and add some new attributes:
- div-class: add class to div tag
Expand All @@ -34,7 +34,7 @@ He accept all normal attributes of input tag and add some new attributes:

### Button Component
```html
<x-template-components::button />
<x-template-components-button />
```
He accept all normal attributes of button tag and add some new attributes:
- div-class: add class to div tag
Expand All @@ -46,15 +46,15 @@ He accept all normal attributes of button tag and add some new attributes:

we support livewire loading state, so if you use livewire you can use loading state like this:
```html
<x-template-components::button wire:target="save" />
<x-template-components-button wire:target="save" />
```

### Select Component
```html
<x-template-components::select>
<x-template-components-select>
<option value="1">option 1</option>
<option value="2">option 2</option>
</x-template-components::select>
</x-template-components-select>
```
He accept all normal attributes of select tag and add some new attributes:
- div-class: add class to div tag
Expand All @@ -63,7 +63,7 @@ He accept all normal attributes of select tag and add some new attributes:

### Textarea Component
```html
<x-template-components::textarea />
<x-template-components-textarea />
```
He accept all normal attributes of textarea tag and add some new attributes:
- div-class: add class to div tag
Expand All @@ -72,14 +72,30 @@ He accept all normal attributes of textarea tag and add some new attributes:

### Form Component
```html
<x-template-components::form>
<x-template-components-form>

</x-template-components::form>
</x-template-components-form>
```
he accept all normal attributes of form tag and add some new attributes:
- route: route name that will be used in form action
- other attributes will be added to form tag

### Card Component
```html
<x-template-components-card>
<x-slot:header>
Heading
</x-slot>
Content
<x-slot:footer>
Footer
</x-slot>
</x-template-components-card>
```
he accept all normal attributes of div tag and add some new attributes:
- div-class: add class to div tag (contener div)
- other attributes will be added to div tag (content div)

## Supported Templates

- [Vuexy](https://demos.pixinvent.com/vuexy-html-admin-template/landing/)
Expand All @@ -90,6 +106,7 @@ he accept all normal attributes of form tag and add some new attributes:
| Vuexy | :white_check_mark: |
| Metronic | :white_check_mark: |
| Html Standards | :white_check_mark: |
| Bootstrap Classes | :white_check_mark: |

## Testing

Expand Down
17 changes: 15 additions & 2 deletions config/template-components.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
return [
'defult_classes' => [
'input' => [
'div' => '',
'div' => 'form-group',
'label' => 'form-label',
'input' => 'form-control ',
'input' => 'form-control',
'error-div' => 'invalid-feedback',
'input-error' => 'is-invalid',
],
Expand All @@ -22,5 +22,18 @@
'error-div' => 'invalid-feedback',
'select-error' => 'is-invalid',
],
'textarea' => [
'div' => 'form-group',
'label' => 'form-label',
'textarea' => 'form-control',
'error-div' => 'invalid-feedback',
'textarea-error' => 'is-invalid',
],
'card' => [
'div' => 'card',
'header' => 'card-header',
'body' => 'card-body',
'footer' => 'card-footer',
],
],
];
24 changes: 12 additions & 12 deletions resources/views/components/button.blade.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<button {{ $attributes->merge(['class' => config('template-components.defult_classes.button.button')]) }} {{ $attributes }} wire:loading.attr="disabled">
<span wire:loading.remove wire:target="{{ $attributes->get('wire:target') }}" class="{{ $attributes->get('span-text-class') }}">
{{ $slot }}
</span>
<div wire:loading wire:target="{{ $attributes->get('wire:target') }}">
<span class="{{ $attributes->get('indicator-progress-class') }}">
{{ $attributes->get('loading-text') ?? 'Please wait...' }}
<span class="{{ $attributes->get('spinner-class') ?? 'spinner-border spinner-border-sm align-middle ms-2' }} {{ config('template-components.defult_classes.button.spinner-class') }}"></span>
</span>
</div>
</button>
<button {{ $attributes->merge(['class' => config('template-components.defult_classes.button.button')]) }} wire:loading.attr="disabled">
<span wire:loading.remove wire:target="{{ $attributes->get('wire:target') }}" class="{{ $attributes->get('span-text-class') }}">
{{ $slot }}
</span>

<div wire:loading wire:target="{{ $attributes->get('wire:target') }}">
<span class="{{ $attributes->get('indicator-progress-class') }}">
{{ $attributes->get('loading-text') ?? 'Please wait...' }}
<span class="{{ $attributes->get('spinner-class') ?? 'spinner-border spinner-border-sm align-middle ms-2' }} {{ config('template-components.defult_classes.button.spinner-class') }}"></span>
</span>
</div>
</button>
17 changes: 17 additions & 0 deletions resources/views/components/card.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@props(['header', 'footer'])

<div class="{{ $attributes->get('div-class') }} {{ config('template-components.defult_classes.card.div') }}">
@isset($header)
<h5 {{ $header->attributes->class([config('template-components.defult_classes.card.header')]) }}>
{{ $header }}
</h5>
@endisset
<div {{ $attributes->class([config('template-components.defult_classes.card.body')]) }}>
{{ $slot }}
</div>
@isset($footer)
<div {{ $footer->attributes->class([config('template-components.defult_classes.card.footer')]) }}>
{{ $footer }}
</div>
@endisset
</div>
8 changes: 4 additions & 4 deletions resources/views/components/form.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form action="{{ $attributes->get('action') ?? route($attributes->get('route')) }}" {{ $attributes }}>
@csrf
{{ $slot }}
</form>
<form action="{{ $attributes->get('action') ?? route($attributes->get('route')) }}" {{ $attributes }}>
@csrf
{{ $slot }}
</form>
40 changes: 20 additions & 20 deletions resources/views/components/textarea.blade.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<div class="{{ config('template-components.defult_classes.input.div') }} {{ $attributes->get('div-class') }}">
<label class="{{ config('template-components.defult_classes.input.label') }} {{ $attributes->get('label-class') }}">
{{ $attributes->get('label') }}
</label>
<textarea class="{{ config('template-components.defult_classes.input.input') }} {{ $attributes->get('class') }}
@error($attributes->get('name') ?? $attributes->whereStartsWith('wire:model')->first())
{{ config('template-components.defult_classes.input.input-error') }}
@enderror"
{{ $attributes }}>
{{ $slot }}
</textarea>
@error($attributes->get('name') ?? $attributes->whereStartsWith('wire:model')->first())
<div class="{{ config('template-components.defult_classes.input.error-div') }}">
{{ $message }}
</div>
@enderror
</div>
<div class="{{ config('template-components.defult_classes.textarea.div') }} {{ $attributes->get('div-class') }}">

<label class="{{ config('template-components.defult_classes.textarea.label') }} {{ $attributes->get('label-class') }}">
{{ $attributes->get('label') }}
</label>

<textarea class="{{ config('template-components.defult_classes.textarea.textarea') }} {{ $attributes->get('class') }}
@error($attributes->get('name') ?? $attributes->whereStartsWith('wire:model')->first())
{{ config('template-components.defult_classes.textarea.textarea-error') }}
@enderror"
{{ $attributes }}>
{{ $slot }}
</textarea>

@error($attributes->get('name') ?? $attributes->whereStartsWith('wire:model')->first())
<div class="{{ config('template-components.defult_classes.textarea.error-div') }}">
{{ $message }}
</div>
@enderror
</div>
10 changes: 9 additions & 1 deletion src/LaravelTemplateComponentsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ public function configurePackage(Package $package): void
$package
->name('laravel-template-components')
->hasConfigFile()
->hasViews()
->hasInstallCommand(function (InstallCommand $command) {
$command
->publishConfigFile()
->askToStarRepoOnGitHub('salahhusa9/laravel-template-components');
});

$this->loadViewsFrom(__DIR__.'/../resources/views/components', 'template-components');
$this->loadViewComponentsAs('template-components', [
'card' => 'template-components::components.card',
'button' => 'template-components::components.button',
'input' => 'template-components::components.input',
'select' => 'template-components::components.select',
'textarea' => 'template-components::components.textarea',
'form' => 'template-components::components.form',
]);
}
}
2 changes: 1 addition & 1 deletion tests/components/ButtonComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
use Illuminate\Support\Facades\View;

it('can render button component', function () {
$this->assertTrue(View::exists('template-components::button'));
$this->assertTrue(View::exists('template-components::components.button'));
});
9 changes: 9 additions & 0 deletions tests/components/CardComponentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

// test card component

use Illuminate\Support\Facades\View;

it('can render card component', function () {
$this->assertTrue(View::exists('template-components::components.card'));
});
2 changes: 1 addition & 1 deletion tests/components/FormComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
use Illuminate\Support\Facades\View;

it('can render form component', function () {
$this->assertTrue(View::exists('template-components::form'));
$this->assertTrue(View::exists('template-components::components.form'));
});
2 changes: 1 addition & 1 deletion tests/components/InputComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
use Illuminate\Support\Facades\View;

it('can render input component', function () {
$this->assertTrue(View::exists('template-components::input'));
$this->assertTrue(View::exists('template-components::components.input'));
});
2 changes: 1 addition & 1 deletion tests/components/SelectComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
use Illuminate\Support\Facades\View;

it('can render select component', function () {
$this->assertTrue(View::exists('template-components::select'));
$this->assertTrue(View::exists('template-components::components.select'));
});
2 changes: 1 addition & 1 deletion tests/components/TextareaComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
use Illuminate\Support\Facades\View;

it('can render textarea component', function () {
$this->assertTrue(View::exists('template-components::textarea'));
$this->assertTrue(View::exists('template-components::components.textarea'));
});