generated from yii-tools/template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d779d13
commit caa7744
Showing
9 changed files
with
294 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Ol | ||
|
||
The `<ol>` `HTML` element represents an ordered list of items, typically rendered as a numbered list. | ||
|
||
## Basic Usage | ||
|
||
Instantiate the `Ol` class using `Ol::widget()`. | ||
|
||
```php | ||
$ol = Ol::widget(); | ||
``` | ||
|
||
## Setting Attributes | ||
|
||
Use the provided methods to set specific attributes for the a element. | ||
|
||
```php | ||
// setting class attribute | ||
$ol->class('external'); | ||
``` | ||
|
||
Or, use the `attributes` method to set multiple attributes at once. | ||
|
||
```php | ||
$ol->attributes(['class' => 'external', 'title' => 'External Link']); | ||
``` | ||
|
||
## Adding Content | ||
|
||
If you want to include content within the `ol` tag, use the `content` method. | ||
|
||
```php | ||
$ol->content('myContent'); | ||
``` | ||
|
||
## Rendering | ||
|
||
Generate the `HTML` output using the `render` method. | ||
|
||
```php | ||
$html = $ol->render(); | ||
``` | ||
|
||
Or, use the magic `__toString` method. | ||
|
||
```php | ||
$html = (string) $ol; | ||
``` | ||
|
||
## Common Use Cases | ||
|
||
Below are examples of common use cases: | ||
|
||
```php | ||
// adding multiple attributes | ||
$ol->class('external')->content('myContent')->title('External Link'); | ||
``` | ||
|
||
Explore additional methods for setting various attributes such as `lang`, `tabindex`, `title`, `value` and more. | ||
|
||
## Attributes | ||
|
||
Refer to the [Attribute Tests](https://github.com/php-forge/html/blob/main/tests/Ol/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. | | ||
| `content()` | Set the `content` within the `ol` element. | | ||
| `id()` | Set the `id` attribute. | | ||
| `lang()` | Set the `lang` attribute. | | ||
| `name()` | Set the `name` attribute. | | ||
| `reversed()` | Set the `reversed` attribute. | | ||
| `start()` | Set the `start` attribute. | | ||
| `style()` | Set the `style` attribute. | | ||
| `tabindex()` | Set the `tabindex` attribute. | | ||
| `title()` | Set the `title` attribute. | | ||
| `type()` | Set the `type` attribute. | | ||
| `value()` | Set the `value` attribute. | | ||
|
||
## Custom methods | ||
|
||
Refer to the [Custom Method Test](https://github.com/php-forge/html/blob/main/tests/Ol/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 `Ol::class`. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Attribute\Tag; | ||
|
||
/** | ||
* Is used by widgets that implement the reversed method. | ||
*/ | ||
trait HasReversed | ||
{ | ||
/** | ||
* Set the reversed attribute. | ||
* | ||
* @return static A new instance of the current class with the specified reversed value. | ||
* | ||
* @link https://html.spec.whatwg.org/multipage/grouping-content.html#attr-ol-reversed | ||
*/ | ||
public function reversed(): static | ||
{ | ||
$new = clone $this; | ||
$new->attributes['reversed'] = true; | ||
|
||
return $new; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Attribute\Tag; | ||
|
||
/** | ||
* Is used by widgets that implement the start method. | ||
*/ | ||
trait HasStart | ||
{ | ||
/** | ||
* The start attribute specifies the value of the first list item in an ordered list. | ||
* | ||
* @param int $value The value of the first list item in an ordered list. | ||
* | ||
* @return static A new instance of the current class with the specified start value. | ||
* | ||
* @link https://html.spec.whatwg.org/multipage/grouping-content.html#attr-ol-start | ||
*/ | ||
public function start(int $value): static | ||
{ | ||
$new = clone $this; | ||
$new->attributes['start'] = $value; | ||
|
||
return $new; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Tests\Attribute\Tag; | ||
|
||
use PHPForge\Html\Attribute\Tag\HasReversed; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class HasReversedTest extends TestCase | ||
{ | ||
public function testImmutability(): void | ||
{ | ||
$instance = new class () { | ||
use HasReversed; | ||
|
||
protected array $attributes = []; | ||
}; | ||
|
||
$this->assertNotSame($instance, $instance->reversed()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Tests\Attribute\Tag; | ||
|
||
use PHPForge\Html\Attribute\Tag\HasStart; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class HasStartTest extends TestCase | ||
{ | ||
public function testImmutability(): void | ||
{ | ||
$instance = new class () { | ||
use HasStart; | ||
|
||
protected array $attributes = []; | ||
}; | ||
|
||
$this->assertNotSame($instance, $instance->start(1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.