-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] Blade component slot attributes (#38372)
* Update slot pattern * Add attributes params to existing tests * Create ComponentSlot class * Pass attributes from slot tag to Blade directive * Compile slot attributes into slot object * Add compilation tests for attribute support * Remove unused exception * Reorder arguments * Fix dynamic components with slot attributes * Escape bound attributes for slots * Update BladeComponentTagCompilerTest.php * formattinG Co-authored-by: Taylor Otwell <taylorotwell@gmail.com>
- Loading branch information
1 parent
ed4f354
commit b75a01f
Showing
7 changed files
with
163 additions
and
18 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,89 @@ | ||
<?php | ||
|
||
namespace Illuminate\View; | ||
|
||
use Illuminate\Contracts\Support\Htmlable; | ||
|
||
class ComponentSlot implements Htmlable | ||
{ | ||
/** | ||
* The slot attribute bag. | ||
* | ||
* @var \Illuminate\View\ComponentAttributeBag | ||
*/ | ||
public $attributes; | ||
|
||
/** | ||
* The slot contents. | ||
* | ||
* @var string | ||
*/ | ||
protected $contents; | ||
|
||
/** | ||
* Create a new slot instance. | ||
* | ||
* @param string $contents | ||
* @param array $attributes | ||
* @return void | ||
*/ | ||
public function __construct($contents = '', $attributes = []) | ||
{ | ||
$this->contents = $contents; | ||
|
||
$this->withAttributes($attributes); | ||
} | ||
|
||
/** | ||
* Set the extra attributes that the slot should make available. | ||
* | ||
* @param array $attributes | ||
* @return $this | ||
*/ | ||
public function withAttributes(array $attributes) | ||
{ | ||
$this->attributes = new ComponentAttributeBag($attributes); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the slot's HTML string. | ||
* | ||
* @return string | ||
*/ | ||
public function toHtml() | ||
{ | ||
return $this->contents; | ||
} | ||
|
||
/** | ||
* Determine if the slot is empty. | ||
* | ||
* @return bool | ||
*/ | ||
public function isEmpty() | ||
{ | ||
return $this->contents === ''; | ||
} | ||
|
||
/** | ||
* Determine if the slot is not empty. | ||
* | ||
* @return bool | ||
*/ | ||
public function isNotEmpty() | ||
{ | ||
return ! $this->isEmpty(); | ||
} | ||
|
||
/** | ||
* Get the slot's HTML string. | ||
* | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return $this->toHtml(); | ||
} | ||
} |
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
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
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
@danharrin @driesvints I think in this line is the problem of #38542