Skip to content

Commit d66a5d8

Browse files
authored
Merge pull request #120 from Gustavinho/feature/support-to-add-js-scripts-manually
feat: Add support to customize the JS scripts
2 parents 8d72016 + 274ada8 commit d66a5d8

File tree

12 files changed

+68
-87
lines changed

12 files changed

+68
-87
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ Add the following Blade directives in the *head* tag, and before the end *body*
5959
</html>
6060
```
6161

62-
These blade directives are also including [Laravel livewire](https://laravel-livewire.com/) and [Tailwindcss](https://tailwindcss.com/) styles and scripts, after that you may need to clear the view cache
62+
Laravel Views includes by default a set up using different parts of the TALL stack assets like the [Laravel livewire](https://laravel-livewire.com/) and [Tailwindcss](https://tailwindcss.com/) styles and scripts, it alsoincludes the [Alpine.js](https://laravel-livewire.com/docs/2.x/alpine-js) script, after adding these directives you may need to clear the view cache
63+
6364
```bash
6465
php artisan view:clear
6566
```
66-
If you are already using your own Tailwindcss setup you can set `laravel-views` to not importing Tailwindcss by default. ([Importing assets](./doc/laravel-views#including-assets))
6767

68+
These directives are fine for a dev environment, however, if you want to use your own Tailwindcss or Alpinde.js setup, you can [disable these assets](./doc/laravel-views#including-assets) from being loaded with the Laravel views directive.
6869
# First table view
6970
This is a basic usage of a table view, you can [read the full table view documentation ](doc/table-view.md)
7071

@@ -179,6 +180,7 @@ Here's the plan for what's coming:
179180
## Upgrade guide
180181
### From 2.2 to 2.3
181182
- Clear your cached views `php artisan view:clear` since some of the internal components changed.
183+
- Update assets
182184
- Update components.
183185
- Update config-file.
184186
- Update the renderIf() function in your action classes as follows:

doc/grid-view.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This view creates a dynamic grid view using card data, same as a TableView this
1111
- [Defining card data](#defining-card-data)
1212
- [Customizing card data](#customizing-card-data)
1313
- [Default card item action](#default-card-item-action)
14+
- [Sorting Data](#sorting-data)
1415
- [More features](#more-features)
1516
- [Searching data](./table-view.md#searching-data)
1617
- [Pagination](./table-view.md#pagination)
@@ -136,6 +137,19 @@ public $withBackground = true
136137

137138
This will render the item with a white background.
138139

140+
## Sorting data
141+
You can add an option to sort the items on the grid view by an specific field defining a `sortableBy` method with an array of the fields to sort by, as the grid view desn't have headers, a `Sort by` button will be displayed with a drop down with all the fields defined in this method.
142+
143+
```php
144+
public function sortableBy()
145+
{
146+
return [
147+
'Name' => 'name',
148+
'Email' => 'email'
149+
];
150+
}
151+
```
152+
139153
## More features
140154
This grid view is based on a table view, so you could use some of the table view features as:
141155

doc/laravel-views.md

Lines changed: 14 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
- [Grid view](doc/grid-view.md)
2222

2323
# Version compatibility
24-
|Laravel views|Livewire|Laravel|
25-
|-|-|-|
26-
|2.x|2.x|7.x, 8.x|
27-
|1.x|1.x|5.x, 6.x|
24+
|Laravel views|Alpine|Livewire|Laravel|
25+
|-|-|-|-|
26+
|2.x|2.8.x|2.x|7.x, 8.x|
27+
|1.x|2.8.x|1.x|5.x, 6.x|
2828

2929
# Installation and basic usage
3030

@@ -69,24 +69,26 @@ You can specify which assets you want to include passing a string to those direc
6969

7070
```php
7171
@laravelViewsStyles(laravel-views,tailwindcss,livewire)
72+
@laravelViewsScripts(laravel-views,livewire,alpine)
7273
```
7374

74-
If you dont need to include `Tailwindcss` or `Livewire` assets you can just set the `laravel-views` assets in the list.
75+
If you dont need to include `Tailwindcss`, `Livewire` or `Alpine` assets you can just set the `laravel-views` assets in the list.
7576

7677
```php
7778
@laravelViewsStyles(laravel-views)
79+
@laravelViewsScripts(laravel-views)
7880
```
7981

82+
This is recomended for a production environment where you surely have a compile assets pipeline, like Laravel Mix, or you want to include the assets from a CDN on your own.
83+
8084
## Purge Tailwindcss styles
8185
If you're using your own Tailwindcss setup you must consider `laravel-views` in your `purge` configuration, for that just add this path to the `purge` array on the `tailwind.config.js`file.
8286

8387
```js
84-
purge: {
85-
content: [
86-
//...Rest of your paths
87-
"./vendor/laravel-views/**/*.php",
88-
],
89-
},
88+
purge: [
89+
//...Rest of your paths
90+
"./vendor/laravel-views/**/*.php",
91+
],
9092
```
9193

9294
# First table view
@@ -147,63 +149,11 @@ In the example above the view is using the User model created by default in ever
147149
This is the basic usage of the table view, but you can customize it with more features.
148150

149151
[Read the full table view documentation ](doc/table-view.md)
150-
151-
# Rendering a view from a controller
152-
153-
You can render a view manually in a controller creating a `LaravelViews` instance and executing the `render` method on a `blade` file.
154-
155-
```php
156-
use use LaravelViews\LaravelViews;
157-
158-
public function index(LaravelViews $laravelViews)
159-
{
160-
$laravelViews->create(App\Http\Livewire\UsersTableView::class);
161-
162-
return view('my-view', [
163-
'view' => $laravelViews
164-
]);
165-
}
166-
```
167-
And render it in your blade file
168-
```blade
169-
{!! $view->render() !!}
170-
```
171-
172-
## Specifying a layout and section
173-
You can also return the view directly from your controller and specify the layout and section of your layout
174-
```php
175-
use use LaravelViews\LaravelViews;
176-
177-
public function index(LaravelViews $laravelViews)
178-
{
179-
$laravelViews->create(App\Http\Livewire\UsersTableView::class)
180-
->layout('layout', 'section-name');
181-
182-
return $laravelViews->render();
183-
}
184-
```
185-
186-
## Send extra data to the layout
187-
In the same way that you would send data to your views, you can send more data to the layout file
188-
```php
189-
use use LaravelViews\LaravelViews;
190-
191-
public function index(LaravelViews $laravelViews)
192-
{
193-
$laravelViews->create(App\Http\Livewire\UsersTableView::class)
194-
->layout('layout', 'section-name', [
195-
'title' => 'My layout title'
196-
]);
197-
198-
return $laravelViews->render();
199-
}
200-
```
201-
202152
# Components customization
203153
These views are build with [Tailwind CSS](https://tailwindcss.com/) and you can either change the colors of the components following tailwindcss utilities or fully customize all the html of the components
204154

205155
## Component variants using tailwindcss
206-
If you are using [Tailwind CSS](https://tailwindcss.com/) or if you don't have issues using Tailwindcss and your own css styles, you can customize some utilities to change the color for each variant of the components publishing a config file
156+
You can customize some of the components styles (like the color) for each one of the variants with a config file.
207157

208158
```bash
209159
php artisan vendor:publish --tag=config

