0.5.3 • Published 2 years ago

@eardi/vanilla-js-sidebar v0.5.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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/vanilla-js-sidebar@0.4.1/src/sidebar.js" crossorigin></script>

Running example app locally

$ yarn install
$ yarn serve-example

License

MIT © ardeshireshghi

0.5.3

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago