diff --git a/Gemfile.lock b/Gemfile.lock index 1a0ee5f..f62cf58 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - katalyst-content (3.0.0.alpha.5) + katalyst-content (3.0.0.alpha.6) active_storage_validations activerecord katalyst-html-attributes diff --git a/app/assets/stylesheets/katalyst/content/frontend/frontend.css b/app/assets/stylesheets/katalyst/content/frontend/frontend.css index 7e5ef9c..68ddb6a 100644 --- a/app/assets/stylesheets/katalyst/content/frontend/frontend.css +++ b/app/assets/stylesheets/katalyst/content/frontend/frontend.css @@ -1,19 +1,46 @@ /* Spacing */ -.content-item { - --flow-space: var(--space-m); - margin-block: var(--block-space, var(--space-m)); +:root { + /* + The container width at which the component switches between a horizontal and vertical layout. + */ + --content-gap: var(--space-l); + --content-gutter: var(--space-m); + --content-block-gutter: var(--content-gutter); + --content-block-gap: var(--content-gap); + --content-inline-gutter: var(--content-gutter); + --content-inline-gap: var(--content-gap); } -/* Themes */ +.content-items { + /* gutters where the theme changes */ -[data-content-theme] { - display: flow-root; + &[data-content-theme] { + padding-block: var(--content-block-gutter); + } + + /* gaps between items with the same theme */ + + > * + * { + margin-block-start: var(--content-block-gap); + } + + /* add gutters to non themed siblings */ + + &[data-content-theme] + .content-items:not([data-content-theme]), + .content-items:not([data-content-theme]) + &[data-content-theme] { + margin-block-start: var(--content-block-gutter); + } } -[data-content-theme] [data-content-theme] { - margin-inline: calc(-1 * var(--gutter)); - padding-inline: var(--gutter); +/* + If a content item has children with a theme applied, we want to steal some space + from the item to give to the children for a gutter. This makes content line up + between items with and without a theme. + */ +.content-item [data-content-theme] { + margin-inline: calc(-1 * var(--content-inline-gutter)); + padding-inline: var(--content-inline-gutter); } [data-content-theme="light"] { @@ -44,3 +71,54 @@ margin-inline: auto; } } + +/* + Columns + + A two-column horizontal layout that switches to vertical layout on narrow screens. + Based on https://every-layout.dev/layouts/switcher/ +*/ + +:root { + /* + The container width at which the component switches between a horizontal and vertical layout. + */ + --content-column-threshold-width: var(--mobile-breakpoint, 37.5rem); +} + +.content-columns { + display: flex; + flex-wrap: wrap; + gap: var(--content-inline-gap) calc(2 * var(--content-inline-gap)); + + > * { + flex-grow: 1; + flex-basis: calc((var(--content-column-threshold-width) - 100%) * 999); + } +} + +.content-column { + display: grid; /* equal height columns */ +} + +.content-aside { + display: flex; + flex-wrap: wrap; + gap: var(--content-inline-gap) calc(2 * var(--content-inline-gap)); + align-items: start; + + > :last-child { + flex-basis: max(var(--content-aside-min-width, 16rem), 33%); + flex-grow: 1; + } + + > :first-child { + flex-basis: 0; + flex-grow: 999; + min-inline-size: 55%; + } + + &[data-wrap-reverse] { + flex-wrap: wrap-reverse; + } +} diff --git a/app/models/katalyst/content/item.rb b/app/models/katalyst/content/item.rb index 194021f..4e9d7b9 100644 --- a/app/models/katalyst/content/item.rb +++ b/app/models/katalyst/content/item.rb @@ -60,7 +60,7 @@ def item_type end def theme - super.presence || parent&.theme + super.presence || parent&.theme || Config.default_theme end private diff --git a/app/views/katalyst/content/asides/_aside.html.erb b/app/views/katalyst/content/asides/_aside.html.erb index 6db0118..d4c516d 100644 --- a/app/views/katalyst/content/asides/_aside.html.erb +++ b/app/views/katalyst/content/asides/_aside.html.erb @@ -1,14 +1,16 @@ -<%= content_item_tag(aside, data: { aside_reverse: ("" if aside.reverse) }) do %> +<%= content_item_tag(aside, class: "flow") do %> <%= tag.h3 aside.heading, class: aside.heading_style_class if aside.show_heading? %> <% if aside.children.any? %> <% items = aside.children.select(&:visible?) %> <% last = items.pop %> -