Skip to content

Commit

Permalink
Add docs text class (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Feb 14, 2024
1 parent 0e18c0e commit 6c18e93
Show file tree
Hide file tree
Showing 39 changed files with 542 additions and 81 deletions.
4 changes: 2 additions & 2 deletions docs/form/Form.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $form->attributes(['class' => 'container', 'style' => 'background-color: #eee;']
If you want to include content within the `form` tag, use the `content` method.

```php
$form->content('My content');
$form->content('MyContent');
```

Or, use `begin()` and `end()` methods to wrap content.
Expand Down Expand Up @@ -75,7 +75,7 @@ Below are examples of common use cases:

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

// using data attributes
$form->dataAttributes(['analytics' => 'trackClick']);
Expand Down
6 changes: 3 additions & 3 deletions docs/form/Label.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $label->attributes(['class' => 'text-primary', 'title' => 'Home']);
If you want to include content within the `label` tag, use the `content` method.

```php
$label->content('Home');
$label->content('MyContent');
```

## Rendering
Expand Down Expand Up @@ -67,10 +67,10 @@ Use `prefix` and `suffix` methods to add text before and after the `label` tag,

```php
// adding a prefix
$html = $label->content('home')->prefix('Welcome')->render();
$html = $label->content('MyContent')->prefix('MyPrefix')->render();

// adding a suffix
$html = $label->content('home')->suffix('Welcome')->render();
$html = $label->content('MyContent')->suffix('MySuffix')->render();
```

## Template
Expand Down
25 changes: 20 additions & 5 deletions docs/form/Select.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,34 @@ Instantiate the `Select` class using `Select::widget()`.
$select = Select::widget();
```

## Generate field id and name

The `generateField` method is used to generate the field id and name for the `HTML` output.

Allowed arguments are:

- `modelName` - The name of the model.
- `fieldName` - The name of the field.
- `arrayable` - Whether the field is an array. For default, it is `false`.

```php
// generate field id and name
$select->generateField('model', 'field');
```

## Setting Attributes

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

```php
// setting class attribute
$select->class('myClass');
$select->class('MyClass');
```

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

```php
$select->attributes(['class' => 'myClass', 'id' => 'myId']);
$select->attributes(['class' => 'MyClass', 'id' => 'myId']);
```

## Add items
Expand Down Expand Up @@ -151,7 +166,7 @@ Below are examples of common use cases:

```php
// adding multiple attributes
$select->class('myClass')->required();
$select->class('MyClass')->required();
```

```php
Expand All @@ -173,10 +188,10 @@ Use `prefix` and `suffix` methods to add text before and after the `select` tag,

```php
// adding a prefix
$html = $select->prefix('myPrefix')->render();
$html = $select->prefix('MyPrefix')->render();

// adding a suffix
$html = $select->suffix('mySuffix')->render();
$html = $select->suffix('MySuffix')->render();
```

## Attributes
Expand Down
56 changes: 53 additions & 3 deletions docs/form/TextArea.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ Instantiate the `TextArea` class using `TextArea::widget()`.
$textArea = TextArea::widget();
```

## Generate field id and name

The `generateField` method is used to generate the field id and name for the `HTML` output.

Allowed arguments are:

- `modelName` - The name of the model.
- `fieldName` - The name of the field.
- `arrayable` - Whether the field is an array. For default, it is `false`.

```php
// generate field id and name
$textArea->generateField('model', 'field');
```

## Setting Attributes

Use the provided methods to set specific attributes for the a element.
Expand All @@ -31,7 +46,7 @@ $textArea->attributes(['class' => 'container', 'style' => 'background-color: #ee
If you want to include content within the `textarea` tag, use the `content` method.

```php
$textArea->content('My content');
$textArea->content('MyContent');
```

## Rendering
Expand All @@ -54,14 +69,43 @@ Below are examples of common use cases:

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

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

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

## Prefix and Suffix

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

```php
// adding a prefix
$html = $textArea->content('MyContent')->prefix('MyPrefix')->render();

// adding a suffix
$html = $textArea->content('MyContent')->suffix('MySuffix')->render();
```

## 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
// using a custom template
$textArea->template('<div>{tag}</div>');
```

## Attributes

Refer to the [Attribute Tests](https://github.com/php-forge/html/blob/main/tests/TextArea/AttributeTest.php) for
Expand Down Expand Up @@ -103,19 +147,25 @@ The following methods are available for customizing the `HTML` output:

| Method | Description |
| ---------------------------- | ------------------------------------------------------------------------------------- |
| `generateField()` | Generate the field id and name for the `HTML` output. |
| `prefix()` | Add text before the `textarea` element. |
| `prefixContainer()` | Set enabled or disabled for the `prefix-container` element. |
| `prefixContainerAttributes()`| Set `attributes` for the `prefix-container` element. |
| `prefixContainerClass()` | Set the `class` attribute for the `prefix-container` element. |
| `prefixContainerTag()` | Set the `tag` for the `prefix-container` element. |
| `render()` | Generates the `HTML` output. |
| `suffix()` | Add text after the `label` element. |
| `suffixContainer()` | Set enabled or disabled for the `suffix-container` element. |
| `suffixContainerAttributes()`| Set `attributes` for the `suffix-container` element. |
| `suffixContainerClass()` | Set the `class` attribute for the `suffix-container` element. |
| `suffixContainerTag()` | Set the `tag` for the `suffix-container` element. |
| `template()` | Set the template for the `HTML` output. |
| `tokenValues()` | Set the token values for the `HTML` output. |
| `widget()` | Instantiates the `TextArea::class`. |

## Validate methods

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

| Method | Description |
Expand Down
174 changes: 174 additions & 0 deletions docs/form/input/Text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# Text

The input element with a type attribute whose value is `text` represents a one-line plain text edit control for the
input element’s value.

## Basic Usage

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

```php
$text = Text::widget();
```

## Generate field id and name

The `generateField` method is used to generate the field id and name for the `HTML` output.

Allowed arguments are:

- `modelName` - The name of the model.
- `fieldName` - The name of the field.
- `arrayable` - Whether the field is an array. For default, it is `false`.

```php
// generate field id and name
$text->generateField('model', 'field');
```

## Setting Attributes

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

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

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

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

## Adding value

If you want to include value in the `text` element, use the `value` method.

```php
$text->value('MyValue');
```

## Rendering

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

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

Or, use the magic `__toString` method.

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

## Common use cases

Below are examples of common use cases:

```php
// adding multiple attributes
$text->class('external')->value('Myvalue');

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

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

## Prefix and Suffix

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

```php
// adding a prefix
$html = $text->content('Home')->prefix('MyPrefix')->render();

// adding a suffix
$html = $text->content('Home')->suffix('MySuffix')->render();
```

## 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
// using a custom template
$textArea->template('<div>{tag}</div>');
```

## Attributes

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

The following methods are available for setting attributes:

| Method | Description |
| ------------------ | ----------------------------------------------------------------------------------------------- |
| `ariaDescribedBy()`| Set the `aria-describedby` attribute. |
| `ariaLabel()` | Set the `aria-label` attribute. |
| `attributes()` | Set multiple `attributes` at once. |
| `autofocus()` | Set the `autofocus` attribute. |
| `class()` | Set the `class` attribute. |
| `dataAttributes()` | Set multiple `data-attributes` at once. |
| `dirName()` | Set the `dirname` attribute. |
| `disabled()` | Set the `disabled` attribute. |
| `form()` | Set the `form` attribute. |
| `hidden()` | Set the `hidden` attribute. |
| `id()` | Set the `id` attribute. |
| `lang()` | Set the `lang` attribute. |
| `name()` | Set the `name` attribute. |
| `placeholder()` | Set the `placeholder` attribute. |
| `readOnly()` | Set the `readonly` attribute. |
| `size()` | Set the `size` attribute. |
| `style()` | Set the `style` attribute. |
| `tabIndex()` | Set the `tabindex` attribute. |
| `title()` | Set the `title` attribute. |
| `value()` | Set the `value` attribute. |

## Custom methods

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

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

| Method | Description |
| ---------------------------- | ------------------------------------------------------------------------------------- |
| `generateField()` | Generate the field id and name for the `HTML` output. |
| `prefix()` | Add text before the `textarea` element. |
| `prefixContainer()` | Set enabled or disabled for the `prefix-container` element. |
| `prefixContainerAttributes()`| Set `attributes` for the `prefix-container` element. |
| `prefixContainerClass()` | Set the `class` attribute for the `prefix-container` element. |
| `prefixContainerTag()` | Set the `tag` for the `prefix-container` element. |
| `render()` | Generates the `HTML` output. |
| `suffix()` | Add text after the `label` element. |
| `suffixContainer()` | Set enabled or disabled for the `suffix-container` element. |
| `suffixContainerAttributes()`| Set `attributes` for the `suffix-container` element. |
| `suffixContainerClass()` | Set the `class` attribute for the `suffix-container` element. |
| `suffixContainerTag()` | Set the `tag` for the `suffix-container` element. |
| `template()` | Set the template for the `HTML` output. |
| `tokenValues()` | Set the token values for the `HTML` output. |
| `widget()` | Instantiates the `Text::class`. |

## Validate methods

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

| Method | Description |
| -------------- | --------------------------------------------------------------------------------------------------- |
| `maxLength()` | Set the `maxlength` attribute. |
| `minLength()` | Set the `minlength` attribute. |
| `pattern()` | Set the `pattern` attribute. |
| `required()` | Set the `required` attribute. |

0 comments on commit 6c18e93

Please sign in to comment.