Skip to content

Commit

Permalink
Add doc input Hidden::class. (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Feb 17, 2024
1 parent ea9e102 commit 6356946
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 170 deletions.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ This is particularly useful for creating forms and other interactive elements on
- [datetime-local](/docs/form/input/DatetimeLocal.md)
- [email](/docs/form/input/Email.md)
- [file](/docs/form/input/File.md)
- [hidden](/docs/form/input/Hidden.md)
- [radio](/docs/form/input/Radio.md)
- [radio-list](/docs/form/input/RadioList.md)
- [text](/docs/form/input/Text.md)
Expand Down
81 changes: 81 additions & 0 deletions docs/form/input/Hidden.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Hidden

The input element with a type attribute whose value is `hidden` represents a value not intended to be examined or
manipulated by the user.

## Basic Usage

Instantiate the `Hidden` class using `Hidden::widget()`.

```php
$Hidden = Hidden::widget();
```

## Setting Attributes

Use the provided methods to set specific attributes for the a element.

```php
// setting class attribute
$Hidden->class('container');
```

Or, use the `attributes` method to set multiple attributes at once.

```php
$Hidden->attributes(['class' => 'container', 'style' => 'background-color: #eee;']);
```

## Rendering

Generate the `HTML` output using the `render` method, for simple instantiation.

```php
$html = $Hidden->render();
```

Or, use the magic `__toString` method.

```php
$html = (string) $Hidden;
```

## Common use cases

Below are examples of common use cases:

```php
// adding multiple attributes
$Hidden->class('external')->value('Myvalue');
```

Explore additional methods for setting various attributes such as `id`, `name`, `style`, `value`, etc.

## Attributes

Refer to the [Attribute Tests](https://github.com/php-forge/html/blob/main/tests/Input/Hidden/AttributeTest.php) for
comprehensive examples.

The following methods are available for setting attributes:

| Method | Description |
| ------------------ | ----------------------------------------------------------------------------------------------- |
| `attributes()` | Set multiple `attributes` at once. |
| `class()` | Set the `class` attribute. |
| `disabled()` | Set the `disabled` attribute. |
| `id()` | Set the `id` attribute. |
| `name()` | Set the `name` attribute. |
| `style()` | Set the `style` attribute. |
| `value()` | Set the `value` attribute. |

## Custom methods

Refer to the [Custom Methods Tests](https://github.com/php-forge/html/blob/main/tests/Input/Hidden/CustomMethodTest.php)
for comprehensive examples.

The following methods are available for customizing the `HTML` output:

| Method | Description |
| ---------------------------- | ------------------------------------------------------------------------------------- |
| `render()` | Generates the `HTML` output. |
| `widget()` | Instantiates the `Hidden::class`. |
10 changes: 0 additions & 10 deletions tests/Input/Hidden/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ public function testName(): void
);
}

public function testRender(): void
{
Assert::equalsWithoutLE(
<<<HTML
<input id="hidden-6582f2d099e8b" type="hidden">
HTML,
Hidden::widget()->id('hidden-6582f2d099e8b')->render()
);
}

public function testStyle(): void
{
Assert::equalsWithoutLE(
Expand Down
162 changes: 2 additions & 160 deletions tests/Input/Hidden/CustomMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,171 +13,13 @@
*/
final class CustomMethodTest extends TestCase
{
public function testPrefix(): void
public function testRender(): void
{
Assert::equalsWithoutLE(
<<<HTML
prefix
<input id="hidden-6582f2d099e8b" type="hidden">
HTML,
Hidden::widget()->id('hidden-6582f2d099e8b')->prefix('prefix')->render()
);
}

public function testPrefixContainer(): void
{
Assert::equalsWithoutLE(
<<<HTML
<div>
prefix
</div>
<input id="hidden-6582f2d099e8b" type="hidden">
HTML,
Hidden::widget()->id('hidden-6582f2d099e8b')->prefix('prefix')->prefixContainer(true)->render()
);
}

public function testPrefixContainerAttributes(): void
{
Assert::equalsWithoutLE(
<<<HTML
<div class="value">
prefix
</div>
<input id="hidden-6582f2d099e8b" type="hidden">
HTML,
Hidden::widget()
->id('hidden-6582f2d099e8b')
->prefix('prefix')
->prefixContainer(true)
->prefixContainerAttributes(['class' => 'value'])
->render()
);
}

public function testPrefixContainerClass(): void
{
Assert::equalsWithoutLE(
<<<HTML
<div class="value">
prefix
</div>
<input id="hidden-6582f2d099e8b" type="hidden">
HTML,
Hidden::widget()
->id('hidden-6582f2d099e8b')
->prefix('prefix')
->prefixContainer(true)
->prefixContainerClass('value')
->render()
);
}

public function testPrefixContainerTag(): void
{
Assert::equalsWithoutLE(
<<<HTML
<article>
prefix
</article>
<input id="hidden-6582f2d099e8b" type="hidden">
HTML,
Hidden::widget()
->id('hidden-6582f2d099e8b')
->prefix('prefix')
->prefixContainer(true)
->prefixContainerTag('article')
->render()
);
}

public function testSuffix(): void
{
Assert::equalsWithoutLE(
<<<HTML
<input id="hidden-6582f2d099e8b" type="hidden">
suffix
HTML,
Hidden::widget()->id('hidden-6582f2d099e8b')->suffix('suffix')->render()
);
}

public function testSuffixContainer(): void
{
Assert::equalsWithoutLE(
<<<HTML
<input id="hidden-6582f2d099e8b" type="hidden">
<div>
suffix
</div>
HTML,
Hidden::widget()->id('hidden-6582f2d099e8b')->suffix('suffix')->suffixContainer(true)->render()
);
}

public function testSuffixContainerAttributes(): void
{
Assert::equalsWithoutLE(
<<<HTML
<input id="hidden-6582f2d099e8b" type="hidden">
<div class="value">
suffix
</div>
HTML,
Hidden::widget()
->id('hidden-6582f2d099e8b')
->suffix('suffix')
->suffixContainer(true)
->suffixContainerAttributes(['class' => 'value'])
->render()
);
}

public function testSuffixContainerClass(): void
{
Assert::equalsWithoutLE(
<<<HTML
<input id="hidden-6582f2d099e8b" type="hidden">
<div class="value">
suffix
</div>
HTML,
Hidden::widget()
->id('hidden-6582f2d099e8b')
->suffix('suffix')
->suffixContainer(true)
->suffixContainerClass('value')
->render()
);
}

public function testSuffixContainerTag(): void
{
Assert::equalsWithoutLE(
<<<HTML
<input id="hidden-6582f2d099e8b" type="hidden">
<article>
suffix
</article>
HTML,
Hidden::widget()
->id('hidden-6582f2d099e8b')
->suffix('suffix')
->suffixContainer(true)
->suffixContainerTag('article')
->render()
);
}

public function testTemplate(): void
{
Assert::equalsWithoutLE(
<<<HTML
<div>
<input id="hidden-6582f2d099e8b" type="hidden">
</div>
HTML,
Hidden::widget()->id('hidden-6582f2d099e8b')->template('<div>\n{tag}\n</div>')->render()
Hidden::widget()->id('hidden-6582f2d099e8b')->render()
);
}
}

0 comments on commit 6356946

Please sign in to comment.