Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
A component that aligns its child relatively to its parent while being aware where it may and may not fit.
npm install react-fit
or yarn add react-fit
.import Fit from 'react-fit'
.function ElementWithChild() {
return (
<Parent>
<Fit>
<PopoverChild />
</Fit>
</Parent>
);
}
Your project needs to use React 16.8 or later.
Add React-Fit to your project by executing npm install react-fit
or yarn add react-fit
.
<Fit />
as a child is displayed below its parent, aligned to the left.<Fit />
checks if there's more space for the element on the other side(s) of the axis/axes the collision(s) has been detected on. If so, the element is moved above its parent and/or aligned to the right, depending on the collision axis.<Fit />
decreases the element's size. If min-width
/min-height
are provided, they will be respected.By default, the element is displayed below its parent, aligned to the left of its parent.
┌────────────┐
│ Parent │
├────────────┴────────────┐
│ │
│ Child │
│ │
└─────────────────────────┘
invertAxis
flag.invertSecondaryAxis
flag.mainAxis="x"
)By providing mainAxis="x"
to <Fit />
, the element is displayed on the right of its parent, aligned to the top of its parent.
┌────────────┬─────────────────────────┐
│ Parent │ │
└────────────┤ Child │
│ │
└─────────────────────────┘
invertAxis
flag.invertSecondaryAxis
flag.By default, React-Fit leaves 8px of space between its child and the borders of the container.
┌──────────────────────────────────────────┐
│ ┌────────────┐ │
│ │ Parent │ │
│ ├────────────┴────────────┐ │
│ │ │ │
│ │ Child │ │
│ │ │ │
│ └─────────────────────────┘ │
└──────────────────────────────────────────┘
If you wish to change this spacing, you can provide spacing
to <Fit />
. For example, if you wish for the child to touch the borders of the container, decrease the spacing by providing spacing={0}
to <Fit />
.
┌──────────────────────────────────────────┐
│ ┌────────────┐ │
│ │ Parent │ │
│ ├────────────┴────────────┐ │
│ │ │ │
│ │ Child │ │
│ │ (now higher) │ │
│ │ │ │
└─┴─────────────────────────┴──────────────┘
You can also provide different spacing for each side by providing an object, for example spacing={{ top: 10, bottom: 20, left: 30, right: 40 }}
, to <Fit />
. Note: Memoize the object or define it outside render function to avoid unnecessary re-renders.
To avoid unnecessary style recalculations that may be caused by React-Fit applying the styles needed to make it work properly, the element should have absolute position, and its parent element should have relative or absolute position.
The MIT License.
Wojciech Maj |
FAQs
Fit a popover element on the screen.
The npm package react-fit receives a total of 217,774 weekly downloads. As such, react-fit popularity was classified as popular.
We found that react-fit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.