Skip to content

Commit fef44f0

Browse files
committed
Initial commit
0 parents  commit fef44f0

23 files changed

+822
-0
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
root = true
2+
3+
[{*.vue, *.js}]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 4
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
ij_javascript_imports_wrap = off
11+
ij_continuation_indent_size = 4
12+
ij_vue_indent_children_of_top_level = script, template, style
13+
14+
[*.php]
15+
charset = utf-8
16+
end_of_line = lf
17+
insert_final_newline = true
18+
indent_style = space
19+
indent_size = 4
20+
trim_trailing_whitespace = true

.github/assets/screenshot1.png

37 KB
Loading

.github/assets/screenshot2.png

29.6 KB
Loading

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/.idea
2+
/vendor
3+
/node_modules
4+
package-lock.json
5+
composer.phar
6+
composer.lock
7+
phpunit.xml
8+
.phpunit.result.cache
9+
.DS_Store
10+
Thumbs.db

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 pavloniym
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Nova Action Buttons
2+
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/pavloniym/nova-action-buttons?style=flat-square)](https://packagist.org/packages/pavloniym/nova-action-buttons)
4+
![Licence](https://img.shields.io/github/license/pavloniym/nova-action-buttons?style=flat-square)
5+
[![Total Downloads](https://poser.pugx.org/pavloniym/nova-action-buttons/downloads?format=flat-square)](https://packagist.org/packages/pavloniym/nova-action-buttons)
6+
7+
This [Laravel Nova](https://nova.laravel.com) package allows you to execute an action directly on your resource table
8+
view.
9+
10+
11+
## Requirements
12+
13+
- `php: >=8.0`
14+
- `laravel/nova: ^4.1`
15+
16+
## Installation
17+
18+
Install the package in a Laravel Nova project via Composer:
19+
20+
```bash
21+
composer require pavloniym/nova-action-buttons
22+
```
23+
24+
## Usage
25+
26+
### Single button
27+
![Nova Action Buttons](https://raw.githubusercontent.com/pavloniym/nova-action-buttons/main/.github/assets/screenshot1.png)
28+
You can add single button to execute action from index row
29+
30+
```php
31+
use Pavloniym\ActionButtons\ActionButton;
32+
33+
public function fields(Request $request)
34+
{
35+
return [
36+
37+
// ... Nova default fields
38+
39+
ActionButton::make('') // Name in resource table column
40+
->icon('<svg></svg>') // Svg icon (optional)
41+
->title('Refresh') // Title (optional)
42+
->styles([]) // Custom css styles (optional)
43+
->classes([]) // Custom css classes (optional)
44+
->action(new RefreshAction, $this->resource->id) // Provide action instance and resource id
45+
->asToolbarButton(), // Display as row toolbar button (optional)
46+
47+
// ... Nova default fields
48+
];
49+
}
50+
```
51+
52+
### Collection of buttons
53+
![Nova Action Buttons](https://raw.githubusercontent.com/pavloniym/nova-action-buttons/main/.github/assets/screenshot2.png)
54+
You can add collection of buttons to index row
55+
56+
57+
```php
58+
use Pavloniym\ActionButtons\ActionButton;
59+
60+
public function fields(Request $request)
61+
{
62+
return [
63+
64+
// ... Nova default fields
65+
66+
ActionButtons::make()->collection([
67+
ActionButton::make('')->action(),
68+
ActionButton::make('')->action(),
69+
ActionButton::make('')->action(),
70+
])
71+
72+
// ... Nova default fields
73+
];
74+
}
75+
```
76+
77+
## Caveats
78+
* Currently, in order to use this field, you still have to declare the action in your resource `actions()` method.
79+
* Tested only on `confirm-action-modal` action
80+
* You should provide action instance in `action()` method of button.
81+
* If you have action fields that are depends on resource instance -> you should inject resource in action constructor, because Nova doesn't provide `NovaRequest` instance to `fields` method on index row
82+
83+
```php
84+
class RefreshAction extends Action
85+
{
86+
87+
private Torrent $torrent
88+
89+
/**
90+
* @param Torrent $torrent
91+
*/
92+
public function __construct(Torrent $torrent)
93+
{
94+
$this->torrent = $torrent;
95+
}
96+
97+
98+
99+
/**
100+
* Get the fields available on the action.
101+
*
102+
* @param NovaRequest $request
103+
* @return array|null
104+
*/
105+
public function fields(NovaRequest $request): ?array
106+
{
107+
108+
// $request is empty if action is called from index row (or inline)
109+
// so use instance injected to action constructor
110+
$torrent = (fn(): ?Torrent => $request?->selectedResources()?->first())();
111+
$torrent = $torrent ?? $this->torrent;
112+
113+
if ($torrent) {
114+
return [
115+
File::make('File')->creationRules(['required'])
116+
];
117+
}
118+
119+
return null;
120+
}
121+
122+
}
123+
124+
```
125+
126+
## License
127+
128+
This project is open-sourced software licensed under the [MIT license](LICENSE.md).

composer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "pavloniym/nova-action-buttons",
3+
"description": "A Laravel Nova field.",
4+
"keywords": [
5+
"laravel",
6+
"nova",
7+
"actions",
8+
"buttons"
9+
],
10+
"license": "MIT",
11+
"require": {
12+
"php": "^7.3|^8.0"
13+
},
14+
"autoload": {
15+
"psr-4": {
16+
"Pavloniym\\ActionButtons\\": "src/"
17+
}
18+
},
19+
"extra": {
20+
"laravel": {
21+
"providers": [
22+
"Pavloniym\\ActionButtons\\FieldServiceProvider"
23+
]
24+
}
25+
},
26+
"config": {
27+
"sort-packages": true
28+
},
29+
"minimum-stability": "dev",
30+
"prefer-stable": true
31+
}

dist/css/field.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

dist/js/field.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/field.js.LICENSE.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*!
2+
* The buffer module from node.js, for the browser.
3+
*
4+
* @author Feross Aboukhadijeh <http://feross.org>
5+
* @license MIT
6+
*/
7+
8+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
9+
10+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

0 commit comments

Comments
 (0)