Skip to content

Commit

Permalink
Add doc Div::class. (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Jan 30, 2024
1 parent bc7b1d1 commit 7cf72db
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 46 deletions.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The following tags are currently supported:
- [body](/docs/tag/Body.md)
- [button](/docs/tag/Button.md)
- [button toggle](/docs/tag/ButtonToggle.md)
- [div](/docs/tag/Div.md)

## Input Tags

Expand Down
12 changes: 6 additions & 6 deletions docs/tag/A.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $anchor = A::widget();
Use the provided methods to set specific attributes for the a element.

```php
// Example: Setting href attribute
// setting href attribute
$anchor->href('/path/to/page');
```

Expand Down Expand Up @@ -53,10 +53,10 @@ $html = (string) $anchor;
Below are examples of common use cases:

```php
// Example: Adding multiple attributes
// adding multiple attributes
$anchor->class('external')->href('/external/link')->content('External Link');

// Example: Using data attributes
// using data attributes
$anchor->dataAttributes(['bs-toggle' => 'modal', 'bs-target' => '#exampleModal', 'analytics' => 'trackClick']);
```

Expand All @@ -67,10 +67,10 @@ Explore additional methods for setting various attributes such as `autofocus`, `
Use `prefix` and `suffix` methods to add text before and after the `anchor` tag, respectively.

```php
// Example: Adding a prefix
// adding a prefix
$html = $anchor->content('Home')->prefix('Go to: ')->render();

// Example: Adding a suffix
// adding a suffix
$html = $anchor->content('Home')->suffix(' | Welcome')->render();
```

Expand All @@ -87,7 +87,7 @@ The following template tags are available:
| `{suffix}` | The suffix text. |

```php
// Example: Using a custom template
// using a custom template
$a->template('<span>{tag}</span>');
```

Expand Down
8 changes: 4 additions & 4 deletions docs/tag/Body.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Or, block style instantiation.

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

Expand All @@ -25,7 +25,7 @@ Or, block style instantiation.
Use the provided methods to set specific attributes for the a element.

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

Expand Down Expand Up @@ -76,10 +76,10 @@ $html = (string) $body;
Below are examples of common use cases:

```php
// Example: Adding multiple attributes
// adding multiple attributes
$body->class('external')->content('My content');

// Example: Using data attributes
// using data attributes
$body->dataAttributes(['analytics' => 'trackClick']);
```

Expand Down
18 changes: 9 additions & 9 deletions docs/tag/Button.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $button = Button::widget();
Use the provided methods to set specific `attribute` for the `button` element.

```php
// Example: Setting the title attribute
// setting the title attribute
$button->title('Click me');
```

Expand Down Expand Up @@ -54,10 +54,10 @@ $html = (string) $button;
Below are examples of common use cases:

```php
// Example: Adding multiple attributes
// adding multiple attributes
$button->class('external')->content('Click me')->title('Click me');

// Example: Using data attributes
// using data attributes
$button->dataAttributes(['bs-toggle' => 'modal', 'bs-target' => '#exampleModal', 'analytics' => 'trackClick']);
```

Expand All @@ -68,7 +68,7 @@ Explore additional methods for setting various `attributes` such as `ariaControl
Use the `container()` method to add a `container` around the `button` tag.

```php
// Example: Adding a container
// adding a container
$button->content('Click me')->container()->render();
```

Expand All @@ -77,10 +77,10 @@ $button->content('Click me')->container()->render();
Use `prefix` and `suffix` methods to add text before and after the `button` tag, respectively.

```php
// Example: Adding a prefix
// adding a prefix
$button = $button->content('Home')->prefix('Go to: ')->render();

// Example: Adding a suffix
// adding a suffix
$button = $button->content('Home')->suffix(' | Welcome')->render();
```

Expand All @@ -89,12 +89,12 @@ $button = $button->content('Home')->suffix(' | Welcome')->render();
Use the `submit` and `reset` methods to set the `type` attribute to `submit` and `reset`, respectively.

```php
// Example: Setting the type attribute to submit
// setting the type attribute to submit
$button = $button->content('Submit')->submit()->render();
```

```php
// Example: Setting the type attribute to reset
// setting the type attribute to reset
$button = $button->content('Reset')->reset()->render();
```

Expand All @@ -111,7 +111,7 @@ The following template tags are available:
| `{suffix}` | The suffix text. |

```php
// Example: Using a custom template
// using a custom template
$button->template('<span>{tag}</span>');
```

Expand Down
8 changes: 4 additions & 4 deletions docs/tag/ButtonToggle.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $buttonToggle = ButtonToggle::widget();
Use the provided methods to set specific `attribute` for the `buttonToggle` element.

```php
// Example: Setting the title attribute
// setting the title attribute
$buttonToggle->title('Click me');
```

Expand Down Expand Up @@ -52,10 +52,10 @@ $html = (string) $button;
Below are examples of common use cases:

```php
// Example: Adding multiple attributes
// adding multiple attributes
$buttonToggle->class('external')->content('Click me')->title('Click me');

// Example: Using data attributes
// using data attributes
$buttonToggle->dataAttributes(['bs-toggle' => 'modal', 'bs-target' => '#exampleModal', 'analytics' => 'trackClick']);
```

Expand All @@ -74,7 +74,7 @@ The following template tags are available:
| `{content}`| The `content` element. |

```php
// Example: Using a custom template
// using a custom template
$buttonToggle->template('<span>{toggle}</span>');
```

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

The `<div>` `HTML` element is the generic container for flow content.

It has no effect on the content or layout until styled in some way using CSS (e.g., styling is directly applied to it,
or some kind of layout model like Flexbox is applied to its parent element).

## Basic Usage

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

```php
$div = Div::widget();
```

Or, block style instantiation.

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

## Setting Attributes

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

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

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

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

## Adding Content

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

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

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

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

## Rendering

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

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

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

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

Or, use the magic `__toString` method.

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

## Common Use Cases

Below are examples of common use cases:

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

// using data attributes
$div->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/Div/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 `div` 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/Div/CustomMethodTest.php) for
comprehensive examples.

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

| Method | Description |
| --------- | -------------------------------------------------------------------------------------------------------- |
| `begin() `| Start the `div` element. |
| `end()` | End the `div` element, and generate the `HTML` output. |
| `render()`| Generates the `HTML` output. |
| `widget()`| Instantiates the `Body::class`. |

0 comments on commit 7cf72db

Please sign in to comment.