Skip to content

Commit

Permalink
Update docs (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Oct 9, 2022
1 parent f694913 commit a58bbdc
Show file tree
Hide file tree
Showing 13 changed files with 281 additions and 130 deletions.
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -36,6 +36,7 @@ For a description of how to use it, see the documentation for each widget:
- [Block](docs/block.md)
- [Breadcrumbs](docs/breadcrumbs.md)
- [ContentDecorator](docs/content-decorator.md)
- [Dropdown](docs/dropdown.md)
- [FragmentCache](docs/fragment-cache.md)
- [Menu](docs/menu.md)

Expand Down Expand Up @@ -66,6 +67,15 @@ The code is statically analyzed with [Psalm](https://psalm.dev/). To run static
./vendor/bin/psalm
```

### Rector

Use [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or
use either newest or any specific version of PHP:

```shell
./vendor/bin/rector
```

## License

The Yii Widgets is free software. It is released under the terms of the BSD License.
Expand Down
36 changes: 22 additions & 14 deletions docs/alert.md
Expand Up @@ -30,7 +30,7 @@ echo Alert::widget()
->iconClass('bi bi-exclamation-triangle-fill flex-shrink-0 me-2')
->id('w0-alert')
->layoutBody('{icon}{body}{button}')
->render(),
->render();
```

The code above generates the following HTML:
Expand All @@ -55,7 +55,7 @@ echo Alert::widget()
->class('notification is-danger')
->id('w0-alert')
->layoutBody('{body}{button}')
->render(),
->render();
```

The code above generates the following HTML:
Expand All @@ -79,7 +79,7 @@ echo Alert::widget()
->buttonOnClick('closeAlert()')
->class('bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative')
->id('w0-alert')
->render(),
->render();
```

The code above generates the following HTML:
Expand All @@ -99,22 +99,30 @@ All setters are immutable and return a new instance of the `Yiisoft\Yii\Widgets\

Method | Description | Default
-------|-------------|---------
`attributes(array $value)` | HTML attributes for the alert container | `[]`
`buttonAttributes(array $value)` | The attributes for rendering the button tag | `[]`
`buttonLabel(string $value)` | The label for the button | `×`
`attributes(array $valuesMap)` | HTML attributes for the alert container | `[]`
`body(string $value)` | The message body. | `''`
`bodyAttributes(array $value)` | HTML attributes for the message body tag | `[]`
`bodyTag(string $value)` | The tag for the message body | `span`
`bodyAttributes(array $valuesMap)` | HTML attributes for the message body tag | `[]`
`bodyClass(string $value)` | CSS class for the message body tag | `''`
`bodyContainer(bool $value)` | Allows you to add an extra wrapper for the body | `false`
`bodyContainerAttributes(array $value)` | HTML attributes for extra wrapper for the body | `[]`
`bodyContainerAttributes(array $valuesMap)` | HTML attributes for extra wrapper for the body | `[]`
`bodyContainerClass(string $value)` | CSS class for extra wrapper for the body | `''`
`bodyTag(string $value)` | The tag for the message body | `span`
`buttonAttributes(array $valuesMap)` | The attributes for rendering the button tag | `[]`
`buttonClass(string $value)` | The CSS class for the close button | `''`
`buttonLabel(string $value)` | The label for the button | `×`
`buttonOnClick(string $value)` | The JavaScript for the button's `onclick` event | `''`
`class(string $value)` | The CSS class for the widget | `''`
`header(string $value)` | The message header. | `''`
`headerAttributes(array $value)` | HTML attributes for the message header | `[]`
`headerAttributes(array $valuesMap)` | HTML attributes for the message header | `[]`
`headerClass(string $value)` | CSS class for the message header tag | `''`
`headerContainer(bool $value)` | Allows you to add an extra wrapper for the header | `false`
`headerContainerAttributes(array $value)` | HTML attributes for extra wrapper for the header | `[]`
`headerContainerAttributes(array $valuesMap)` | HTML attributes for extra wrapper for the header | `[]`
`headerContainerClass(string $value)` | CSS class for extra wrapper for the header | `''`
`headerTag(string $value)` | The tag for the message header | `<span>`
`id(string $value)` | The unique identifier of the Alert. | `null`
`iconAttributes(array $value)` | HTML attributes for the icon | `[]`
`iconContainerAttributes(array $value)` | HTML attributes for the icon container | `[]`
`iconAttributes(array $valuesMap)` | HTML attributes for the icon | `[]`
`iconClass(string $value)` | CSS class for the icon | `''`
`iconContainerAttributes(array $valuesMap)` | HTML attributes for the icon container | `[]`
`iconText(string $value)` | The text for the icon | `''`
`id(string $value)` | The unique identifier of the Alert. | `null`
`layoutBody(string $value)` | The layout for the body. | `''`
`layoutHeader(string $value)` | The layout for the header. | `''`
4 changes: 2 additions & 2 deletions docs/block.md
Expand Up @@ -48,5 +48,5 @@ All setters are immutable and return a new instance of the `Yiisoft\Yii\Widgets\

Method | Description | Default
-------|-------------|---------
`id(string $value)` | The unique identifier of the block. | `null`
`renderInPlace()` | Enables in-place rendering of the block contents. | `disabled`
`id(string $value)` | The unique identifier of the block. | `''`
`renderInPlace()` | Enables in-place rendering of the block contents. | `false`
10 changes: 4 additions & 6 deletions docs/breadcrumbs.md
Expand Up @@ -28,8 +28,7 @@ echo Breadcrumbs::widget()
'class' => 'item',
],
])
->render()
;
->render();
```

The code above generates the following HTML:
Expand All @@ -49,10 +48,9 @@ class with the specified value.

Method | Description | Default
-------|-------------|---------
`tag(string $value)` | The container tag name. | `'ul'`
`activeItemTemplate(string $value)`| Template used to render each active item in the breadcrumbs. | `"<li class=\"active\">{link}</li>\n"`
`attributes(array $valuesMap)` | HTML attributes for the breadcrumbs container | `[]`
`homeItem(?array $value)` | The first item in the breadcrumbs (called home link). | `['label' => 'Home', 'url' => '/']`
`items(array $value)` | List of items to appear in the breadcrumbs. | `[]`
`options(array $value)` | HTML attributes for the widget container tag. | `['label' => 'Home', 'url' => '/']`
`itemTemplate(string $value)` | Template used to render each inactive item in the breadcrumbs. | `"<li>{link}</li>\n"`
`activeItemTemplate(string $value)`| Template used to render each active item in the breadcrumbs. | `"<li class=\"active\">{link}</li>\n"`
`withoutEncodeLabels()` | Disables encoding for labels. | `enabled`
`tag(string $value)` | The container tag name. | `'ul'`
2 changes: 1 addition & 1 deletion docs/content-decorator.md
Expand Up @@ -12,8 +12,8 @@ For more information about view rendering,
use Yiisoft\Yii\Widgets\ContentDecorator;

ContentDecorator::widget()
->viewFile('@app/views/layouts/main.php')
->parameters(['name' => 'value'])
->viewFile('@app/views/layouts/main.php')
->begin();

echo 'Some content here.';
Expand Down
100 changes: 100 additions & 0 deletions docs/dropdown.md
@@ -0,0 +1,100 @@
# Dropdown widget

The dropdown widget is a simple widget that allows you to select a single value from a list of options.

## Usage

```php
echo Yiisoft\Yii\Widgets\Dropdown::widget()
->id('dropdown-example')
->items(
[
[
'label' => 'Action',
'link' => '#',
'items' => [
['label' => 'Action', 'link' => '#'],
['label' => 'Another action', 'link' => '#'],
['label' => 'Something else here', 'link' => '#'],
'-',
['label' => 'Separated link', 'link' => '#'],
],
],
]
)
->toggleType('link')
->toggleType('split')
->render();
```

The code above generates the following HTML:

```html
<div class="btn-group">
<button type="button" class="btn btn-danger">Action</button>
<button type="button" id="dropdown-example" class="btn btn-danger dropdown-toggle dropdown-toggle-split" aria-expanded="false" data-bs-toggle="dropdown"><span class="visually-hidden">Action</span></button>
<ul class="dropdown-menu" aria-labelledby="dropdown-example">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
</div>
```

## Setters

All setters are immutable and return a new instance of the `Yiisoft\Yii\Widgets\Menu` class with the specified value.

Method | Description | Default
-------|-------------|---------
`activeCssClass(string $value)` | The CSS class to be added to the active item. | `active`
`container(bool $value)` | If the container is enabled, or not. | `true`
`containerAttributes(array $valuesMap)` | The HTML attributes for the container tag. | `[]`
`containerClass(string $value)` | The CSS class for the container tag. | `''`
`containerTag(string $value)` | The tag name for the container tag. | `div`
`disabledClass(string $value)` | The CSS class to be added to the disabled item. | `disabled`
`dividerAttributes(array $valuesMap)` | The HTML attributes for the divider tag. | `[]`
`dividerClass(string $value)` | The CSS class for the divider tag. | `dropdown-divider`
`dividerTag(string $value)` | The tag name for the divider tag. | `hr`
`headerClass(string $value)` | The CSS class for the header tag. | `''`
`headerTag(string $value)` | The tag name for the header tag. | `h6`
`id(string $value)` | The ID of the widget. | `''`
`itemClass(string $value)` | The CSS class for the item tag. | `dropdown-item`
`itemContainer(string $value)` | Item container to use. If false, the item container will not be rendered. | `true`
`itemContainerAttributes(array $valuesMap)` | The HTML attributes for the item container tag. | `[]`
`itemContainerClass(string $value)` | The CSS class for the item container tag. | `dropdown-menu`
`itemContainerTag(string $value)` | The tag name for the item container tag. | `ul`
`itemTag(string $value)` | The tag name for the item tag. | `a`
`items(array $value)` | List of menu items in the dropdown. | `[]`
`itemsContainerAttributes(array $valuesMap)` | The HTML attributes for the items container tag. | `[]`
`itemsContainerClass(string $value)` | The CSS class for the items container tag. | `''`
`itemsContainerTag(string $value)` | The tag name for the items container tag. | `li`
`splitButtonAttributes(array $valuesMap)` | The HTML attributes for the split button tag. | `[]`
`splitButtonClass(string $value)` | The CSS class for the split button tag. | `''`
`toggleAttributes(array $valuesMap)` | The HTML attributes for the toggle tag. | `[]`
`toggleClass(string $value)` | The CSS class for the toggle tag. | `''`
`toggleType(string $value)` | The type of the toggle button. | `button`

### Items structure is an array of the following structure:

```php
[
[
'label' => '',
'active' => false,
'disabled' => false,
'enclose' => true,
'encode' => true,
'headerAttributes' => [],
'link' => '',
'linkAttributes' => [],
'icon' => '',
'iconAttributes' => [],
'items' => [],
'itemsContainerAttributes' => [],
'visible' => true,
],
]

4 changes: 2 additions & 2 deletions docs/fragment-cache.md
Expand Up @@ -48,7 +48,7 @@ class with the specified value.

Method | Description | Default
-------|-------------|---------
`id(string $value)` | The unique identifier of the cache fragment. | `null`
`ttl(int $value)` | The number of seconds that the data can remain valid in cache. | `60`
`dynamicContents(DynamicContent ...$value)` | The dynamic content instances. | `null`
`id(string $value)` | The unique identifier of the cache fragment. | `''`
`ttl(int $value)` | The number of seconds that the data can remain valid in cache. | `60`
`variations(string ...$value)` | The factors that would cause the variation of the content being cached. | `[]`

0 comments on commit a58bbdc

Please sign in to comment.