💡 UI eXtension - Add CSS styles to (almost) any part of the Home Assistant UI

I’m just having a play with this - Seems great - thanks for all the work!
I’m using the following code to add styling to an entire section - which I will want in several places. I was wondering if I can use a class on all sections I want to modify, then add the styling code to the Dashboards YAML?

uix:
  style: |
    :host {
      background: rgba(74, 74, 99, 0.35);   /* translucent base */
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);

      border: 1px solid rgba(255,255,255,0.18);
      border-radius: var(--ha-card-border-radius, var(--ha-border-radius-lg));

      padding: 10px;

      box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    }

Hi @dcapslock, I am responding to this post. I know that there are significant changes in ha-dialog. I have one specific problem with the browser mod popup. I am unable to set dynamic widths for the popup dialog.

As popup content, I have custom:layout-card, type grid-layout. I have various column layouts for media queries. Before the update, the widths changed dynamically according to the defined var(–max-popup-column), which is set in the style for browser_mod.popup. It worked perfectly.

browser_mod.popup

action: fire-dom-event
browser_mod:
  service: browser_mod.popup
  data:
    title: System Information
    style: >
      --max-popup-column: 3;
    content:
      type: custom:mod-card
      card_mod: !include ../../snippets/style_popup_footer.yaml
      card:
        type: custom:layout-card
        layout_type: custom:grid-layout
        layout: !include ../../snippets/popup_footer_layout.yaml
        cards:
          #################################################
          #                                               #
          #                HOME ASSISTANT                 #
          #                                               #
          #################################################
          - type: entities
            title: Home Assistant
            show_header_toggle: false
            card_mod:
              class: header

popup_footer_layout.yaml

grid-template-columns: 1fr
grid-template-rows: auto
margin: 0
padding: 0
mediaquery:
  '(min-width: 1441.99px)':
    grid-template-columns: repeat(var(--max-popup-column, auto-fill), var(--max-popup-column-width, 560px))
    grid-template-rows: auto
  '(min-width: 800px)':
    grid-template-columns: 560px
    grid-template-rows: auto
    margin: 0
    padding: 0

Before the update, it looks like this. Which I would like to have now.

Currently, the width for the dialog is set fixed according to —popup-width. This variable can be changed via themes, but I would lose control over different popup layouts. Do you know how I could set different widths for layout-card?

edit: So I’ve come up with a solution… you need to set it in ha-dialog.type-browser-mod-popup

    ha-dialog.type-browser-mod-popup {
      --ha-dialog-width-md: calc(var(--max-popup-column) * var(--popup-width, 550px)) !important;
      --bar-card-border-radius: 12px !important;
      --ha-card-border-radius: 0px !important;
      --ha-card-background: none !important;
    }
1 Like

In my existing cards using card-mod, I evaulate some items such as background-color using Jinja. Is that still supported in UIX? For example, here:

background-color: {{ 'red' if states('sensor.bermuda_f3_79_4c_5a_db_2b_area') == 'Down Back Room' else 'black' if states('sensor.bermuda_f3_79_4c_5a_db_2b_area') in ['Up Front','Office','Up Back'] else 'blue' }};

I’ve just looked at the websites and found that jinja2 templates are supported. I’ll read a bit more next time before posting!

1 Like

You can use common styling in theme, adding a class if you need.

My Theme:
  uix-theme: My Theme
  uix-grid-section: |
    :host(.my-section-class) {
      background: rgba(74, 74, 99, 0.35);   /* translucent base */
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);

      border: 1px solid rgba(255,255,255,0.18);
      border-radius: var(--ha-card-border-radius, var(--ha-border-radius-lg));

      padding: 10px;

      box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    }

In section on dashboard…

uix:
  class: my-section-class
2 Likes

Neat, nice solution. For those reading, overall you can set --popup-width on popup style, which will set --ha-dialog-width-md, though for this case bringing the popup calc in as well needs to have this specific treatment.

Can you share on which level and position of your call you have added it

Thanks for this. I’m running into an issue I could do with some help with - I am trying to create two variants for sections on my dashboard. My code only seems to be picking up the first version (.my-section-class) and ignoring the second one (.subtle-section). Any ideas?

Material You:
  uix-theme: Material You
  uix-grid-section: |
    :host(.my-section-class) {
      background: rgba(74, 74, 99, 0.35);   /* translucent base */
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
      border: 1px solid rgba(255,255,255,0.18);
      border-radius: var(--ha-card-border-radius, var(--ha-border-radius-lg));
      padding: 20px;
      margin: 20px 0px 20px 0px;
      box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    }

    :host(.subtle-section-1) {
      background: rgba(255,255,255,0.03);
      border: 1px solid rgba(255,255,255,0.07);
      border-radius: var(--ha-card-border-radius, var(--ha-border-radius-lg));
      padding: 20px;
      margin: 20px 0px 20px 0px;
    }

