admin管理员组文章数量:1320631
such as:
button.tsx:
import {buttonStyle} from './buttuon.css.ts'
const Button = ({backgroundColor}) => {
return (
<button className={buttonStyle}>button<button/>
)
}
button.css.ts:
import { style } from '@vanilla-extract/css';
export const buttonStyle = style({
width: '100%',
backgroundColor: ?
});
I tried to write it this way, but it didn't solve the problem.
button.tsx:
import {buttonStyle} from './buttuon.css.ts'
const Button = ({backgroundColor}) => {
return (
<button className={buttonStyle(backgroundColor)}>button<button/>
)
}
button.css.ts:
import { style } from '@vanilla-extract/css';
export const buttonStyle = (backgroundColor) => style({
width: '100%',
backgroundColor: backgroundColor
});
error info: storybook: You can only export plain objects, arrays, strings, numbers and null/undefined.null/undefined. storybook: Plugin: vanilla-extract
such as:
button.tsx:
import {buttonStyle} from './buttuon.css.ts'
const Button = ({backgroundColor}) => {
return (
<button className={buttonStyle}>button<button/>
)
}
button.css.ts:
import { style } from '@vanilla-extract/css';
export const buttonStyle = style({
width: '100%',
backgroundColor: ?
});
I tried to write it this way, but it didn't solve the problem.
button.tsx:
import {buttonStyle} from './buttuon.css.ts'
const Button = ({backgroundColor}) => {
return (
<button className={buttonStyle(backgroundColor)}>button<button/>
)
}
button.css.ts:
import { style } from '@vanilla-extract/css';
export const buttonStyle = (backgroundColor) => style({
width: '100%',
backgroundColor: backgroundColor
});
error info: storybook: You can only export plain objects, arrays, strings, numbers and null/undefined.null/undefined. storybook: Plugin: vanilla-extract
Share Improve this question asked Jan 18 at 10:26 ShawkryShawkry 111 silver badge1 bronze badge1 Answer
Reset to default 1In order to dynamically style a HTML element background color using vanilla-extract
, you'll need to use its built-in mechanism for creating dynamic styles, such as createVar
and vars
. import if from @vanilla-extract/css
.
Refer the code below for reference:
import { style, createVar } from '@vanilla-extract/css';
export const backgroundColorVar = createVar(); // Create varible to hold background color
export const buttonStyle = style({
width: '100%',
backgroundColor: backgroundColorVar, // Set value here
});
In your button.tsx refer it like below:
import {buttonStyle, backgroundColorVar} from './button.css';
<button className = {buttonStyle} style = {{ [backgroundColorVar]: backgroundColor}}> Button </button>
本文标签:
版权声明:本文标题:storybook - How to dynamically style a button's background color using vanilla-extract and TypeScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742076009a2419414.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论