Skip to content

Split "flex" layout type into separate "row" and "stack" layout types #44880

@cbirdsong

Description

@cbirdsong

Picking up from #39336 (comment):

"Flex" attempts to encapsulate all "one-dimensional" layouts in a single type, but I think "one-dimensional" isn't enough to hang a type on conceptually. You see the issues start as soon as you write the justification utility classes. For vertical layout, you need to modify align-items, and for a horizontal layout you need to modify justify-content, and if your classes are human-readable they are basically unable to operate in both contexts. Look at how the buttons block CSS needed to be written1:

.is-layout-flex {
  &.is-vertical {
    flex-direction: column;
  }

  &.is-content-justification-left {
    justify-content: flex-start;
    &.is-vertical {
      align-items: flex-start;
    }
  }

  &.is-content-justification-center {
    justify-content: center;
    &.is-vertical {
      align-items: center;
    }
  }

  &.is-content-justification-right {
    justify-content: flex-end;

    &.is-vertical {
      align-items: flex-end;
    }
  }

  &.is-content-justification-space-between {
    justify-content: space-between;
  }
}

Changing layout behavior based on the presence of .is-vertical is needed at basically every step of the way, because it's an entirely different layout. Everything is much cleaner when you just start with that premise:

.is-layout-stack {
  flex-direction: column;

  &.is-content-justification-left {
    align-items: flex-start;
  }
  &.is-content-justification-center {
    align-items: center;
  }
  &.is-content-justification-right {
    align-items: flex-end;
  }
}

.is-layout-row {
  flex-direction: row;

  &.is-content-justification-left {
    justify-content: flex-start;
  }
  &.is-content-justification-center {
    justify-content: center;
  }
  &.is-content-justification-right {
    justify-content: flex-end;
  }
  &.is-content-justification-space-between {
    justify-content: space-between;
  }
}

The layout types are conceptually much cleaner when split this way, and the names "stack" and "row" map directly onto the group block variations with the same name.

Footnotes

  1. Lightly modified into a generic "flex" layout for easier comparison.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] LayoutLayout block support, its UI controls, and style output.[Type] EnhancementA suggestion for improvement.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions