Suggestions for Optimizing Row Layout Code

Hello everyone,

I’m working on a Framework7 layout and aiming to make my code cleaner and more efficient. I have the following f7-row structure, which includes an icon, label, and toggle switch, but I’d love suggestions for optimizing or simplifying it.

Here’s my current code:

- component: f7-row
  config:
    class:
      - align-items-center
    style:
      margin-bottom: 15px
  slots:
    default:
      - component: f7-col
        config:
          width: "5"
        slots:
          default:
            - component: oh-icon
              config:
                height: 20px
                icon: light
      - component: f7-col
        config:
          width: "60"
        slots:
          default:
            - component: Label
              config:
                text: Toggle Switch
                style:
                  font-size: 16px
                  font-weight: bold
      - component: f7-col
        config:
          width: "30"
          class:
            - justify-content-flex-end
            - display-flex
        slots:
          default:
            - component: oh-toggle
              config:
                item: =props.SwitchGroupItem

Specific Goals:

Maintain alignment and styling as currently displayed.

Thanks in advance for any guidance on making this code more efficient!

Honestly, there’s not much to improve here, in my opinion. Responsive, flexible UI’s just require a lot of piece under the hood. Sometimes it feels a little overboard to have so many different pieces that are not the actual interactive elements, but that’s the nature of xml type documents; defining an entire tree needs a lot of branches before you get to the leaves. You’re using the f7 rows and columns pretty much how they are intended, and the yaml is clear and understandable.

I personally would not use the cols in this situation, but that is truly just a matter of personal preference - there’s nothing “wrong” with using them. I simply tend to prefer to work directly with the flexbox spacing and placement within the f7 row instead of using the cols for placement and spacing. The cols are simpler and cleaner, the flexbox styling is more powerful and customizable.

Might it be possible …that you can post your solution so that I can learn out of it?

The exact final solution depends on a lot of factors, including what behavior you want as the size of the row changes. Here are two similar solutions that differ from yours only in the position of the label relative to the icon as the row increases in size:

- component: f7-row
  config:
    class:
      - align-items-center
    style:
      margin-bottom: 15px
  slots:
    default:
      - component: oh-icon
        config:
          height: 20px
          icon: light
      - component: Label
        config:
          text: Toggle Switch
          style:
            font-size: 16px
            font-weight: bold
            width: 60%
      - component: f7-row
        config:
          style:
            width: 30%
            justify-content: flex-end
        slots:
          default:
            - component: oh-toggle
              config:
                item: =props.SwitchGroupItem
- component: f7-row
  config:
    class:
      - align-items-center
    style:
      margin-bottom: 15px
      gap: 5px
  slots:
    default:
      - component: oh-icon
        config:
          height: 20px
          icon: light
      - component: f7-row
        config:
          style:
            flex: 1 1 0
        slots:
          default:
            - component: Label
              config:
                text: Toggle Switch
                style:
                  font-size: 16px
                  font-weight: bold
            - component: oh-toggle
              config:
                item: =props.SwitchGroupItem

Again, there is no one solution, and neither of these are “better” than what you have posted.