Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
{
"name": "arcanedev/php-html",
"name": "arcanedev/php-html",
"description": "A simple way to create html tags with php.",
"homepage": "https://github.com/ARCANEDEV/php-html",
"keywords": ["arcanedev", "html", "form", "tags"],
"authors": [
"homepage": "https://github.com/ARCANEDEV/php-html",
"keywords": [
"arcanedev",
"html",
"form",
"tags"
],
"authors": [
{
"name": "ARCANEDEV",
"email": "[email protected]",
"name": "ARCANEDEV",
"email": "[email protected]",
"homepage": "https://github.com/arcanedev-maroc",
"role": "Developer"
"role": "Developer"
}
],
"type": "library",
"type": "library",
"license": "MIT",
"require": {
"php": "^8.2",
"illuminate/support": "^11.0"
"illuminate/support": "^11.0|^12.0"
},
"require-dev": {
"ext-dom": "*",
Expand Down
4 changes: 2 additions & 2 deletions src/Contracts/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function number(
mixed $value = null,
mixed $min = null,
mixed $max = null,
mixed $step = null
mixed $step = null,
): Input;

/**
Expand Down Expand Up @@ -175,7 +175,7 @@ public function range(
mixed $value = null,
mixed $min = null,
mixed $max = null,
mixed $step = null
mixed $step = null,
): Input;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Elements/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function forgetAttribute(string $name): static
/**
* Get an attribute.
*
* @return \Arcanedev\Html\Entities\Attributes\MiscAttribute|mixed
* @return Attributes\MiscAttribute|mixed
*/
public function getAttribute(string $name, mixed $default = null): mixed
{
Expand Down
2 changes: 1 addition & 1 deletion src/Elements/Concerns/HasChildElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function addChild(mixed $child, Closure|array|null $mapper = null): stati

return tap(clone $this, function (HtmlElement $elt) use ($child, $mapper): void {
$elt->setChildren(
$elt->getChildren()->merge(ChildrenCollection::parse($child, $mapper))
$elt->getChildren()->merge(ChildrenCollection::parse($child, $mapper)),
);
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/Elements/Dl.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Dl extends HtmlElement
public function dt(mixed $value, array $attributes = []): static
{
return $this->addChild(
$this->makeTerm($value, $attributes)
$this->makeTerm($value, $attributes),
);
}

Expand All @@ -45,7 +45,7 @@ public function dt(mixed $value, array $attributes = []): static
public function dd(mixed $value, array $attributes = []): static
{
return $this->addChild(
$this->makeDefinition($value, $attributes)
$this->makeDefinition($value, $attributes),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Elements/Fieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Fieldset extends HtmlElement
public function legend(mixed $content): static
{
return $this->prependChild(
Legend::make()->text($content)
Legend::make()->text($content),
);
}
}
8 changes: 4 additions & 4 deletions src/Elements/HtmlElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function style(array|string $style): static
$style = implode('; ', array_map(
fn($value, $attribute) => "{$attribute}: {$value}",
$style,
array_keys($style)
array_keys($style),
));
}

Expand All @@ -183,7 +183,7 @@ public function data(array|string $name, mixed $value = null): static
{
return $this->attributes(
Collection::make(is_array($name) ? $name : [$name => $value])
->mapWithKeys(fn($mapValue, $mapKey) => ["data-{$mapKey}" => $mapValue])
->mapWithKeys(fn($mapValue, $mapKey) => ["data-{$mapKey}" => $mapValue]),
);
}

Expand Down Expand Up @@ -223,7 +223,7 @@ public function open(): HtmlString
: "<{$this->getTag()}>";

return new HtmlString(
$html . $this->getChildren()->toHtml()
$html . $this->getChildren()->toHtml(),
);
}

Expand All @@ -233,7 +233,7 @@ public function open(): HtmlString
public function close(): HtmlString
{
return new HtmlString(
$this->isVoidElement() ? '' : "</{$this->getTag()}>"
$this->isVoidElement() ? '' : "</{$this->getTag()}>",
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Elements/ListElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function items(iterable $items, array $attributes = []): static
{
return $this->children($items, fn($value) => $this->makeItem(
is_array($value) ? static::make()->items($value) : $value, // Create nested items if the value is array
$attributes
$attributes,
));
}
}
16 changes: 8 additions & 8 deletions src/Elements/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function multiple(): static

return $elt->if(
$name && ! Str::endsWith($name->value(), '[]'),
fn(self $elt) => $elt->name($name->value() . '[]')
fn(self $elt) => $elt->name($name->value() . '[]'),
)->applyValueToOptions();
}

Expand All @@ -74,7 +74,7 @@ public function options(iterable $options, array $attributes = [], array $groupA
$options,
fn($text, $value) => is_array($text) || $text instanceof Collection
? $this->makeOptionsGroup($value, $text, $attributes, $groupAttributes[$value] ?? [])
: $this->makeOption($value, $text, $attributes[$value] ?? [])
: $this->makeOption($value, $text, $attributes[$value] ?? []),
);
}

Expand All @@ -88,7 +88,7 @@ public function placeholder(string $text, mixed $value = null, bool $disabled =
return $this->prependChild(
$this->makeOption($value, $text)
->selectedUnless($this->hasSelection())
->disabled($disabled)
->disabled($disabled),
);
}

Expand Down Expand Up @@ -116,7 +116,7 @@ protected static function applyValueToElements(Collection $value, Collection $ch

if ($child instanceof Selectable) {
return $child->selectedIf(
$value->contains($child->getAttribute('value')->value())
$value->contains($child->getAttribute('value')->value()),
);
}

Expand All @@ -135,7 +135,7 @@ protected static function applyValueToElements(Collection $value, Collection $ch
protected function hasSelection(): bool
{
return $this->getChildren()->contains(
fn(HtmlElement $child) => $child->hasAttribute('selected')
fn(HtmlElement $child) => $child->hasAttribute('selected'),
);
}

Expand All @@ -158,14 +158,14 @@ protected function makeOptionsGroup(
string $label,
array $options,
array $attributes = [],
array $groupAttributes = []
array $groupAttributes = [],
): Optgroup {
return Optgroup::make()
->label($label)
->attributes($groupAttributes)
->children(
$options,
fn($optionText, $optionValue) => $this->makeOption($optionValue, $optionText, $attributes[$optionValue] ?? [])
fn($optionText, $optionValue) => $this->makeOption($optionValue, $optionText, $attributes[$optionValue] ?? []),
);
}

Expand All @@ -183,7 +183,7 @@ protected function applyValueToOptions(): static
}

return $this->setNewChildren(
static::applyValueToElements($value, $this->getChildren())
static::applyValueToElements($value, $this->getChildren()),
);
}
}
4 changes: 2 additions & 2 deletions src/Entities/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function render(): string

return implode(' ', array_map(
fn(AbstractAttribute $attribute) => $attribute->render(),
$this->items
$this->items,
));
}

Expand All @@ -160,7 +160,7 @@ public function toArray(): array
{
return array_map(
fn(AbstractAttribute $attribute) => $attribute->value(),
$this->items
$this->items,
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Entities/Attributes/ClassAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ public function remove(string $class): static
return $this;
}

$class = trim($class);
$class = mb_trim($class);

return $this->setValue(
array_diff($this->all(), [$class])
array_diff($this->all(), [$class]),
);
}

Expand Down Expand Up @@ -166,7 +166,7 @@ public function contains(string $class): bool
*/
public function has(string $class): bool
{
return in_array(trim($class), $this->all());
return in_array(mb_trim($class), $this->all());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Attributes/MiscAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function render(): string
*/
protected function setValue(mixed $value): static
{
$this->value = trim((string) $value);
$this->value = mb_trim((string) $value);

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidHtmlException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InvalidHtmlException extends Exception
public static function onTag(string $tag): static
{
return new static(
"Can't set inner contents on `{$tag}` because it's a void element"
"Can't set inner contents on `{$tag}` because it's a void element",
);
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/MissingTagException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MissingTagException extends Exception
public static function onClass(string $className): static
{
return new static(
"Class {$className} has no `\$tag` property or empty."
"Class {$className} has no `\$tag` property or empty.",
);
}
}
4 changes: 2 additions & 2 deletions src/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function number(
mixed $value = null,
mixed $min = null,
mixed $max = null,
mixed $step = null
mixed $step = null,
): Input {
return $this->input('number', $name, $value)
->attributeIfNotNull($min, 'min', $min)
Expand Down Expand Up @@ -312,7 +312,7 @@ public function range(
mixed $value = null,
mixed $min = null,
mixed $max = null,
mixed $step = null
mixed $step = null,
): Input {
return $this->input('range', $name, $value)
->attributeIfNotNull($min, 'min', $min)
Expand Down
2 changes: 1 addition & 1 deletion tests/Concerns/AssertsHtmlStrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function assertHtmlStringEqualsHtmlString(string $expected, mixed
static::assertEqualsCanonicalizing(
static::convertToDomDocument($expected),
static::convertToDomDocument($actual),
$message
$message,
);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Elements/ATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function it_can_create(): void
{
static::assertHtmlStringEqualsHtmlString(
'<a></a>',
A::make()
A::make(),
);
}

Expand All @@ -33,7 +33,7 @@ public function it_can_create_with_a_href(): void
{
static::assertHtmlStringEqualsHtmlString(
'<a href="https://github.com"></a>',
A::make()->href('https://github.com')
A::make()->href('https://github.com'),
);
}

Expand All @@ -42,7 +42,7 @@ public function it_can_create_with_custom_data_attributes(): void
{
static::assertHtmlStringEqualsHtmlString(
'<a href="#delete-user-modal" data-role="modal" data-id="1" data-name="User 1"></a>',
A::make()->href('#delete-user-modal')->data(['role' => 'modal', 'id' => 1, 'name' => 'User 1'])
A::make()->href('#delete-user-modal')->data(['role' => 'modal', 'id' => 1, 'name' => 'User 1']),
);
}

Expand All @@ -51,7 +51,7 @@ public function it_can_create_an_a_element_with_a_target(): void
{
static::assertHtmlStringEqualsHtmlString(
'<a target="_blank"></a>',
A::make()->target('_blank')
A::make()->target('_blank'),
);
}
}
Loading