@vimeo/iris
Version:
Vimeo Design System
27 lines (24 loc) • 1.16 kB
JavaScript
import { b as __rest, _ as __read, c as __assign } from '../../tslib.es6-7f0e734f.js';
import React__default, { useRef, useState, useLayoutEffect } from 'react';
import { withIris } from '../../utils/HOCs/withIris.esm.js';
import 'styled-components';
var SlideUpDown = withIris(SlideUpDownComponent);
function SlideUpDownComponent(_a) {
var _b = _a.automatic, automatic = _b === void 0 ? false : _b; _a.forwardRef; var children = _a.children, showing = _a.showing, props = __rest(_a, ["automatic", "forwardRef", "children", "showing"]);
var ref = useRef(null);
var _c = __read(useState(0), 2), maxHeight = _c[0], setMaxHeight = _c[1];
useLayoutEffect(function () {
if (showing)
setMaxHeight(ref.current.scrollHeight);
}, [children, showing]);
useLayoutEffect(function () {
if (!automatic)
setMaxHeight(0);
}, [automatic]);
return (React__default.createElement("div", __assign({ ref: ref, style: {
overflowY: 'hidden',
transition: 'all 200ms ease-in-out',
maxHeight: showing ? maxHeight : 0,
} }, props), children));
}
export { SlideUpDown };