Loading src/HookHandler/PreprocessPatternDropdown.php 0 → 100644 +24 −0 Original line number Diff line number Diff line <?php declare(strict_types = 1); namespace Drupal\ui_suite_bootstrap\HookHandler; use Drupal\Component\Utility\Html; /** * Handle variables needed for the pattern. */ class PreprocessPatternDropdown { /** * Handle variables needed for the pattern. * * @param array $variables * The preprocessed variables. */ public function preprocess(array &$variables): void { $variables['dropdown_id'] = Html::getUniqueId('bootstrap-dropdown'); } } templates/patterns/alert/alert.ui_patterns.yml +1 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ alert: label: "Dismissible?" description: "It is possible to dismiss any alert inline." preview: True allow_expose: true fields: heading: type: "text" Loading templates/patterns/button/button.ui_patterns.yml +8 −0 Original line number Diff line number Diff line Loading @@ -104,6 +104,8 @@ button: label: "Outline Light large" outline_dark__lg: label: "Outline Dark large" dropdown_item: label: "(Dropdown item)" settings: disabled: type: "boolean" Loading @@ -111,6 +113,12 @@ button: description: "Is the button disabled?" preview: true allow_expose: true label_visually_hidden: type: "boolean" label: "Hide button label?" description: "Is the button's label hidden?" preview: false allow_expose: true fields: label: type: "text" Loading templates/patterns/button/pattern-button.html.twig +12 −3 Original line number Diff line number Diff line {% if variant != '' and variant|lower != 'default' %} {% if variant != '' and variant|lower != 'dropdown_item' %} {% set variants = variant|split('__') %} {% for variant in variants %} {% set attributes = attributes.addClass('btn-' ~ variant|lower|replace({'_': '-'})) %} {% endfor %} {% set attributes = attributes.addClass('btn') %} {% endif %} {% set attributes = attributes.addClass('btn') %} {% set attributes = variant|lower == 'dropdown_item' ? attributes.addClass('dropdown-item') : attributes %} {% if label_visually_hidden %} {% set label %} <span class="visually-hidden"> {{ label }} </span> {% endset %} {% endif %} {% if url or attributes.href %} {% set url = url ?: attributes.href %} Loading @@ -20,5 +29,5 @@ {% set attributes = attributes.setAttribute('disabled', '') %} {% endif %} <span{{ attributes }}>{{ label }}</span> <button{{ attributes.setAttribute('type', 'button') }}>{{ label }}</button> {% endif %} templates/patterns/card/card.ui_patterns.yml +1 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ card: top: "Top (Default)" bottom: "Bottom" preview: "top" allow_expose: true fields: image: type: "render" Loading Loading
src/HookHandler/PreprocessPatternDropdown.php 0 → 100644 +24 −0 Original line number Diff line number Diff line <?php declare(strict_types = 1); namespace Drupal\ui_suite_bootstrap\HookHandler; use Drupal\Component\Utility\Html; /** * Handle variables needed for the pattern. */ class PreprocessPatternDropdown { /** * Handle variables needed for the pattern. * * @param array $variables * The preprocessed variables. */ public function preprocess(array &$variables): void { $variables['dropdown_id'] = Html::getUniqueId('bootstrap-dropdown'); } }
templates/patterns/alert/alert.ui_patterns.yml +1 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ alert: label: "Dismissible?" description: "It is possible to dismiss any alert inline." preview: True allow_expose: true fields: heading: type: "text" Loading
templates/patterns/button/button.ui_patterns.yml +8 −0 Original line number Diff line number Diff line Loading @@ -104,6 +104,8 @@ button: label: "Outline Light large" outline_dark__lg: label: "Outline Dark large" dropdown_item: label: "(Dropdown item)" settings: disabled: type: "boolean" Loading @@ -111,6 +113,12 @@ button: description: "Is the button disabled?" preview: true allow_expose: true label_visually_hidden: type: "boolean" label: "Hide button label?" description: "Is the button's label hidden?" preview: false allow_expose: true fields: label: type: "text" Loading
templates/patterns/button/pattern-button.html.twig +12 −3 Original line number Diff line number Diff line {% if variant != '' and variant|lower != 'default' %} {% if variant != '' and variant|lower != 'dropdown_item' %} {% set variants = variant|split('__') %} {% for variant in variants %} {% set attributes = attributes.addClass('btn-' ~ variant|lower|replace({'_': '-'})) %} {% endfor %} {% set attributes = attributes.addClass('btn') %} {% endif %} {% set attributes = attributes.addClass('btn') %} {% set attributes = variant|lower == 'dropdown_item' ? attributes.addClass('dropdown-item') : attributes %} {% if label_visually_hidden %} {% set label %} <span class="visually-hidden"> {{ label }} </span> {% endset %} {% endif %} {% if url or attributes.href %} {% set url = url ?: attributes.href %} Loading @@ -20,5 +29,5 @@ {% set attributes = attributes.setAttribute('disabled', '') %} {% endif %} <span{{ attributes }}>{{ label }}</span> <button{{ attributes.setAttribute('type', 'button') }}>{{ label }}</button> {% endif %}
templates/patterns/card/card.ui_patterns.yml +1 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ card: top: "Top (Default)" bottom: "Bottom" preview: "top" allow_expose: true fields: image: type: "render" Loading