Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@commercetools-uikit/collapsible-motion
Advanced tools
Readme
A component which allows building collapsible elements with an arbitrary height. The component can be controlled or uncontrolled, depending if the isClosed
props is defined or not. A controlled component requires the onToggle
prop additionally.
Animating a div from height: 0
to height: auto
is something the browser will refuse to do out of the box, because calculations of this animation would be expensive.
There are many existing workaround which all have their different tradeoffs.
CollapsibleMotion
uses a nice workaround which allows the browser to run this animation. CollapsibleMotion
measures the resulting since and then animates between height: 0
and the resulting size (at 99% of the animation). At the end of the animation, it sets the height
back to auto
.
This component also supports passing in a minHeight
prop. By default this is 0.
Technically, we need to dynamically create the keyframes for this animation.
yarn add @commercetools-uikit/collapsible-motion
npm --save install @commercetools-uikit/collapsible-motion
Additionally install the peer dependencies (if not present)
yarn add react
npm --save install react
import CollapsibleMotion from '@commercetools-uikit/collapsible-motion';
const Example = () => (
<CollapsibleMotion>
{({ isOpen, toggle, containerStyles, registerContentNode }) => (
<div>
<button data-testid="button" onClick={toggle}>
{isOpen ? 'Close' : 'Open'}
</button>
<div data-testid="container-node" style={containerStyles}>
<div data-testid="content-node" ref={registerContentNode}>
Content
</div>
</div>
</div>
)}
</CollapsibleMotion>
);
export default Example;
Props | Type | Required | Default | Description |
---|---|---|---|---|
children | Function See signature. | ✅ | A render function, called with the following named arguments: isOpen (boolean), toggle (function),
containerStyles (css-in-js object), registerContentNode (React reference to be used on the animated container).
Siganture: ({ isOpen, containerStyles, toggle, registerContentNode }) => React.node | |
isClosed | boolean | |||
onToggle | Function See signature. | A callback function called when the toggle function is called. This prop is required when the component is controlled. | ||
minHeight | number | 0 | The minimal height of the container being animated. | |
isDefaultClosed | boolean | The initial value to the internal toggle state isOpen . |
children
(options: TRenderFunctionOptions) => ReactNode;
onToggle
() => void
FAQs
A component which allows building collapsible elements with an arbitrary height.
The npm package @commercetools-uikit/collapsible-motion receives a total of 7,391 weekly downloads. As such, @commercetools-uikit/collapsible-motion popularity was classified as popular.
We found that @commercetools-uikit/collapsible-motion demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.