@chakra-ui/ 过渡
安装
yarn add @chakra-ui/transition
# or
npm i @chakra-ui/transition
折叠
折叠组件用于创建内容区域 用简单的动画来扩展/缩合。 它有助于隐藏内容不是 与用户直接相关.
导入组件
import { Collapse } from "@chakra-ui/transition"
使用量
function SampleSpring() {
const { isOpen, onToggle } = useDisclosure()
return (
<>
<Button onClick={onToggle}>Click</Button>
<Collapse in={isOpen}>
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus
terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer
labore wes anderson cred nesciunt sapiente ea proident.
</Collapse>
</>
)
}
更改起始高度
function Example() {
const [show, setShow] = React.useState(false)
const handleToggle = () => setShow(!show)
return (
<>
<Collapse startingHeight={20} in={show}>
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus
terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer
labore wes anderson cred nesciunt sapiente ea proident.
</Collapse>
<Button size="sm" onClick={handleToggle} mt="1rem">
Show {show ? "Less" : "More"}
</Button>
</>
)
}
//TODO: 解释 framer-motion 部分以及如何自定义运动
变体