01 说明

使用 override 只能改变 text 的内容,要想改变 text 的样式(如颜色、字号等),需使用 codeComponent 来实现。

02 悬浮改变样式

2020-02-29 10.14.17.gif

  1. import * as React from "react"
  2. import { Frame, Data } from "framer"
  3. export function HoverChangeColor(props) {
  4. const { buttonText } = props
  5. const style = {
  6. // text color
  7. color: "white",
  8. fontSize: 32,
  9. fontWeight: 900,
  10. background: "",
  11. width: 400,
  12. height: 100,
  13. }
  14. return (
  15. <Frame
  16. center
  17. style={style}
  18. whileHover={{
  19. color: "yellow",
  20. fontSize: 48,
  21. transition: {
  22. duration: 0.3,
  23. },
  24. }}
  25. >
  26. {buttonText}
  27. </Frame>
  28. )
  29. }
  30. HoverChangeColor.defaultProps = {
  31. buttonText: "Text Content",
  32. }

03 点击改变样式

2020-02-29 10.49.23.gif

  1. import * as React from "react"
  2. import { Frame } from "framer"
  3. export function TapChangeColor() {
  4. // 设置 didTap 的默认值为 false 且定义 setDidTap() 方法
  5. const [didTap, setDidTap] = React.useState(false)
  6. const style = {
  7. // text color,didTap 为 true 时为 yellow ,为 false 时为 white
  8. color: didTap ? "yellow" : "white",
  9. fontSize: 32,
  10. fontWeight: 900,
  11. background: "",
  12. width: 400,
  13. height: 100,
  14. }
  15. return (
  16. <Frame
  17. center
  18. style={style}
  19. onTap={() => {
  20. // 设置 didTap 为相反值
  21. setDidTap(!didTap)
  22. }}
  23. >
  24. Text Content
  25. </Frame>
  26. )
  27. }