GithubHelp home page GithubHelp logo

mattchannn / floating-ui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from floating-ui/floating-ui

1.0 0.0 0.0 14.53 MB

A low-level toolkit to position floating elements while intelligently keeping them in view. Tooltips, popovers, dropdowns, menus, and more

Home Page: https://floating-ui.com

License: MIT License

JavaScript 26.96% HTML 0.23% TypeScript 71.68% CSS 1.13%

floating-ui's Introduction

Floating UI

Popper is now Floating UI! For Popper v2, visit its dedicated branch.

Rolling Versions

Website

Floating UI is a low-level library for positioning "floating" elements like tooltips, popovers, dropdowns, menus and more while intelligently keeping them in view.

Challenges arise when positioning floating elements as they get taken out of the normal layout flow of a document, leading to issues with clipping and overflow, which is where this library can help!

  • Tiny: 600-byte core with highly modular architecture for tree-shaking
  • Low-level: Granular control over positioning behavior
  • Pure: Predictable and side-effect free
  • Extensible: Powerful middleware system
  • Platform-agnostic: Runs on any JavaScript environment which provides measurement APIs, including the web and React Native

Installation

To use it on the web:

npm install @floating-ui/dom
yarn add @floating-ui/dom

Quick start

import {computePosition} from '@floating-ui/dom';

const referenceElement = document.querySelector('#button');
const floatingElement = document.querySelector('#tooltip');

function applyStyles({x = 0, y = 0, strategy = 'absolute'}) {
  Object.assign(floatingElement.style, {
    position: strategy,
    left: `${x}px`,
    top: `${y}px`,
  });
}

applyStyles();

computePosition(referenceElement, floatingElement, {
  placement: 'right',
}).then(applyStyles);

Visit the docs for detailed information.

Development and production builds

Floating UI is published with default, development, and production builds, using Node's support for export conditions.

  • "default": uses process.env.NODE_ENV, in which your bundler handles the env variable, dead code elimination, and minification
  • "production": minified with no debug logging
  • "development": unminified with debug logging

If you're using a bundler like webpack, Vite, or Parcel, this is handled for you automatically.

If this is not handled, you must opt into one of the builds in tools that support export conditions. This is done differently for each tool.

React

Components

Right now, Floating UI focuses on positioning floating elements, but a package that exposes higher-level primitives for building these elements more easily is in development.

Contributing

This project is a monorepo written in TypeScript using npm workspaces. The website is using Next.js SSG and Tailwind CSS for styling.

  • Fork and clone the repo
  • Install dependencies in root directory with npm install
  • Build initial package dist files with npm run build

Testing grounds

npm run dev in the root will launch the @floating-ui/dom development visual tests at http://localhost:1234. The playground uses React to write each test route, bundled by Parcel. When making changes to packages/core or packages/dom, Parcel will hot reload the app and display the changes.

Each route has screenshots taken of the page by Playwright to ensure all the functionalities work as expected; this is an easy, reliable and high-level way of testing the code.

Below the main container are UI controls to turn on certain state and options. Every single combination of state is tested visually via the snapshots to cover as much as possible.

Website

npm -w website run dev in the root will launch the website at localhost:3000.

License

MIT

floating-ui's People

Contributors

fezvrasta avatar atomiks avatar semeleven avatar hipstersmoothie avatar jspangler avatar westbrook avatar cuberoot avatar ayc0 avatar alexfsmirnov avatar jacwright avatar lyleunderwood avatar lsroman avatar ptu14 avatar mcous avatar cuyl avatar andarist avatar silvenon avatar atlas-fox avatar oliverjash avatar pascalduez avatar tvanro avatar dependabot[bot] avatar eps1lon avatar ktmouk avatar lpoulter avatar ling1726 avatar sandstrom avatar wszydlak avatar juanm04 avatar jsg2021 avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.