reactjs - 仅获取特定 Tailwind CSS 类的 CSS 值
问题描述
有没有办法只获取 Tailwind CSS 类的 CSS 值?例如,如果我有translate-x-4
tailwind 类,我只想要1rem
CSS 值(因为 classtranslate-x-4
是--tw-translate-x: 1rem;
)。这对Framer Motion非常有用,因为 framer 运动动画对象可以接受各种 CSS 值1rem
,如#ff3322
. 有没有办法做这样的事情<motion.div animate={{ x: getValue('translate-x-4') }} initial={false} />
。
我知道存在twin.macro但它“返回”整个 Tailwind CSS 类。是否有类似的实用程序仅用于获取价值?
解决方案
我认为xwind是您正在寻找的。
import xw from "xwind";
const styles = xw`text-red-100 hover:text-green-100 hover:bg-blue-200`;
// OR (with custom array syntax)
const styles = xw`text-red-100 hover[text-green-100 bg-blue-200]`;
Xwind 将您的顺风类转换为 Postcss-js / JSS 兼容的语法。像这样的东西:
const styles = {
"--text-opacity": "1",
color: ["#fde8e8", "rgba(253, 232, 232, var(--text-opacity))"],
"&:hover": {
"--text-opacity": "1",
"--bg-opacity": "1",
color: ["#def7ec", "rgba(222, 247, 236, var(--text-opacity))"],
backgroundColor: ["#c3ddfd", "rgba(195, 221, 253, var(--bg-opacity))"],
},
};
推荐阅读
- excel - 如何在索引函数中嵌套替代公式?
- graph - 具有初始猜测的二部图快速最大匹配算法
- html - 移动页面上的 Css 动画和里面的文本
标签不换行而是放大页面
- c# - File.Exists 可以抛出异常吗?
- wordpress - “插件无法激活,因为它触发了致命错误。” 尝试在 WordPress 上安装 WooCommerce 插件时,我该如何解决?
- python - 将 JSON 文件放入字典
- asp.net-core - 两个表单(1 个 ajax 和 1 个常规帖子),一个模型在同一个剃须刀页面上
- c# - 如何从控制器获取到 Identity/Pages/Account/ConfirmEmail 的回调 URL?
- php - 我可以在 PHP 中使用“use”关键字的路径中使用连字符吗?
- java - 无法将文本设置为文本视图