Skip to content
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

Fix/1.x/705 lgd icon doesnt use theme variable #706

Open
wants to merge 3 commits into
base: 1.x
Choose a base branch
from

Conversation

ctorgalson
Copy link
Contributor

@ctorgalson ctorgalson commented Jan 23, 2025

What does this change?

The PR adds the following to localgov_base:icon:

  1. use the theme variable to namespace the path to the icon file if icon_path does not begin with @,
  2. document that the theme variable exists in icon.component.yml (it was already documented in code),
  3. adds a |default('includes/icons') to the icon_path variable to make the SDC behave as described in comments

How to test

  1. create a child theme, lgdtest,
  2. add an icon like web/themes/custom/lgdtest/assets/icons/someIcon.svg (preferably different from any icon in localgov_base),
  3. include the localgov_base:icon component in the new child theme in each of the following ways:
    {# Test icon from another theme, using 'theme' var #}
    {% include 'localgov_base:icon' with {
      theme: 'lgdtest',
      icon_path: 'assets/icons',
      icon_name: 'someIcon',
    } %}
    
    {# Test icon from another theme, namespacing 'icon_path' var (note: `theme` var will be ignored) #}
    {% include 'localgov_base:icon' with {
      theme: 'lgdtest',
      icon_path: '@lgdtest/assets/icons',
      icon_name: 'someIcon',
    } %}
    
    {# Test icon from localgov_base, using 'theme' var #}
    {% include 'localgov_base:icon' with {
      theme: 'localgov_base',
      icon_name: 'arrow-down',
    } %}
    
    {# Test icon from localgov_base, namespacing 'icon_path' var (note: `theme` var will be ignored) #}
    {% include 'localgov_base:icon' with {
      theme: 'localgov_base',
      icon_path: '@localgov_base/includes/icons',
      icon_name: 'arrow-down',
    } %}
    
    {# Test icon from localgov_base, using *only* icon_name var #}
    {% include 'localgov_base:icon' with {
      icon_name: 'arrow-down',
    } %}
  4. verify that the expected icons all appear.

How can we measure success?

  • check that existing consumers of localgov_base:icon (i.e. localgov_base:prev-next)work as expected
  • verify all the anticipated modes (above) render correctly
  • this should leave existing implementations untouched

Have we considered potential risks?

  • the potential risks are wsod on templates making use of the localgov_base:icon SDC, so testing matters :)

Images

n/a

Accessibility

n/a

The new variable uses icon_path alone if it begins with '@' (i.e. if
it's Twig-namespaced), but will use the value of theme (defaulting to
'localgov_base') in other circumstances.
Variable was present but unused, and undocumented outside of code
comments.
This is the path that's used in localgov_base.
@ctorgalson ctorgalson requested a review from markconroy January 24, 2025 13:44
Copy link
Member

@markconroy markconroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I've added a small suggestion that we can accept or reject, it won't make much of a difference either way.

@@ -35,12 +35,16 @@
{% set theme = theme|default('localgov_base') %}
{% set icon_wrapper_element = icon_wrapper_element|default('div') %}

{%- set icon_fullpath -%}
{% if icon_path|first != '@' %}@{{ theme }}/{% endif %}{{ icon_path|default('includes/icons') }}/{{ icon_name }}.svg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove the {% set ... %} here then replace line 49 later with line 39 from here.

{% set attributes = create_attribute()
.setAttribute('aria-hidden', decoration|default('true'))
.addClass('lgd-icon')
.addClass(icon_classes)
%}

<{{ icon_wrapper_element }}{{ attributes }}>
{% include icon_path ~ '/' ~ icon_name ~ '.svg' %}
{% include icon_fullpath %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change this line to
{% if icon_path|first != '@' %}@{{ theme }}/{% endif %}{{ icon_path|default('includes/icons') }}/{{ icon_name }}.svg

after we remove the set from above, like so:

<{{ icon_wrapper_element }}{{ attributes }}>
  {% if icon_path|first != '@' %}@{{ theme }}/{% endif %}{{ icon_path|default('includes/icons') }}/{{ icon_name }}.svg
</{{ icon_wrapper_element }}>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will be nicer. I'll do that this afternoon.

@finnlewis
Copy link
Member

@ctorgalson I think if you merge 1.x back to your forked branch, the eslint checks will pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants