Привет. Я пытаюсь сделать анимацию максимальной высоты, но она работает только при закрытии кнопки переключения (выпадающий список):
gif:
но я хотел добавить анимацию при открытии выпадающего элемента тоже
я использую reactjs и эмоции
jsx:
const MenuItem = ({ key, index, tag, setVisible, visibleMenu }) => {
const { name, dropdownItems, icon } = tag;
const handleClick = index => {
if (visibleMenu === true) return setVisible("none");
if (visibleMenu === index) return setVisible("none");
return setVisible(index);
};
return (
<ListItem active={visibleMenu}>
<div
onClick={() => {
handleClick(index);
}}
className="li-menuOpen"
>
<a>
<FontAwesomeIcon
className="icon-li"
icon={icon}
size={"lg"}
fixedWidth
color="white"
/>
<span
className="li-name"
onClick={() => {
handleClick(index);
}}
>
{name}
</span>
</a>
<span className="svg-arrow">
{dropdownItems ? (
<FontAwesomeIcon
className="down-up_svg"
icon={visibleMenu ? faAngleUp : faAngleDown}
size="1x"
fixedWidth
color="white"
/>
) : (
""
)}
</span>
</div>
{dropdownItems ? (
<DropDown list={dropdownItems} active={visibleMenu} />
) : (
""
)}
</ListItem>
);
};
здесь у меня есть компонент с анимацией:
const OpenedSide = ({ open, active, list }) => {
return (
<>
<OpenedStyled open={open} active={active}>
{list.map(item => (
<li className="li-open" key={item.name}>
<FontAwesomeIcon
className="icon-li-drop"
icon={faCircleNotch}
size="1x"
fixedWidth
color="white"
/>
<a>{item.name}</a>
</li>
))}
</OpenedStyled>
</>
);
};
css:
export const ListItem = styled.li`
display: flex;
flex-direction: column;
position: relative;
justify-content: space-between;
cursor: pointer;
& .icon-li {
margin-right: 10px;
}
& .li-menuOpen {
${props => {
if (props.active) {
return css`
border-left: 3px solid orange;
background: ${shade(0.4, "#3c8dbc")};
:hover,
:active {
background: ${shade(0.4, "#3c8dbc")};
}
`;
}
}}
padding: 12px 5px 12px 15px;
display: flex;
justify-content: ${props => (props.open ? "center" : "space-between")};
}
& .down-up_svg,
.li-name {
display: ${props => (props.open ? "none" : "space-between")};
}
`;
export const OpenedStyled = styled.ul`
${props => {
if (props.active) {
return css`
max-height: 400px !important;
`;
}
}}
position:relative;
max-height: 0;
overflow: hidden;
background: ${shade(0.4, "#3c8dbc")};
transition: max-height 5s cubic-bezier(0, 1, 0, 1);
li {
display: flex;
align-items: center;
white-space: nowrap;
padding: 12px 20px 12px 20px;
svg {
margin-right: 20px;
}
}
a {
font-family: "Ubuntu";
font-size: 14px;
font-weight: 400;
text-decoration: none;
color: #fff;
}
& .li-open:hover > .icon-li-drop {
color: orange;
transition: color 0.5s;
}
& .icon-li-drop {
margin-right: 10px;
}
`;
пример работы:
https://codesandbox.io/s/purple-silence-ytc5h?file= / src / styleled. js: 299-1028