/** * Initializes a Navbar instance. * * @param array $options options the display options for the NavBar. * @param mixed $block Block to generate a customized inside NavBar content. */ public function __construct($options = [], callable $block = null) { if (is_callable($options)) { $block = $options; $options = []; } Base::set_navbar_id(!isset($options['id']) ? 'navbar-collapse-' . (string) mt_rand(1, pow(10, 7)) : $options['id']); unset($options['id']); $navbar = $this->build_navbar($options, $block); Base::set_navbar_id(''); $this->set_html_object($navbar->get_html_object()); }
/** * Generates de ButtonGroup object. * * @param Array $options the display options for the ButtonGroup. * @param Callable $block Block to generate inside ButtonGroup content. * @return ContentTag a ContentTag instance that represents the Button Group. */ private function build_button_group(array $options, $block) { $is_a_justified_button_group = $this->is_a_justified_button_group($options); $button_group_type = $this->get_button_group_type($options); $this->append_class($options, $button_group_type); $size_class = $this->get_button_group_size($options); $this->append_class($options, $size_class); if ($is_a_justified_button_group) { $this->append_class($options, 'btn-group-justified'); } $bg = new ContentTag('div', array_merge($options, ['aria-label' => 'button-group', 'role' => 'group']), function () use($block, $is_a_justified_button_group) { Base::set_justified_button_group($is_a_justified_button_group); $buttons = call_user_func($block); Base::set_justified_button_group(false); return $buttons; }); return $bg; }
/** * Process the Nav's options. * * @param array $options Nav's options. * @return array Nav's options processed. */ private function nav_options($options = []) { $this->append_class($options, 'nav'); if (Base::get_navbar_id()) { $this->append_class($options, 'navbar-nav'); } else { if (isset($options['as'])) { $as = 'single' === $options['as'] ? '' : 'nav-' . $options['as']; unset($options['as']); } else { $as = 'nav-tabs'; } $this->append_class($options, $as); if (isset($options['layout'])) { $this->append_class($options, "nav-{$options['layout']}"); unset($options['layout']); } } return $options; }
/** * Builds the Panel object * * @param mixed $content Panel's content. * @param array $options Panel's options. * @return ContentTag a ContentTag instance that represents a Panel object. */ private function build_panel($content = null, $options = []) { !is_array($options) ? $options = [] : null; $body = $this->build_panel_body($content); $heading = $this->build_panel_heading($options); $footer = $this->build_panel_footer($options); if (isset($options['tag'])) { $tag = $options['tag']; unset($options['tag']); } else { $tag = 'div'; } if (isset($options['context'])) { $context = $options['context']; unset($options['context']); } else { $context = null; } $this->append_class($options, $this->panel_class($context)); $panel_string = new ContentTag($tag, $options, function () use($heading, $body, $footer) { return [$heading, $body, $footer]; }); if (!is_null(Base::get_panel_column_class())) { $panel_string = new ContentTag('div', $panel_string, ['class' => Base::get_panel_column_class()]); } return $panel_string; }
/** * Initializes the PanelRow instance. * * @param mixed $options [optional] the display options for the panel. * @param Callable $block [optional] Block to generate inside panel row content. */ public function __construct($options, $block = null) { Base::set_panel_column_class(is_array($options) && isset($options['column_class']) ? $options['column_class'] : null); $panel_row = new ContentTag('div', call_user_func($block), $this->set_panel_row_options($options)); $this->set_html_object($panel_row->get_html_object()); }
/** * Returns the Divider object built. * * @return mixed a ContentTag instance or null. */ private function build_divider() { return Base::get_dropdown_link() ? new ContentTag('li', '', ['class' => 'divider']) : null; }
/** * Determines the correct class associated with the link. * * @param array $options options associated with the link. */ private function select_link_class(&$options) { is_null($options) ? $options = [] : null; if ($this->get_alert_link()) { $this->append_class($options, 'alert-link'); } elseif ($this->get_navbar_vertical()) { $this->append_class($options, 'navbar-brand'); } elseif ($this->get_dropdown_link()) { $options = array_merge($options, ['role' => 'menuitem']); } Base::set_alert_link(false); }
/** * Sets the different Button classes. * * @param array $options Button's options. * @return string html class for the button. */ private function btn_class(&$options = []) { $base_options = ['context' => null, 'size' => '', 'layout' => null]; $valid_contexts = ['primary', 'success', 'info', 'warning', 'danger', 'link']; $this->set_options($base_options, $options); $context = $this->context_for($options['context'], ['valid' => $valid_contexts]); $size = null; switch ($options['size']) { case 'lg': case 'large': $size = 'btn-lg'; break; case 'sm': case 'small': $size = 'btn-sm'; break; case 'xs': case 'extra_small': $size = 'btn-xs'; break; } $layout = $options['layout'] === 'block' ? 'btn-block' : null; $navbar_btn_class = '' !== Base::get_navbar_id() ? 'navbar-btn' : null; unset($options['context']); unset($options['size']); unset($options['layout']); return join(Base::SPACE, array_filter(['btn', "btn-{$context}", $size, $layout, $navbar_btn_class], 'strlen')); }
/** * Build the Horizontal object. * * @param array $options options to build the Horizontal object. * @param closure $block Closure to build the Horizontal object. * @return ContentTag instance of ContenTag that represents the Horizontal object. */ private function build_horizontal($options = [], $block = null) { $this->append_class($options, 'collapse navbar-collapse'); $options['id'] = Base::get_navbar_id(); return new ContentTag('div', $options, $block); }
/** * Tells if badge options has been detected to generate a Badge component. * * @param mixed $options options. * @return Badge a instance of Badge component. */ private function check_for_badge(&$options) { $badge = Base::get_and_unset('badge', $options); return !is_null($badge) ? new Badge($badge) : null; }
/** * Gets the column class associated to the thumbnail. * * @param array $options thumbnail's options. * @return string thumbnail's column class. */ private function get_column_class(&$options) { $column_class = Base::get_and_unset('column_class', $options); return $column_class; }
/** * Builds the toggle button that shows up when resizing browser. * * @param arrray $options options to build the toggle button. * @return mixed Html that represents the toggle button. */ private function toggle_button($options = []) { $options['type'] = 'button'; $options['class'] = 'navbar-toggle'; $options['data-toggle'] = 'collapse'; $options['data-target'] = '#' . Base::get_navbar_id(); return (new ContentTag('button', $options, function () { return [$this->toggle_text(), $this->toggle_bar(), $this->toggle_bar(), $this->toggle_bar()]; }))->get_html_object(); }
/** * Returns the image responsive class. * * @param array $options image's options. * @return mixed responsive class or null. */ private function get_responsive_class(&$options) { $responsive = Base::get_and_unset('responsive', $options); return $responsive ? 'img-responsive' : null; }
/** * Builds a standard Dropdown that is rendered within a Nav, so the Button * is not going to be generated instead a LinkTo is generated to trigger the * dropdown menu. * * @param array $options Dropdown's options. * @param mixed $yield Dropdown's content. * @return ContentTag a ContentTag instance that represents a Dropdown within a Nav. */ private function build_standard_dropdown_into_nav($options, $yield) { return new ContentTag('li', ['class' => 'dropdown'], function () use($options, $yield) { $nav_link_status = Base::get_nav_link(); $dropdown_link_status = Base::get_dropdown_link(); Base::set_dropdown_link(false); Base::set_nav_link(false); $link = new LinkTo(['href' => '#', 'class' => 'dropdown-toggle', 'data-toggle' => 'dropdown'], function () use($options) { return [$options['caption'], new ContentTag('span', '', ['class' => 'caret'])]; }); Base::set_nav_link($nav_link_status); Base::set_dropdown_link($dropdown_link_status); return [$link, new ContentTag('ul', $yield, ['class' => $options['list_class'], 'role' => 'menu', 'aria-labelledby' => $options['id']])]; }); }
/** * Sets Base alert link flag to true to then catches the closure output. * * This behaviour is necessary because any link (<a></a> tag) within an alert box * have to match the correct color when it displayed. * * @param callable $block * @return type */ private function capture_alert(callable $block) { Base::set_alert_link(true); $capture = call_user_func($block); Base::set_alert_link(false); return $capture; }