Skip to content

Commit

Permalink
Add docs input ButtonGroup::class. (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Feb 16, 2024
1 parent 3e09beb commit 27d9b53
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 36 deletions.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ In addition to basic `HTML` tags, the repository also supports the generation of
This is particularly useful for creating forms and other interactive elements on a webpage.

- [button](/docs/form/input/Button.md)
- [button-group](/docs/form/input/ButtonGroup.md)
- [date](/docs/form/input/Date.md)
- [datetime-local](/docs/form/input/DatetimeLocal.md)
- [datetime](/docs/form/input/Datetime.md)
Expand Down
63 changes: 63 additions & 0 deletions docs/form/input/ButtonGroup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# ButtonGroup

ButtonGroup renders a button group widget.

## Basic Usage

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

```php
$buttonGroup = ButtonGroup::widget();
```

## Buttons

Add buttons to the `ButtonGroup` widget using the `buttons` method.

```php
$buttonGroup->buttons(
ButtonGroup::widget()->labelContent('Submit')->type('submit'),
ButtonGroup::widget()->labelContent('Reset')->type('reset')
);
```

## Rendering

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

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

Or, use the magic `__toString` method.

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

## Common use cases

Below are examples of common use cases:

```php
// adding multiple attributes
$buttonGroup->container()->containerClass('MyClass');
```

## Custom methods

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

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

| Method | Description |
| ---------------------------- | ------------------------------------------------------------------------------------- |
| `buttons()` | Set the `buttons` for the `ButtonGroup` widget. |
| `container()` | Set enabled or disabled for the `container` element. |
| `containerAttributes()` | Set `attributes` for the `container` element. |
| `containerClass()` | Set the `class` attribute for the `container` element. |
| `containerTag()` | Set the `tag` for the `container` element. |
| `individualContainer()` | Set enabled or disabled for the `individualContainer` for each button. |
| `render()` | Generates the `HTML` output. |
| `widget()` | Instantiates the `ButtonGroup::class`. |
4 changes: 2 additions & 2 deletions src/Input/ButtonGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* <?=
* ButtonGroup::create()
* ->buttons(
* Button::widget()->label('Submit')->type('submit'),
* Button::widget()->label('Reset')->type('reset')
* Button::widget()->labelContent('Submit')->type('submit'),
* Button::widget()->labelContent('Reset')->type('reset')
* );
* ?>
* ```
Expand Down
34 changes: 0 additions & 34 deletions tests/Input/ButtonGroup/AttributeTest.php

This file was deleted.

18 changes: 18 additions & 0 deletions tests/Input/ButtonGroup/CustomMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,22 @@ public function testIndividualContainer(): void
->render()
);
}

public function testRender(): void
{
Assert::equalsWithoutLE(
<<<HTML
<div>
<input id="button-6582f2d099e8a" type="submit" value="Submit">
<input id="button-6582f2d099e8b" type="reset" value="Reset">
</div>
HTML,
ButtonGroup::widget()
->buttons(
Button::widget()->id('button-6582f2d099e8a')->type('submit')->value('Submit'),
Button::widget()->id('button-6582f2d099e8b')->type('reset')->value('Reset')
)
->render()
);
}
}

0 comments on commit 27d9b53

Please sign in to comment.