2.0.1 • Published 1 year ago

draggable-menu v2.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Draggable Menu

This is a draggable menu web component. It allows you to create a menu that can be dragged out of view as well as toggled in/out.

See demo

Usage

First, import the component:

import 'draggable-menu';

Then you can use it in your HTML:

<draggable-menu
  position="left"
  duration="0.8"
  ease="power2.inOut"
>  
  <!-- Your content here -->
</draggable-menu>

Attributes

nametypedescriptiondefault
placementstring (right | left | top | bottom)The position of the menu in the viewportright
openPositionstring (% or px)The position of the menu in the open state100%
closedPositionstring (% or px)The position of the menu in the closed state0%
durationnumberThe speed of the open/close animation in seconds.0.4
easestringGSAP easing function (see options here)power4.out
enableInertbooleanToggles the inert attribute when the menu is closed/openfalse
handlestringAn element in your slotted content that acts as the drag handle. Defined as a css queryable string (fx. #handle or .handle)undefined

openPosition / closedPosition

A value in percent is calculated as a percentage of the viewport from the placement. A value in pixels will be the value in pixels from the placement.

Examples

/*
  This content would be at 0% from the left of the viewport when closed and
  100% from the left of the viewport when open
  Note that the width of your content also determines how much of it the user will see.
  A width of 100vw would make the entire content visible when open and all of it hidden when closed.
*/
<draggable-menu
  position="left"
  openPosition="100%"
  closedPosition="0%"
>

Events

Every state change is dispatched as a CustomEvent. The event is dispatched on toggle() and drag actions. The event type is DRAGGABLE_MENU_STATE and the event detail is an object with the following properties:

{
  open: boolean, //The current state of the menu, true if open, false if closed
  progress: number //The current progress of the animation from 0 to 1 (o being completey in the closedPosition and 1 being the openPosition,
}

API

The component provides the following methods:

  • toggle(): Toggles the state of the menu. If the menu is open, it will close it, and vice versa.

  • updateValues(): Updates the draggable menu's values.

2.0.1

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago