Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@codewithshin/svelte-sidebar

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codewithshin/svelte-sidebar

A Svelte package for sidebar

  • 0.5.3
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Svelte-sidebar

Installation

npm i -D @codewithshin/svelte-sidebar@latest

Features

  • Inert
  • Responsive menu
  • Slide in/out
  • Sidebar style
  • Sidebar style 2
  • Top menu
  • Fixed top menu
  • Scroll sidebar

Inert

HTMLElement.inert makes the browser to ignore user input events for the element. For example, when a user press a tab key, it cycles down links and input fields.

Test Svelte-Sidebar demo by pressing the tab keyboard when the sidebar closed and opened. When the sidebar is closed, the tab ignores the sidebar links and when it is open the tab goes throught the menu links.

Responsive Top Menu Fixed

The demo set the breaking point at 1024. When the window is greater than 1024px, the sidebar is kept open. When the winddow is less than 1024px, the sidebar is open by the bars at top-left.

<script lang="ts">
	import { Aside, Nav, SidebarList, Navbar, TopMenu, open, isInert, responsive } from '@codewithshin/svelte-sidebar';
  const menuList = [
    { href: "/", name: "Sidebar Default" },
    //  ...
  ];
	$: console.log('open', $open);
	let width: number;
	$: if (width > 1024) {
		open.update((n) => (n = true));
		isInert.update((n) => (n = false));
		responsive.update((n) => (n = true));
	} else {
		open.update((n) => (n = false));
		isInert.update((n) => (n = true));
		responsive.update((n) => (n = false)); // when open a sidebar clicking outside closes it
	}
	const topMenus = [
		{
			id: 1,
			name: 'Menu',
			href: '/'
		},
		//... more
	];
	let siteName = 'Responsive with fixed top menu';
	let headerClass = 'bg-white py-3 px-8 items-center text-gray-600 border-b-2 px-4';
	let navClass = 'py-8 px-4 bg-white text-base ';
	let navDivClass = 'pb-10';
	let asideClass =
		'absolute w-auto bg-gray-200 border-r-2 shadow-lg z-50  h-screen overflow-scroll';
</script>

