From ead266cd50281b43cf094548010b8fded7ab94cc Mon Sep 17 00:00:00 2001 From: Josh Bruce Date: Sun, 4 Oct 2026 11:57:24 -0400 Subject: [PATCH] add: HTML props --- src/Document.php | 13 +++++++++++- tests/DocumentBaselineTest.php | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/Document.php b/src/Document.php index 30bef31..36363a0 100644 --- a/src/Document.php +++ b/src/Document.php @@ -9,6 +9,11 @@ class Document implements Stringable { + /** + * @var array + */ + private array $htmlProps = []; + /** * @var array */ @@ -39,6 +44,12 @@ final private function __construct( ) { } + public function htmlProps(string ...$props): Document + { + $this->htmlProps = $props; + return $this; + } + public function head(string|Stringable ...$content): Document { $this->head = $content; @@ -75,7 +86,7 @@ public function toString(): string ...$this->headContent() ), Element::body(...$this->bodyContent())->props(...$this->bodyProps) - )->props($this->lang()); + )->props($this->lang(), ...$this->htmlProps); return $doctype . $html; } diff --git a/tests/DocumentBaselineTest.php b/tests/DocumentBaselineTest.php index c950969..9b0c59d 100644 --- a/tests/DocumentBaselineTest.php +++ b/tests/DocumentBaselineTest.php @@ -14,6 +14,43 @@ class DocumentBaselineTest extends TestCase { + #[Test] + public function adding_lang_to_html_props_overrides_create(): void // phpcs:ignore + { + $expected = << + Second | First + html; + + $result = (string) Document::create( + PageTitle::create(['Second', 'First']), + 'en-us' + )->htmlProps('class dark-theme', 'lang fr'); + + $this->assertSame( + $expected, + $result + ); + } + + #[Test] + public function can_add_properties_to_html_element(): void // phpcs:ignore + { + $expected = << + Second | First + html; + + $result = (string) Document::create( + PageTitle::create(['Second', 'First']) + )->htmlProps('class dark-theme'); + + $this->assertSame( + $expected, + $result + ); + } + #[Test] public function can_add_properties_to_body_element(): void // phpcs:ignore {