Skip to content

Commit

Permalink
Merge pull request #23 from Yuq140/master
Browse files Browse the repository at this point in the history
Rename compact function to compactTheme
  • Loading branch information
p-jrv authored Jun 30, 2023
2 parents 289cd4c + 790178b commit f94ad56
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function fields(Request $request) {

### Themes

Available themes: `chrome, compact, grayscale, material, photoshop, sketch, slider, swatches, twitter`.
Available themes: `chrome, compactTheme, grayscale, material, photoshop, sketch, slider, swatches, twitter`.

See the theme demos [here](http://xiaokaike.github.io/vue-color/).

Expand Down Expand Up @@ -76,7 +76,7 @@ Adding custom pallette colors to the pickers can be done like so:

```php
Color::make('Color')
->compact()
->compactTheme()
->palette(['#beaf00', '#DEADAF', '#000']),
```

Expand Down
23 changes: 16 additions & 7 deletions src/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Exception;
use Laravel\Nova\Fields\Field;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Fields\SupportsDependentFields;
use Laravel\Nova\Http\Requests\NovaRequest;

class Color extends Field
{
Expand Down Expand Up @@ -48,7 +48,7 @@ public function twitter()
return $this->pickerType('twitter');
}

public function compact()
public function compactTheme()
{
return $this->pickerType('compact');
}
Expand Down Expand Up @@ -90,15 +90,21 @@ public function hidePicker()

public function saveAs($saveAs = 'hex')
{
if (!in_array($saveAs, ['rgb', 'rgba', 'hex', 'hex8', 'hsl'])) throw new Exception("Invalid saveAs option provided [$saveAs].");
$saveAs = ($saveAs === "rgba") ? "rgb" : $saveAs;
if (! in_array($saveAs, ['rgb', 'rgba', 'hex', 'hex8', 'hsl'])) {
throw new Exception("Invalid saveAs option provided [{$saveAs}].");
}
$saveAs = ($saveAs === 'rgba') ? 'rgb' : $saveAs;

return $this->withMeta(['saveAs' => $saveAs]);
}

public function displayAs($displayAs = 'hex')
{
if (!in_array($displayAs, ['rgb', 'rgba', 'hex', 'hex8', 'hsl'])) throw new Exception("Invalid displayAs option provided [$displayAs].");
$displayAs = ($displayAs === "rgba") ? "rgb" : $displayAs;
if (! in_array($displayAs, ['rgb', 'rgba', 'hex', 'hex8', 'hsl'])) {
throw new Exception("Invalid displayAs option provided [{$displayAs}].");
}
$displayAs = ($displayAs === 'rgba') ? 'rgb' : $displayAs;

return $this->withMeta(['displayAs' => $displayAs]);
}

Expand All @@ -108,7 +114,10 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib
// Try to turn into array
$value = $request[$requestAttribute];
$arrayValue = json_decode($value, true);
if (!empty($arrayValue)) $value = $arrayValue;

if (! empty($arrayValue)) {
$value = $arrayValue;
}

$model->{$attribute} = $this->isNullValue($value) ? null : $value;
}
Expand Down

0 comments on commit f94ad56

Please sign in to comment.