-
Notifications
You must be signed in to change notification settings - Fork 13
OEL-4322: Migrate Alert and Description list components. #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
piotrsmykaj
wants to merge
1
commit into
epic/OEL-3864
Choose a base branch
from
OEL-4322
base: epic/OEL-3864
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| name: Alert | ||
| description: 'Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages. https://v5.getbootstrap.com/docs/5.0/components/alerts/' | ||
| variants: | ||
| primary: | ||
| title: 'Primary (default)' | ||
| secondary: | ||
| title: Secondary | ||
| success: | ||
| title: Success | ||
| danger: | ||
| title: Danger | ||
| warning: | ||
| title: Warning | ||
| info: | ||
| title: Info | ||
| light: | ||
| title: Light | ||
| dark: | ||
| title: Dark | ||
| link: | ||
| title: Link | ||
| slots: | ||
| heading: | ||
| title: Heading | ||
| description: 'The alert heading. Optional.' | ||
| message: | ||
| title: Message | ||
| description: 'The alert message.' | ||
| props: | ||
| type: object | ||
| properties: | ||
| icon: | ||
| title: 'Icon name' | ||
| description: 'Add an icon to the alert. Optional.' | ||
| type: string | ||
| dismissible: | ||
| title: Dismissible | ||
| description: 'Add close button to dismiss the alert inline. Defaults to true.' | ||
| type: boolean | ||
| animated_dismiss: | ||
| title: 'Animated dismiss' | ||
| description: 'Add fade animation to the dismissible alert. Defaults to true.' | ||
| type: boolean |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| name: Preview | ||
| slots: | ||
| heading: 'Well done!' | ||
| message: 'A simple alert—check it out!' | ||
| props: | ||
| icon: info-circle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| {# | ||
| /** | ||
| * @file | ||
| * Alert component. | ||
| */ | ||
| #} | ||
|
|
||
| {% set _bcl_icon_path = file_url(get_theme_path('oe_bootstrap_theme') ~ '/assets/icons/bcl-default-icons.svg') %} | ||
| {% set _icon_path = icon_path|default(_bcl_icon_path) %} | ||
|
|
||
| {% include '@oe-bcl/alert' with { | ||
| 'heading': heading, | ||
| 'message': message, | ||
| 'variant': variant, | ||
| 'dismissible': dismissible, | ||
| 'animated_dismiss': animated_dismiss, | ||
| 'icon_path': _icon_path, | ||
| 'icon_name': icon, | ||
| 'attributes': attributes, | ||
| } only %} |
77 changes: 77 additions & 0 deletions
77
components/description_list/description_list.component.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| name: 'Description list' | ||
| description: 'Description lists are used to display and organise content that belongs to a category with a descriptions. Common use cases include glossary type lists or a list of speakers with their biographies.' | ||
| slots: | ||
| title: | ||
| title: Title | ||
| type: string | ||
| description: 'Title of the description list.' | ||
| props: | ||
| type: object | ||
| properties: | ||
| title_tag: | ||
| title: 'Title tag' | ||
| type: string | ||
| description: 'The tag to use for the title. Defaults to h2.' | ||
| items: | ||
| title: 'List items' | ||
| type: array | ||
| description: 'Each item is composed by one or more terms and one or more definitions. Each term entry can have an icon.' | ||
| items: | ||
| type: object | ||
| properties: | ||
| term: | ||
| title: 'Terms' | ||
| type: [string, array] | ||
| description: 'Can be a single string or an array of term objects.' | ||
| items: | ||
| type: object | ||
| properties: | ||
| label: | ||
| title: Label | ||
| type: [string, array, object] | ||
| description: 'Label text or render array.' | ||
| icon: | ||
| type: [object, string] | ||
| properties: | ||
| name: | ||
| type: string | ||
| size: | ||
| type: string | ||
| path: | ||
| type: string | ||
| definition: | ||
| title: 'Definition' | ||
| type: [string, array] | ||
| items: | ||
| type: object | ||
| properties: | ||
| label: | ||
| type: [string, array, object] | ||
| icon_path: | ||
| type: string | ||
| title: "Icons path" | ||
| description: "Path to icons" | ||
| orientation: | ||
| title: Orientation | ||
| type: string | ||
| description: 'Orientation of the list.' | ||
| enum: | ||
| - vertical | ||
| - horizontal | ||
| 'meta:enum': | ||
| vertical: Vertical | ||
| horizontal: Horizontal | ||
| bordered: | ||
| title: Bordered | ||
| type: boolean | ||
| description: 'Adds a border to the description list.' | ||
| col_classes: | ||
| title: 'Column classes' | ||
| type: string | ||
| description: 'Classes for the columns.' | ||
| title_attributes: | ||
| title: 'Title attributes' | ||
| type: Drupal\Core\Template\Attribute | ||
| wrapper_attributes: | ||
| title: Attributes | ||
| type: Drupal\Core\Template\Attribute |
44 changes: 44 additions & 0 deletions
44
components/description_list/description_list.preview-default.story.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: Preview | ||
| slots: | ||
| title: 'This is the title of this description list.' | ||
| props: | ||
| items: | ||
| - | ||
| term: | ||
| - | ||
| label: 'Single label with icon' | ||
| icon: | ||
| name: 'geo-alt-fill' | ||
| definition: 'Description of first term text goes here.' | ||
| - | ||
| term: | ||
| - | ||
| label: 'First label without icon' | ||
| - | ||
| label: 'Second label' | ||
| icon: | ||
| name: 'upload' | ||
| definition: 'Description of second term text goes here.' | ||
| - | ||
| term: | ||
| - | ||
| label: | ||
| - | ||
| '#markup': 'A label with <em>some</em> markup.' | ||
| definition: | ||
| - | ||
| label: 'First description of third term text goes here.' | ||
| - | ||
| label: 'Second description of third term text goes here.' | ||
| - | ||
| term: | ||
| - | ||
| label: 'Custom icon size' | ||
| icon: | ||
| name: calendar-x | ||
| size: xl | ||
| definition: 'This is a bigger icon.' | ||
| - | ||
| term: 'A single term without icon.' | ||
| definition: 'Yet another definition text.' | ||
| orientation: horizontal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| {# | ||
| /** | ||
| * @file | ||
| * Description list component. | ||
| */ | ||
| #} | ||
|
|
||
| {% set _bcl_icon_path = file_url(get_theme_path('oe_bootstrap_theme') ~ '/assets/icons/bcl-default-icons.svg') %} | ||
| {% set _icon_path = icon_path|default(_bcl_icon_path) %} | ||
|
|
||
| {% set _items = [] %} | ||
| {% for item in items %} | ||
| {% set _terms = [] %} | ||
| {% set item_terms = item.term is iterable ? item.term : [item.term] %} | ||
| {% for term in item_terms %} | ||
| {% set _term = term is iterable ? term : {'label': term} %} | ||
|
|
||
| {% if _term.icon is defined and _term.icon %} | ||
| {% set _icon = _term.icon is iterable ? _term.icon : {'name': _term.icon} %} | ||
| {% set _term = _term|merge({ | ||
| 'icon': {'size': 'xs', 'path': _icon_path}|merge(_icon) | ||
| }) %} | ||
| {% endif %} | ||
|
|
||
| {% set _terms = _terms|merge([_term]) %} | ||
| {% endfor %} | ||
|
|
||
| {% set _items = _items|merge([item|merge({'term': _terms})]) %} | ||
| {% endfor %} | ||
|
|
||
| {% include '@oe-bcl/description-list' with { | ||
| title: title, | ||
| title_tag: title_tag|default('h2'), | ||
| title_attributes: title_attributes, | ||
| items: _items, | ||
| variant: orientation, | ||
| bordered: bordered, | ||
| col_classes: col_classes, | ||
| attributes: wrapper_attributes, | ||
| } %} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,39 +59,6 @@ function oe_bootstrap_theme_preprocess_pattern_offcanvas(array &$variables): voi | |
| $variables['offcanvas_id'] = $variables['attributes']['id'] ?? Html::getUniqueId('bcl_offcanvas'); | ||
| } | ||
|
|
||
| /** | ||
| * Implements hook_preprocess_HOOK() for description list pattern. | ||
| */ | ||
| function oe_bootstrap_theme_preprocess_pattern_description_list(&$variables) { | ||
| // Multiple terms can be passed for each item. Process all the entries to | ||
| // add path and size to icons, if not yet specified. | ||
| foreach ($variables['items'] as &$item) { | ||
| // Allow to pass a single term, without forcing users to pass an array with | ||
| // the "label" key in it. This covers for a bug in the BCL pattern. | ||
| if (!is_array($item['term'])) { | ||
| $item['term'] = [ | ||
| ['label' => $item['term']], | ||
| ]; | ||
| continue; | ||
| } | ||
|
|
||
| foreach ($item['term'] as &$term) { | ||
| if (is_array($term) && !empty($term['icon'])) { | ||
| // If the icon is not an array, the icon name has been passed. | ||
| if (!is_array($term['icon'])) { | ||
| $term['icon'] = [ | ||
| 'name' => $term['icon'], | ||
| ]; | ||
| } | ||
| $term['icon'] += [ | ||
| 'size' => 'xs', | ||
| 'path' => $variables['bcl_icon_path'], | ||
| ]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see we are removing the preprocess, but the pattern itself is still there. |
||
| /** | ||
| * Implements hook_preprocess_HOOK(). | ||
| */ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be simplified by using
|map(..)?(on two levels)
The AI gives me this:
{% set _items = items|map(item => item|merge({ terms: (item.term is iterable ? item.term : [item.term])|map(term => { _term = term is iterable ? term : {'label': term} } => _term.icon is defined and _term.icon ? _term|merge({ icon: { size: 'xs', path: _icon_path }|merge(_term.icon is iterable ? _term.icon : { name: _term.icon }) }) : _term ) }) ) %}I am not saying this will work as-is, just as a starting point to explore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also create twig functions or filters if that helps. Either generic helpers, or more specific functions aimed at specific templates.
But not sure it would be worthwhile in this case.