<svelte:window bind:innerWidth={width} />
<div class="fixed z-50 top-0 left-0 w-full">
	<Navbar {siteName} {headerClass} hamburgerClass="lg:hidden">
		<TopMenu {topMenus} />
	</Navbar>
	<Aside {asideClass}>
		<Nav {navClass} {navDivClass}>
			<h3>Menu 1</h3>
			{#each menuList as { href, name, rel }}
				<SidebarList {href} {name} {rel} />
			{/each}
		</Nav>
		<Nav {navClass} {navDivClass}>
			<h3>Menu 2</h3>
			{#each menuList as { href, name, rel }}
				<SidebarList {href} {name} {rel} />
			{/each}
		</Nav>
	</Aside>
</div>
<main class="container mx-auto pt-24 p-8 lg:pl-80">
  Your contente
</main>

Responsive Sidebar

The demo set the breaking point at 1024. When the window is greater than 1024px, the sidebar is kept open. When the winddow is less than 1024px, the sidebar is open by the bars at top-left.

<script lang="ts">
	import { Sidebar, open, isInert, responsive } from '@codewithshin/svelte-sidebar';
	const menuList = [
    { href: "/", name: "Sidebar Default" },
  // ...
  ];
	let siteName = 'Responsive Sidebar';
	let width: number;
	$: if (width > 1024) {
		open.update((n) => (n = true));
		isInert.update((n) => (n = false));
		responsive.update((n) => (n = true));
	} else {
		open.update((n) => (n = false));
		isInert.update((n) => (n = true));
	}
</script>

<svelte:window bind:innerWidth={width} />
<Sidebar
	lists={menuList}
	{siteName}
	hamburgerClass=" lg:hidden"
	asideClass="absolute w-auto h-screen bg-white lg:fixed lg:w-64"
	logo="/images/svelte-sidebar-logo.png"
	alt="Svelte Sidebar"
/>
<main class="container mx-auto pt-24 p-8 lg:pl-64">
...
</main>

Sidebar default

Demo

<script>
  import Sidebar from "@codewithshin/svelte-sidebar";
  const menuList = [
    { href: "/", name: "Sidebar Default" },
    { href: "sidebar-custom-style", name: "Sidebar Custom Style" },
    { href: "sidebar-topmenu", name: "Sidebar Top Menu" },
    { href: "multi-default", name: "Multiple-menu Default" },
    { href: "multi-custom-style", name: "Multiple-menu Custom Style" },
    { href: "fixed-menu", name: "Fixed Top Menu" },
    { href: "scroll-sidebar", name: "Scroll Sidebar"},
  ];

  let siteName = "Svelte-sidebar";
</script>

<Sidebar lists={menuList} {siteName} />
<main class="container mx-auto p-24">
  ...
</main>

Custom default sidebar example

Demo

<script>
  import Sidebar from "@codewithshin/svelte-sidebar";
  const menuList = [
    { href: "/", name: "Sidebar Default" },
    { href: "sidebar-custom-style", name: "Sidebar Custom Style" },
    { href: "sidebar-topmenu", name: "Sidebar Top Menu" },
    { href: "multi-default", name: "Multiple-menu Default" },
    { href: "multi-custom-style", name: "Multiple-menu Custom Style" },
    { href: "fixed-menu", name: "Fixed Top Menu" },
    { href: "scroll-sidebar", name: "Scroll Sidebar"},
  ];
  let siteName = 'Custom Styled Sidebar';
  let headerClass = 'bg-pink-700 py-3 px-10 items-center text-white border-b-2';
  let asideClass = 'absolute w-auto h-screen bg-red-50 pt-8 border-r-2 shadow-lg';
  let navClass = 'p-5 text-base';
</script>

<Sidebar lists={menuList} {siteName} {headerClass} {asideClass} {navClass} />

Multiple sidebar menu example

Demo

<script>
  import { Aside, Nav, SidebarList, Navbar } from "@codewithshin/svelte-sidebar";
  const menuList = [
    { href: "/", name: "Sidebar Default" },
    { href: "sidebar-custom-style", name: "Sidebar Custom Style" },
    { href: "sidebar-topmenu", name: "Sidebar Top Menu" },
    { href: "multi-default", name: "Multiple-menu Default" },
    { href: "multi-custom-style", name: "Multiple-menu Custom Style" },
    { href: "fixed-menu", name: "Fixed Top Menu" },
    { href: "scroll-sidebar", name: "Scroll Sidebar"},
  ];

  let siteName = 'Default Styled Multi-menu Sidebar';
</script>

<Navbar {siteName} />
<Aside>
  <Nav>
    <h3>Menu 1</h3>
    {#each menuList as { href, name, rel }}
      <SidebarList {href} {name} {rel} />
    {/each}
  </Nav>
  <Nav>
    <h3>Menu 2</h3>
    {#each menuList as { href, name, rel }}
      <SidebarList {href} {name} {rel} />
    {/each}
  </Nav>
</Aside>

Custom multi-menu example

Demo

<script>
  import { Aside, Nav, SidebarList, Navbar } from "@codewithshin/svelte-sidebar";
  const menuList = [
    { href: "/", name: "Sidebar Default" },
    { href: "sidebar-custom-style", name: "Sidebar Custom Style" },
    { href: "sidebar-topmenu", name: "Sidebar Top Menu" },
    { href: "multi-default", name: "Multiple-menu Default" },
    { href: "multi-custom-style", name: "Multiple-menu Custom Style" },
    { href: "fixed-menu", name: "Fixed Top Menu" },
    { href: "scroll-sidebar", name: "Scroll Sidebar"},
  ];

  let siteName = 'Custom Styled Multi-menu Sidebar';
  let navClass = 'p-5 text-lg';
  let navDivClass = 'pb-10';
  let sideBarListClass = 'mb-2 px-4 hover:text-gray-500';
  let hamburgerClass =
    'text-white hover:text-gray-500 cursor-pointer mr-4 border-none focus:outline-none';
  let asideClass = 'absolute w-auto h-screen bg-gray-700 text-white border-r-2 shadow-lg';
  let headerClass = 'bg-gray-700 py-3 px-10 items-center text-white border-b-2';
</script>

<Navbar {siteName} {hamburgerClass} {headerClass} />
<Aside {asideClass}>
  <Nav {navClass} {navDivClass}>
    <h3>Menu 1</h3>
    {#each menuList as { href, name }}
      <SidebarList {href} {name} {sideBarListClass} />
    {/each}
  </Nav>
  <Nav {navClass}>
    <h3>Menu 2</h3>
    {#each menuList as { href, name }}
      <SidebarList {href} {name} {sideBarListClass} />
    {/each}
  </Nav>
</Aside>

Top menu example

Demo

<script>
  import { Aside, Nav, SidebarList, Navbar, TopMenu } "$lib/Aside.svelte";
  const menuList = [
    { href: "/", name: "Sidebar Default" },
    { href: "sidebar-custom-style", name: "Sidebar Custom Style" },
    { href: "sidebar-topmenu", name: "Sidebar Top Menu" },
    { href: "multi-default", name: "Multiple-menu Default" },
    { href: "multi-custom-style", name: "Multiple-menu Custom Style" },
    { href: "fixed-menu", name: "Fixed Top Menu" },
    { href: "scroll-sidebar", name: "Scroll Sidebar"},
  ];
  const topMenus = [
  {
    id: 1,
    name: "Menu",
    href: "/"
  },
  {
    id: 2,
    name: "Dropdown",
    href: "/",
    child: [
      {
        id: 3,
        name: "Dropdown 1-1",
        href: "/"
      },
      {
        id: 4,
        name: "Dropdown 1-2",
        href: "/"
      },
      {
        id: 5,
        name: "Dropdown 1-3",
        href: "/"
      },
    ],
  },
  {
    id: 6,
    name: "Dropdown",
    href: "/",
    child: [
      {
        id: 7,
        name: "Dropdown 2-1",
        href: "/"
      },
      {
        id: 8,
        name: "Dropdown 2-2",
        href: "/",
      },
      {
        id: 9,
        name: "Dropdown 2-3",
        href: "/",
      },
    ],
  }
];
  let siteName = "Svelte-sidebar";
</script>

<Navbar {siteName}>
  <TopMenu {topMenus} />
</Navbar>
<Aside>
  <Nav>
    <h3>Menu 1</h3>
    {#each menuList as { href, name, rel }}
      <SidebarList {href} {name} {rel} />
    {/each}
  </Nav>
  <Nav>
    <h3>Menu 2</h3>
    {#each menuList as { href, name, rel }}
      <SidebarList {href} {name} {rel} />
    {/each}
  </Nav>
</Aside>

Fixed menu example

Demo

<script>
  import { Aside, Nav, SidebarList, Navbar, TopMenu } from "@codewithshin/svelte-sidebar";
  const menuList = [
    { href: "/", name: "Sidebar Default" },
    { href: "sidebar-custom-style", name: "Sidebar Custom Style" },
    { href: "sidebar-topmenu", name: "Sidebar Top Menu" },
    { href: "multi-default", name: "Multiple-menu Default" },
    { href: "multi-custom-style", name: "Multiple-menu Custom Style" },
    { href: "fixed-menu", name: "Fixed Top Menu" },
    { href: "scroll-sidebar", name: "Scroll Sidebar"},
  ];
  const topMenus = [
  {
    id: 1,
    name: "Menu",
    href: "/"
  },
  {
    id: 2,
    name: "Dropdown",
    href: "/",
    child: [
      {
        id: 3,
        name: "Dropdown 1-1",
        href: "/"
      },
      {
        id: 4,
        name: "Dropdown 1-2",
        href: "/"
      },
      {
        id: 5,
        name: "Dropdown 1-3",
        href: "/"
      },
    ],
  },
  {
    id: 6,
    name: "Dropdown",
    href: "/",
    child: [
      {
        id: 7,
        name: "Dropdown 2-1",
        href: "/"
      },
      {
        id: 8,
        name: "Dropdown 2-2",
        href: "/",
      },
      {
        id: 9,
        name: "Dropdown 2-3",
        href: "/",
      },
    ],
  }
];

  let siteName = 'Fixed Top Menu';
  let asideClass =
    'absolute w-auto bg-white overflow-scroll h-screen py-8 shadow-lg z-50 px-4 min-h-screen';
  let headerClass = 'bg-white py-3 px-8 items-center text-gray-600 border-b-2 p-8';
  let navClass = 'p-8 bg-white text-xl ';
  let navDivClass = 'pb-10';
</script>

<div class="fixed z-50 top-0 left-0 w-full">
  <Navbar {siteName} {headerClass}>
    <TopMenu {topMenus} />
  </Navbar>
  <Aside {asideClass}>
    <Nav {navClass} {navDivClass}>
      <h3>Menu 1</h3>
      {#each menuList as { href, name, rel }}
        <SidebarList {href} {name} {rel} />
      {/each}
    </Nav>
    <Nav {navClass} {navDivClass}>
      <h3>Menu 2</h3>
      {#each menuList as { href, name, rel }}
        <SidebarList {href} {name} {rel} />
      {/each}
    </Nav>
  </Aside>
</div>

Scroll sidebar

Demo

<script lang="ts">
  import { Aside, Nav, SidebarList, Navbar } from '@codewithshin/svelte-sidebar';
  const longMenuList = [
  { href: "/", name: "Sidebar Default" },
  { href: "sidebar-custom-style", name: "Sidebar Custom Style" },
  { href: "sidebar-topmenu", name: "Sidebar Top Menu" },
  { href: "multi-default", name: "Multiple-menu Default" },
  { href: "multi-custom-style", name: "Multiple-menu Custom Style" },
  { href: "fixed-menu", name: "Fixed Top Menu" },
  { href: "scroll-sidebar", name: "Scroll Sidebar"},
];
  let siteName = 'Scroll Sidebar';
  let asideClass =
    'absolute w-auto h-screen bg-gray-200 border-r-2 shadow-lg z-50  h-screen overflow-scroll';
</script>

<Navbar {siteName} />

<Aside {asideClass}>
  <Nav>
    <h3>Long Side Menu</h3>
    {#each longMenuList as { href, name, rel }}
      <SidebarList {href} {name} {rel} />
    {/each}
  </Nav>
</Aside>

Article

A Svelte Sidebar Menu Component Implemented with Tailwind CSS

Keywords

FAQs

Package last updated on 03 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc