Skip to content

Commit

Permalink
Cleaup, update assets, add BootstrapIcon, and Cdn Asset
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Dec 15, 2020
1 parent f933254 commit f6de65e
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 22 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"require": {
"php": "^7.4|^8.0",
"npm-asset/bootstrap": "^5.0.0",
"npm-asset/bootstrap-icons": "^1.2.1",
"oomphinc/composer-installers-extender": "^2.0.0",
"yiisoft/arrays": "^3.0@dev",
"yiisoft/assets": "^1.0@dev",
Expand Down
3 changes: 2 additions & 1 deletion src/Accordion.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* ]);
* ```
*/
class Accordion extends Widget
final class Accordion extends Widget
{
private array $items = [];
private bool $encodeLabels = true;
Expand All @@ -71,6 +71,7 @@ protected function run(): string

$this->registerPlugin('collapse', $this->options);

/** @psalm-suppress InvalidArgument */
Html::addCssClass($this->options, 'accordion');

return Html::div($this->renderItems(), $this->options);
Expand Down
2 changes: 1 addition & 1 deletion src/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* ->body('Say hello...');
* ```
*/
class Alert extends Widget
final class Alert extends Widget
{
private ?string $body = null;
private array $closeButton = [];
Expand Down
22 changes: 15 additions & 7 deletions src/Assets/BootstrapAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Yiisoft\Yii\Bootstrap5\Assets;

use Yiisoft\Assets\AssetBundle;
use Yiisoft\Files\PathMatcher\PathMatcher;

/**
* Asset bundle for the Twitter bootstrap css files.
Expand All @@ -13,7 +14,7 @@
*
* @package Bootstrap5
*/
class BootstrapAsset extends AssetBundle
final class BootstrapAsset extends AssetBundle
{
public ?string $basePath = '@assets';

Expand All @@ -29,10 +30,17 @@ class BootstrapAsset extends AssetBundle
'js/bootstrap.bundle.js',
];

public array $publishOptions = [
'only' => [
'css/bootstrap.css',
'js/bootstrap.bundle.js',
],
];
public function __construct()
{
$pathMatcher = new PathMatcher();

$this->publishOptions = [
'filter' => $pathMatcher->only(
'css/bootstrap.css',
'css/bootstrap.css.map',
'js/bootstrap.bundle.js',
'js/bootstrap.bundle.js.map',
),
];
}
}
28 changes: 28 additions & 0 deletions src/Assets/BootstrapCdnAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Bootstrap5\Assets;

use Yiisoft\Assets\AssetBundle;

final class BootstrapCdnAsset extends AssetBundle
{
public bool $cdn = true;

public array $css = [
[
'https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css',
'integrity' => 'sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1',
'crossorigin' => 'anonymous',
],
];

public array $js = [
[
'https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js',
'integrity' => 'sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW',
'crossorigin' => 'anonymous',
],
];
}
37 changes: 37 additions & 0 deletions src/Assets/BootstrapIconsAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Bootstrap5\Assets;

use Yiisoft\Assets\AssetBundle;
use Yiisoft\Files\PathMatcher\PathMatcher;

/**
* Asset bundle for the Twitter bootstrap css files.
*
* BootstrapAsset.
*
* @package Bootstrap5
*/
final class BootstrapIconsAsset extends AssetBundle
{
public ?string $basePath = '@assets';

public ?string $baseUrl = '@assetsUrl';

public ?string $sourcePath = '@npm/bootstrap-icons/font';

public array $css = [
'bootstrap-icons.css',
];

public function __construct()
{
$pathMatcher = new PathMatcher();

$this->publishOptions = [
'filter' => $pathMatcher->only('bootstrap-icons.css', 'fonts/*'),
];
}
}
3 changes: 2 additions & 1 deletion src/Breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* ->links(['label' => !empty($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : []]);
* ```
*/
class Breadcrumbs extends Widget
final class Breadcrumbs extends Widget
{
private string $tag = 'ol';
private bool $encodeLabels = true;
Expand All @@ -41,6 +41,7 @@ protected function run(): string
$this->options['id'] = "{$this->getId()}-breadcrumb";
}

/** @psalm-suppress InvalidArgument */
Html::addCssClass($this->options, ['widget' => 'breadcrumb']);

$this->registerPlugin('breadcrumb', $this->options);
Expand Down
3 changes: 2 additions & 1 deletion src/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* ->options(['class' => 'btn-lg']);
* ```
*/
class Button extends Widget
final class Button extends Widget
{
private string $tagName = 'button';
private string $label = 'Button';
Expand All @@ -30,6 +30,7 @@ protected function run(): string
$this->options['id'] = "{$this->getId()}-button";
}

/** @psalm-suppress InvalidArgument */
Html::addCssClass($this->options, ['widget' => 'btn']);

$this->registerPlugin('button', $this->options);
Expand Down
3 changes: 2 additions & 1 deletion src/ButtonDropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ]);
* ```
*/
class ButtonDropdown extends Widget
final class ButtonDropdown extends Widget
{
/**
* The css class part of dropdown
Expand Down Expand Up @@ -71,6 +71,7 @@ protected function run(): string
$html = $this->renderButton() . "\n" . $this->renderDropdown();

if ($this->renderContainer) {
/** @psalm-suppress InvalidArgument */
Html::addCssClass($this->options, ['widget' => 'drop' . $this->direction, 'btn-group']);

$options = $this->options;
Expand Down
3 changes: 2 additions & 1 deletion src/ButtonGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*
* Pressing on the button should be handled via JavaScript. See the following for details:
*/
class ButtonGroup extends Widget
final class ButtonGroup extends Widget
{
private array $buttons = [];
private bool $encodeLabels = true;
Expand All @@ -48,6 +48,7 @@ protected function run(): string
$this->options['id'] = "{$this->getId()}-button-group";
}

/** @psalm-suppress InvalidArgument */
Html::addCssClass($this->options, ['widget' => 'btn-group']);

if (!isset($this->options['role'])) {
Expand Down
3 changes: 2 additions & 1 deletion src/ButtonToolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*
* Pressing on the button should be handled via JavaScript. See the following for details:
*/
class ButtonToolbar extends Widget
final class ButtonToolbar extends Widget
{
private array $buttonGroups = [];
private array $options = [];
Expand All @@ -59,6 +59,7 @@ protected function run(): string
$this->options['id'] = "{$this->getId()}-button-toolbar";
}

/** @psalm-suppress InvalidArgument */
Html::addCssClass($this->options, ['widget' => 'btn-toolbar']);

if (!isset($this->options['role'])) {
Expand Down
5 changes: 3 additions & 2 deletions src/Carousel.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@
* ]);
* ```
*/
class Carousel extends Widget
final class Carousel extends Widget
{
private ?array $controls = [
'<span class="carousel-control-prev-icon" aria-hidden="true"></span><span class="visually-hidden">Previous</span>',
'<span class="carousel-control-next-icon" aria-hidden="true"></span><span class="visually-hidden">Next</span>',
];

private bool $showIndicators = true;
private array $items = [];
private bool $crossfade = false;
Expand All @@ -53,6 +52,7 @@ protected function run(): string
$this->options['id'] = "{$this->getId()}-carousel";
}

/** @psalm-suppress InvalidArgument */
Html::addCssClass($this->options, ['widget' => 'carousel', 'slide']);

if ($this->crossfade) {
Expand Down Expand Up @@ -81,6 +81,7 @@ public function renderIndicators(): string
for ($i = 0, $count = count($this->items); $i < $count; $i++) {
$options = ['data-bs-target' => '#' . $this->options['id'], 'data-bs-slide-to' => $i];
if ($i === 0) {
/** @psalm-suppress InvalidArgument */
Html::addCssClass($options, 'active');
}
$indicators[] = Html::tag('li', '', $options);
Expand Down
3 changes: 2 additions & 1 deletion src/Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* </div>
* ```
*/
class Dropdown extends Widget
final class Dropdown extends Widget
{
private array $items = [];
private bool $encodeLabels = true;
Expand All @@ -44,6 +44,7 @@ protected function run(): string
$this->options['id'] = "{$this->getId()}-dropdown";
}

/** @psalm-suppress InvalidArgument */
Html::addCssClass($this->options, ['widget' => 'dropdown-menu']);

$this->registerClientEvents($this->options['id']);
Expand Down
3 changes: 2 additions & 1 deletion src/Modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* echo Modal::end();
* ```
*/
class Modal extends Widget
final class Modal extends Widget
{
/**
* The additional css class of large modal
Expand Down Expand Up @@ -211,6 +211,7 @@ protected function initOptions(): void
'aria-hidden' => 'true',
], $this->options);

/** @psalm-suppress InvalidArgument */
Html::addCssClass($this->options, ['widget' => 'modal']);

if ($this->getEnableClientOptions() !== false) {
Expand Down
3 changes: 2 additions & 1 deletion src/Nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
* {@see http://getbootstrap.com/components/#dropdowns}
* {@see http://getbootstrap.com/components/#nav}
*/
class Nav extends Widget
final class Nav extends Widget
{
private array $items = [];
private bool $encodeLabels = true;
Expand All @@ -122,6 +122,7 @@ protected function run(): string
$this->options['id'] = "{$this->getId()}-nav";
}

/** @psalm-suppress InvalidArgument */
Html::addCssClass($this->options, ['widget' => 'nav']);

return $this->renderItems();
Expand Down
4 changes: 3 additions & 1 deletion src/NavBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
* }
* ```
*/
class NavBar extends Widget
final class NavBar extends Widget
{
private array $collapseOptions = [];
private ?string $brandLabel = null;
Expand All @@ -132,8 +132,10 @@ public function begin(): ?string
}

if (empty($this->options['class'])) {
/** @psalm-suppress InvalidArgument */
Html::addCssClass($this->options, ['widget' => 'navbar', 'navbar-expand-lg', 'navbar-light', 'bg-light']);
} else {
/** @psalm-suppress InvalidArgument */
Html::addCssClass($this->options, ['widget' => 'navbar']);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Progress.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* ]);
* ```
*/
class Progress extends Widget
final class Progress extends Widget
{
private ?string $label = null;
private ?string $percent = null;
Expand All @@ -65,6 +65,7 @@ protected function run(): string
$this->options['id'] = "{$this->getId()}-progress";
}

/** @psalm-suppress InvalidArgument */
Html::addCssClass($this->options, ['widget' => 'progress']);

return $this->renderProgress();
Expand Down Expand Up @@ -126,6 +127,7 @@ protected function renderBar(string $percent, string $label = '', array $options
'aria-valuemax' => 100,
]);

/** @psalm-suppress InvalidArgument */
Html::addCssClass($options, ['widget' => 'progress-bar']);
Html::addCssStyle($options, ['width' => $valuePercent . '%'], true);

Expand Down
5 changes: 4 additions & 1 deletion src/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* ]);
* ```
*/
class Tabs extends Widget
final class Tabs extends Widget
{
private array $items = [];
private array $itemOptions = [];
Expand All @@ -75,6 +75,7 @@ protected function run(): string
$this->options['id'] = "{$this->getId()}-tabs";
}

/** @psalm-suppress InvalidArgument */
Html::addCssClass($this->options, ['widget' => 'nav', $this->navType]);
Html::addCssClass($this->tabContentOptions, 'tab-content');

Expand Down Expand Up @@ -143,12 +144,14 @@ protected function prepareItems(array &$items, string $prefix = ''): void
ArrayHelper::setValueByPath($items[$n], 'linkOptions.aria-selected', $selected ? 'true' : 'false');
}

/** @psalm-suppress InvalidArgument */
Html::addCssClass($options, ['widget' => 'tab-pane']);

if ($selected) {
Html::addCssClass($options, 'active');
}

/** @psalm-suppress ConflictingReferenceConstraint */
if ($this->renderTabContent) {
$tag = ArrayHelper::remove($options, 'tag', 'div');
$this->panes[] = Html::tag($tag, $item['content'] ?? '', $options);
Expand Down
Loading

0 comments on commit f6de65e

Please sign in to comment.