Skip to content

Commit

Permalink
Add docs Nav::class. (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Feb 7, 2024
1 parent d57e50e commit d779d13
Show file tree
Hide file tree
Showing 22 changed files with 254 additions and 211 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"ext-dom": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
"php-forge/awesome-widget": "^0.1",
"php-forge/awesome-widget": "^0.1.2",
"voku/anti-xss": "^4.1"
},
"require-dev": {
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The following tags are currently supported:
- [label](/docs/tag/Label.md)
- [li](/docs/tag/Li.md)
- [meta](/docs/tag/Meta.md)
- [nav](/docs/tag/Nav.md)

## Input Tags

Expand Down
2 changes: 1 addition & 1 deletion docs/tag/Body.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Or, block style instantiation.
Use the provided methods to set specific attributes for the a element.

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

Expand Down
2 changes: 1 addition & 1 deletion docs/tag/Div.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Or, block style instantiation.
Use the provided methods to set specific attributes for the a element.

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

Expand Down
2 changes: 1 addition & 1 deletion docs/tag/Footer.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Or, block style instantiation.
Use the provided methods to set specific attributes for the a element.

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

Expand Down
2 changes: 1 addition & 1 deletion docs/tag/Form.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Or, block style instantiation.
Use the provided methods to set specific attributes for the a element.

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

Expand Down
2 changes: 1 addition & 1 deletion docs/tag/H.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Or, block style instantiation.
Use the provided methods to set specific attributes for the a element.

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

Expand Down
2 changes: 1 addition & 1 deletion docs/tag/Head.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Or, block style instantiation.
Use the provided methods to set specific attributes for the a element.

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

Expand Down
2 changes: 1 addition & 1 deletion docs/tag/Header.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Or, block style instantiation.
Use the provided methods to set specific attributes for the a element.

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

Expand Down
2 changes: 1 addition & 1 deletion docs/tag/Html.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Or, block style instantiation.
Use the provided methods to set specific attributes for the a element.

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

Expand Down
119 changes: 119 additions & 0 deletions docs/tag/Nav.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Nav

The `<nav>` HTML element represents a section of a page whose purpose is to provide navigation links, either within the
current document or to other documents. Common examples of navigation sections are menus, tables of contents, and
indexes.

## Basic Usage

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

```php
$nav = Nav::widget();
```

Or, block style instantiation.

```php
<?= Nav::begin() ?>
// ... content to be wrapped by `nav` element
<?= Nav::end() ?>
```

## Setting Attributes

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

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

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

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

## Adding Content

If you want to include content within the `nav` tag, use the `content` method.

```php
$nav->content('My content');
```

Or, use `begin()` and `end()` methods to wrap content.

```php
<?= Nav::begin() ?>
My content
<?= Nav::end() ?>
```

## Rendering

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

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

For block style instantiation, use the `end()` method, which returns the `HTML` output.

```php
$html = Nav::end();
```

Or, use the magic `__toString` method.

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

## Common Use Cases

Below are examples of common use cases:

```php
// adding multiple attributes
$nav->class('external')->content('My content');

// using data attributes
$nav->dataAttributes(['analytics' => 'trackClick']);
```

Explore additional methods for setting various attributes such as `lang`, `name`, `style`, `title`, etc.

## Attributes

Refer to the [Attribute Tests](https://github.com/php-forge/html/blob/main/tests/Nav/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 `nav` element. |
| `dataAttributes()`| Set multiple `data-attributes` at once. |
| `id()` | Set the `id` attribute. |
| `lang()` | Set the `lang` attribute. |
| `name()` | Set the `name` attribute. |
| `style()` | Set the `style` attribute. |
| `title()` | Set the `title` attribute. |

## Custom methods

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

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

| Method | Description |
| --------- | -------------------------------------------------------------------------------------------------------- |
| `begin() `| Start the `nav` element. |
| `end()` | End the `nav` element, and generate the `HTML` output. |
| `render()`| Generates the `HTML` output. |
| `widget()`| Instantiates the `Body::class`. |
20 changes: 0 additions & 20 deletions tests/A/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,24 +261,4 @@ public function testType(): void
A::widget()->type('value')->render()
);
}

public function testWithoutId(): void
{
Assert::equalsWithoutLE(
<<<HTML
<a></a>
HTML,
A::widget()->id(null)->render()
);
}

public function testWithoutName(): void
{
Assert::equalsWithoutLE(
<<<HTML
<a></a>
HTML,
A::widget()->name(null)->render()
);
}
}
22 changes: 0 additions & 22 deletions tests/Body/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,4 @@ public function testTitle(): void
Body::widget()->title('value')->render()
);
}

public function testWithoutId(): void
{
Assert::equalsWithoutLE(
<<<HTML
<body>
</body>
HTML,
Body::widget()->id(null)->render()
);
}

public function testWithoutName(): void
{
Assert::equalsWithoutLE(
<<<HTML
<body>
</body>
HTML,
Body::widget()->name(null)->render()
);
}
}
22 changes: 0 additions & 22 deletions tests/Div/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,4 @@ public function testTitle(): void
Div::widget()->title('value')->render()
);
}

public function testWithoutId(): void
{
Assert::equalsWithoutLE(
<<<HTML
<div>
</div>
HTML,
Div::widget()->id(null)->render()
);
}

public function testWithoutName(): void
{
Assert::equalsWithoutLE(
<<<HTML
<div>
</div>
HTML,
Div::widget()->name(null)->render()
);
}
}
22 changes: 0 additions & 22 deletions tests/Footer/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,4 @@ public function testTitle(): void
Footer::widget()->title('value')->render()
);
}

public function testWithoutId(): void
{
Assert::equalsWithoutLE(
<<<HTML
<footer>
</footer>
HTML,
Footer::widget()->id(null)->render()
);
}

public function testWithoutName(): void
{
Assert::equalsWithoutLE(
<<<HTML
<footer>
</footer>
HTML,
Footer::widget()->name(null)->render()
);
}
}
22 changes: 0 additions & 22 deletions tests/Form/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,4 @@ public function testTitle(): void
Form::widget()->title('value')->render()
);
}

public function testWithoutId(): void
{
Assert::equalsWithoutLE(
<<<HTML
<form>
</form>
HTML,
Form::widget()->id(null)->render()
);
}

public function testWithoutName(): void
{
Assert::equalsWithoutLE(
<<<HTML
<form>
</form>
HTML,
Form::widget()->name(null)->render()
);
}
}
22 changes: 0 additions & 22 deletions tests/H/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,4 @@ public function testTitle(): void
H::widget()->title('value')->render()
);
}

public function testWithoutId(): void
{
Assert::equalsWithoutLE(
<<<HTML
<h1>
</h1>
HTML,
H::widget()->id(null)->render()
);
}

public function testWithoutName(): void
{
Assert::equalsWithoutLE(
<<<HTML
<h1>
</h1>
HTML,
H::widget()->name(null)->render()
);
}
}
22 changes: 0 additions & 22 deletions tests/Head/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,4 @@ public function testTitle(): void
Head::widget()->title('value')->render()
);
}

public function testWithoutId(): void
{
Assert::equalsWithoutLE(
<<<HTML
<head>
</head>
HTML,
Head::widget()->id(null)->render()
);
}

public function testWithoutName(): void
{
Assert::equalsWithoutLE(
<<<HTML
<head>
</head>
HTML,
Head::widget()->name(null)->render()
);
}
}

0 comments on commit d779d13

Please sign in to comment.