source: trip-planner-front/node_modules/@popperjs/core/README.md@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 12.4 KB
Line 
1<!-- <HEADER> // IGNORE IT -->
2<p align="center">
3 <img src="https://rawcdn.githack.com/popperjs/popper-core/8805a5d7599e14619c9e7ac19a3713285d8e5d7f/docs/src/images/popper-logo-outlined.svg" alt="Popper" height="300px"/>
4</p>
5
6<div align="center">
7 <h1>Tooltip & Popover Positioning Engine</h1>
8</div>
9
10<p align="center">
11 <a href="https://www.npmjs.com/package/@popperjs/core">
12 <img src="https://img.shields.io/npm/v/@popperjs/core?style=for-the-badge" alt="npm version" />
13 </a>
14 <a href="https://www.npmjs.com/package/@popperjs/core">
15 <img src="https://img.shields.io/endpoint?style=for-the-badge&url=https://runkit.io/fezvrasta/combined-npm-downloads/1.0.0?packages=popper.js,@popperjs/core" alt="npm downloads per month (popper.js + @popperjs/core)" />
16 </a>
17 <a href="https://rollingversions.com/popperjs/popper-core">
18 <img src="https://img.shields.io/badge/Rolling%20Versions-Enabled-brightgreen?style=for-the-badge" alt="Rolling Versions" />
19 </a>
20</p>
21
22<br />
23<!-- </HEADER> // NOW BEGINS THE README -->
24
25**Positioning tooltips and popovers is difficult. Popper is here to help!**
26
27Given an element, such as a button, and a tooltip element describing it, Popper
28will automatically put the tooltip in the right place near the button.
29
30It will position _any_ UI element that "pops out" from the flow of your document
31and floats near a target element. The most common example is a tooltip, but it
32also includes popovers, drop-downs, and more. All of these can be generically
33described as a "popper" element.
34
35## Demo
36
37[![Popper visualized](https://i.imgur.com/F7qWsmV.jpg)](https://popper.js.org)
38
39## Docs
40
41- [v2.x (latest)](https://popper.js.org/docs/v2/)
42- [v1.x](https://popper.js.org/docs/v1/)
43
44We've created a
45[Migration Guide](https://popper.js.org/docs/v2/migration-guide/) to help you
46migrate from Popper 1 to Popper 2.
47
48To contribute to the Popper website and documentation, please visit the [dedicated repository](https://github.com/popperjs/website).
49
50## Why not use pure CSS?
51
52CSS tooltips have accessibility and usability problems:
53
54- **Clipping and overflow issues**: CSS tooltips will not be prevented from
55 overflowing clipping boundaries, such as the viewport. The tooltip gets
56 partially cut off or overflows if it's near the edge since there is no dynamic
57 positioning logic. When using Popper, your tooltip will always be positioned
58 in the right place.
59- **No flipping**: CSS tooltips will not flip to a different placement to fit
60 better in view if necessary. Popper automatically flips the tooltip to make it
61 fit in view as best as possible for the user.
62- **Using HTML**: Popovers containing interactive HTML are difficult or not
63 possible to create without UX issues using pure CSS. Popper positions any HTML
64 element – no pseudo-elements are used.
65- **No virtual positioning**: CSS tooltips cannot follow the mouse cursor or be
66 used as a context menu. Popper allows you to position your tooltip relative to
67 any coordinates you desire.
68- **Lack of extensibility**: CSS tooltips cannot be easily extended to fit any
69 arbitrary use case you may need to adjust for. Popper is built with
70 extensibility in mind.
71
72## Why Popper?
73
74With the CSS drawbacks out of the way, we now move on to Popper in the
75JavaScript space itself.
76
77Naive JavaScript tooltip implementations usually have the following problems:
78
79- **Scrolling containers**: They don't ensure the tooltip stays with the
80 reference element while scrolling when inside any number of scrolling
81 containers.
82- **DOM context**: They often require the tooltip move outside of its original
83 DOM context because they don't handle `offsetParent` contexts.
84- **Configurability**: They often lack advanced configurability to suit any
85 possible use case.
86- **Size**: They are usually relatively large in size, or require an ancient
87 jQuery dependency.
88- **Performance**: They often have runtime performance issues and update the
89 tooltip position too slowly.
90
91**Popper solves all of these key problems in an elegant, performant manner.** It
92is a lightweight ~3 kB library that aims to provide a reliable and extensible
93positioning engine you can use to ensure all your popper elements are positioned
94in the right place.
95
96When you start writing your own popper implementation, you'll quickly run into
97all of the problems mentioned above. These widgets are incredibly common in our
98UIs; we've done the hard work figuring this out so you don't need to spend hours
99fixing and handling numerous edge cases that we already ran into while building
100the library!
101
102Popper is used in popular libraries like Bootstrap, Foundation, Material UI, and
103more. It's likely you've already used popper elements on the web positioned by
104Popper at some point in the past few years.
105
106Since we write UIs using powerful abstraction libraries such as React or Angular
107nowadays, you'll also be glad to know Popper can fully integrate with them and
108be a good citizen together with your other components. Check out `react-popper`
109for the official Popper wrapper for React.
110
111## Installation
112
113### 1. Package Manager
114
115```bash
116# With npm
117npm i @popperjs/core
118
119# With Yarn
120yarn add @popperjs/core
121```
122
123### 2. CDN
124
125```html
126<!-- Development version -->
127<script src="https://unpkg.com/@popperjs/core@2/dist/umd/popper.js"></script>
128
129<!-- Production version -->
130<script src="https://unpkg.com/@popperjs/core@2"></script>
131```
132
133### 3. Direct Download?
134
135Managing dependencies by "directly downloading" them and placing them into your
136source code is not recommended for a variety of reasons, including missing out
137on feat/fix updates easily. Please use a versioning management system like a CDN
138or npm/Yarn.
139
140## Usage
141
142The most straightforward way to get started is to import Popper from the `unpkg`
143CDN, which includes all of its features. You can call the `Popper.createPopper`
144constructor to create new popper instances.
145
146Here is a complete example:
147
148```html
149<!DOCTYPE html>
150<title>Popper example</title>
151
152<style>
153 #tooltip {
154 background-color: #333;
155 color: white;
156 padding: 5px 10px;
157 border-radius: 4px;
158 font-size: 13px;
159 }
160</style>
161
162<button id="button" aria-describedby="tooltip">I'm a button</button>
163<div id="tooltip" role="tooltip">I'm a tooltip</div>
164
165<script src="https://unpkg.com/@popperjs/core@^2.0.0"></script>
166<script>
167 const button = document.querySelector('#button');
168 const tooltip = document.querySelector('#tooltip');
169
170 // Pass the button, the tooltip, and some options, and Popper will do the
171 // magic positioning for you:
172 Popper.createPopper(button, tooltip, {
173 placement: 'right',
174 });
175</script>
176```
177
178Visit the [tutorial](https://popper.js.org/docs/v2/tutorial/) for an example of
179how to build your own tooltip from scratch using Popper.
180
181### Module bundlers
182
183You can import the `createPopper` constructor from the fully-featured file:
184
185```js
186import { createPopper } from '@popperjs/core';
187
188const button = document.querySelector('#button');
189const tooltip = document.querySelector('#tooltip');
190
191// Pass the button, the tooltip, and some options, and Popper will do the
192// magic positioning for you:
193createPopper(button, tooltip, {
194 placement: 'right',
195});
196```
197
198All the modifiers listed in the docs menu will be enabled and "just work", so
199you don't need to think about setting Popper up. The size of Popper including
200all of its features is about 5 kB minzipped, but it may grow a bit in the
201future.
202
203#### Popper Lite (tree-shaking)
204
205If bundle size is important, you'll want to take advantage of tree-shaking. The
206library is built in a modular way to allow to import only the parts you really
207need.
208
209```js
210import { createPopperLite as createPopper } from "@popperjs/core";
211```
212
213The Lite version includes the most necessary modifiers that will compute the
214offsets of the popper, compute and add the positioning styles, and add event
215listeners. This is close in bundle size to pure CSS tooltip libraries, and
216behaves somewhat similarly.
217
218However, this does not include the features that makes Popper truly useful.
219
220The two most useful modifiers not included in Lite are `preventOverflow` and
221`flip`:
222
223```js
224import { createPopperLite as createPopper, preventOverflow, flip } from "@popperjs/core";
225
226const button = document.querySelector('#button');
227const tooltip = document.querySelector('#tooltip');
228
229createPopper(button, tooltip, {
230 modifiers: [preventOverflow, flip],
231});
232```
233
234As you make more poppers, you may be finding yourself needing other modifiers
235provided by the library.
236
237See [tree-shaking](https://popper.js.org/docs/v2/tree-shaking/) for more
238information.
239
240## Distribution targets
241
242Popper is distributed in 3 different versions, in 3 different file formats.
243
244The 3 file formats are:
245
246- `esm` (works with `import` syntax — **recommended**)
247- `umd` (works with `<script>` tags or RequireJS)
248- `cjs` (works with `require()` syntax)
249
250There are two different `esm` builds, one for bundler consumers (e.g. webpack,
251Rollup, etc..), which is located under `/lib`, and one for browsers with native
252support for ES Modules, under `/dist/esm`. The only difference within the two,
253is that the browser-compatible version doesn't make use of
254`process.env.NODE_ENV` to run development checks.
255
256The 3 versions are:
257
258- `popper`: includes all the modifiers (features) in one file (**default**);
259- `popper-lite`: includes only the minimum amount of modifiers to provide the
260 basic functionality;
261- `popper-base`: doesn't include any modifier, you must import them separately;
262
263Below you can find the size of each version, minified and compressed with the
264[Brotli compression algorithm](https://medium.com/groww-engineering/enable-brotli-compression-in-webpack-with-fallback-to-gzip-397a57cf9fc6):
265
266<!-- Don't change the labels to use hyphens, it breaks, even when encoded -->
267
268![](https://badge-size.now.sh/https://unpkg.com/@popperjs/core/dist/umd/popper.min.js?compression=brotli&label=popper)
269![](https://badge-size.now.sh/https://unpkg.com/@popperjs/core/dist/umd/popper-lite.min.js?compression=brotli&label=popper%20lite)
270![](https://badge-size.now.sh/https://unpkg.com/@popperjs/core/dist/umd/popper-base.min.js?compression=brotli&label=popper%20base)
271
272## Hacking the library
273
274If you want to play with the library, implement new features, fix a bug you
275found, or simply experiment with it, this section is for you!
276
277First of all, make sure to have
278[Yarn installed](https://yarnpkg.com/lang/en/docs/install).
279
280Install the development dependencies:
281
282```bash
283yarn install
284```
285
286And run the development environment:
287
288```bash
289yarn dev
290```
291
292Then, simply open one the development server web page:
293
294```bash
295# macOS and Linux
296open localhost:5000
297
298# Windows
299start localhost:5000
300```
301
302From there, you can open any of the examples (`.html` files) to fiddle with
303them.
304
305Now any change you will made to the source code, will be automatically compiled,
306you just need to refresh the page.
307
308If the page is not working properly, try to go in _"Developer Tools >
309Application > Clear storage"_ and click on "_Clear site data_".
310To run the examples you need a browser with
311[JavaScript modules via script tag support](https://caniuse.com/#feat=es6-module).
312
313## Test Suite
314
315Popper is currently tested with unit tests, and functional tests. Both of them
316are run by Jest.
317
318### Unit Tests
319
320The unit tests use JSDOM to provide a primitive document object API, they are
321used to ensure the utility functions behave as expected in isolation.
322
323### Functional Tests
324
325The functional tests run with Puppeteer, to take advantage of a complete browser
326environment. They are currently running on Chromium, and Firefox.
327
328You can run them with `yarn test:functional`. Set the `PUPPETEER_BROWSER`
329environment variable to `firefox` to run them on the Mozilla browser.
330
331The assertions are written in form of image snapshots, so that it's easy to
332assert for the correct Popper behavior without having to write a lot of offsets
333comparisons manually.
334
335You can mark a `*.test.js` file to run in the Puppeteer environment by
336prepending a `@jest-environment puppeteer` JSDoc comment to the interested file.
337
338Here's an example of a basic functional test:
339
340```js
341/**
342 * @jest-environment puppeteer
343 * @flow
344 */
345import { screenshot } from '../utils/puppeteer.js';
346
347it('should position the popper on the right', async () => {
348 const page = await browser.newPage();
349 await page.goto(`${TEST_URL}/basic.html`);
350
351 expect(await screenshot(page)).toMatchImageSnapshot();
352});
353```
354
355You can find the complete
356[`jest-puppeteer` documentation here](https://github.com/smooth-code/jest-puppeteer#api),
357and the
358[`jest-image-snapshot` documentation here](https://github.com/americanexpress/jest-image-snapshot#%EF%B8%8F-api).
359
360## License
361
362MIT
Note: See TracBrowser for help on using the repository browser.