【发布时间】:2022-06-10 22:10:52
【问题描述】:
我想使用 Tailwind CSS 类将坐标值作为道具传递给组件。每次鼠标悬停时值都会改变,但类不起作用。
我的组件
import classNames from "classnames";
interface TooltipProps {
coordinate: { left: string; top: string; isFavorite: boolean };
}
const Tooltip: React.FC<TooltipProps> = ({ coordinate }: TooltipProps) => {
return (
<div
id="tooltip"
className={classNames(
`fixed ml-[auto] z-[999] p-[10px] text-sm font-medium text-white bg-gray-900 rounded-[6px] shadow-tooltip dark:bg-gray-700`,
coordinate.left,
coordinate.top
)}
>
{coordinate.isFavorite ? "حذف" : "افزودن"} به علاقهمندی
<svg
className="absolute bottom-[-10px] center "
width="16"
height="10"
viewBox="0 0 16 10"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M8 10L0 0L16 1.41326e-06L8 10Z" fill="black" />
</svg>
</div>
);
};
export default Tooltip;
在我传递的道具中:
setCoordinate({
top: `top-[${Math.round(top)}px]`,
left: `left-[${Math.round(left)}px]`,
});
这些值在使用 Tailwind CSS 实用程序类时不起作用。
【问题讨论】:
标签: reactjs typescript tailwind-css