ant-design / antd-style

css-in-js library with antd v5 token system
https://ant-design.github.io/antd-style/
MIT License
187 stars 29 forks source link

🧐[问题] 如何获取组件的token呢? #96

Closed Jveen-D closed 10 months ago

Jveen-D commented 10 months ago

🧐 问题描述

我在写业务的时候为了遵循UI的规范,需要用到各个组件的token,例如Upload组件的actionsColor值我要如何获取,我并没有在useTheme或者在createStyles中找到它们,我要如何获取组件token.

💻 示例代码

import { createStyles } from 'antd-style'
const useStyles = createStyles(({ cx, css, prefixCls, token, responsive }) => {
  console.log(
    '🚀 ~ file: styles.ts:3 ~ useStyles ~ token:',
    token.actionsColor
  )

  return {
    DesignScheduleDetail: css`
      height: calc(100vh - 64px);
      width: 100%;
      padding: 16px;
    `
  }
})
export default useStyles

获取不到组件token

Jveen-D commented 10 months ago

我现在的处理方式是查找ant-design的仓库,然后找到对应组件的某个token计算方法,然后粘贴到自己的项目中。

arvinxx commented 10 months ago

目前 antd-style 没有组件 token,后续应该也不会加组件 token。为啥你希望开发的组件使用组件 token 呢?理论上使用 map 就够用了

Jveen-D commented 10 months ago

目前 antd-style 没有组件 token,后续应该也不会加组件 token。为啥你希望开发的组件使用组件 token 呢?理论上使用 map 就够用了

举个项目中的例子,我需要把左边table的表头背景色给到右边甘特图的表头背景色。 image 现在唯一的操作方法就是翻仓库并拿到table表头背景色的计算规则,我这里使用的是

const tableBg = new TinyColor(token.colorFillAlter)
    .onBackground(token.colorBgContainer)
    .toHexShortString()

文档上有组件token,但是没有通过useThemecreateStyles获取到。我还以为有其他的方式来获取组件token,拿不到组件token问题也不大,翻翻文档也没啥坏处。