-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
feat(BelongsToMany): add ability to set custom color for badge in inLine format #1090
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Может быть есть смысл сделать цвет через замыкание? Тогда мы сможем изменять цвет каждого badge. Или сам badge через замыкание, чтоб не было много параметров
Еще как вариант передавать компонент Badge (тоже через closure) но не уверен |
…pe of the $badge variable and added support for the Badge component
@DissNik убрал параметр, добавил замыкание и возможность передачи компонента Badge, сохранил логику работы при BelongsToMany::make('Label name', 'relationName', formatted: 'name', resource: new TestResource())
->inline(" ", badge: function($model, $value) {
return Badge::make($value, 'green');
}), |
@@ -70,7 +70,7 @@ class BelongsToMany extends ModelRelationField implements | |||
|
|||
protected string $inLineSeparator = ''; | |||
|
|||
protected bool $inLineBadge = false; | |||
protected Closure|bool|null $badgeCallback = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected Closure|bool|null $badgeCallback = null; | |
protected Closure|bool $inLineBadge = false; |
а зачем нужен null? и я бы оставил название
@@ -100,11 +100,11 @@ public function onlyCount(): static | |||
return $this; | |||
} | |||
|
|||
public function inLine(string $separator = '', bool $badge = false, ?Closure $link = null): static | |||
public function inLine(string $separator = '', Closure|bool $badge = null, ?Closure $link = null): static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
вы указали что badge может быть или Closure или bool, но присвоили null
public function inLine(string $separator = '', Closure|bool $badge = null, ?Closure $link = null): static | |
public function inLine(string $separator = '', Closure|bool $badge = false, ?Closure $link = null): static |
{ | ||
$this->inLine = true; | ||
$this->inLineSeparator = $separator; | ||
$this->inLineBadge = $badge; | ||
$this->badgeCallback = $badge; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->badgeCallback = $badge; | |
$this->inLineBadge = $badge; |
return Badge::make((string) $value, 'primary') | ||
->customAttributes(['class' => 'm-1']) | ||
->render(); | ||
if ($this->badgeCallback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я бы сделал что-то такое, но нужно подумать
if ($this->inLineBadge) {
$badgeValue = value($this->inLineBadge, $item, $value, $this);
$badge = $badgeValue instanceof Badge
? $badgeValue
: Badge::make((string) $value, 'primary');
return $badge->customAttributes(['class' => 'm-1'])->render();
}
…d the logic of the badge to a ternary
@DissNik поправил, с учётом ваших комментариев. |
@@ -418,9 +418,13 @@ protected function resolvePreview(): View|string | |||
} | |||
|
|||
if ($this->inLineBadge) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не очень понятная проверка, лучше сделать value до этого if а потом проверить на false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
да, тут value нужно до if, т.к. в замыкании мы можем вернуть false
…d show Badge if Closure has Badge
->render(); | ||
$badgeValue = value($this->inLineBadge, $item, (string) $value, $this); | ||
|
||
if ($badgeValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
если я правильно понял, Данил предложил сделать такую проверку
if ($badgeValue) { | |
if ($badgeValue !== false) { |
return Badge::make((string) $value, 'primary') | ||
->customAttributes(['class' => 'm-1']) | ||
->render(); | ||
$badgeValue = value($this->inLineBadge, $item, (string) $value, $this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
зачем здесь value приводить к строке?
…, corrected the $badgeValue check
a196fee
to
8749849
Compare
Пожалуйста, измените описание, чтоб оно соответствовало итоговому решению. Документацию сможете поправить? |
Описание поменял. В документацию внесу изменения. |
Для поля BelongsToMany в сахар
->inline()
добавил возможность в качестве badge передавать компонентBadge
.Теперь при наличии нескольких полей BelongsToMany на индексной странице есть возможность указать цвет, отличный от primary.