🔹 Card-mod - Super-charge your themes!

I guess that code is now outdated since HA changed a structure of a page.
Try the code below.
I changed a DOM path (did not touch height, width & position).

  card-mod-root-yaml: |
    ha-button-menu ha-icon-button $ mwc-icon-button: |
      ha-svg-icon {
        display: none;
      }
      mwc-icon-button::after {
        font-size: 22px;
        height: 20px; 
        width: 100px;
        margin-left: 0px;
        margin-right: 0px;
        content: "{{ '13:34:21' }}";
        position: absolute;
        top: 14px;
        right: 0px;
      }

изображение

Or you may have this button still displayed:

  card-mod-root-yaml: |
    ha-button-menu ha-icon-button $: |
      mwc-icon-button::before {
        font-size: 22px;
        height: 20px; 
        width: 100px;
        margin-left: 0px;
        margin-right: 30px;
        content: "{{ '13:34:21' }}";
        position: absolute;
        top: 14px;
        right: 0px;
      }

изображение

2 Likes

trying to change the icon of a tab is about the only thing left I like to establish in replacing my Custom Header from the old days. Please help me figuring this out.

We can change the color of a tab with:

        paper-tab[aria-label='Home'] {
          color: {{'red' if states('sensor.count_alerts_notifying') > '0'}};
        }

but adding an icon line there wont work, inspector says the icon is inherited from ha-tabs, and shows a yellow exclamation mark.

If I try and do something like:

/* Set the color of the currently selected tab indicator. */
        ha-tabs {
          --paper-tabs-selection-bar-color: black !important;
          --paper-tab[aria-label='Home summary'] {
            ha-icon: mdi:help !important;
          };
        }

nothing happens, except for the tab indicator being colored black.

same for:

        paper-tab[aria-selected='Home'] > ha-svg-icon {
          icon: mdi:help !important;
        }

Hope someone can assist me in finding the correct item in inspector to set an icon…

this works for me:

        /* Optionally set a replacement template text. */
        ha-button-menu::before {
          content: "{% if states('sensor.browser_mod_safari') not in ['unknown','unavailable'] %}{{states('sensor.custom_header_template')}}{%endif%}";
          color: var(--text-primary-color);
          visibility: visible;
          position: relative;
          top: 24px;
          white-space: nowrap;
        }

Looking for this?
изображение

      paper-tab[aria-label='test'] ha-icon::after {
        margin-left: 10px;
        content: "xxxxxxxxxxxxxxx";
      }

Just specify an icon for the tab settings.

Good, easy & simple))

dont think so, I want to replace the icon set in the view, with a state dependent icon.

for example this is what we do in the regular Views:

title: Home
icon: mdi:home
path: home

in Custom Header we did:

tab_icons:
  settings_motion: >-
    {%- if states('binary_sensor.motion_sensors_all') == 'on' -%}mdi:motion-sensor
    {%- else -%}mdi:motion-sensor-off
    {%- endif -%}

which in a card-mod-theme would become something like:

        paper-tab[aria-label='Home'] ha-icon {
          icon:  {{'mdi:motion-sensor' if states('binary_sensor.motion_sensors_all') == 'on' else 'mdi:motion-sensor-off'}}
        }

ofc this doesnt work…

I am not sure it is possible to REPLACE an icon in the tab.
I tried using --card-mod-icon - seems it does not work here.

Alternatively, you may add a state-dependent IMAGE instead of icon:

    paper-tab[aria-label='zont'] ha-icon $: |
      ha-svg-icon {
        display: none;
      }
    .: |
      paper-tab[aria-label='zont'] ha-icon::before {
        background: url("/local/images/persons/ildar.png");
        content: " --------------";
        color: transparent;         
        background-size: 100% 100%;
      }
      paper-tab[aria-label='zont'] ha-icon::after {
        margin-left: 10px;
        content: "my tab";
      }

изображение


Update: this variant allows to show a square image:
изображение

    paper-tab[aria-label='CM-themes-3'] ha-icon $: |
      ha-svg-icon {
        display: none !important;
      }
    .: |
      paper-tab[aria-label='CM-themes-3'] ha-icon::before {
        background: url("/local/images/persons/ildar.png");
        content: "-";
        color: transparent;         
        background-size: 100% 100%;
        height: 40px;
        width: 40px;
      }
      paper-tab[aria-label='CM-themes-3'] ha-icon {
        display: contents;
      }
      paper-tab[aria-label='CM-themes-3'] ha-icon::after {
        margin-left: 10px;
        content: "my tab";
      }
2 Likes

Nice :wink:

not what I was looking for, but at least some progress …

maybe we could ask Thomas for a FR here, since if you aren’t able to do it, it probably isnt an option currently :wink:

And these ::after & ::before stuff does not look as a reliable decision, does not work sometimes.

right, and, tbh, even the

        paper-tab[aria-label='Home'] ha-icon $: |
          ha-svg-icon {
            display: none;
          }

doesnt remove the icon in my config…
o. wait, I had to move it up, directly under the card-mod-root-yaml. now it works :wink:

One more attempt (seems to be same, but just in case):

    paper-tab[aria-label='zont'] ha-icon:
      $: |
        ha-svg-icon {
          display: none;
        }
      .: |
        paper-tab[aria-label='zont'] ha-icon::before {
          background: url("/local/images/persons/ildar.png");
          content: " --------------";
          color: transparent;         
          background-size: 100% 100%;
        }
        paper-tab[aria-label='zont'] ha-icon::after {
          margin-left: 10px;
          content: "my tab";
        }

As I said it is not stable - in my setup it works after F5

maybe we should investigate another way, just like we can do with the background:

weather-background:
  card-mod-theme: weather-background
  card-mod-view: |
    hui-masonry-view {
      background: url({{state_attr('camera.buienradar','entity_picture')}});
    }

which overrides a background set in the regular View:

title: Solar
path: solar
icon: mdi:solar-power
background: center / cover no-repeat url('/local/images/solar_grid.png') fixed

maybe we can also override the icon like that?
answering myself: no we cant… there simp’y doesnt seem to be an item to override (set a value for in card-mod-theme) for icon?

Background may be changed by a corresponding property.
Icon may be changed by a brute force method:
Untitled Projectxcvrfe3333

  card-mod-root-yaml: |
    paper-tab[aria-label='zont'] ha-icon $ ha-svg-icon $: |
      path {
        {% if is_state('input_boolean.test_boolean','on') %}
        d: path("M 20.2 5.9 L 21 5.1 C 19.6 3.7 17.8 3 16 3 C 14.2 3 12.4 3.7 11 5.1 L 11.8 5.9 C 13 4.8 14.5 4.2 16 4.2 C 17.5 4.2 19 4.8 20.2 5.9 M 19.3 6.7 C 18.4 5.8 17.2 5.3 16 5.3 C 14.8 5.3 13.6 5.8 12.7 6.7 L 13.5 7.5 C 14.2 6.8 15.1 6.5 16 6.5 C 16.9 6.5 17.8 6.8 18.5 7.5 L 19.3 6.7 M 19 13 H 17 V 9 H 15 V 13 H 5 A 2 2 0 0 0 3 15 V 19 A 2 2 0 0 0 5 21 H 19 A 2 2 0 0 0 21 19 V 15 A 2 2 0 0 0 19 13 M 8 18 H 6 V 16 H 8 V 18 M 11.5 18 H 9.5 V 16 H 11.5 V 18 M 15 18 H 13 V 16 H 15 V 18 Z") !important;
        color: magenta !important;
        {% else %}
        d: path("M 12 2 A 10 10 0 0 0 2 12 A 10 10 0 0 0 12 22 A 10 10 0 0 0 22 12 A 10 10 0 0 0 12 2 M 16.2 16.2 L 11 13 V 7 H 12.5 V 12.2 L 17 14.9 L 16.2 16.2 Z") !important;
        color: cyan !important;
        {% endif %}
      }

Cannot say that this is a stable solution.

1 Like

Ooh nice! Going to play with that. The move to SVG icons sometime ago probably caused this brute force need…
Will test if it combines with my current colorizing settings.

After some thinking I may propose this more universal code since it does not depend on these top, position etc - it uses flex instead:

    .: |
      ha-button-menu {
        display: flex;
      }
      ha-button-menu::before {
        content: "{{ '13:34:21' }}";
        color: var(--text-primary-color);
        align-self: center;
        outline: 1px solid var(--text-primary-color);
        outline-offset: 5px;
        border-radius: 2px;
      }

изображение

Update 28.12.21 - added rounded outline.

1 Like

I admit I have been looking for a more generic way too, however your code does this:

where my absolute code makes it along to the right edge nicely:

align-self: right does odd things: moving it upward instead of to the left…

Do you have your [:] buttons hidden?
My code is for not hidden buttons.

no, I make them transparent depending on a template:

        /* Optionally set the three-dots transparency,
           to allow for a replacement template text. */
        ha-button-menu {
          color: {% if states('sensor.browsermod_safari') not in ['unknown','unavailable'] %}
                   {% if is_state('input_boolean.menu_options_template','on')%}transparent /*var(--primary-color)*/
                   {% endif %}
                 {% endif %};
        }

also, I cant make the icon changer happen…

Did you set display: flex for the ha-button-menu ?

If the [:] button is transparent then my code gives this:
изображение
Surely there will be a gap between added element and the right border.

Why not setting display: none instead of color: transparent?
Then the text will be close to the right border:
изображение

it was necessary to have that transparent (and still have the menu functional) while not shining through the template. Right now, I can click the text of the template

Schermafbeelding 2021-12-28 om 10.46.54

so it pops up the allowed menu options

In this case you cannot use flex and have to specify a position explicitly, agreed!