Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
domthomas-dev committed May 18, 2020
0 parents commit ac20a83
Show file tree
Hide file tree
Showing 19 changed files with 889 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.idea
/vendor
/node_modules
package-lock.json
composer.phar
composer.lock
phpunit.xml
.phpunit.result.cache
.DS_Store
Thumbs.db
194 changes: 194 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
#Nova grid system for Laravel Nova

## Install

You can install this package via composer:

```
composer require codenco-dev/nova-grid-system
```

Then, you will need to register the tool within the NovaServiceProvider.php:


```
use CodencoDev\NovaGridSystem\NovaGridSystem;
/**
* Get the tools that should be listed in the Nova sidebar.
*
* @return array
*/
public function tools()
{
return [
//other tools
new NovaGridSystem
];
}
```

## How to use?

This package allows you to define field sizes for detail, update or resource creation pages with tailwind CSS classes.
### Like I want
You can use the `size` method on your field to add a meta property for each page. All Tailwind fluid classes for size can be used.
See https://tailwindcss.com/docs/width/#fluid-width

### Where I want
If you don't want to change the size of fields on each page, you can use methods to filter the effect:

- `sizeOnCreating`
- `sizeOnUpdating`
- `sizeOnForms`
- `sizeOnDetail`

### Stacked or not stacked...
Automatically, with the default configuration, the field labels are stacked.
If you don't want this, you can use the `stacked` method with a parameter value of `false`.
As for previous point, you can do it wherever you want with:

- `stackedOnCreating`
- `stackedOnUpdating`
- `stackedOnForms`
- `stackedOnDetail`

### Damn ! There is a bottom border
On the detail page, Nova automatically remove its lower border for the last field.
In this package, it's not possible to calculate the last field, so you can delete it yourself.
You can use these methods:

- `removeBottomBorderOnCreating`
- `removeBottomBorderOnUpdating`
- `removeBottomBorderOnForms`
- `removeBottomBorderOnDetail`


### Example

This code uses the simplest method of configuration::

```
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Gravatar::make()->maxWidth(50),
Text::make('Name')
->size('w-1/3')
->sortable()
->rules('required', 'max:255'),
Text::make('Email')
->size('w-1/3')
->sortable()
->rules('required', 'email', 'max:254')
->creationRules('unique:users,email')
->updateRules('unique:users,email,{{resourceId}}'),
Password::make('Password')
->size('w-1/3') // Only on forms, because we use onlyOnForms method with
->onlyOnForms()
->creationRules('required', 'string', 'min:8')
->updateRules('nullable', 'string', 'min:8'),
];
}
```

In this previous example, sizes are ok in forms pages but not in detail pages.
This code presents several configurations depending on the context and uses different methods

```
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Gravatar::make()->maxWidth(50),
Text::make('Name')
->sizeOnDetail('w-1/2')
->stackedOnDetail(false)
->sizeOnForms('w-1/3')
->sortable()
->rules('required', 'max:255'),
Text::make('Email')
->sizeOnDetail('w-1/2')
->stackedOnDetail(false)
->sizeOnForms('w-1/3')
->sortable()
->rules('required', 'email', 'max:254')
->creationRules('unique:users,email')
->updateRules('unique:users,email,{{resourceId}}'),
Password::make('Password')
->size('w-1/3') // Only on forms, because we use onlyOnForms method with
->onlyOnForms()
->creationRules('required', 'string', 'min:8')
->updateRules('nullable', 'string', 'min:8'),
Date::make('Created At')
->hideWhenCreating()
->size('w-1/2')
->stacked(false)
->stackedOnForms(true)
->removeBottomBorderOnForms(),
Date::make('Updated At')
->hideWhenCreating()
->size('w-1/2')
->stacked(false)
->stackedOnForms(true)
->removeBottomBorderOnForms(),
Badge::make('Status 1', function () {
return 'info';
})->size('w-1/6')->removeBottomBorder(),
Badge::make('Status 2', function () {
return 'success';
})->size('w-1/6')->removeBottomBorder(),
Badge::make('Status 3', function () {
return 'warning';
})->size('w-1/6')->removeBottomBorder(),
Badge::make('Status 4', function () {
return 'info';
})->size('w-1/6')->removeBottomBorder(),
Badge::make('Status 5', function () {
return 'success';
})->size('w-1/6')->removeBottomBorder(),
Badge::make('Status 6', function () {
return 'warning';
})->size('w-1/6')->removeBottomBorder(),
];
}
```


### Configuration

You can disable each "automatic" feature for each type of page with the `nova-grid-system.php` config file.
To publish it, you can use this command:

```
php artisan vendor:publish --tag="nova-grid-system"
```

## License

The MIT License (MIT). Please see License File for more information.

## About
This package is inspired by a deleted package by Eduardo Geschonke https://github.com/jobcerto
47 changes: 47 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "codenco-dev/nova-grid-system",
"description": "A Laravel Nova tool to have a grid system",
"keywords": [
"laravel",
"nova",
"grid",
"layout"
],
"license": "MIT",
"authors": [
{
"name": "Dominic THOMAS",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"php": ">=7.1.0"
},
"require-dev": {
"orchestra/testbench": "^5.0",
"phpunit/phpunit": "^8.0"
},
"autoload": {
"psr-4": {
"CodencoDev\\NovaGridSystem\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"CodencoDev\\NovaGridSystem\\Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"CodencoDev\\NovaGridSystem\\ToolServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
45 changes: 45 additions & 0 deletions config/nova-grid-system.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Automatism stacked
|--------------------------------------------------------------------------
|
| If true, the size macro put automatically the stacked field attritute to true
|
*/
'nova_grid_system_enabled' => true, //desactive

'stacked_scope' => [ //si true, dès qu'on utilise sizeX cela stacked les labels selon le scope
'creating' => true,
'detail' => true,
'updating' => true,
],
'size_scope' => [
'creating' => true,
'detail' => true,
'updating' => true,
],
'remove_bottom_border_scope' => [
'creating' => true,
'detail' => true,
'updating' => true,
],
'detail' => [
'size' => true, //la size fonctionne en mode detail en utilisant size (si celui d'en dessous est à true : c'est la merde ici) ou sizeOnDetails
'remove_bottom_border' => true, //on peut supprimer les bottomBorder sur détail
'stacked' => true, //on peut utiliser la methode sur le detail
],
'creating' => [
'size' => true,
'remove_bottom_border' => true,
'stacked' => true,
],
'updating' => [
'size' => true,
'remove_bottom_border' => true,
'stacked' => true,
]
];
Empty file added dist/css/tool.css
Empty file.
1 change: 1 addition & 0 deletions dist/js/tool.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"/js/tool.js": "/js/tool.js?id=bcd7e6a6a2ff074dbf60",
"/css/tool.css": "/css/tool.css?id=d41d8cd98f00b204e980"
}
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"cross-env": "^5.0.0",
"laravel-mix": "^1.0"
},
"dependencies": {
"vue": "^2.5.0",
"laravel-nova": "^1.2.2"
}
}
22 changes: 22 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="CodeNCO Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
Loading

0 comments on commit ac20a83

Please sign in to comment.