Skip to content

Commit

Permalink
Added bg-colors and button-colors to config
Browse files Browse the repository at this point in the history
Added translation settings to config
New Notification Trait
New Notification Blade component
  • Loading branch information
tanthammar committed Jul 31, 2020
1 parent d330f04 commit f988e7c
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 12 deletions.
20 changes: 20 additions & 0 deletions config/tall-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@

return [
'form-title' => "trans('global.create').' '.trans('crud.dummymodel.title_singular')",
//form buttons translations
'saved' => 'global.saved',
'delete' => 'global.delete',
'save-and-stay' =>'global.save',
'save-go-back' => 'global.save_go_back',
'message-updated-success' => 'messages.updated_success',
//notification trait popup bg colors
'positive' => 'bg-green-500',
'negative' => 'bg-red-500',
'info' => 'bg-blue-500',
'warning' => 'bg-orange-500',
'default' => 'bg-teal-500',
//button component classes
'button-info' => 'text-white bg-frost-dimmed hover:bg-frost-blue focus:border-blue-700 focus:shadow-outline-blue active:bg-frost-dimmed',
'button-positive' => 'text-white bg-aurora-green hover:bg-green-500 focus:border-green-600 focus:shadow-outline-green active:bg-aurora-green',
'button-negative' => 'text-red-100 bg-aurora-red hover:bg-red-500 focus:border-red-600 focus:shadow-outline-red active:bg-aurora-red',
'button-warning' => 'text-orange-100 bg-aurora-orange hover:bg-orange-600 focus:border-orange-700 focus:shadow-outline-orange active:bg-orange-700',
'button-primary' => 'text-blue-100 bg-night-lighter hover:bg-night-dark focus:border-night-light focus:shadow-outline-blue active:bg-night-dark',
//file uploads
'storage_disk' => env('FORM_STORAGE_DISK', 'public'),
'storage_path' => env('FORM_STORAGE_PATH', 'uploads'),
//icons
'arrow-up-icon' => 'light/arrow-up', //used as @svg('light/arrow-up', 'classes')
'arrow-down-icon' => 'light/arrow-down',
'trash-icon' => 'light/trash-alt',
Expand Down
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ If you want to use Bootstrap CSS you can use the package made by kdion4891, whic
- [kdion4891](https://github.com/kdion4891)

# Documentation [See the wiki](https://github.com/tanthammar/tall-forms/wiki)
The package is actively maintained and being used in live projects without issues, but please test thoroughly in your project.
12 changes: 6 additions & 6 deletions resources/views/components/button.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
'gray' => 'text-gray-100 bg-gray-500 hover:bg-gray-600 focus:border-gray-700 focus:shadow-outline-gray active:bg-gray-700',
'orange' => 'text-orange-100 bg-orange-500 hover:bg-orange-600 focus:border-orange-700 focus:shadow-outline-orange active:bg-orange-700',
'teal' => 'text-teal-100 bg-teal-500 hover:bg-teal-600 focus:border-teal-700 focus:shadow-outline-teal active:bg-teal-700',
'info' => 'text-white bg-frost-dimmed hover:bg-frost-blue focus:border-blue-700 focus:shadow-outline-blue active:bg-frost-dimmed',
'positive' => 'text-white bg-aurora-green hover:bg-green-500 focus:border-green-600 focus:shadow-outline-green active:bg-aurora-green',
'negative' => 'text-red-100 bg-aurora-red hover:bg-red-500 focus:border-red-600 focus:shadow-outline-red active:bg-aurora-red',
'warning' => 'text-orange-100 bg-aurora-orange hover:bg-orange-600 focus:border-orange-700 focus:shadow-outline-orange active:bg-orange-700',
'primary' => 'text-blue-100 bg-night-lighter hover:bg-night-dark focus:border-night-light focus:shadow-outline-blue active:bg-night-dark',
'info' => config('tall-forms.button-info'),
'positive' => config('tall-forms.button-positive'),
'negative' => config('tall-forms.button-negative'),
'warning' => config('tall-forms.button-warning'),
'primary' => config('tall-forms.button-primary'),
]])
<{{$tag}} {{ $attributes->merge([
'class' => "{$sizes[$size]} {$colors[$color]} inline-flex items-center border border-transparent font-semibold tracking-wider rounded text-white focus:outline-none transition ease-in-out duration-150",
'type' => ($tag == 'a') ? 'text/html' : $type
]) }}>@if(isset($icon))@svg($icon, $icons[$size])@endif{{ $text ?? null }}{{ $slot }}
</{{$tag}}>
</{{$tag}}>
44 changes: 44 additions & 0 deletions resources/views/components/notification.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<div
class="fixed inset-0 flex items-end justify-center px-4 py-6 pointer-events-none sm:p-6 sm:items-start sm:justify-end"
style="margin-top: 50px" xmlns:x-bind="http://www.w3.org/1999/xhtml"
xmlns:x-transition="http://www.w3.org/1999/xhtml" xmlns:x-on="http://www.w3.org/1999/xhtml">
<div x-cloak x-data="{ show: {{ $show ?? 'false' }}, message: '{{ $message ?? '' }}', bg: '{{ $bg ?? 'bg-aurora-green'}}' }"
x-on:notify.window="
show = true;
message = $event.detail.message;
bg = $event.detail.bg;
setTimeout(() => { show = false }, 5000)" x-show="show"
x-description="Notification panel, show/hide based on alert state."
x-transition:enter="transform ease-out duration-300 transition"
x-transition:enter-start="translate-y-2 opacity-0 sm:translate-y-0 sm:translate-x-2"
x-transition:enter-end="translate-y-0 opacity-100 sm:translate-x-0"
x-transition:leave="transition ease-in duration-100" x-transition:leave-start="opacity-100"
x-transition:leave-end="opacity-0" x-bind:class="bg"
class="w-full max-w-sm rounded-lg shadow-lg pointer-events-auto">
<div class="overflow-hidden rounded-lg shadow-xs">
<div class="p-4">
<div class="flex items-start">
<div class="flex-shrink-0">
<svg class="w-6 h-6 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</div>
<div class="ml-3 w-0 flex-1 pt-0.5">
<p x-text="message" class="text-sm font-medium leading-5 text-white"></p>
</div>
<div class="flex flex-shrink-0 ml-4">
<button x-on:click.stop="show = false"
class="inline-flex text-gray-100 transition duration-150 ease-in-out focus:outline-none focus:white">
<svg class="w-5 h-5" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
clip-rule="evenodd"></path>
</svg>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
8 changes: 4 additions & 4 deletions resources/views/form-layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
<div class="w-full mt-8 border-t border-gray-200 pt-5">
<div class="space-x-3 flex justify-center sm:justify-end items-center">
@if($showDelete)
<x-button wire:click.prevent="delete" :text="trans('global.delete')" color="negative" />
<x-button wire:click.prevent="delete" :text="trans(config('tall-forms.delete'))" color="negative" />
@endif
<span x-data="{ open: false }"
x-init="
@this.on('notify-saved', () => { if (open === false) setTimeout(() => { open = false }, 2500); open = true;})"
x-show.transition.out.duration.1000ms="open" style="display: none;"
class="text-gray-500">{{ trans('global.saved') }}</span>
class="text-gray-500">{{ trans(config('tall-forms.saved')) }}</span>
@if($showGoBack)
<x-button wire:click="saveAndGoBack" color="primary">@lang('global.save_go_back')</x-button>
<x-button wire:click="saveAndGoBack" color="primary">@lang(config('tall-forms.save-go-back'))</x-button>
@endif
<x-button wire:click="saveAndStay" wire:loading.attr="disabled" color="positive">
<span class="mr-2" wire:loading wire:target="saveAndStay">
<x-spinners.button /></span>
@lang('global.save')
@lang(config('tall-forms.save-and-stay'))
</x-button>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/FormComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Tanthammar\TallForms;

