-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update core components
- Loading branch information
Showing
6 changed files
with
491 additions
and
138 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
## Description | ||
The `krait-ui` DynamicTable component represents the table data on front-end. | ||
|
||
## Example | ||
|
||
```html | ||
<script setup> | ||
defineProps({ | ||
'filtersForm': { | ||
type: String, | ||
required: false, | ||
default: undefined, | ||
} | ||
}); | ||
</script> | ||
|
||
<template> | ||
<DynamicTable | ||
apiEndpoint="users-table" | ||
tableName="users-table" | ||
:filtersForm="filtersForm" | ||
> | ||
<template #row="{ record, column }"> | ||
<div class="cell" v-if="column.name === 'my_first_column'"> | ||
Krait is awesome! | ||
</div> | ||
<div class="cell" v-else> | ||
{{ record[column.name] ?? 'N/A' }} | ||
</div> | ||
</template> | ||
</DynamicTable> | ||
</template> | ||
|
||
<style scoped lang="scss"></style> | ||
``` | ||
|
||
## Highlights | ||
|
||
### Slots Usage | ||
The `DynamicTable` component uses slots to provide an easy way to manipulate the front-end data. | ||
|
||
```html | ||
<template #row="{ record, column }"> | ||
<div class="cell" v-if="column.name === 'my_first_column'"> | ||
Krait is awesome! | ||
</div> | ||
<div class="cell" v-else> | ||
{{ record[column.name] ?? 'N/A' }} | ||
</div> | ||
</template> | ||
``` | ||
|
||
- The `record` object contains the record values for all columns | ||
- The `column` object contains all column properties (`name`, `fixed`, `label`, etc.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
## Description | ||
|
||
All columns are internally represented by the [`TableColumnDTO`](https://github.com/mtrdesign/krait/blob/main/krait/src/DTO/TableColumnDTO.php) class. We define the columns | ||
inside our Table Definition Classes using the `column` method. Here is the list of all parameters that can be assigned to specific column. | ||
|
||
|
||
|
||
```php | ||
<?php | ||
protected column( | ||
string $name, | ||
string $label, | ||
bool $hideLabel = false, | ||
bool $datetime = false, | ||
bool $sortable = true, | ||
bool $fixed = false, | ||
string|null $classes = null, | ||
callable|null $process = null, | ||
callable|null $sort = null | ||
): void | ||
``` | ||
|
||
**Parameters:** | ||
|
||
| Parameter | Type | Description | | ||
|-------------|------------------------|-----------------------------------------------------| | ||
| `name` | **string** | The columns name | | ||
| `label` | **string** | The columns label | | ||
| `hideLabel` | **bool** | Flags if the label should be visible in the header. | | ||
| `datetime` | **bool** | Flags if the column contains datetime object. | | ||
| `sortable` | **bool** | Flags if the column is sortable. | | ||
| `fixed` | **bool** | Flags if the column is resizable. | | ||
| `classes` | **string|null** | Additional classes that will be added on FE. | | ||
| `process` | **callable|null** | The column result generation callback. | | ||
| `sort` | **callable|null** | The column sorting callback. | | ||
|
||
|
||
## TableColumnDTO Description | ||
|
||
DTO Object for handling consistent column generation. | ||
|
||
* Full name: `\MtrDesign\Krait\DTO\TableColumnDTO` | ||
|
||
## TableColumnDTO Methods | ||
|
||
### __construct | ||
|
||
```php | ||
public __construct( | ||
string $name, | ||
string $label, | ||
bool $hideLabel = false, | ||
bool $datetime = false, | ||
bool $sortable = true, | ||
bool $fixed = false, | ||
string|null $classes = null, | ||
callable|null $process = null, | ||
callable|null $sort = null | ||
): mixed | ||
``` | ||
|
||
**Parameters:** | ||
|
||
| Parameter | Type | Description | | ||
|--------------|------------------------|------------------------------------------------------| | ||
| `$name` | **string** | - The column name. | | ||
| `$label` | **string** | - The column label. | | ||
| `$hideLabel` | **bool** | - Flags if the label should be visible. | | ||
| `$datetime` | **bool** | - Flags if the column contains datetime information. | | ||
| `$sortable` | **bool** | - Flags if the column is sortable. | | ||
| `$fixed` | **bool** | - Flags if the column is resizable. | | ||
| `$classes` | **string|null** | - Sets FE style classes. | | ||
| `$process` | **callable|null** | - Sets the result processing callback. | | ||
| `$sort` | **callable|null** | - Sets the records sorting callback. | | ||
|
||
*** | ||
|
||
### process | ||
|
||
Processes one record. | ||
|
||
```php | ||
public process(mixed $model): mixed | ||
``` | ||
|
||
**Parameters:** | ||
|
||
| Parameter | Type | Description | | ||
|------------|-------------|--------------------------| | ||
| `$model` | **mixed** | the target resource data | | ||
|
||
*** | ||
|
||
### sort | ||
|
||
Sorts records. | ||
|
||
```php | ||
public sort(mixed $records, string $direction): mixed | ||
``` | ||
|
||
**Parameters:** | ||
|
||
| Parameter | Type | Description | | ||
|--------------|-------------|--------------------------| | ||
| `$records` | **mixed** | - The records. | | ||
| `$direction` | **string** | - The sorting direction. | | ||
|
||
*** | ||
|
||
### hasProcessingCallback | ||
|
||
Flags if the column has processing callback assigned. | ||
|
||
```php | ||
public hasProcessingCallback(): bool | ||
``` | ||
|
||
*** | ||
|
||
### toArray | ||
|
||
Returns the column represented as array. | ||
|
||
```php | ||
public toArray(): array | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## Description | ||
|
||
All table-related controllers are created in the `app/Http/Controllers/Tables` directory. | ||
These controllers are invokable and have only one purpose - to fetch the table data and pass it to the . | ||
`Table Definition Class`. | ||
|
||
```php | ||
<?php | ||
|
||
namespace App\Http\Controllers\Tables; | ||
|
||
use App\Tables\MyAwesomeTable; | ||
use MtrDesign\Krait\Http\Resources\TableCollection; | ||
|
||
class MyAwesomeTableController extends Controller | ||
{ | ||
public function __invoke(): TableCollection | ||
{ | ||
$records = [['my_first_column' => 'foo']]; | ||
|
||
/** | ||
* Here you might fetch/manipulate the data. | ||
*/ | ||
|
||
return MyAwesomeTable::from($records); | ||
} | ||
} | ||
``` | ||
|
||
## Methods | ||
|
||
*** | ||
|
||
### __invoke | ||
|
||
Processes the incoming front-end request. | ||
|
||
```php | ||
public invoke(): MtrDesign\Krait\Http\Resources\TableCollection | ||
``` |
Oops, something went wrong.