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

🐛[BUG] 开启 babel-plugin-antd-style 插件后内部 cx 生成的类名和导出的不一致 #83

Open pokerboard opened 11 months ago

pokerboard commented 11 months ago

🐛 bug 描述

控制台输出:
cx(label): acss-17f3slo
styles.label: acss-1o3nxki-pages-Home-label

💻 复现代码

const useStyles = createStyles(({ css, cx }) => {
  const label = css`
    color: red;
  `;

  const box1 = css`
    &:hover {
      font-weight: 600;

      .${cx(label)} {
        color: green;
      }
    }
  `;

  const box2 = css`
    &:hover {
      font-weight: 600;

      .${cx(label)} {
        color: blue;
      }
    }
  `;

  console.log('cx(label):', cx(label));

  return {
    box1,
    box2,
    label,
  };
});

const Home: React.FC = () => {
  const { styles } = useStyles();

  console.log('styles.label:', styles.label);

  return (
    <>
      <div className={styles.box1}>
        <span className={styles.label}>box1-lable</span>
      </div>
      <div className={styles.box2}>
        <span className={styles.label}>box2-lable</span>
      </div>
    </>
  );
};

© 版本信息

arvinxx commented 11 months ago

@chenshuai2144 这个要咋处理?

chenshuai2144 commented 11 months ago

我想想办法

FrankFan commented 11 months ago

@chenshuai2144 请问有解决办法了吗? 遇到了同样的问题

arvinxx commented 11 months ago

@FrankFan 可能可以尝试下的方式:

const useStyles = createStyles(({ css, cx }) => {
+  const label = cx(css`
    color: red;
  `);

  const box2 = css`
    &:hover {
      font-weight: 600;

+      .${label} {
        color: blue;
      }
    }
  `;

  return {
    box1,
    box2,
    label,
  };
});
pokerboard commented 11 months ago

@arvinxx 虽然可以解决问题,但是用 cx 生成的类名都会缺少定位信息,这个插件根本就不能和 cx 搭配使用

arvinxx commented 11 months ago

用 cx 生成的类名都会缺少定位信息

直接用cx 生成的类名应该不会太多,虽然瘸了点但还是能用的。

babel 插件和 cx 的搭配问题,我们再研究研究。

Wxh16144 commented 6 months ago

有什么更新吗,遇到同样的问题了。