【发布时间】:2021-08-03 21:45:59
【问题描述】:
我有一个组件,其宽度必须根据道具而改变。
我的组件风格:
const SidebarContainer = styled.div`
width: ${props.isOpen ? 340 : 73}px;
height: 100vh;
background-color: ${colors.white100};
padding-left: 30px;
padding-top: 17px;
overflow: hidden;
position: fixed;
transition: all 0.5s ease;
`
样式变化,但没有过渡。我尝试使用数据attributes,但它不起作用。
我该如何解决这个问题?
【问题讨论】:
-
尝试宽度:${({ isOpen }) => (isOpen ? '340' : '73')}px
-
尝试 ${({props.isOpen }) => (props.isOpen ? '340' : '73')}px,但什么也没有