All Projects → Simonwep → Nanopop

Simonwep / Nanopop

Licence: mit
🍦 Minimalistic, small, positioning engine. Build for high-performance, minimal footprint and maximum control over positioning behavior.

Projects that are alternatives of or similar to Nanopop

Scriptable
scriptable widget
Stars: ✭ 405 (-22.12%)
Mutual labels:  widget
Flutter easyloading
✨A clean and lightweight loading/toast widget for Flutter, easy to use without context, support iOS、Android and Web
Stars: ✭ 455 (-12.5%)
Mutual labels:  widget
Aws Lex Web Ui
Sample Amazon Lex chat bot web interface
Stars: ✭ 500 (-3.85%)
Mutual labels:  widget
Projectx
所有个人开源项目合集,便于管理及维护。
Stars: ✭ 417 (-19.81%)
Mutual labels:  widget
Sliding Panel
Android sliding panel that is part of the view hierarchy, not above it.
Stars: ✭ 433 (-16.73%)
Mutual labels:  widget
Switchbutton
A cute widget of Switch Button for you to create beautiful and friendly UI.
Stars: ✭ 4,531 (+771.35%)
Mutual labels:  widget
Dragpointview
A draggable PointView for Android.
Stars: ✭ 401 (-22.88%)
Mutual labels:  widget
Checkable Chip View
Android Chipview Widget
Stars: ✭ 513 (-1.35%)
Mutual labels:  widget
Lottie Flutter
Render After Effects animations natively on Flutter. This package is a pure Dart implementation of a Lottie player.
Stars: ✭ 444 (-14.62%)
Mutual labels:  widget
Vue Grid Layout
A draggable and resizable grid layout, for Vue.js.
Stars: ✭ 5,170 (+894.23%)
Mutual labels:  widget
Qt Advanced Docking System
Advanced Docking System for Qt
Stars: ✭ 422 (-18.85%)
Mutual labels:  widget
Avatarview
A circular Image View with a lot of perks. Including progress animation and highlight state with borders and gradient color.
Stars: ✭ 429 (-17.5%)
Mutual labels:  widget
Radarchartview
Android view (widget) for rendering radial diagrams
Stars: ✭ 488 (-6.15%)
Mutual labels:  widget
Githubcontributionsios
Show off your GitHub contributions from your lock screen 📱
Stars: ✭ 410 (-21.15%)
Mutual labels:  widget
React Event Timeline
A responsive event timeline in React.js
Stars: ✭ 504 (-3.08%)
Mutual labels:  widget
Tabulator
Interactive Tables and Data Grids for JavaScript
Stars: ✭ 4,329 (+732.5%)
Mutual labels:  widget
Dividerdrawable
Help to layout and draw dividers on android views.
Stars: ✭ 464 (-10.77%)
Mutual labels:  widget
Maskara
A simple way to format text fields without getting affected by input filters
Stars: ✭ 515 (-0.96%)
Mutual labels:  widget
Material Viewpagerindicator
Dot-based Android ViewPager indicator with Material Design animations.
Stars: ✭ 511 (-1.73%)
Mutual labels:  widget
Chip Navigation Bar
An android navigation bar widget
Stars: ✭ 491 (-5.58%)
Mutual labels:  widget

Logo

Ultra Tiny, Opinionated Positioning Engine

gzip size brotli size Build Status Download count No dependencies JSDelivr download count Current version Support me


NanoPop is an ultra-tiny positioning engine. Hold up, isn't there PopperJS? Yeah - and PopperJS is great! But there are tons of features that, in most cases, you just might not need. This library is less than a third of PopperJS.

When should I use Nanopop and not PopperJS?

  1. Situations where you want full control over positioning, including handling events such as scrolling, and manual resizing.
  2. Performance-critical cases with lots of elements [...] nanopop will only makes changes if you say so.
  3. Poppers with minimal footprint such as drop-downs and tooltips which don't require that much configurability.
  4. You might have some special needs about how your popper behaves. NanoPop exposes a function for the sole purpose of positioning something, use it in your own library!

This library was originally part of pickr - now ported to TS with tests and a few updates / bug-fixes.

Heads up! This is the readme for v2 - if you're looking for the first version head over here (v1 is not maintained anymore).

Getting Started

Install via npm:

$ npm install nanopop

Install via yarn:

$ yarn add nanopop

Include directly via jsdelivr:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/nanopop.min.js"></script>

Using JavaScript Modules:

import {
    reposition,   // Core, stateless function to reposition an element
    createPopper, // Stateful function which keeps track of your configuration
    defaults,     // A subset of nanopops options used as default values
    version       // Current version
} from 'https://cdn.jsdelivr.net/npm/nanopop/lib/nanopop.min.mjs'

🌟 NanoPop is fully tree-shakable! E.g. if you only use reposition you'll probably end up with less than 500B code!

Usage

reposition(
    /* reference: */ document.querySelector('.btn'),
    /* popper: */ document.querySelector('.dropdown'),
    /* We're using the default options */
);

⚠ The popper-element must have set position to fixed.

ℹ Because the default-container is document.documentElement you might have to increase the height of the html element to make room for your popper (e.g. html {height: 100vh;})

All options

import {reposition, createPopper} from 'nanopop';

// Using a object and reposition directly
const nanopop = reposition(reference, popper, {

    // The DOMRect of the container, it used the html-element as default.
    // You could also create your own boundary using a custon DOMRect (https://developer.mozilla.org/en-US/docs/Web/API/DOMRect)!
    container: document.documentElement.getBoundingClientRect(),

    // Margin between the popper element and the reference
    margin: 8,

    // Preferred position, any combination of [top|right|bottom|left]-[start|middle|end] is valid.
    // 'middle' is used as default-variant if you leave it out.
    position: 'bottom-middle',

    // In case the variant-part (start, middle or end) cannot be applied you can specify what (and if)
    // should be tried next.
    variantFlipOrder: {
        start: 'sme', // In case of -start try 'start' first, if that fails 'middle' and 'end' if both doesn't work.
        middle: 'mse',
        end: 'ems'
    },

    // The same as variantFlipOrder, but if all variants fail you might want to try other positions.
    positionFlipOrder: {
        top: 'tbrl', // Try 'top' first, 'bottom' second, 'right' third and 'left' as latest position.
        right: 'rltb',
        bottom: 'btrl',
        left: 'lrbt'
    }
});

/**
 * Using the createPopper function to create a stateful wrapper
 *
 * Correct ways of calling it are:
 * createPopper(reference: HTMLElement, popper: HTMLElement, options?: NanoPopOptions)
 * createPopper(options?: NanoPopOptions)
 * ⚠ If you omit options entierly you'll have to set both the reference and the popper later when calling .update!
 */
const popper = createPopper({...});
popper.update(); // You can pass an object to update which will get merged with the existing config.

Calling popper.update(...) or reposition(...) both returns a position-pair (For example te for Top-End) or null based on if it was possible to find a position for the popper without clipping it._

Tip: The returned position-pair is perfect for tool-tips to give them a little arrow!

Caveats

  1. The popper-element must have position set to fixed.
  2. If nanopop cannot find a position without clipping your popper it'll revert its top and left values - you can use css / js to handle this case.
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].