reactjs 填充错误与帧运动开关自定义

ecbunoof  于 2023-04-05  发布在  React
关注(0)|答案(1)|浏览(150)

我试图使一个自定义开关组件,但有一些小故障的效果时,动画播放。正如你所看到的一切似乎移动。

import React from "react";
import { clsx } from "@mantine/core";
import { motion } from "framer-motion";

type Props = {
  checked: boolean;
  onChange: () => void;
  labelChecked: string;
  labelUnchecked: string;
};

export const AppSwitch: React.FC<Props> = ({ checked, onChange, labelChecked, labelUnchecked }) => (
  <motion.div
    onClick={onChange}
    animate={{ backgroundColor: checked ? "#68A4F5" : "#70707015" }}
    className={clsx(
      "cursor-pointer select-none shadow-md inline-flex items-center rounded-xl p-0.5",
      checked ? "flex-row-reverse" : "flex-row",
    )}
  >
    <motion.div
      layout="position"
      className={clsx("pl-3 pr-2 uppercase font-semibold text-black")}
      style={{ fontSize: "clamp(10px, 12px, 14px)" }}
    >
      {checked ? labelChecked : labelUnchecked}
    </motion.div>
    <motion.div layout="position" className="w-6 h-6 bg-white rounded-full" />
  </motion.div>
);

此外,我试图在一个给定的空间缩放字体,似乎不工作。
谢谢

vc6uscn9

vc6uscn91#

我可以使用<div className="flex flex-col justify-center items-start">在内容周围 Package div来解决这个问题。我不知道为什么会这样,但它确实有效...

相关问题