Convert Figma logo to code with AI

HubSpot logodrop

A library for creating dropdowns and other floating elements. #hubspot-open-source

2,357
211
2,357
53

Top Related Projects

A JavaScript library to position floating elements and create interactions for them.

A JavaScript library to position floating elements and create interactions for them.

A JavaScript library to position floating elements and create interactions for them.

Quick Overview

Drop is a JavaScript library for creating positioning engines and dropdown menus. It allows developers to create customizable, positioning-aware dropdowns that can be attached to any element on a webpage. Drop is lightweight, dependency-free, and designed to be highly flexible and extensible.

Pros

  • Lightweight and dependency-free, making it easy to integrate into existing projects
  • Highly customizable with a wide range of options for positioning and behavior
  • Supports both mouse and touch events for broad device compatibility
  • Extensible architecture allows for easy creation of custom themes and plugins

Cons

  • Documentation could be more comprehensive, especially for advanced use cases
  • Limited built-in themes, requiring more custom styling for complex designs
  • May require additional effort to ensure accessibility compliance
  • Not actively maintained, with the last major update in 2019

Code Examples

Creating a basic dropdown:

const drop = new Drop({
  target: document.querySelector('#target-element'),
  content: 'This is the dropdown content',
  position: 'bottom left',
  openOn: 'click'
});

Customizing dropdown behavior:

const customDrop = new Drop({
  target: document.querySelector('#custom-target'),
  content: document.querySelector('#custom-content'),
  classes: 'my-custom-class',
  tetherOptions: {
    constraints: [
      {
        to: 'window',
        pin: true,
        attachment: 'together'
      }
    ]
  }
});

Using callbacks:

const callbackDrop = new Drop({
  target: document.querySelector('#callback-target'),
  content: 'Callback dropdown',
  beforeOpen: () => console.log('About to open'),
  open: () => console.log('Dropdown opened'),
  close: () => console.log('Dropdown closed')
});

Getting Started

  1. Install Drop via npm:

    npm install tether-drop
    
  2. Import Drop in your JavaScript file:

    import Drop from 'tether-drop';
    
  3. Create a new Drop instance:

    const myDrop = new Drop({
      target: document.querySelector('#my-target'),
      content: 'Hello, Drop!',
      position: 'bottom center',
      openOn: 'click'
    });
    
  4. To open or close the dropdown programmatically:

    myDrop.open();
    myDrop.close();
    

Competitor Comparisons

A JavaScript library to position floating elements and create interactions for them.

Pros of Floating UI

  • More actively maintained with frequent updates and bug fixes
  • Offers a wider range of positioning options and customization
  • Supports TypeScript out of the box

Cons of Floating UI

  • Steeper learning curve due to more complex API
  • Requires more setup and configuration for basic use cases

Code Comparison

Drop:

const drop = new Drop({
  target: document.querySelector('#target'),
  content: 'Hello, world!',
  position: 'bottom center'
});

Floating UI:

import {computePosition, flip, shift, offset} from '@floating-ui/dom';

computePosition(referenceEl, floatingEl, {
  placement: 'bottom',
  middleware: [offset(6), flip(), shift({padding: 5})]
}).then(({x, y}) => {
  Object.assign(floatingEl.style, {
    left: `${x}px`,
    top: `${y}px`,
  });
});

Summary

Floating UI offers more flexibility and features but requires more setup. Drop provides a simpler API for basic positioning needs. Choose Floating UI for complex positioning requirements and TypeScript support, or Drop for quick and easy implementation of simple tooltips or dropdowns.

A JavaScript library to position floating elements and create interactions for them.

Pros of Floating UI

  • More actively maintained with frequent updates and bug fixes
  • Offers a wider range of positioning options and customization
  • Supports TypeScript out of the box

Cons of Floating UI

  • Steeper learning curve due to more complex API
  • Requires more setup and configuration for basic use cases

Code Comparison

Drop:

const drop = new Drop({
  target: document.querySelector('#target'),
  content: 'Hello, world!',
  position: 'bottom center'
});

Floating UI:

import {computePosition, flip, shift, offset} from '@floating-ui/dom';

computePosition(referenceEl, floatingEl, {
  placement: 'bottom',
  middleware: [offset(6), flip(), shift({padding: 5})]
}).then(({x, y}) => {
  Object.assign(floatingEl.style, {
    left: `${x}px`,
    top: `${y}px`,
  });
});

Summary

Floating UI offers more flexibility and features but requires more setup. Drop provides a simpler API for basic positioning needs. Choose Floating UI for complex positioning requirements and TypeScript support, or Drop for quick and easy implementation of simple tooltips or dropdowns.

A JavaScript library to position floating elements and create interactions for them.

Pros of Floating UI

  • More actively maintained with frequent updates and bug fixes
  • Offers a wider range of positioning options and customization
  • Supports TypeScript out of the box

Cons of Floating UI

  • Steeper learning curve due to more complex API
  • Requires more setup and configuration for basic use cases

Code Comparison

Drop:

const drop = new Drop({
  target: document.querySelector('#target'),
  content: 'Hello, world!',
  position: 'bottom center'
});

Floating UI:

import {computePosition, flip, shift, offset} from '@floating-ui/dom';

computePosition(referenceEl, floatingEl, {
  placement: 'bottom',
  middleware: [offset(6), flip(), shift({padding: 5})]
}).then(({x, y}) => {
  Object.assign(floatingEl.style, {
    left: `${x}px`,
    top: `${y}px`,
  });
});

Summary

Floating UI offers more flexibility and features but requires more setup. Drop provides a simpler API for basic positioning needs. Choose Floating UI for complex positioning requirements and TypeScript support, or Drop for quick and easy implementation of simple tooltips or dropdowns.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Drop

GitHub
version

Drop.js is a powerful Javascript and CSS library for creating dropdowns and other floating displays.

Drop Docs

Install

Dependencies

npm

$ npm install tether-drop

bower

$ bower install tether-drop

Usage

let dropInstance = new Drop({
  target: document.querySelector('.drop-target'),
  content: 'Welcome to the future',
  classes: 'drop-theme-arrows',
  position: 'bottom left',
  openOn: 'click'
})

API documentation

Demo

Contributing

We encourage contributions of all kinds. If you would like to contribute in some way, please review our guidelines for contributing.

License

Copyright © 2015 HubSpot - MIT License

NPM DownloadsLast 30 Days