All Projects β†’ web-padawan β†’ Vanilla Hamburger

web-padawan / Vanilla Hamburger

Licence: mit
Animated hamburger menu icons for modern web apps (1.8 KB) πŸ”

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Vanilla Hamburger

Vanilla Colorful
A tiny color picker custom element for modern web apps (2.7 KB) 🎨
Stars: ✭ 467 (+324.55%)
Mutual labels:  web-components, webcomponents, custom-elements, vanilla
smart-webcomponents-community
Material & Bootstrap Web Components built with Smart
Stars: ✭ 30 (-72.73%)
Mutual labels:  webcomponents, web-components, custom-elements
web-components
A set of high-quality standards based web components for enterprise web applications. Part of Vaadin 20+
Stars: ✭ 322 (+192.73%)
Mutual labels:  webcomponents, web-components, custom-elements
lego
πŸš€ Web-components made lightweight & Future-Proof.
Stars: ✭ 69 (-37.27%)
Mutual labels:  webcomponents, web-components, custom-elements
symbiote.js
Simple, light and very powerful library to create embedded components for any purpose, with a data flow management included.
Stars: ✭ 40 (-63.64%)
Mutual labels:  webcomponents, web-components, custom-elements
Omi
Front End Cross-Frameworks Framework - ε‰η«―θ·¨ζ‘†ζžΆθ·¨εΉ³ε°ζ‘†ζžΆ
Stars: ✭ 12,153 (+10948.18%)
Mutual labels:  web-components, webcomponents, custom-elements
modulor-html
Missing template engine for Web Components
Stars: ✭ 36 (-67.27%)
Mutual labels:  webcomponents, web-components, custom-elements
Nutmeg
Build, test, and publish vanilla Web Components with a little spice
Stars: ✭ 111 (+0.91%)
Mutual labels:  web-components, webcomponents, custom-elements
toggle-icon
toggle-icon is a custom element created with Polymer. It provides an extremely powerful and customizable switch that looks like a paper-icon-button.
Stars: ✭ 21 (-80.91%)
Mutual labels:  webcomponents, web-components, custom-elements
cwco
Powerful and Fast Web Component Library with a Simple API
Stars: ✭ 27 (-75.45%)
Mutual labels:  webcomponents, web-components, custom-elements
custom-elements-manifest
Custom Elements Manifest is a file format that describes custom elements in your project.
Stars: ✭ 81 (-26.36%)
Mutual labels:  webcomponents, web-components, custom-elements
lit-components
Moved to https://github.com/vaadin/component-mixins
Stars: ✭ 59 (-46.36%)
Mutual labels:  webcomponents, web-components, custom-elements
anywhere-webcomponents
A UI work in progress based on custom elements (web components) for use in anywhere.
Stars: ✭ 17 (-84.55%)
Mutual labels:  webcomponents, web-components, custom-elements
Aybolit
Lightweight web components library built with LitElement.
Stars: ✭ 90 (-18.18%)
Mutual labels:  web-components, webcomponents, custom-elements
Calcite Components
Web Components for the Calcite Design System. Built with Stencil JS. Currently in Beta!
Stars: ✭ 96 (-12.73%)
Mutual labels:  webcomponents, custom-elements
Blazor.fast
A tiny wrapper around Fast and Fluent Web Components to integrate with Blazor and easily use the EditForm components
Stars: ✭ 23 (-79.09%)
Mutual labels:  web-components, webcomponents
Dataformsjs
🌟 DataFormsJS 🌟 A minimal JavaScript Framework and standalone React and Web Components for rapid development of high quality websites and single page applications.
Stars: ✭ 95 (-13.64%)
Mutual labels:  web-components, custom-elements
File Input
A better <input type="file">
Stars: ✭ 59 (-46.36%)
Mutual labels:  web-components, custom-elements
Dna
Progressive Web Components.
Stars: ✭ 22 (-80%)
Mutual labels:  webcomponents, custom-elements
Custom Elements Ts
Create native custom elements using Typescript
Stars: ✭ 52 (-52.73%)
Mutual labels:  web-components, custom-elements

Preview

vanilla-hamburger is a port of hamburger-react to vanilla Custom Elements.

Features

  • Small: Just 1,8 KB (minified and gzipped). Size Limit controls the size.
  • Fast: Built with standards based Custom Elements.
  • Bulletproof: Written in strict TypeScript and covered by 30+ tests.
  • Framework-agnostic: Can be used with any framework.
  • Simple: Uses native <button> with a click listener internally.
  • Accessible: Follows WAI-ARIA guidelines for toggle buttons.
  • No dependencies

