Skip to content

Commit

Permalink
Add docs for widget A::class. (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Jan 24, 2024
1 parent df4c159 commit d03ffed
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 91 deletions.
165 changes: 165 additions & 0 deletions docs/A.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# A

The `<a>` `HTML` element (or `anchor` element), with its `href` attribute, creates a hyperlink to web pages, files,
email addresses, locations in the same page, or anything else a `URL` can address.

# Basic Usage

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

```php
$anchor = A::widget();
```

## Setting Attributes

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

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

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

```php
$anchor->attributes(['href' => '/path/to/page']);
```

## Adding Content

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

```php
$anchor->content('Click me');
```

## Rendering

Generate the `HTML` output using the `render` method.

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

Or, use the magic `__toString` method.

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

## Common Use Cases

Below are examples of common use cases:

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

// Example: Using data attributes
$anchor->dataAttributes(['target' => '_blank', 'analytics' => 'trackClick']);

// Example: Applying a custom template
$anchor->template('<span>{tag}</span>')->class('styled-link')->content('Styled Link');
```

Explore additional methods for setting various attributes such as `autofocus`, `hidden`, `download`, etc.

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

## Prefix and Suffix

Use `prefix` and `suffix` methods to add text before and after the `anchor` tag, respectively.

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

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

Examples of `prefix` and `suffix` usage can be found in the [Custom Method Test](https://github.com/php-forge/html/blob/main/tests/A/CustomMethodTest.php)
for comprehensive examples.

# Template

The `template` method allows you to customize the `HTML` output of the a element.

The following template tags are available:

| Tag | Description |
| ---------- | ---------------- |
| `{prefix}` | The prefix text. |
| `{tag}` | The a element. |
| `{suffix}` | The suffix text. |

```php
// Example: Using a custom template
$a->template('<span>{tag}</span>')->class('styled-link')->content('Styled Link');
```

Examples of `template` usage can be found in the [Custom Method Test](https://github.com/php-forge/html/blob/main/tests/A/CustomMethodTest.php)
for comprehensive examples.

# Attributes

The following methods are available for setting attributes:

| Method | Description |
| ----------------- | ------------------------------------------------------------------------------------------------ |
| `ariaControls()` | Sets the `aria-controls` attribute. |
| `ariaDisabled()` | Sets the `aria-disabled` attribute. |
| `ariaExpanded()` | Sets the `aria-expanded` attribute. |
| `ariaLabel()` | Sets the `aria-label` attribute. |
| `attributes()` | Sets multiple attributes at once. |
| `autofocus()` | Sets the `autofocus` attribute. |
| `attributes()` | Sets multiple attributes at once. |
| `class()` | Sets the `class` attribute. |
| `content()` | Sets the content within the a element. |
| `dataAttributes()`| Sets multiple data attributes at once. |
| `download()` | Sets the `download` attribute. |
| `hidden()` | Sets the `hidden` attribute. |
| `href()` | Sets the `href` attribute. |
| `hreflang()` | Sets the `hreflang` attribute. |
| `id()` | Sets the `id` attribute. |
| `lang()` | Sets the `lang` attribute. |
| `name()` | Sets the `name` attribute. |
| `ping()` | Sets the `ping` attribute. |
| `referrerpolicy()`| Sets the `referrerpolicy` attribute. |
| | Allowed values: `no-referrer`, `no-referrer-when-downgrade`, `origin`, `origin-when-cross-origin`|
| | `same-origin`, `strict-origin`, `strict-origin-when-cross-origin`, `unsafe-url` |
| `rel()` | Sets the `rel` attribute. |
| | Allowed values: 'alternate', 'author', 'bookmark', 'help', 'icon', 'license', 'next', 'nofollow' |
| | 'noopener', 'noreferrer', 'pingback', 'preconnect', 'prefetch', 'preload', 'prerender', 'prev' |
| | 'search', 'sidebar', 'stylesheet', 'tag' |
| `render()` | Generates the `HTML` output. |
| `role()` | Sets the `role` attribute. |
| `style()` | Sets the `style` attribute. |
| `target()` | Sets the `target` attribute. |
| | Allowed values: `_blank`, `_parent`, `_self`, `_top` |
| `tabindex()` | Sets the `tabindex` attribute. |
| `title()` | Sets the `title` attribute. |
| `type()` | Sets the `type` attribute. |

## Custom methods

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

| Method | Description |
| ---------------------------- | ------------------------------------------------------------------------------------- |
| `prefix()` | Adds text before the a element. |
| `prefixContainer()` | Adds a container before the a element. |
| `prefixContainerAttributes()`| Sets attributes for the prefix container. |
| `prefixContainerClass()` | Sets the class attribute for the prefix container. |
| `prefixContainerTag()` | Sets the tag for the prefix container. |
| `suffix()` | Adds text after the a element. |
| `suffixContainer()` | Adds a container after the a element. |
| `suffixContainerAttributes()`| Sets attributes for the suffix container. |
| `suffixContainerClass()` | Sets the class attribute for the suffix container. |
| `suffixContainerTag()` | Sets the tag for the suffix container. |
| `template()` | Sets the template for the a element. |



45 changes: 45 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# HTML

The **HTML** repository is a powerful tool for generating `HTML` code using `PHP`.

It provides a wide range of functionalities, including:

## Basic HTML Tags

The repository can generate basic `HTML` tags, allowing you to create `HTML` elements programmatically using `PHP`.

The following tags are currently supported:

- [a](/docs/A.md)

## Input Tags

In addition to basic `HTML` tags, the repository also supports the generation of input tags.

This is particularly useful for creating forms and other interactive elements on a webpage.

## Traits

One of the standout features of the `HTML` repository is its use of `PHP` traits. Traits are a mechanism for code reuse
in single inheritance languages like `PHP`. They allow you to group specific functionalities together in a coherent way.
The `HTML` repository provides traits that you can use to assemble your own widgets. This gives you the flexibility to
create custom `HTML` elements that are tailored to your specific needs.

To use the repository, you would typically import the necessary classes and traits into your `PHP` script, and then call
the appropriate methods to generate the `HTML` code. The generated code can then be outputted to the browser or used in
other parts of your application.

Please note that the exact usage may vary depending on the specific classes and traits you are using. Be sure to check
the tests and traits in the repository for more detailed examples and usage instructions.

## Abstract Classes

The repository also provides a number of abstract classes that you can use to create your own custom widgets. These
classes provide a basic implementation of the `HTML` interface, and can be extended to create more complex widgets.

## Interfaces

The repository provides a number of interfaces that you can use to create your own custom widgets. These interfaces
provide a basic implementation of the `HTML` interface, and can be extended to create more complex widgets.


1 change: 0 additions & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
)
->withPhpCsFixerSets(perCS20: true)
->withPreparedSets(
arrays: true,
cleanCode: true,
comments:true,
docblocks: true,
Expand Down

0 comments on commit d03ffed

Please sign in to comment.