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.
This one has no events: it shows what it's given.
Source: sidebar-layout.zb, and its registry item.
Install
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
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
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
<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
<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>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>
);
}<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('-') } } }) --><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>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
| Property | Type | Default |
|---|---|---|
side | string | "16rem" |
contentMinattribute content-min | string | "55%" |
gap | string | "1.5rem" |
end | boolean | false |
| Slot | For |
|---|---|
(default) | The main content. |
side | The 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.