Skip to content

Commit

Permalink
[9.x] Support kebab case for slot name shortcut (#42574)
Browse files Browse the repository at this point in the history
* Support kebab case for slot names

The inline slot name shortcut was added in laravel 9 but it does not comply with the blade component kebab case naming convention (for when the slot name has more than 1 word). This edit will will make the feature fit intuitively with the blade component naming conventions.

* Matches catpture group increment

A new capture group was added in order to support kebab case so the check for the existence of the dynamic component should be increased by 1

* pattern should have been a non-capturing group

the pattern should have been a non capturing group instead of incrementing the index for matches.

* kebab-cased slot names are converted to camelCase rather than snake_case

* fix code style issue
  • Loading branch information
Waghabond authored May 31, 2022
1 parent 34be11b commit dea48b6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Compilers/ComponentTagCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public function compileSlots(string $value)
<
\s*
x[\-\:]slot
(?:\:(?<inlineName>\w+))?
(?:\:(?<inlineName>\w+(?:-\w+)*))?
(?:\s+(:?)name=(?<name>(\"[^\"]+\"|\\\'[^\\\']+\\\'|[^\s>]+)))?
(?<attributes>
(?:
Expand Down Expand Up @@ -460,6 +460,10 @@ public function compileSlots(string $value)
$value = preg_replace_callback($pattern, function ($matches) {
$name = $this->stripQuotes($matches['inlineName'] ?: $matches['name']);

if (Str::contains($name, '-')) {
$name = Str::camel($name);
}

if ($matches[2] !== ':') {
$name = "'{$name}'";
}
Expand Down

0 comments on commit dea48b6

Please sign in to comment.