Skip to content

A simple sidebar component written in vanilla JS and also as React wrapper

Notifications You must be signed in to change notification settings

ardeshireshghi/vanilla-js-sidebar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vanilla-js-sidebar

A simple sidebar component

NPM

Install

vanilla-js-sidebar requires Node.js version 12

# npm
npm install --save @eardi/vanilla-js-sidebar

# yarn
yarn add @eardi/vanilla-js-sidebar

Usage

Default usage

import Sidebar from '@eardi/vanilla-js-sidebar';

const buttonSelector = 'someselector'; // Change this to your button el

// Content of sidebar can be HTML string
const sidebarContent = `<div class="sidebar-content">
    <h1>Hello! I am a sidebar</h1>
    <p>The content of the sidebar goes here. You can also set the direction to show from TOP, BOTTOM, LEFT, or RIGHT.</p>
</div>`;

// OR let's say you want to pass a reference to a DOM element
const sidebarContentElement = document.createElement('div');
sidebarContent.innerHTML = sidebarContent;

const sidebar = new Sidebar({
  direction: Sidebar.direction.LEFT,
  panelStyles: {
    maxWidth: 'min(90%, 400px)'
  }
});

sidebar.renderContent(sidebarContent || sidebarContentElement);
buttonSelector.onclick = () => sidebar.show();

Use with React

This is a Codesandbox example which shows the usage in React:

React Example

Loading through adding script tag

Add this right before the closing of <body>:

<script src="https://unpkg.com/@eardi/[email protected]/src/sidebar.js" crossorigin></script>

Running example app locally

$ yarn install
$ yarn serve-example

License

MIT © ardeshireshghi

About

A simple sidebar component written in vanilla JS and also as React wrapper

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published