diff --git a/src/Panel/Ui/Button.php b/src/Panel/Ui/Button.php index 563fc52078..59aed69e95 100644 --- a/src/Panel/Ui/Button.php +++ b/src/Panel/Ui/Button.php @@ -35,7 +35,9 @@ public function __construct( public string|array|null $title = null, public string $type = 'button', public string|null $variant = null, + ...$attrs ) { + $this->attrs = $attrs; } public function props(): array diff --git a/src/Panel/Ui/Buttons/ViewButton.php b/src/Panel/Ui/Buttons/ViewButton.php index 121458eb76..1ab1a55e7a 100644 --- a/src/Panel/Ui/Buttons/ViewButton.php +++ b/src/Panel/Ui/Buttons/ViewButton.php @@ -46,7 +46,9 @@ public function __construct( public string|array|null $title = null, public string $type = 'button', public string|null $variant = 'filled', + ...$attrs ) { + $this->attrs = $attrs; } /** diff --git a/src/Panel/Ui/Component.php b/src/Panel/Ui/Component.php index 9cb23748e7..448f14269b 100644 --- a/src/Panel/Ui/Component.php +++ b/src/Panel/Ui/Component.php @@ -20,12 +20,15 @@ abstract class Component { protected string $key; + public array $attrs = []; public function __construct( public string $component, public string|null $class = null, - public string|null $style = null + public string|null $style = null, + ...$attrs ) { + $this->attrs = $attrs; } /** @@ -70,6 +73,7 @@ public function props(): array return [ 'class' => $this->class, 'style' => $this->style, + ...$this->attrs ]; } diff --git a/tests/Panel/Ui/ButtonTest.php b/tests/Panel/Ui/ButtonTest.php index 73d7300a7e..8185bbf408 100644 --- a/tests/Panel/Ui/ButtonTest.php +++ b/tests/Panel/Ui/ButtonTest.php @@ -10,6 +10,24 @@ */ class ButtonTest extends TestCase { + /** + * @covers ::__construct + */ + public function testAttrs() + { + $button = new Button( + text: 'Attrs', + foo: 'bar' + ); + + $this->assertSame([ + 'foo' => 'bar', + 'responsive' => true, + 'text' => 'Attrs', + 'type' => 'button', + ], array_filter($button->props())); + } + /** * @covers ::props */ diff --git a/tests/Panel/Ui/Buttons/ViewButtonTest.php b/tests/Panel/Ui/Buttons/ViewButtonTest.php index 62b18e765c..8f00525b8b 100644 --- a/tests/Panel/Ui/Buttons/ViewButtonTest.php +++ b/tests/Panel/Ui/Buttons/ViewButtonTest.php @@ -19,6 +19,26 @@ public function setUp(): void $this->login(); } + /** + * @covers ::__construct + */ + public function testAttrs() + { + $button = new ViewButton( + text: 'Attrs', + foo: 'bar' + ); + + $this->assertSame([ + 'foo' => 'bar', + 'responsive' => true, + 'size' => 'sm', + 'text' => 'Attrs', + 'type' => 'button', + 'variant' => 'filled' + ], array_filter($button->props())); + } + /** * @covers ::factory */ diff --git a/tests/Panel/Ui/ComponentTest.php b/tests/Panel/Ui/ComponentTest.php index 3e262d375c..b1b06bda7e 100644 --- a/tests/Panel/Ui/ComponentTest.php +++ b/tests/Panel/Ui/ComponentTest.php @@ -15,6 +15,26 @@ class UiComponent extends Component */ class ComponentTest extends TestCase { + /** + * @covers ::__construct + */ + public function testAttrs() + { + $props = [ + 'component' => 'k-text', + 'class' => 'k-test', + 'foo' => 'bar' + ]; + + $component = new UiComponent(...$props); + + $this->assertSame([ + 'class' => 'k-test', + 'style' => null, + 'foo' => 'bar', + ], $component->props()); + } + /** * @covers ::__call */