Zubra UI
Code for
GitHub

switcher-layout

Children side by side in equal columns while the container is wide enough, and stacked one above the other below threshold (the container's width, not the screen's, so it works in a sidebar as well as the page). More than limit children always stack. Every child switches at once: no awkward row of two over one.

Plan
Build
Ship

This one has no events: it shows what it's given.

Source: switcher-layout.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/switcher-layout.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/switcher-layout.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/switcher-layout.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/switcher-layout.json
One file, no dependencies (3.6 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/switcher-layout.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/switcher-layout.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/switcher-layout.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/switcher-layout.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/switcher-layout.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/switcher-layout.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/switcher-layout.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/switcher-layout.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/switcher-layout.js"></script>

The compiled install writes src/components/zubra/switcher-layout.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<switcher-layout threshold="28rem" gap="0.75rem">
  <div class="demo-box">Plan</div>
  <div class="demo-box">Build</div>
  <div class="demo-box">Ship</div>
</switcher-layout>

<script type="module">
  import './components/zubra/switcher-layout.js';
</script>
Example.jsx
import './components/zubra/switcher-layout.js';

export function SwitcherLayoutExample() {
  return (
    <switcher-layout threshold="28rem" gap="0.75rem">
      <div className="demo-box">Plan</div>
      <div className="demo-box">Build</div>
      <div className="demo-box">Ship</div>
    </switcher-layout>
  );
}
Example.vue
<script setup>
import './components/zubra/switcher-layout.js';
</script>

<template>
  <switcher-layout threshold="28rem" gap="0.75rem">
    <div class="demo-box">Plan</div>
    <div class="demo-box">Build</div>
    <div class="demo-box">Ship</div>
  </switcher-layout>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/switcher-layout.js';
</script>

<switcher-layout threshold="28rem" gap="0.75rem">
  <div class="demo-box">Plan</div>
  <div class="demo-box">Build</div>
  <div class="demo-box">Ship</div>
</switcher-layout>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/switcher-layout.js';

@Component({
  selector: 'app-switcher-layout-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <switcher-layout threshold="28rem" gap="0.75rem">
      <div class="demo-box">Plan</div>
      <div class="demo-box">Build</div>
      <div class="demo-box">Ship</div>
    </switcher-layout>
  `,
})
export class SwitcherLayoutExample {

}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
thresholdstring"30rem"
gapstring"1rem"
limitnumber4
alignstring"stretch"
Slots
SlotFor
(default)The children.

Size

0.8 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 17.4 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour