Skip to content

Commit

Permalink
Merge branches 'initial-commit' and 'initial-commit' of https://githu…
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Nov 11, 2023
2 parents d26c6f3 + 749dbb1 commit 534bff4
Show file tree
Hide file tree
Showing 59 changed files with 564 additions and 406 deletions.
51 changes: 28 additions & 23 deletions src/Accordion.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* @link https://www.yiiframework.com/
*
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
Expand Down Expand Up @@ -52,6 +53,7 @@
* ```
*
* @see https://getbootstrap.com/docs/5.1/components/collapse/#accordion-example
*
* @author Antonio Ramirez <amigo.cobos@gmail.com>
* @author Simon Karlen <simi.albi@outlook.com>
*/
Expand Down Expand Up @@ -109,30 +111,31 @@ class Accordion extends Widget
* 'class' => 'custom-toggle',
* ]
* ```
*
*/
public $itemToggleOptions = [];


/**
* @return string
* @throws InvalidConfigException
*
* @return string
*/
public function run(): string
{
$this->registerPlugin('collapse');
Html::addCssClass($this->options, ['widget' => 'accordion']);

return implode("\n", [
Html::beginTag('div', $this->options),
$this->renderItems(),
Html::endTag('div'),
]) . "\n";
Html::beginTag('div', $this->options),
$this->renderItems(),
Html::endTag('div'),
]) . "\n";
}

/**
* Renders collapsible items as specified on [[items]].
*
* @throws InvalidConfigException if label isn't specified
*
* @return string the rendering result
*/
public function renderItems(): string
Expand All @@ -151,9 +154,8 @@ public function renderItems(): string
if (!array_key_exists('label', $item)) {
if (is_int($key)) {
throw new InvalidConfigException("The 'label' option is required.");
} else {
$item['label'] = $key;
}
$item['label'] = $key;
}
$header = ArrayHelper::remove($item, 'label');
$options = ArrayHelper::getValue($item, 'options', []);
Expand All @@ -166,12 +168,15 @@ public function renderItems(): string

/**
* Renders a single collapsible item group
*
* @param string $header a label of the item group [[items]]
* @param array $item a single item from [[items]]
* @param int $index the item index as each item group content must have an id
* @return string the rendering result
*
* @throws InvalidConfigException
* @throws Exception
*
* @return string the rendering result
*/
public function renderItem(string $header, array $item, int $index): string
{
Expand Down Expand Up @@ -201,12 +206,12 @@ public function renderItem(string $header, array $item, int $index): string
'type' => 'button',
'data' => [
'bs-toggle' => 'collapse',
'bs-target' => '#' . $options['id']
'bs-target' => '#' . $options['id'],
],
'aria' => [
'expanded' => $expand ? 'true' : 'false',
'controls' => $options['id']
]
'controls' => $options['id'],
],
], $this->itemToggleOptions);

$itemToggleTag = ArrayHelper::remove($itemToggleOptions, 'tag', 'button');
Expand All @@ -220,10 +225,10 @@ public function renderItem(string $header, array $item, int $index): string
Html::addCssClass($itemToggleOptions, ['widget' => 'accordion-button']);
}
$headerToggle = Button::widget([
'label' => $header,
'encodeLabel' => false,
'options' => $itemToggleOptions,
]) . "\n";
'label' => $header,
'encodeLabel' => false,
'options' => $itemToggleOptions,
]) . "\n";
}

$header = Html::tag('h5', $headerToggle, ['class' => 'mb-0']);
Expand All @@ -232,12 +237,12 @@ public function renderItem(string $header, array $item, int $index): string
$content = Html::tag('div', $item['content'], ['class' => 'accordion-body']) . "\n";
} elseif (is_array($item['content'])) {
$content = Html::ul($item['content'], [
'class' => 'list-group',
'itemOptions' => [
'class' => 'list-group-item',
],
'encode' => false,
]) . "\n";
'class' => 'list-group',
'itemOptions' => [
'class' => 'list-group-item',
],
'encode' => false,
]) . "\n";
} else {
throw new InvalidConfigException('The "content" option should be a string, array or object.');
}
Expand Down
14 changes: 12 additions & 2 deletions src/ActiveField.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

declare(strict_types=1);
/**
* @link https://www.yiiframework.com/
*
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
Expand Down Expand Up @@ -152,7 +155,7 @@ class ActiveField extends \yii\widgets\ActiveField
*/
public $hintOptions = ['class' => ['widget' => 'form-text', 'text-muted'], 'tag' => 'div'];
/**
* @var null|array CSS grid classes for horizontal layout. This must be an array with these keys:
* @var array|null CSS grid classes for horizontal layout. This must be an array with these keys:
* - 'offset' the offset grid class to append to the wrapper if no label is rendered
* - 'label' the label grid class
* - 'wrapper' the wrapper grid class
Expand Down Expand Up @@ -201,7 +204,6 @@ class ActiveField extends \yii\widgets\ActiveField
*/
public $enableLabel = true;


/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -254,6 +256,7 @@ public function render($content = null): string
/**
* {@inheritdoc}
* Enable option `switch` to render as toggle switch.
*
* @see https://getbootstrap.com/docs/5.1/forms/checks-radios/#switches
*/
public function checkbox($options = [], $enclosedByLabel = false)
Expand Down Expand Up @@ -447,12 +450,14 @@ public function dropDownList($items, $options = [])

/**
* Renders Bootstrap static form control.
*
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. There are also a special options:
*
* - encode: bool, whether value should be HTML-encoded or not.
*
* @return $this the field object itself
*
* @see https://getbootstrap.com/docs/5.1/components/forms/#readonly-plain-text
*/
public function staticControl(array $options = []): self
Expand Down Expand Up @@ -484,6 +489,7 @@ public function label($label = null, $options = [])

/**
* @param bool $value whether to render a inline list
*
* @return $this the field object itself
* Make sure you call this method before [[checkboxList()]] or [[radioList()]] to have any effect.
*/
Expand Down Expand Up @@ -514,6 +520,7 @@ public function fileInput($options = [])
* - 'step': range step, by default, 1
*
* @return $this
*
* @see https://getbootstrap.com/docs/5.1/forms/range/
*/
public function rangeInput(array $options = [])
Expand All @@ -527,7 +534,9 @@ public function rangeInput(array $options = [])
* Renders a color picker (custom input).
*
* @param array $options the tag options in terms of name-value pairs
*
* @return $this
*
* @see https://getbootstrap.com/docs/5.1/forms/form-control/#color
*/
public function colorInput(array $options = [])
Expand All @@ -540,6 +549,7 @@ public function colorInput(array $options = [])

/**
* @param array $instanceConfig the configuration passed to this instance's constructor
*
* @return array the layout specific default configuration for this instance
*/
protected function createLayoutConfig(array $instanceConfig): array
Expand Down
14 changes: 9 additions & 5 deletions src/ActiveForm.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* @link https://www.yiiframework.com/
*
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
Expand Down Expand Up @@ -68,22 +69,23 @@ class ActiveForm extends \yii\widgets\ActiveForm
/**
* Default form layout
*/
const LAYOUT_DEFAULT = 'default';
public const LAYOUT_DEFAULT = 'default';
/**
* Horizontal form layout
*/
const LAYOUT_HORIZONTAL = 'horizontal';
public const LAYOUT_HORIZONTAL = 'horizontal';
/**
* Inline form layout
*/
const LAYOUT_INLINE = 'inline';
public const LAYOUT_INLINE = 'inline';
/**
* Floating labels form layout
*/
const LAYOUT_FLOATING = 'floating';
public const LAYOUT_FLOATING = 'floating';

/**
* @var string the default field class name when calling [[field()]] to create a new field.
*
* @see fieldConfig
*/
public $fieldClass = ActiveField::class;
Expand All @@ -96,6 +98,7 @@ class ActiveForm extends \yii\widgets\ActiveForm
* By choosing a layout, an appropriate default field configuration is applied. This will
* render the form fields with slightly different markup for each layout. You can
* override these defaults through [[fieldConfig]].
*
* @see ActiveField for details on Bootstrap 5 field configuration
*/
public $layout = self::LAYOUT_DEFAULT;
Expand All @@ -116,9 +119,9 @@ class ActiveForm extends \yii\widgets\ActiveForm
*/
public $validationStateOn = self::VALIDATION_STATE_ON_INPUT;


/**
* {@inheritdoc}
*
* @throws InvalidConfigException
*/
public function init()
Expand All @@ -135,6 +138,7 @@ public function init()

/**
* {@inheritDoc}
*
* @return ActiveField|\yii\widgets\ActiveField
*/
public function field($model, $attribute, $options = []): ActiveField

Check failure on line 144 in src/ActiveForm.php

View workflow job for this annotation

GitHub Actions / phpstan / PHP 8.1-ubuntu-latest

PHPDoc tag @return with type yii\widgets\ActiveField is not subtype of native type yii\bootstrap5\ActiveField.

Check failure on line 144 in src/ActiveForm.php

View workflow job for this annotation

GitHub Actions / phpstan / PHP 8.1-ubuntu-latest

PHPDoc tag @return with type yii\widgets\ActiveField is not subtype of native type yii\bootstrap5\ActiveField.
Expand Down
10 changes: 6 additions & 4 deletions src/Alert.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* @link https://www.yiiframework.com/
*
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
Expand Down Expand Up @@ -42,6 +43,7 @@
* ```
*
* @see https://getbootstrap.com/docs/5.1/components/alerts/
*
* @author Antonio Ramirez <amigo.cobos@gmail.com>
* @author Simon Karlen <simi.albi@outlook.com>
*/
Expand All @@ -68,7 +70,6 @@ class Alert extends Widget
*/
public $closeButton = [];


/**
* {@inheritdoc}
*/
Expand All @@ -94,6 +95,7 @@ public function run()

/**
* Renders the alert body and the close button (if any).
*
* @return string the rendering result
*/
protected function renderBodyEnd(): string
Expand All @@ -103,6 +105,7 @@ protected function renderBodyEnd(): string

/**
* Renders the close button.
*
* @return string|null the rendering result
*/
protected function renderCloseButton()
Expand All @@ -115,9 +118,8 @@ protected function renderCloseButton()
}

return Html::tag($tag, $label, $closeButton);
} else {
return null;
}
return null;

Check warning on line 122 in src/Alert.php

View check run for this annotation

Codecov / codecov/patch

src/Alert.php#L122

Added line #L122 was not covered by tests
}

/**
Expand All @@ -132,7 +134,7 @@ protected function initOptions()
$this->closeButton = array_merge([
'class' => ['widget' => 'btn-close'],
'data' => ['bs-dismiss' => 'alert'],
'aria' => ['label' => Yii::t('yii/bootstrap5', 'Close')]
'aria' => ['label' => Yii::t('yii/bootstrap5', 'Close')],
], $this->closeButton);

Html::addCssClass($this->options, ['toggle' => 'alert-dismissible']);
Expand Down
7 changes: 7 additions & 0 deletions src/BaseHtml.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* @link https://www.yiiframework.com/
*
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
Expand All @@ -19,11 +20,13 @@ abstract class BaseHtml extends \yii\helpers\Html
{
/**
* @var int a counter used to generate [[id]] for widgets.
*
* @internal
*/
public static $counter = 0;
/**
* @var string the prefix to the automatically generated widget IDs.
*
* @see getId()
*/
public static $autoIdPrefix = 'i';
Expand All @@ -40,6 +43,7 @@ abstract class BaseHtml extends \yii\helpers\Html
* the attributes of the resulting tag. There are also a special options:
*
* @return string generated HTML
*
* @see https://getbootstrap.com/docs/5.1/components/forms/#readonly-plain-text
*/
public static function staticControl(string $value, array $options = []): string
Expand All @@ -57,7 +61,9 @@ public static function staticControl(string $value, array $options = []): string
* @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
* about attribute expression.
* @param array $options the tag options in terms of name-value pairs. See [[staticControl()]] for details.
*
* @return string generated HTML
*
* @see staticControl()
*/
public static function activeStaticControl(Model $model, string $attribute, array $options = []): string
Expand Down Expand Up @@ -196,6 +202,7 @@ protected static function booleanInput($type, $name, $checked = false, $options

/**
* Returns an autogenerated ID
*
* @return string Autogenerated ID
*/
protected static function getId(): string
Expand Down
Loading

0 comments on commit 534bff4

Please sign in to comment.