use App\Http\Livewire\Traits\Notify;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Arr;
use Tanthammar\TallForms\Traits\FollowsRules;
use Tanthammar\TallForms\Traits\HandlesArrays;
use Tanthammar\TallForms\Traits\Notify;
use Tanthammar\TallForms\Traits\UploadsFiles;
use Livewire\Component;

Expand Down
1 change: 1 addition & 0 deletions src/FormServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ protected function bootViews()
Blade::component('tall-forms::components.label', 'tall-label');
Blade::component('tall-forms::components.error-icon', 'tall-error-icon');
Blade::component('tall-forms::components.field-wrapper', 'tall-field-wrapper');
Blade::component('tall-forms::components.notification', 'tall-notification');
}
}
69 changes: 69 additions & 0 deletions src/Traits/Notify.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Tanthammar\TallForms\Traits;

trait Notify
{
/*
You can use this trait in both php or in frontend js
It either sets a LiveWire property that calls the notify method or
you can call the notify method directly.
example use in js to update the property
@this.set('alert', {
type: 'negative',
message: Locale == 'sv' //locale is shared to window
? "Bilden du valt överskrider max tillåten dokument storlek. Se 'Max file size' ovanför bilden."
: "The image you uploaded exceeds max allowed file size, stated above the picture"
});
exeample use in js to call the notify function
@this.call('notify', 'negative', 'Oh No!');
*/
public array $alert = [];

public function updatedAlert()
{
$this->notify(
array_get($this->alert, 'type', 'saved'),
array_get($this->alert, 'message', trans(config('tall-forms.message-updated-success')))
);
}

public function notify($type = "saved", $message = "")
{
$bg = null;
switch ($type) {
case 'saved':
$bg = config('tall-forms.positive');
$message = trans(config('tall-forms.message-updated-success'));
$this->emitSelf('notify-saved');
break;

case 'positive':
$bg = config('tall-forms.positive');
break;

case 'negative':
$bg = config('tall-forms.negative');
break;

case 'info':
$bg = config('tall-forms.info');
break;

case 'warning':
$bg = config('tall-forms.warning');
break;

default:
$bg = config('tall-forms.default');
break;
}
$this->dispatchBrowserEvent(
'notify',
[
'bg' => $bg,
'message' => $message,
]
);
}
}

0 comments on commit f988e7c

Please sign in to comment.