Live demo

Installation

npm install vanilla-hamburger --save

Or use one of the following content delivery networks:

unpkg.com CDN:

<script type="module" src="https://unpkg.com/vanilla-hamburger?module"></script>

Skypack CDN:

<script type="module" src="https://cdn.skypack.dev/vanilla-hamburger"></script>

Usage

<tilt-burger size="lg" label="Menu"></tilt-burger>
<script type="module">
  import 'vanilla-hamburger';

  const burger = document.querySelector('tilt-burger');
  burger.addEventListener('pressed-changed', (event) => {
    const pressed = event.detail.value;
  });
</script>

ES modules

vanilla-hamburger is authored using ES modules which are natively supported by modern browsers. However, it also uses "bare module imports" which are not yet standardized and require a small transform.

We recommend the following tools for the ES modules based development:

None of these tools are needed when importing the component from CDN.

Available variants

vanilla-hamburger provides 13 separate elements for different hamburger types.

File to import HTML element
"cross-burger.js" <cross-burger>
"fade-burger.js" <fade-burger>
"pivot-burger.js" <pivot-burger>
"rotate-burger.js" <rotate-burger>
"slant-burger.js" <slant-burger>
"sling-burger.js" <sling-burger>
"spin-burger.js" <spin-burger>
"spiral-burger.js" <spiral-burger>
"squash-burger.js" <squash-burger>
"squeeze-burger.js" <squeeze-burger>
"tilt-burger.js" <tilt-burger>
"turn-burger.js" <turn-burger>
"twirl-burger.js" <twirl-burger>

When using one hamburger, ~1.8 KB will be added to your bundle (min + gzip).

Properties

The following properties can be used to customize hamburger elements:

Property Default Description
direction left The animation direction of the icon, left or right.
disabled false When set to true, the internal <button> id disabled.
distance md The distance between the lines: sm, md or lg.
duration 0.4 The duration of the animation. Can be set to zero.
easing cubic-bezier(0, 0, 0, 1) A valid transition-timing-function CSS value.
label hamburger Accessible label set on the internal <button>.
pressed false Set to true when element is pressed.
size 32 Size of the icon. Should be a number between 12 and 48.

Note: direction property is not supported by <squash-burger> and <squeeze-burger>.

Overriding styles

vanilla-hamburger exposes CSS Shadow Parts allowing to override the default styles:

cross-burger {
  color: #999;
}

cross-burger[pressed] {
  color: #666;
}

cross-burger[disabled] {
  opacity: 0.7;
}

cross-burger::part(bar) {
  border-radius: 9em;
}

cross-burger::part(button) {
  outline: none;
  background: currentColor;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.5s;
}

cross-burger::part(button):hover {
  opacity: 0.12;
}

cross-burger::part(button):focus {
  opacity: 0.16;
}

Base classes

vanilla-hamburger provides a set of base classes that can be imported without registering custom elements. This is useful if you want to create your own hamburger icon with a different tag name.

import { Cross } from 'vanilla-hamburger/lib/entrypoints/cross.js';

customElements.define('custom-burger', class extends Cross {});

Accessibility

It is recommended to have a tap/click area of at least 48x48 pixels. Therefore, padding will be added around the icon to create a surface of exactly this size.

Keyboard interaction is provided using native <button>, which dispatches the click event on Enter and Space keys. The underlying native button has aria-pressed attribute set based on the pressed property.

Remember to use label property to provide an accessible label for the native button.

TypeScript support

vanilla-hamburger supports TypeScript and ships with types in the library itself; no need for any other install.

All the included custom elements are compatible with lit-analyzer and lit-plugin extension for Visual Studio Code, so you can benefit from type checking in lit-html templates.

Browser support

vanilla-hamburger uses Custom Elements and Shadow DOM, and does not support IE11 or legacy Edge.

Why vanilla-hamburger?

vanilla-hamburger has all the benefits of hamburger-react with one important difference.

While hamburger-react does not have direct dependencies, it still expects you to use React. This means that Angular, Vue, Svelte or vanilla JS users would have an extra dependency in their apps.

Now when all the evergreen browsers support standards based Custom Elements, it's perfect time to build such tiny and lightweight UI controls as web components rather than framework components.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].