Can you share your dashboard code where you are setting uix classes?

My bad - I had added a ‘.’ in the dashboard - so ‘.subtle-section-1’ instead of ‘subtle-section-1’

1 Like

I’d appreciate some help on how to target the size of a picture card. They are currently the default size:

Using developer tools in Firefox, I can change the size by injecting:

display: block;
width: 100px;
height: 100px;

height: actually isn’t needed when I choose to render the cards as square

but I can’t get my head around to target the hui-picture-card with uix.

The card itself is trsgetted in CSS as:host { }

1 Like

Perfect, thank you. Working code as follows:

uix:
  style: |
    :host {
      display: block !important;
      width: 100px !important;
    }

I didn’t really think about it too much, I just created an anchor for all types. :joy:

  uix-dialog: &popup_card_mod |
    :host([card]) .content .container {
      padding: 0px !important;
    }
    :host {
      font-family: Poppins, Raleway, SF Pro Text, sans-serif, system-ui !important;
    }
    ha-adaptive-dialog,
    ha-dialog {
      --vertical-align-dialog: unset !important;
      --dialog-surface-top: unset !important;
      --dialog-surface-margin-top: unset !important;
      --dialog-box-shadow: 0 0px 16px 4px rgba(101,115,134, .15), 0 16px 64px 32px rgba(101,115,134, .5) !important;
      --ha-dialog-surface-background: rgba(22, 24, 29, 0.7) !important;
      --wa-color-overlay-modal: rgba(0, 0, 0, 0.7) !important;
      --mdc-dialog-scrim-color: var(--dialog-scrim-color, rgba(0, 0, 0, 0.32)) !important;
      --mdc-text-field-fill-color: rgb(50 50 50 / 22%) !important;
      --mdc-select-fill-color: rgb(50 50 50 / 22%) !important;
      --mdc-theme-surface: rgba(22, 24, 29, 1) !important;
    }


    @media (max-width: 800px), (max-height: 500px) {
      ha-dialog {
        --mdc-dialog-min-width: 100vw !important;
        --mdc-dialog-min-height: 100vh !important;
        --popup-border-radius: 0 !important;
        --dialog-box-shadow: none !important;
      }
    }
    ha-dialog.type-browser-mod-popup {
      --ha-dialog-width-md: calc(var(--max-popup-column) * var(--popup-width, 550px)) !important;
      --bar-card-border-radius: 12px !important;
      --ha-card-border-radius: 0px !important;
      --ha-card-background: none !important;
      --ha-card-box-shadow: none !important;
      --entities-divider-color: rgba(58, 69, 73, 0.2) !important;
      --dialog-content-padding: 0 !important;
    }
  uix-browser-mod-popup-inner: *popup_card_mod
  uix-more-info: *popup_card_mod

and css var is defined in browser_mod popup style…

action: fire-dom-event
browser_mod:
  service: browser_mod.popup
  data:
    title: System Information
    style: >
      --max-popup-column: 3;

First i wanna say; thank you very much for this new mod / uix for home assistant!!
Super awesome! It works and awesome to also have python custom plugin like to communicate also in different way with homeassistnant (frontend <> backend)
I wanna try to style home assistant uising my old cardmod theme now with uix. But i also have noticed that uix-view doesnt work but uix-view-yaml does?

This does? But it didnt when i removed all the “-yaml” parts

    uix-view-yaml: |
      .: |
       #tabbar { font-size: 10pt; text-transform: uppercase; font-weight: 500; }
       #tabbar:not(.bottom-bar) { justify-content: left; }
      hui-masonry-view$: |
       @media screen and (max-width: 599px) { 
        #columns { margin-top: -2px !important; } 
        #columns, #columns > .column, #columns > .column > hui-card { margin-left: 0px !important; margin-right: 0px !important; }
        #columns > .column > hui-card:not(:last-child) { margin-bottom: 2px !important; }
       }
       @media screen and (min-width: 600px) { 
        #columns { margin-left: 1px !important; margin-right: 1px !important; margin-top: 2px !important; }}
        #columns > .column { max-width: none !important; }

How to save the theme to edit the energy badges?

What are you asking here? Same as in the release thread?

Please try to be explicit otherwise we have no idea what you mean

Btw we did post an example for those badges, is t that working for you?

Yes, i saw the post, but i don’t know how to use that theme, and more i don’t know also how to edit the energy badges… sorry if i am not so clear.

Well the theme is used just like you use any other theme, copy and paste what Darryn describes into whatever you have for themes now

The badges , you can’t edit those as they are made by the strategy of the energy pages

If you wish to use a shadow root selector you need to use uix-view-yaml:. So no way to use uix-view: for the coe you have provided.

1 Like