--- layout: layouts/page.njk title: Sidebar description: A composable, themeable and customizable sidebar component. toc: - label: Usage id: usage children: - label: HTML + Javascript id: usage-default - label: Jinja and Nunjucks id: usage-macro --- {% from "macros/code_preview.njk" import code_preview %} {% from "macros/code_block.njk" import code_block %} {% from "sidebar.njk" import sidebar %}

Usage

HTML + Javascript

{% lucide "circle-alert" %}

This component requires Javascript.

To use a sidebar, you will need the sidebar itself and a sibling container for the content of the page (e.g. <main>), with the following structure for the sidebar:

Any elememt on the page can toggle, open or close the sidebar by dispatching the sidebar:toggle, sidebar:open or sidebar:close events.

You can include the Javascript code provided below, load it as an individual file or use the CLI. Some Alpine.js properties are also required on certain elements (e.g. x-bind, x-data, @click).

Components with Javascript {% lucide "arrow-right" %} Use the CLI {% lucide "arrow-right" %} Individual JS file (sidebar.js) {% lucide "arrow-right" %}
{% set code_html %} {% set icon_square_terminal %}{% lucide "square-terminal" %}{% endset %} {% set icon_bot %}{% lucide "bot" %}{% endset %} {% set icon_settings %}{% lucide "settings" %}{% endset %} {% set menu = [ { type: "group", label: "Getting started", items: [ { label: "Playground", url: "#", icon: icon_square_terminal }, { label: "Models", url: "#", icon: icon_bot }, { label: "Settings", type: "submenu", icon: icon_settings, items: [ { label: "General", url: "#" }, { label: "Team", url: "#" }, { label: "Billing", url: "#" }, { label: "Limits", url: "#" } ] } ]} ] %} {{ sidebar( label="Sidebar navigation", content_attrs={ "class": "scrollbar" }, menu=menu ) }}

Content

{% endset %} {% set code_script %} {% endset %} {% from "tabs.njk" import tabs %} {% set tabsets = [ { tab: "HTML", panel: code_block(code_html | prettyHtml, class="") }, { tab: "Javascipt (Alpine.js)", panel: code_block(code_script | prettyHtml, class="") } ] %} {{ tabs(id="sidebar", tabsets=tabsets) }}

Jinja and Nunjucks

You can use the sidebar() Nunjucks or Jinja macro for this component.

Use Nunjucks or Jinja macros {% lucide "arrow-right" %} Jinja macro {% lucide "arrow-right" %} Nunjucks macro {% lucide "arrow-right" %}
{% set raw_code %}{% raw %}{% set menu = [ { type: "group", label: "Getting started", items: [ { label: "Playground", url: "#" }, { label: "Models", url: "#" }, { label: "Settings", type: "submenu", items: [ { label: "General", url: "#" }, { label: "Team", url: "#" }, { label: "Billing", url: "#" }, { label: "Limits", url: "#" } ] } ]} ] %} {{ sidebar( label="Sidebar navigation", menu=menu ) }}

Content

{% endraw %}{% endset%} {{ code_block(raw_code, "jinja") }}