0.2.0 • Published 6 years ago

popper-max-size-modifier v0.2.0

Weekly downloads
29,865
License
MIT
Repository
-
Last release
6 years ago

popper-max-size-modifier

A Popper.js modifier to change the size of your popper to fit it within the available viewport space.

Installation

# With npm
npm i popper-max-size-modifier

# With Yarn
yarn add popper-max-size-modifier

Demo

https://codesandbox.io/s/great-tesla-3roz7

Usage

import {createPopper} from '@popperjs/core';
import maxSize from 'popper-max-size-modifier';

// Create your own apply modifier that adds the styles to the state
const applyMaxSize = {
  name: 'applyMaxSize',
  enabled: true,
  phase: 'beforeWrite',
  requires: ['maxSize'],
  fn({state}) {
    // The `maxSize` modifier provides this data
    const {width, height} = state.modifiersData.maxSize;

    state.styles.popper = {
      ...state.styles.popper,
      maxWidth: `${width}px`,
      maxHeight: `${height}px`
    };
  }
};

createPopper(reference, popper, {
  modifiers: [maxSize, applyMaxSize]
});

Sometimes you may want the flip modifier to take precedence in cases where the maxSize modifier will make the popper too small (e.g. a minimum acceptable size):

// Minimum acceptable size is 100px
`${Math.max(100, width)}px`;
`${Math.max(100, height)}px`;

Options

All detectOverflow options can be passed.

createPopper(reference, popper, {
  modifiers: [
    {
      ...maxSize,
      options: {
        boundary: customBoundaryElement,
        padding: 20
      }
    },
    applyMaxSize
  ]
});

Contributing

The source is located in the root package at src/modifiers/maxSize.js.

@arthswap/widgets@openos.com/uniswappangea-widgets@everything-registry/sub-chunk-2457wido-widgetwido-widget-v4wido-widget-v5test-swap-widgetsswap-swapy-widgetsv3ui-liblacront-core-componentshns-reactintergalacticmeme-widgets@web3-react-widgets/core@wunsz-4soft/uniswap-widgets@washingtonpost/wpds-navigation-menu@washingtonpost/wpds-ui-kit@worksolutions/components@wtchtwr/uniswap-widgets@trugly-labs/widgets-fork@uif/next@uif/next-over@uif/core@uniswap/widgets@totality-fi/widgets@testlio/panthera@treelab/panda@yumyumswap/widgetsalfalab-core-components-fixedaxelra-uniswap-widgetsforgetwidgetseasydefi_packageex-home-uifacilmap-frontenddeno-uniswapwidgetbase5-uiblueswapbasewidgetsdmode-widgetstratoswap-widgetsuperdesk-ui-frameworktstststtest-copy-widgetstobiuniswap-widgetuniswap-widgets-for-extensionuniswap-widgets-qwquniswap-pool-swapzxtest666qihw-uniswapv3-widgetsramp-pcar@intimefinance/widgets@keyko.io/widgets@kofime/uniswap-widgets@kokal33/widgets@sussyswap/widgets@sunmoon11100/uniswap-widgets@ntbjs/react-components@justdev337/widgets@nftearth/uniswap-widgets@jagra_/widgets@openoscom/uniswap@planningcenter/tapestry-react@planning-center/ui-kit@pondx/widgets@pollum-io/widgets@overdose/components@prezly/slate-editor@0xgingi/uniswap-widgets@adfuel/uniswap-widgets@alfalab/core-components@alfalab/core-components-popover@bitswap/widgets@bombswap/widgets@balafla/core-components-popover@barneyspectral/widgets@axelraag/frigg-uniswap-widgets@atestalth/widgets@airtame/ui@boy-who-cried-wolf/uniswap-widgets@brydge-network/demo-widget@brydge-network/widget@byzanteam/jet-components@divswap/widgets@crescentswap/widgets@cronus-finance/widgets@degenfrens/swapper@derpdex/widgets@dex-swap/widgets@dso-toolkit/core@frontapp/ui-kit@friggeco/uniswap-widgets@fulcanellee/core-components-sandbox@forge-trade/widgets@glide-finance/widgets@sanity/base@semcore/base-components@mokatte/widgets@mokatte/widgets-mod@misfer-alethea/widgets@sheetxl/common-mui
0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago