Skip to content

Commit 2e04a53

Browse files
author
Joeri
committed
Fix viewAll and table styling
- Fixed table style 'tight' - Fixed viewAll not showing - Add viewAll styling and positioning
1 parent af7727b commit 2e04a53

File tree

6 files changed

+75
-17
lines changed

6 files changed

+75
-17
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## [1.0.4] - 2024-04-23
2+
3+
Fixed table style 'tight' \
4+
Fixed viewAll not showing \
5+
Add viewAll styling and positioning \
6+
Update README
7+
18
## [1.0.3] - 2023-05-31
29

310
Fixed return type

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ class LatestOrders extends TableCard
103103
$header = collect(['Date', 'Order Number', 'Status', 'Price', 'Name']);
104104

105105
$this->title('Latest Orders');
106-
$this->viewAll(['label' => 'View All', 'link' => '/resources/orders']);
106+
$this->viewAll([
107+
'label' => 'View All', //Default value `View All`
108+
'link' => '/resources/orders', //Required field
109+
'position' => 'bottom' //Default value `top`
110+
'style' => 'button' //Default value `link`
111+
]);
107112

108113
// $orders = Order::take(10)->latest->get();
109114
// Data from you model
@@ -133,6 +138,10 @@ class LatestOrders extends TableCard
133138
Cell::make($order['name'])
134139
);
135140
})->toArray());
141+
142+
//Possible style configuration
143+
// $this->style = 'tight';
144+
136145
}
137146

138147
private function getStatusSortableData (string $status) : int
@@ -160,8 +169,21 @@ protected function cards()
160169
}
161170
```
162171

163-
Note: If you don't specify viewLink() on a row `Row::make()->viewLink()`, show icon will not be visible.
172+
#### Note:
173+
If you don't specify viewLink() on a row `Row::make()->viewLink()`, show icon will not be visible.
174+
#### Additional Fields in viewAll
164175
You can also show a viewAll on the table with `$this->viewAll()`
176+
- **label (optional)**: By default, it is set to 'View All'.
177+
- **position (optional)**: By default, it is set to 'top'. You can change it to 'bottom' if needed.
178+
- **style (optional)**: DThe default style is a 'link'. Alternatively, you can set it to 'button' for a button-style appearance.
179+
```php
180+
$this->viewAll([
181+
'label' => '__('Latest Orders')',
182+
'link' => '/resources/orders', //URL to navigate when the link is clicked
183+
'position' => 'bottom', //(Possible values `top` - `bottom`)
184+
'style' => 'button', //(Possible values `link` - `button`)
185+
]);
186+
```
165187

166188
## Table Style Customization
167189
To show more data on your table, you can use the "tight" table style option designed to increase the visual density of your table rows.
@@ -180,7 +202,7 @@ protected function cards()
180202
```
181203
Or override the `$style` property on your custom class:
182204
```php
183-
public $style = 'tight';
205+
$this->style = 'tight';
184206
```
185207

186208
## Using the pagination

