Skip to content

Commit

Permalink
Add Panel widget
Browse files Browse the repository at this point in the history
  • Loading branch information
shkolin committed Jan 28, 2021
1 parent 7c2ef65 commit e80b4e6
Show file tree
Hide file tree
Showing 5 changed files with 908 additions and 41 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -95,6 +95,7 @@ We will quickly and easily describe how to use widgets, and be able to use all t
- [Modal](docs/modal.md)
- [ModalCard](docs/modalcard.md)
- [Tabs](docs/tabs.md)
- [Panel](docs/panel.md)

### Unit testing

Expand Down
129 changes: 129 additions & 0 deletions docs/panel.md
@@ -0,0 +1,129 @@
# Panel widget

A composable [panel](https://bulma.io/documentation/components/panel/), for compact controls

## Usage

```php
<?php

declare(strict_types=1);

use Yiisoft\Yii\Bulma\Panel;
use Yiisoft\Yii\Bulma\Asset\BulmaAsset;
use Yiisoft\Yii\Bulma\Asset\BulmaJsAsset;

/**
* @var \Yiisoft\Assets\AssetManager $assetManager
* @var \Yiisoft\View\WebView $this
*/

$assetManager->register([
BulmaAsset::class,
BulmaJsAsset::class,
]);

$this->setCssFiles($assetManager->getCssFiles());
$this->setJsFiles($assetManager->getJsFiles());

$template =<<<HTML
{panelBegin}
{panelHeading}
{panelTabs}
<div class="panel-block">
<p class="control has-icons-left">
<input class="input" type="text" placeholder="Search" />
<span class="icon is-left">
<i class="fas fa-search" aria-hidden="true"></i>
</span>
</p>
</div>
{panelItems}
<div class="panel-block">
<button class="button is-link is-outlined is-fullwidth">
Reset all filters
</button>
</div>
{panelEnd}
HTML;

echo Panel::widget()
->template($template)
->heading('Repositories')
->color(Panel::COLOR_PRIMARY)
->tabs([
[
'label' => 'All',
'active' => true,
'items' => [
[
'label' => 'bulma',
'icon' => 'fas fa-book',
],
[
'label' => 'marksheet',
'icon' => 'fas fa-book',
],
],
],
['label' => 'Public'],
['label' => 'Private'],
['label' => 'Sources'],
['label' => 'Forks'],
])
```

HTML produced is like the following:

```html
<article class="panel is-primary">
<p class="panel-heading">Repositories</p>
<p class="panel-tabs">
<a class="is-active" href="#w1-panel-c0">All</a>
<a>Public</a>
<a>Private</a>
<a>Sources</a>
<a>Forks</a>
</p>
<div class="panel-block">
<p class="control has-icons-left">
<input class="input" type="text" placeholder="Search" />
<span class="icon is-left">
<i class="fas fa-search" aria-hidden="true"></i>
</span>
</p>
</div>
<div id="w1-panel-c0">
<a class="panel-block is-active">
<span class="panel-icon">
<i class="fas fa-book" aria-hidden="true"></i>
</span>
bulma
</a>
<a class="panel-block">
<span class="panel-icon">
<i class="fas fa-book" aria-hidden="true"></i>
</span>
marksheet
</a>
</div>
<div class="panel-block">
<button class="button is-link is-outlined is-fullwidth">
Reset all filters
</button>
</div>
</article>
```

## Reference

| Method | Description | Default |
| ------------------------------ | --------------------------------------------------------- | ------------------------------------------------------------- |
| `options(array $value)` | HTML attributes for the widget container tag. | [`class` => `panel`] |
| `headingOptions(array $value)` | HTML attributes of the heading. | [`class` => `panel-heading`] |
| `heading(?string $value)` | Text of the brand heading. | `''` |
| `color(string $value)` | Color panel. | `''` |
| `tabs(array $value)` | List of panel tabs items. | `[]` |
| `tabsOptions(array $value)` | HTML attributes for the tabs container tag. | `[]` |
| `encodeLabels(bool $value)` | Whether the labels for tabs items should be HTML-encoded. | `true` |
| `template(string $value)` | String the template for rendering panel. | `{panelBegin}{panelHeading}{panelTabs}{panelItems}{panelEnd}` |
90 changes: 49 additions & 41 deletions docs/tabs.md
Expand Up @@ -50,52 +50,60 @@ HTML produced is like the following:

```html
<div class="tabs is-centered is-large is-boxed">
<ul>
<li class="is-active">
<a href="#w0-tabs-c1">
<span class="icon is-small"><i class="fas fa-image" aria-hidden="true"></i></span>
<span>Pictures</span>
</a>
</li>
<li>
<a href="#w0-tabs-c2">
<span class="icon is-small"><i class="fas fa-music" aria-hidden="true"></i></span>
<span>Music</span>
</a>
</li>
<li>
<a href="#w0-tabs-c3">
<span class="icon is-small"><i class="fas fa-film" aria-hidden="true"></i></span>
<span>Videos</span>
</a>
</li>
<li>
<a href="#w0-tabs-c4">
<span class="icon is-small"><i class="far fa-file-alt" aria-hidden="true"></i></span>
<span>Documents</span>
</a>
</li>
</ul>
<ul>
<li class="is-active">
<a href="#w0-tabs-c1">
<span class="icon is-small"
><i class="fas fa-image" aria-hidden="true"></i
></span>
<span>Pictures</span>
</a>
</li>
<li>
<a href="#w0-tabs-c2">
<span class="icon is-small"
><i class="fas fa-music" aria-hidden="true"></i
></span>
<span>Music</span>
</a>
</li>
<li>
<a href="#w0-tabs-c3">
<span class="icon is-small"
><i class="fas fa-film" aria-hidden="true"></i
></span>
<span>Videos</span>
</a>
</li>
<li>
<a href="#w0-tabs-c4">
<span class="icon is-small"
><i class="far fa-file-alt" aria-hidden="true"></i
></span>
<span>Documents</span>
</a>
</li>
</ul>
</div>

<div class="tabs-content">
<div id="w0-tabs-c1" class="is-active">Some text about pictures</div>
<div id="w0-tabs-c2">Some text about music</div>
<div id="w0-tabs-c3">Some text about videos</div>
<div id="w0-tabs-c4">Some text about documents</div>
<div id="w0-tabs-c1" class="is-active">Some text about pictures</div>
<div id="w0-tabs-c2">Some text about music</div>
<div id="w0-tabs-c3">Some text about videos</div>
<div id="w0-tabs-c4">Some text about documents</div>
</div>
```

## Reference

Method | Description | Default
------------------------------|------------------------------------------------------------------------------|---------
`options(array $value)` | HTML attributes for the widget container tag. | [`class` => `tabs`]
`items(array $value)` | List of tab items. | `[]`
`currentPath(?string $value)` | Allows you to assign the current path of the URL from request controller. | `null`
`activateItems(bool $value)` | Whether to activate item if its route matches the currently requested route. | `true`
`encodeLabels(bool $value)` | Whether the labels for menu items should be HTML-encoded. | `true`
`size(string $value)` | Size of the tabs list. | `''`
`alignment(string $value)` | Alignment of the tabs list. | `''`
`style(string $value)` | Style of the tabs list. | `''`
`tabsContentOptions(array $value)` | List of HTML attributes for the `tabs-content` container. | `[]`
| Method | Description | Default |
| ---------------------------------- | ---------------------------------------------------------------------------- | ------------------- |
| `options(array $value)` | HTML attributes for the widget container tag. | [`class` => `tabs`] |
| `items(array $value)` | List of tab items. | `[]` |
| `currentPath(?string $value)` | Allows you to assign the current path of the URL from request controller. | `null` |
| `activateItems(bool $value)` | Whether to activate item if its route matches the currently requested route. | `true` |
| `encodeLabels(bool $value)` | Whether the labels for menu items should be HTML-encoded. | `true` |
| `size(string $value)` | Size of the tabs list. | `''` |
| `alignment(string $value)` | Alignment of the tabs list. | `''` |
| `style(string $value)` | Style of the tabs list. | `''` |
| `tabsContentOptions(array $value)` | List of HTML attributes for the `tabs-content` container. | `[]` |

0 comments on commit e80b4e6

Please sign in to comment.