Skip to content

Develop #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ jobs:
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
token: ${{secrets.GITHUB_TOKEN}}
commit_message: Fix styling
6 changes: 6 additions & 0 deletions resources/views/richtext.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@props([
'hasError' => false,
'value' => '',
'options' => [],
])
<textarea {{ $attributes->merge(['class' => 'textarea'.($hasError ? ' textarea-error' : '')]) }}>{{ $value ?: $slot }}</textarea>
65 changes: 65 additions & 0 deletions src/Components/Richtext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Step2dev\LazyUI\Components;

use Illuminate\Contracts\View\View;
use Illuminate\Support\Js;
use Step2dev\LazyUI\DTO\RichText\QuillOptions;
use Step2dev\LazyUI\LazyComponent;

class Richtext extends LazyComponent
{
public bool $autoFocus = false;
public bool $readonly = false;

public function __construct(public string $placeholder = '', public bool $required = false, public ?QuillOptions $quillOptions = null)
{
$this->placeholder = (string) str($placeholder)->trim()->ucfirst();
$this->quillOptions = $quillOptions ?? QuillOptions::defaults();
$this->autoFocus = false;
$this->readonly = false;
}

public function render(): \Closure|View
{
return function (array $data) {
$attributes = $this->getAttributesFromData($data);
$attributes['required'] = $this->required;
$data['attributes'] = $attributes;
$data['options'] = $this->options();

$color = $this->getColorByAttribute($attributes);
$size = $this->getSizeByAttribute($attributes);

return view('lazy::richtext', $this->mergeData($data, [
'textarea',
//colors
'textarea-bordered' => ! $color || $color === 'bordered' || $color !== 'no-border',
'textarea-ghost' => $color === 'ghost',
'textarea-primary' => $color === 'primary',
'textarea-secondary' => $color === 'secondary',
'textarea-accent' => $color === 'accent',
'textarea-info' => $color === 'info',
'textarea-success' => $color === 'success',
'textarea-warning' => $color === 'warning',
'textarea-error' => $color === 'error',
//sizes
'textarea-lg' => $size === 'lg',
'textarea-md' => $size === 'md',
'textarea-sm' => $size === 'sm',
'textarea-xs' => $size === 'xs',
]))->render();
};
}

public function options(): Js
{
return Js::from([
'autofocus' => $this->autoFocus,
'theme' => $this->quillOptions->theme,
'readOnly' => $this->readonly,
'placeholder' => $this->placeholder,
'toolbar' => $this->quillOptions->getToolbar(),
]);
}
}
2 changes: 1 addition & 1 deletion src/Components/Textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function render(): \Closure|View
return view('lazy::textarea', $this->mergeData($data, [
'textarea',
//colors
'textarea-bordered' => $color === 'bordered',
'textarea-bordered' => ! $color || $color === 'bordered' || $color !== 'no-border',
'textarea-ghost' => $color === 'ghost',
'textarea-primary' => $color === 'primary',
'textarea-secondary' => $color === 'secondary',
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/RichText/QuillOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function make(): self
return new self;
}

public static function defaults(callable $callback = null): ?self
public static function defaults(callable|null $callback = null): ?self
{
if ($callback === null) {
return static::default();
Expand Down