
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
@zalando/react-automatic-width
Advanced tools
Automatically sets width property on child components
So, you found those cool components like fixed-data-table and react-d3-components that do whatever you want, with just one problem: They only work on fixed width! You care about responsiveness and different display sizes. You want variable width! HULK SMASH!
One solution: Just wrap it in AutoWidth
, so that this:
import D3 from 'react-d3-components';
<D3.BarChart
width={500} /> // ;_;
Can work like this:
import D3 from 'react-d3-components';
import AutoWidth from '@zalando/react-automatic-width';
<AutoWidth>
<D3.BarChart /> {/* ^_^ */}
</AutoWidth>
react-automatic-width is a React component that automatically sets width
property on child components. It works out-of-the-box and accepts any property you throw at it. This way, you can use classes and media queries for the autowidth container.
It does its job by attaching a listener to the resize
event of window
. In it, react-automatic-width reads the current width of its DOM node and sets this as the width
property on its children. Since it creates an event listener every time it's used, you might want to reconsider when you have a lot of components that need to be wrapped separately. react-dimensions
might then be useful to you as it offers the option to use element-resize-event
underneath (using requestAnimationFrame
).
It's currently not under active development because the codebase is tiny and works. If appropriate, it will be updated to accomodate future React versions.
Install react-automatic-width with:
npm i -S @zalando/react-automatic-width
Then load it however you want (example: ES6):
import AutoWidth from '@zalando/react-automatic-width'
Finally, omit the width
property on your component and wrap it in AutoWidth
:
<AutoWidth className="responsive">
<D3.BarChart />
</AutoWidth>
Optionally, you can set up the debouncing rate in milliseconds (default is 100)
<AutoWidth className="responsive" debounceWait={150}>
<D3.BarChart />
</AutoWidth>
This project welcomes contributions from the community. Here are some issues and areas where we could use some help:
clientWidth
because that worked in Chrome forty-something. Might be funky in your browser. PRs welcome.Apache 2.0
FAQs
Automatically sets width property on child components
The npm package @zalando/react-automatic-width receives a total of 2 weekly downloads. As such, @zalando/react-automatic-width popularity was classified as not popular.
We found that @zalando/react-automatic-width demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.