Zubra UI
Code for
GitHub

sidebar-layout

A sidebar beside the main content that moves above it when the content would get too narrow (content-min), with no media queries, so it works in any container.

The main content takes the rest of the width, and the contents move above it on a narrow screen.

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

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

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/sidebar-layout.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/sidebar-layout.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/sidebar-layout.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/sidebar-layout.json
One file, no dependencies (3.1 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/sidebar-layout.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/sidebar-layout.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/sidebar-layout.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/sidebar-layout.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/sidebar-layout.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/sidebar-layout.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/sidebar-layout.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/sidebar-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/sidebar-layout.js"></script>

The compiled install writes src/components/zubra/sidebar-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
<sidebar-layout side="10rem" content-min="55%">
  <nav slot="side" class="demo-box">Contents</nav>
  <article class="demo-box">The main content takes the rest of the width, and the contents move above it on a narrow screen.</article>
</sidebar-layout>

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

export function SidebarLayoutExample() {
  return (
    <sidebar-layout side="10rem" content-min="55%">
      <nav slot="side" className="demo-box">Contents</nav>
      <article className="demo-box">The main content takes the rest of the width, and the contents move above it on a narrow screen.</article>
    </sidebar-layout>
  );
}
Example.vue
<script setup>
import './components/zubra/sidebar-layout.js';
</script>

<template>
  <sidebar-layout side="10rem" content-min="55%">
    <nav slot="side" class="demo-box">Contents</nav>
    <article class="demo-box">The main content takes the rest of the width, and the contents move above it on a narrow screen.</article>
  </sidebar-layout>
</template>

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

<sidebar-layout side="10rem" content-min="55%">
  <nav slot="side" class="demo-box">Contents</nav>
  <article class="demo-box">The main content takes the rest of the width, and the contents move above it on a narrow screen.</article>
</sidebar-layout>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/sidebar-layout.js';

@Component({
  selector: 'app-sidebar-layout-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <sidebar-layout side="10rem" content-min="55%">
      <nav slot="side" class="demo-box">Contents</nav>
      <article class="demo-box">The main content takes the rest of the width, and the contents move above it on a narrow screen.</article>
    </sidebar-layout>
  `,
})
export class SidebarLayoutExample {

}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
sidestring"16rem"
contentMin
attribute content-min
string"55%"
gapstring"1.5rem"
endbooleanfalse
Slots
SlotFor
(default)The main content.
sideThe sidebar.

Size

0.6 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 16.7 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