Skip to content

Commit

Permalink
Merge pull request #15 from 8fold/forms
Browse files Browse the repository at this point in the history
Add page title
  • Loading branch information
joshbruce authored Apr 21, 2023
2 parents 7ab381a + c3f6aa4 commit 84d1172
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 45 deletions.
70 changes: 37 additions & 33 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@
colors="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">./src/</directory>
</include>
<exclude>
<directory>vendor/</directory>
</exclude>
</coverage>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" backupStaticProperties="false">
<coverage/>
<testsuites>
<testsuite name="base">
<directory suffix="Test.php">./tests/</directory>
Expand All @@ -25,4 +17,12 @@
<ini name="display_errors" value="On"/>
<ini name="display_startup_errors" value="On"/>
</php>
<source>
<include>
<directory suffix=".php">./src/</directory>
</include>
<exclude>
<directory>vendor/</directory>
</exclude>
</source>
</phpunit>
35 changes: 35 additions & 0 deletions src/Components/PageTitle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);

namespace Eightfold\HTMLBuilder\Components;

use Stringable;

use Eightfold\HTMLBuilder\Element;

class PageTitle implements Stringable
{
/**
* @param string[] $titles
*/
public static function create(array $titles, string $separator = ' | '): self
{
return new self($titles, $separator);
}

/**
* @param string[] $titles
*/
final private function __construct(
private array $titles,
private readonly string $separator
) {
}

public function __toString(): string
{
return (string) Element::title(
implode($this->separator, $this->titles)
);
}
}
4 changes: 2 additions & 2 deletions src/Forms/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private function selectDropdown(): Element
{
$elements = [];
foreach ($this->options as $value => $content) {
$value = strval($value);
$value = (string) $value;
$option = Element::option($content)->props('value ' . $value);
if ($this->isSelected($value)) {
$option = $option->prop('selected selected');
Expand All @@ -151,7 +151,7 @@ private function selectOther(): Element
$type = 'checkbox';
}
foreach ($this->options as $value => $content) {
$value = strval($value);
$value = (string) $value;
$id = $this->name . '-' . $value;
$label = Element::label($content)->props('for ' . $id);
$input = Element::input()->omitEndTag()->props(
Expand Down

0 comments on commit 84d1172

Please sign in to comment.