网站搜索

reactjs - 为什么我不能在 css 属性中使用 stitches token?


我相信对于那些每天处理缝针工作的人来说,我的问题很简单。

我在关注 Pedro Duarte 的帖子时看到,有一种方法可以创建配置文件,也就是 stitches.config.ts。

我确实做了这件事,然而,当尝试使用这些令牌时,它不起作用,它被定义为这样的:

 export const { styled } = createStitches({
  theme: {
    turq: 'rgba(0, 245, 196, 1)',
  }
})

在创建这个令牌之后,我进入了下一步,即创建一个组件,它看起来像这样:

import { styled } from '@stitches/react';

export const Box = styled('div');

只是测试 CSS 属性。

然而,当调用组件并通过 css 属性传递令牌时,它并没有返回带有令牌颜色的文本。

问题是,我做错了什么吗?这是文档中出现的内容。

答案#1

没错!这样…

// customTheme.ts
export const { styled } = createStitches({
  theme: {
    turq: 'rgba(0, 245, 196, 1)',
  }
})

// Component.ts
import { styled } from 'customTheme'

export const Box = styled('div')

答案#2

我刚刚看到这里的问题是,我导入的 styled 与我从 createStitches 导出的不是同一个。

所以要解决这个问题,当你需要 styled 时,你应该直接从 stitches.config.ts 导入它