- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 @emotion\styled
声明了以下样式按钮:
const Button = styled.button`
background: blue;
${size({
width: props => props.width
)}
`
在我的代码中,size
是一个函数,它根据传递的 prop 返回 size css 序列化样式:
const size = ({ width: "m"} = {}) => {
switch(width) {
case "s":
return css`width: 100px`;
break;
case "m":
return css`width: 150px`;
break;
}
}
<Button width="s">Some text</Button>
但是,我在 size
函数中收到的 width
值不是来自传递的 prop 的解析值,即 s
,而是它是一个字符串 props => props.width
。
有什么方法可以将 Prop 从类似于我想要实现的样式组件传递到函数中吗?
最佳答案
它不起作用,因为您在不需要函数的地方将匿名函数传递给 width
。
我很确定这就是您想要做的:
const Button = styled.button`
background: blue;
${props => size({ width: props.width })}
`
这样,您就可以在样式声明的范围内传递一个匿名函数,从 Emotion 获取 props 并随意使用它。
关于javascript - 使用 Emotion.sh 从样式组件传递 Prop ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60168380/
我正在尝试在利用 Emotion 的 React 项目中使用本地托管字体及其 Global component .此方法适用于网络字体,例如 Google Fonts ,但是当我下载相同的字体并尝试将
在 Emotion v10 中,文档说“如果您从 @emotion/css/macro 导入它,则有一个 Babel 宏可用于来自 @emotion/core 的 css。”这显然适用于无法更改 ba
我正在使用 @emotion/react主题并将主题注入(inject)其中,我可以使用 useTheme 访问主题到组件中,但无法使用 @emotion/styled 将主题访问到样式中.请问有什么
我正在尝试使用 React Emotion设置一条水平线,中间有文本。它看起来像这样: ----------------------SOME TEXT-------------------------
运行 React 测试库以在使用 Emotion css 属性的 JSX 上生成快照,导致没有渲染任何 CSS。 我试过使用“@emotion/jest/serializer”,但仍然没有运气。 组件
在 Emotion 11 之前的版本中,我曾经像这样在开发中禁用 CSS 前缀: const emotionCache = createCache({ prefix: process.env.NO
我想设计两个按钮的样式:使用情感 css 使用图像向上和向下,但无法这样做。目前,我通常在函数中设置元素的样式。如何使用情感 css 实现这一目标? 我关注了 https://emotion.sh/d
我正在将我的应用程序的样式从 Less 转换为 Emotion 在 Less 中我有如下样式: @blue: #476882; background: rgba(red(@blue), green(@
我正在为我的应用创建聊天功能,我们有一组自定义表情符号。 如果用户在他们的评论中键入其中一个表情的快捷方式,我们需要能够检测到快捷方式按出现顺序并用适当的表情替换它们。 例如。 let emotes
我知道这与 Target another styled component on hover 非常相似 不过我想用emotion-js达到同样的效果 更具体地说,我正在尝试重新创建 this使用情感风
我正在尝试在 Emotion 中创建可重复使用的动画但遇到了一些问题。我为 fadeUp 定义了一个动画。效果很好。 export const animatedFadeUp = css` opac
在决定何时使用样式化组件而不是 css prop 时,是否有最佳实践或优缺点列表? 最佳答案 我通常更喜欢 styledComponent但是,有一些极端情况,比如为 设置样式对于 react-ro
我要安装neumorphism-react包裹。 但我得到了这个错误 Module not found: Can't resolve '@emotion/react' in'C:\Users\Asus
如果我安装 emotion那么 API 很好而且很清晰: 包.json: "dependencies": { "emotion": "^10.0.9", react 组件: import Reac
我使用 @emotion\styled 声明了以下样式按钮: const Button = styled.button` background: blue; ${size({ width: p
我目前正在开发一个不和谐的机器人,我试图在嵌入消息中显示自定义服务器表情,它应该出现在“插入表情图标”中,但我无法完成它。这是否可能?如果可能,如何实现? if (member.hasPermissi
我正在使用 Affectiva 的 Emotion SDK for Javascript 来播放和分析视频文件。目前,我正在以流的形式播放视频,并按照 "Analyze a video frame s
在元素中,我遇到了使用 Emotion 实现的 CSS-IN-JS。通常,我都是通过CSS样式的名称来查找对应组件的代码,但是由于生成的样式名称,我在元素代码中尝试从浏览器中查找元素时感到很痛苦。 实
在我维护的设计系统中,我们使用修改后的 BEM 格式来命名导出的 @emotion/css JSS 样式。 语法看起来像这样: Selector_descendant___modifier 例如(伪代
我想使用来自 react-emotion 的样式来使用 HighChartWrapper 包装 HighchartsReact。 下面是我正在尝试的伪代码。 import HighchartsReac
我是一名优秀的程序员,十分优秀!