-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64feb6f
commit 63f5938
Showing
3 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace Whitecube\BemComponents; | ||
|
||
use Closure; | ||
use Illuminate\View\ComponentAttributeBag; | ||
|
||
class BemComponentAttributeBag extends ComponentAttributeBag | ||
{ | ||
/** | ||
* The BEM macro callback function | ||
*/ | ||
protected Closure $bemResolver; | ||
|
||
/** | ||
* Define the BEM resolver callback. | ||
*/ | ||
public function setBemResolver(Closure $bemResolver): static | ||
{ | ||
$this->bemResolver = $bemResolver; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Resolve the BEM attributes and merge the resulting CSS classes | ||
* in this bag. | ||
*/ | ||
public function resolveBemClasses(string $base, string|array $extraModifiers = []): static | ||
{ | ||
call_user_func($this->bemResolver, $base, $extraModifiers); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Only include the given attribute from the attribute array. | ||
*/ | ||
public function only($keys) | ||
{ | ||
$instance = parent::only($keys); | ||
$instance->setBemResolver($this->bemResolver); | ||
|
||
return $instance; | ||
} | ||
|
||
/** | ||
* Exclude the given attribute from the attribute array. | ||
*/ | ||
public function except($keys) | ||
{ | ||
$instance = parent::except($keys); | ||
$instance->setBemResolver($this->bemResolver); | ||
|
||
return $instance; | ||
} | ||
|
||
/** | ||
* Filter the attributes, returning a bag of attributes that pass the filter. | ||
*/ | ||
public function filter($callback) | ||
{ | ||
$instance = parent::filter($callback); | ||
$instance->setBemResolver($this->bemResolver); | ||
|
||
return $instance; | ||
} | ||
|
||
/** | ||
* Merge additional attributes / values into the attribute bag. | ||
*/ | ||
public function merge(array $attributeDefaults = [], $escape = true) | ||
{ | ||
$instance = parent::merge($attributeDefaults, $escape); | ||
$instance->setBemResolver($this->bemResolver); | ||
|
||
return $instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters