/** * @inheritdoc */ public function init() { parent::init(); Html::addCssClass($this->options, ['widget' => 'info-box']); $iconOptions = ['class' => 'info-box-icon']; if ($this->type === self::COLORED_ICON) { Html::addCssClass($iconOptions, 'bg-' . $this->color); } else { Html::addCssClass($this->options, 'bg-' . $this->color); } echo Html::beginTag('div', $this->options); echo Html::tag('span', FA::icon($this->icon), $iconOptions); echo '<div class="info-box-content">'; if (!empty($this->contents)) { foreach ($this->contents as $content) { if (is_array($content)) { $type = ArrayHelper::getValue($content, 'type', 'text'); $text = ArrayHelper::getValue($content, 'text', ''); if (in_array($type, ['text', 'number'])) { echo Html::tag('span', $text, ['class' => 'info-box-' . $type]); } elseif ($type == 'progress') { $value = ArrayHelper::getValue($content, 'value', $text); echo '<div class="progress">'; echo Html::tag('div', '', ['class' => 'progress-bar', 'style' => ['width' => $value . '%']]); echo '</div>'; } else { echo Html::tag('span', $text, ['class' => $type]); } } else { echo $content; } } } }
/** * Generates a label. * * @param string $content the label content * @param string $type the label type - default is empty * - is one of [[self::TYPE_SECONDARY]], [[self::TYPE_SUCCESS]], [[self::TYPE_WARNING]], [[self::TYPE_ALERT]] * @param string $border the border type - defaults is empty * - is one of [[self::BORDER_RADIUS]], [[self::BORDER_ROUND]] * @param array $options html options for the label container * @param string $tag the label container tag - defaults to 'span' * * Example(s): * ~~~ * echo Html::fLabel('Regular'); * echo Html::fLabel('Primary', Html::TYPE_PRIMARY); * echo Html::fLabel('Success round', Html::TYPE_SUCCESS, Html::BORDER_ROUND); * ~~~ * * @see http://getbootstrap.com/components/#labels */ public static function fLabel($content, $type = '', $border = '', $options = [], $tag = 'span') { Html::addCssClass($options, 'label'); Html::addCssClass($options, $type); Html::addCssClass($options, $border); return static::tag($tag, $content, $options); }
public function run() { AdminlteAsset::register($this->getView()); Html::addCssClass($this->options, ['widget' => 'progress']); if ($this->vertical) { Html::addCssClass($this->options, 'vertical'); } if (!empty($this->size)) { Html::addCssClass($this->options, $this->size); } $barOptions = ['class' => 'progress-bar']; if (!empty($this->type)) { Html::addCssClass($barOptions, 'progress-bar-' . $this->type); } if ($this->striped) { Html::addCssClass($barOptions, 'progress-bar-striped'); } $barOptions['style']['width'] = $this->value . '%'; if (empty($this->text)) { $text = ''; } else { $text = Html::tag('span', $text, ['class' => 'sr-only']); } return Html::tag('div', Html::tag('div', $text, $barOptions), $this->options); }
/** * @inheritdoc */ public function init() { parent::init(); Html::addCssClass($this->options, ['widget' => 'box']); if ($this->solid) { Html::addCssClass($this->options, 'box-solid'); if ($this->variant === null) { Html::addCssClass($this->options, 'box-default'); } } if ($this->variant !== null) { Html::addCssClass($this->options, 'box-' . $this->variant); } echo Html::beginTag('div', $this->options); // header if ($this->header || !empty($this->boxTools)) { echo '<div class="box-header with-border">'; echo Html::tag('h3', $this->header, ['class' => 'box-title']); } // box-tools if (!empty($this->boxTools)) { echo Html::beginTag('div', ['class' => 'box-tools pull-right']); foreach ($this->boxTools as $toolbox) { if (is_array($toolbox)) { $tag = 'span'; if (($widget = ArrayHelper::getValue($toolbox, 'button')) !== null) { $tag = 'button'; $toolbox['options']['data-widget'] = $widget; Html::addCssClass($toolbox['options'], 'btn btn-box-tool'); } elseif (($label = ArrayHelper::getValue($toolbox, 'label')) !== null) { Html::addCssClass($toolbox['options'], 'label label-' . $label); } elseif (($badge = ArrayHelper::getValue($toolbox, 'badge')) !== null) { Html::addCssClass($toolbox['options'], 'badge bg-' . $badge); } $tag = ArrayHelper::getValue($toolbox, 'tag', $tag); $options = ArrayHelper::getValue($toolbox, 'options', []); $text = ArrayHelper::getValue($toolbox, 'text', ''); $icon = ArrayHelper::getValue($toolbox, 'icon'); if ($icon !== null) { $text .= ' ' . FA::icon($icon); } if (($tooltip = ArrayHelper::getValue($toolbox, 'tooltip')) !== null) { $options['data-toggle'] = 'tooltip'; $options['title'] = $tooltip; } echo Html::tag($tag, $text, $options); } else { echo $toolbox; } } echo '</div>'; } if ($this->header || !empty($this->boxTools)) { echo '</div>'; } // body echo '<div class="box-body">'; echo $this->body; }
/** * Initializes the widget. * If you override this method, make sure you call the parent implementation first. */ public function init() { parent::init(); $this->clientOptions = false; if ($this->defaultClass) { Html::addCssClass($this->options, $this->defaultClass); } }
/** * Fetch the icon for a icon identifier * * @param string $id suffix the icon suffix name * @param array $options the icon HTML attributes * @param string $prefix the icon css prefix name * * @return string the parsed icon */ public function icon($id, $options = ['style' => 'margin-right:5px'], $prefix = null) { if ($prefix === null) { $prefix = $this->prefix; } Html::addCssClass($options, explode(' ', $prefix . $id)); return Html::tag('i', '', $options); }
public function init() { parent::init(); Html::addCssClass($this->options, ['weui_grid']); if (!isset($this->options['href'])) { $this->options['href'] = "javascript:;"; } }
/** * @inheritdoc */ public function init() { if (!in_array($this->layout, ['default', 'horizontal', 'inline'])) { throw new InvalidConfigException('Invalid layout type: ' . $this->layout); } if ($this->layout !== 'default') { Html::addCssClass($this->options, 'form-' . $this->layout); } parent::init(); }
/** * Renders and inline list * @param array $items the items to render * @param array $htmlOptions the HTML attributes * @return string the generated list */ public static function inlineList($items, $htmlOptions = array()) { $listItems = array(); Html::addCssClass($htmlOptions, 'inline-list'); foreach ($items as $item) { $listItems[] = \CHtml::tag('li', $htmlOptions, $item); } if (!empty($listItems)) { return \CHtml::tag('ul', $htmlOptions, implode("\n", $listItems)); } }
/** * @inheritdoc */ public static function checkbox($name, $checked = false, $options = []) { $options['checked'] = (bool) $checked; $value = array_key_exists('value', $options) ? $options['value'] : '1'; if (isset($options['uncheck'])) { // add a hidden field so that if the checkbox is not selected, it still submits a value $hidden = static::hiddenInput($name, $options['uncheck']); unset($options['uncheck']); } else { $hidden = ''; } if (isset($options['label'])) { $label = $options['label']; $labelOptions = isset($options['labelOptions']) ? $options['labelOptions'] : []; $divOptions = isset($options['divOptions']) ? $options['divOptions'] : []; Html::addCssClass($divOptions, 'checkbox'); unset($options['label'], $options['labelOptions'], $options['divOptions']); $options['id'] = str_replace(['[]', '][', '[', ']', ' '], ['', '-', '-', '', '-'], $name) . '-' . $value; $content = Html::tag('div', static::input('checkbox', $name, $value, $options) . static::label($label, $options['id'], $labelOptions), $divOptions); return $hidden . $content; } else { return $hidden . static::input('checkbox', $name, $value, $options); } }
/** * Initializes the widget options. * This method sets the default values for various options. */ protected function initOptions() { Html::addCssClass($this->options, ['alert', 'fade', 'in']); if ($this->closeButton !== false) { $this->closeButton = array_merge(['data-dismiss' => 'alert', 'aria-hidden' => 'true', 'class' => 'close'], $this->closeButton); } }
/** * @inheritdoc */ public function label($label = null, $options = []) { if (is_bool($label)) { $this->enableLabel = $label; if ($label === false && $this->form->layout === 'horizontal') { Html::addCssClass($this->wrapperOptions, $this->horizontalCssClasses['offset']); } } else { $this->enableLabel = true; $this->renderLabelParts($label, $options); parent::label($label, $options); } return $this; }
/** * Check to see if a child item is active optionally activating the parent. * @param array $items @see items * @param boolean $active should the parent be active too * @return array @see items */ protected function isChildActive($items, &$active) { foreach ($items as $i => $child) { if (ArrayHelper::remove($items[$i], 'active', false) || $this->isItemActive($child)) { Html::addCssClass($items[$i]['options'], 'active'); if ($this->activateParents) { $active = true; } } } return $items; }
/** * Render single alert. * @param string $tag Alert html tag. * @param string $type Alert type. * @param string $alert Alert text. * @param array $options Alert type specific options. */ protected function renderAlert($tag, $type, $alert, array $options) { $classes = ['alert', 'in', 'alert-' . $type]; if ($options['block']) { $classes[] = 'alert-block'; } if ($options['fade']) { $classes[] = 'fade'; } Html::addCssClass($options['htmlOptions'], implode(' ', $classes)); echo Html::openTag($tag, $options['htmlOptions']); if ($options['closeText'] !== false) { echo '<a href="#" class="close" data-dismiss="alert">' . $options['closeText'] . '</a>'; } echo $alert; echo Html::closeTag($tag); }
/** * Initializes the widget. */ public function init() { parent::init(); $this->clientOptions = false; if (empty($this->options['class'])) { Html::addCssClass($this->options, ['navbar', 'navbar-default']); } else { Html::addCssClass($this->options, ['widget' => 'navbar']); } if (empty($this->options['role'])) { $this->options['role'] = 'navigation'; } $options = $this->options; $tag = ArrayHelper::remove($options, 'tag', 'nav'); echo Html::beginTag($tag, $options); if ($this->renderInnerContainer) { if (!isset($this->innerContainerOptions['class'])) { Html::addCssClass($this->innerContainerOptions, 'container'); } echo Html::beginTag('div', $this->innerContainerOptions); } echo Html::beginTag('div', ['class' => 'navbar-header']); if (!isset($this->containerOptions['id'])) { $this->containerOptions['id'] = "{$this->options['id']}-collapse"; } echo $this->renderToggleButton(); if ($this->brandLabel !== false) { Html::addCssClass($this->brandOptions, ['widget' => 'navbar-brand']); echo Html::a($this->brandLabel, $this->brandUrl === false ? Yii::$app->homeUrl : $this->brandUrl, $this->brandOptions); } echo Html::endTag('div'); Html::addCssClass($this->containerOptions, ['collapse' => 'collapse', 'widget' => 'navbar-collapse']); $options = $this->containerOptions; $tag = ArrayHelper::remove($options, 'tag', 'div'); echo Html::beginTag($tag, $options); }
protected function addListInputCssClass(&$options, $class) { if (!isset($options['itemOptions'])) { $options['itemOptions'] = ['class' => $class]; } else { Html::addCssClass($options['itemOptions'], $class); } }
/** * Generates a bar * @param integer $percent the percentage of the bar * @param string $label, optional, the label to display at the bar * @param array $options the HTML attributes of the bar * @return string the rendering result. */ protected function renderBar($percent, $label = '', $options = []) { $defaultOptions = ['role' => 'progressbar', 'aria-valuenow' => $percent, 'aria-valuemin' => 0, 'aria-valuemax' => 100, 'style' => "width:{$percent}%"]; $options = array_merge($defaultOptions, $options); Html::addCssClass($options, ['widget' => 'progress-bar']); $out = Html::beginTag('div', $options); $out .= $label; $out .= Html::tag('span', \Yii::t('yii', '{percent}% Complete', ['percent' => $percent]), ['class' => 'sr-only']); $out .= Html::endTag('div'); return $out; }
/** * Default callback for checkbox/radio list item rendering. * @param integer $index item index. * @param string $label item label. * @param string $name input name. * @param boolean $checked whether value is checked or not. * @param string $value input value. * @return string generated HTML. * @see Html::checkbox() * @see Html::radio() */ public function renderItem($index, $label, $name, $checked, $value) { $labelOptions = $this->labelOptions; Html::addCssClass($labelOptions, 'btn'); if ($checked) { Html::addCssClass($labelOptions, 'active'); } $type = $this->type; if ($this->encodeLabels) { $label = Html::encode($label); } return Html::$type($name, $checked, ['label' => $label, 'labelOptions' => $labelOptions, 'value' => $value]); }
public function init() { parent::init(); Html::addCssClass($this->options, ['weui_grids']); }
/** * Renders add-on end. * * @param string $appendText Appended text. * @param array $appendOptions Append options. */ protected function renderAddOnEnd($appendText, $appendOptions) { if (!empty($appendText)) { if (isset($appendOptions['isRaw']) && $appendOptions['isRaw']) { echo $appendText; } else { Html::addCssClass($appendOptions, $this->addOnCssClass); echo \CHtml::tag($this->addOnTag, $appendOptions, $appendText); } } echo \CHtml::closeTag($this->addOnWrapperTag); }
/** * Initializes the widget. * If you override this method, make sure you call the parent implementation first. */ public function init() { parent::init(); $this->clientOptions = false; Html::addCssClass($this->options, ['widget' => 'btn']); }
/** * Initializes the widget. * If you override this method, make sure you call the parent implementation first. */ public function init() { parent::init(); Html::addCssClass($this->options, ['widget' => 'btn-group']); }
/** * @inheritdoc */ public function init() { Html::addCssClass($this->options, 'smart-form'); parent::init(); }
/** * Initializes the widget options. * This method sets the default values for various options. */ protected function initOptions() { $this->options = array_merge(['class' => 'fade', 'role' => 'dialog', 'tabindex' => -1], $this->options); Html::addCssClass($this->options, ['widget' => 'modal']); if ($this->clientOptions !== false) { $this->clientOptions = array_merge(['show' => false], $this->clientOptions); } if ($this->closeButton !== false) { $this->closeButton = array_merge(['data-dismiss' => 'modal', 'aria-hidden' => 'true', 'class' => 'close'], $this->closeButton); } if ($this->toggleButton !== false) { $this->toggleButton = array_merge(['data-toggle' => 'modal'], $this->toggleButton); if (!isset($this->toggleButton['data-target']) && !isset($this->toggleButton['href'])) { $this->toggleButton['data-target'] = '#' . $this->options['id']; } } }
public function init() { parent::init(); Html::addCssClass($this->options, [self::CLASS_CELL]); }
/** * Renders menu items. * @param array $items the menu items to be rendered * @param array $options the container HTML attributes * @return string the rendering result. * @throws InvalidConfigException if the label option is not specified in one of the items. */ protected function renderItems($items, $options = []) { $lines = []; foreach ($items as $item) { if (isset($item['visible']) && !$item['visible']) { continue; } if (is_string($item)) { $lines[] = $item; continue; } if (!isset($item['label']) && !isset($item['icon'])) { throw new InvalidConfigException("The 'label' option is required."); } $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels; $label = ArrayHelper::getValue($item, 'label', ''); if ($encodeLabel) { $label = Html::encode($label); } $icon = ArrayHelper::getValue($item, 'icon'); if ($icon) { $label .= ' ' . FA::icon($icon); } $itemOptions = ArrayHelper::getValue($item, 'options', []); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []); $linkOptions['tabindex'] = '-1'; $url = array_key_exists('url', $item) ? $item['url'] : null; if (empty($item['items'])) { if ($url === null) { $content = $label; } else { $content = Html::a($label, $url, $linkOptions); } } else { $submenuOptions = $this->submenuOptions; if (isset($item['submenuOptions'])) { $submenuOptions = array_merge($submenuOptions, $item['submenuOptions']); } $content = Html::a($label, $url === null ? '#' : $url, $linkOptions) . $this->renderItems($item['items'], $submenuOptions); Html::addCssClass($itemOptions, ['widget' => 'dropdown-submenu']); } $lines[] = Html::tag('li', $content, $itemOptions); } return Html::tag('ul', implode("\n", $lines), $options); }
/** * Normalizes dropdown item options by removing tab specific keys `content` and `contentOptions`, and also * configure `panes` accordingly. * @param string $itemNumber number of the item * @param array $items the dropdown items configuration. * @param array $panes the panes reference array. * @return boolean whether any of the dropdown items is `active` or not. * @throws InvalidConfigException */ protected function renderDropdown($itemNumber, &$items, &$panes) { $itemActive = false; foreach ($items as $n => &$item) { if (is_string($item)) { continue; } if (isset($item['visible']) && !$item['visible']) { continue; } if (!array_key_exists('content', $item)) { throw new InvalidConfigException("The 'content' option is required."); } $content = ArrayHelper::remove($item, 'content'); $options = ArrayHelper::remove($item, 'contentOptions', []); Html::addCssClass($options, ['widget' => 'tab-pane']); if (ArrayHelper::remove($item, 'active')) { Html::addCssClass($options, 'active'); Html::addCssClass($item['options'], 'active'); $itemActive = true; } $options['id'] = ArrayHelper::getValue($options, 'id', $this->options['id'] . '-dd' . $itemNumber . '-tab' . $n); $item['url'] = '#' . $options['id']; if (!isset($item['linkOptions']['data-toggle'])) { $item['linkOptions']['data-toggle'] = 'tab'; } $panes[] = Html::tag('div', $content, $options); unset($item); } return $itemActive; }
/** * Renders a single carousel item * @param string|array $item a single item from [[items]] * @param integer $index the item index as the first item should be set to `active` * @return string the rendering result * @throws InvalidConfigException if the item is invalid */ public function renderItem($item, $index) { if (is_string($item)) { $content = $item; $caption = null; $options = []; } elseif (isset($item['content'])) { $content = $item['content']; $caption = ArrayHelper::getValue($item, 'caption'); if ($caption !== null) { $caption = Html::tag('div', $caption, ['class' => 'carousel-caption']); } $options = ArrayHelper::getValue($item, 'options', []); } else { throw new InvalidConfigException('The "content" option is required.'); } Html::addCssClass($options, ['widget' => 'item']); if ($index === 0) { Html::addCssClass($options, 'active'); } return Html::tag('div', $content . "\n" . $caption, $options); }
/** * Generates the button dropdown. * @return string the rendering result. */ protected function renderButton() { Html::addCssClass($this->options, ['widget' => 'btn']); $label = $this->label; if ($this->encodeLabel) { $label = Html::encode($label); } if ($this->split) { $options = $this->options; $this->options['data-toggle'] = 'dropdown'; Html::addCssClass($this->options, ['toggle' => 'dropdown-toggle']); unset($this->options['id']); $splitButton = Button::widget(['label' => '<span class="caret"></span>', 'encodeLabel' => false, 'options' => $this->options, 'view' => $this->getView()]); } else { $label .= ' <span class="caret"></span>'; $options = $this->options; if (!isset($options['href']) && $this->tagName === 'a') { $options['href'] = '#'; } Html::addCssClass($options, ['toggle' => 'dropdown-toggle']); $options['data-toggle'] = 'dropdown'; $splitButton = ''; } return Button::widget(['tagName' => $this->tagName, 'label' => $label, 'options' => $options, 'encodeLabel' => false, 'view' => $this->getView()]) . "\n" . $splitButton; }
/** * 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 integer $index the item index as each item group content must have an id * @return string the rendering result * @throws InvalidConfigException */ public function renderItem($header, $item, $index) { if (array_key_exists('content', $item)) { $id = $this->options['id'] . '-collapse' . $index; $options = ArrayHelper::getValue($item, 'contentOptions', []); $options['id'] = $id; Html::addCssClass($options, ['widget' => 'panel-collapse', 'collapse' => 'collapse']); $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels; if ($encodeLabel) { $header = Html::encode($header); } $headerToggle = Html::a($header, '#' . $id, ['class' => 'collapse-toggle', 'data-toggle' => 'collapse', 'data-parent' => '#' . $this->options['id']]) . "\n"; $header = Html::tag('h4', $headerToggle, ['class' => 'panel-title']); if (is_string($item['content']) || is_object($item['content'])) { $content = Html::tag('div', $item['content'], ['class' => 'panel-body']) . "\n"; } elseif (is_array($item['content'])) { $content = Html::ul($item['content'], ['class' => 'list-group', 'itemOptions' => ['class' => 'list-group-item'], 'encode' => false]) . "\n"; if (isset($item['footer'])) { $content .= Html::tag('div', $item['footer'], ['class' => 'panel-footer']) . "\n"; } } else { throw new InvalidConfigException('The "content" option should be a string, array or object.'); } } else { throw new InvalidConfigException('The "content" option is required.'); } $group = []; $group[] = Html::tag('div', $header, ['class' => 'panel-heading']); $group[] = Html::tag('div', $content, $options); return implode("\n", $group); }