dist/js/card.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/components/Card.vue

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
<template>
2-
<div class="overflow-x-auto bg-white dark:bg-gray-800 rounded-lg shadow h-full pt-4">
3-
<h1 v-if="title" class="h-6 flex mb-3 text-sm font-bold px-6">{{ title }}</h1>
2+
<div class="overflow-x-auto bg-white dark:bg-gray-800 rounded-lg shadow h-full">
3+
<div v-if="title || useViewAll"
4+
class="flex items-center justify-between py-3 text-sm px-6">
5+
<h1 v-if="title" class="font-bold">
6+
{{ title }}
7+
</h1>
8+
<div v-if="useViewAll && !viewAllBottomPosition">
9+
<a :class="viewAllUseButton ?
10+
'flex-shrink-0 shadow rounded focus:outline-none ring-primary-200 dark:ring-gray-600 focus:ring bg-primary-500 hover:bg-primary-400 active:bg-primary-600 text-white dark:text-gray-800 inline-flex items-center font-bold px-3 h-8 text-xs' :
11+
'link-default'"
12+
:href="viewAll.link"
13+
>
14+
{{ viewAll.label ?? 'View All' }}
15+
</a>
16+
</div>
17+
</div>
418
<table
519
class="w-full"
6-
:class="card.style"
720
data-testid="resource-table"
821
ref="table"
922
>
@@ -22,10 +35,16 @@
2235
/>
2336
</tbody>
2437
</table>
25-
<div v-if="viewAll && viewAll.label" class="w-full border-t border-gray-200 dark:border-gray-700 rounded-b-lg flex justify-center py-3">
26-
<div>
27-
<a class="text-primary-200 text-xs hover:text-primary-600" :href="viewAll.link">{{ viewAll.label }}</a>
28-
</div>
38+
<div v-if="useViewAll &&viewAllBottomPosition"
39+
class="w-full border-t border-gray-200 dark:border-gray-700 rounded-b-lg flex justify-center py-3"
40+
>
41+
<a :class="viewAllUseButton ?
42+
'flex-shrink-0 shadow rounded focus:outline-none ring-primary-200 dark:ring-gray-600 focus:ring bg-primary-500 hover:bg-primary-400 active:bg-primary-600 text-white dark:text-gray-800 inline-flex items-center font-bold px-3 h-8 text-xs' :
43+
'link-default'"
44+
:href="viewAll.link"
45+
>
46+
{{ viewAll.label ?? 'View All' }}
47+
</a>
2948
</div>
3049

3150
<Pagination v-if="paginator" v-model="paginator" @update-rows="update"></Pagination>
@@ -51,7 +70,7 @@ export default {
5170
rows: [],
5271
header: [],
5372
title: '',
54-
viewAll: false,
73+
viewAll: null,
5574
paginator: null,
5675
}
5776
},
@@ -61,7 +80,7 @@ export default {
6180
},
6281
6382
shouldShowTight() {
64-
return this.card.style === 'table-tight';
83+
return this.card.style === 'tight';
6584
},
6685
6786
/**
@@ -70,19 +89,29 @@ export default {
7089
shouldShowColumnBorders() {
7190
return !! this.card.showBorders;
7291
},
92+
useViewAll() {
93+
return this.viewAll && this.viewAll.link;
94+
},
95+
viewAllUseButton() {
96+
return this.viewAll && this.viewAll.style && this.viewAll.style === 'button';
97+
},
98+
viewAllBottomPosition() {
99+
return this.viewAll && this.viewAll.position && this.viewAll.position === 'bottom';
100+
}
73101
},
74102
methods: {
75103
update(event){
76104
this.rows = event;
77105
}
78106
},
79107
created () {
80-
const {header, rows, title, paginator} = this.card;
108+
const {header, rows, title, paginator, viewAll} = this.card;
81109
82110
this.header = header;
83111
this.title = title;
84112
this.rows = rows;
85113
this.paginator = paginator;
114+
this.viewAll = viewAll;
86115
},
87116
}
88117
</script>

resources/js/components/Pagination.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="bg-20 rounded-b">
2+
<div class="bg-20 border-t border-gray-200 dark:border-gray-700 rounded-b">
33
<pagination-links
44
:is="paginationComponent"
55
:all-matching-resource-count="allMatchingResourceCount"

src/TableCard.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class TableCard extends Card
2727
* @param array $header
2828
* @param array $data
2929
* @param string $title
30-
* @param bool|array $viewAll
30+
* @param array $viewAll
3131
*/
32-
public function __construct(array $header = [], array $data = [], string $title = '', bool $viewAll = false)
32+
public function __construct(array $header = [], array $data = [], string $title = '', array $viewAll = [])
3333
{
3434
parent::__construct();
3535

0 commit comments

Comments
 (0)