0.2.0 • Published 5 years ago

popper-max-size-modifier v0.2.0

Weekly downloads
29,865
License
MIT
Repository
-
Last release
5 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-lib@divswap/widgets@dso-toolkit/core@cronus-finance/widgets@crescentswap/widgets@derpdex/widgets@prezly/slate-editorlacront-core-componentsstratoswap-widgetsuperdesk-ui-frameworktstststtest-copy-widgetstobiuniswap-widget@atestalth/widgets@alfalab/core-components@alfalab/core-components-popover@airtame/ui@axelraag/frigg-uniswap-widgets@bitswap/widgets@byzanteam/jet-components@brydge-network/demo-widget@brydge-network/widget@0xgingi/uniswap-widgets@adfuel/uniswap-widgets@bombswap/widgets@boy-who-cried-wolf/uniswap-widgets@degenfrens/swapper@dex-swap/widgetsuniswap-widgets-for-extensionuniswap-widgets-qwquniswap-pool-swapzxtest666@fibery/ui-kit@gravityfinance/widgets@forge-trade/widgets@friggeco/uniswap-widgets@frontapp/ui-kit@fulcanellee/core-components-sandbox@glide-finance/widgets@intimefinance/widgets@mageswap/widgets@mypublished/widgets@nftearth/uniswap-widgets@ensi-platform/core-components@max2204/widget-with-charity@misfer-alethea/widgets@mokatte/widgets@mokatte/widgets-mod@mana-ui/ui@justdev337/widgets@jagra_/widgets@kofime/uniswap-widgets@kokal33/widgets@keyko.io/widgets@sanity/base@rescui/dropdown@openoscom/uniswap@pondx/widgets@pollum-io/widgets@ntbjs/react-components@planningcenter/tapestry-react@planning-center/ui-kit@overdose/components@roheat/widgets@ricokahler/sanity-ui-testqihw-uniswapv3-widgetsramp-pcarhns-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-widgetsdeno-uniswapwidgetbase5-uiblueswapbasewidgetsdmode-widget
0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago