Skip to content

Try to make a right expandable tab #1815

Answered by lambrosx77
lambrosx77 asked this question in Support
Discussion options

You must be logged in to vote

Ok, I've got the solution so if it can help, here it is.

According to this nice tuto, we can't mix units so I had to convert all in pixels and use ref to keep it the right size resizing my window.

const vwToPx = value => `${(window.innerWidth * value) / 100}px`;
const remToPx = value => `${value * 16}px`;

export default function Shutter({ children }) {
    const shutterRef = React.useRef(null);
    const [isOpen, setIsOpen] = React.useState(false);

    const shutterSpring = useSpring({
        width: isOpen ? vwToPx(50) : remToPx(2.5),
        config: { clamp: true, friction: 1 },
        onRest: () => {
            if (isOpen && shutterRef.current) {
                shutterRef.current.…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by lambrosx77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant