Skip to content

Commit

Permalink
Refactor TailwindClassMergeServiceProvider to use updated component a…
Browse files Browse the repository at this point in the history
…ttribute prefix
  • Loading branch information
mr-chetan committed Apr 30, 2024
1 parent 1667244 commit 10b4f4b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/TailwindClassMergeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,20 @@ protected function registerAttributesBagMacros(): void
});

ComponentAttributeBag::macro('forAttributes', function (string $for): ComponentAttributeBag {
$prefix = (string) config('tailwind-class-merge.attribute_prefix', 'component:'); // @phpstan-ignore-line
$prefix = Str::finish($prefix, ':');
$prefixFor = $for . ':';

if (! Str::of($for)->startsWith($prefix)) {
$prefixFor = Str::finish($prefix . $for, ':');
}

$attrBag = new ComponentAttributeBag;
$forAttributes = [];

/** @var ComponentAttributeBag $this */
foreach ($this->getAttributes() as $key => $value) { // @phpstan-ignore-line
if (Str::of($key)->contains($for . ':')) {
if (Str::of($key)->startsWith($prefixFor)) {
$attributes = Str::of($key)->after($for . ':')->__toString();
$forAttributes[] = $attributes;

Expand Down

0 comments on commit 10b4f4b

Please sign in to comment.