doc/list-view.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,19 @@ public function sortableBy()
127127
}
128128
```
129129

130+
## Sorting data
131+
You can add an option to sort the items on the list view by an specific field defining a `sortableBy` method with an array of the fields to sort by, as the list view desn't have headers, a `Sort by` button will be displayed with a drop down with all the fields defined in this method.
132+
133+
```php
134+
public function sortableBy()
135+
{
136+
return [
137+
'Name' => 'name',
138+
'Email' => 'email'
139+
];
140+
}
141+
```
142+
130143
## More features
131144
This list view is based on a table view, so you could use some of the table view features as:
132145

public/laravel-views.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/laravel-views.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/bootstrap.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
import $ from 'jquery'
21
import feather from 'feather-icons'
32
import Pikaday from 'pikaday'
4-
import moment from 'moment'
5-
import alpine from 'alpinejs'
63

74
try {
8-
window.Alpine = alpine
9-
// window.$ = window.jQuery = require('jquery')
10-
115
const setUpUiLibraries = () => {
126
feather.replace()
137
}
@@ -33,12 +27,10 @@ try {
3327
}
3428

3529
// require('bootstrap')
36-
$(document).ready(function() {
30+
document.addEventListener("DOMContentLoaded", () => {
3731
setUpUiLibraries()
38-
});
3932

40-
$(document).on("livewire:load", () => {
41-
window.livewire.hook('message.processed', () => {
33+
Livewire.hook('message.processed', () => {
4234
setUpUiLibraries()
4335
})
4436
})

resources/scss/app.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
@import "~pikaday/scss/pikaday.scss";
2-
@import "custom-utilities";
2+
@import "custom-utilities";
3+
4+
[x-cloak] { display: none !important; }

resources/views/components/confirmation-message.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
message = actionObject.message;
88
})"
99
>
10-
<div x-show="open">
10+
<div x-show="open" x-cloak>
1111
<x-lv-modal>
1212
<div x-text='message' class="text-gray-900 text-lg font-medium" ></div>
1313
<div class="mt-4 flex flex-col space-y-2 sm:space-y-0 sm:space-x-2 sm:flex-row sm:items-center">

resources/views/components/toolbar/filters.blade.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
@if (count($filters) > 0)
1818
{{-- Clear filters button --}}
1919
<div class="p-4 bg-gray-100 text-right flex justify-end">
20-
<a wire:click="clearFilters" @click="open = false" href="#"
21-
class="text-gray-600 flex items-center hover:text-gray-700">
20+
<button wire:click.prevent="clearFilters" @click="open = false" class="text-gray-600 flex items-center hover:text-gray-700 focus:outline-none text-sm">
2221
<i data-feather="x-circle" class="mr-2 w-5 h-5"></i>
2322
{{__('Clear filters')}}
24-
</a>
23+
</button>
2524
</div>
2625
@endif
2726
</x-lv-drop-down>

0 commit comments

Comments
 (0)