Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛[BUG]特定情况下createStyles中获取不到当前设置的prefixCls #174

Open
blogwy opened this issue Oct 23, 2024 · 0 comments
Open

Comments

@blogwy
Copy link

blogwy commented Oct 23, 2024

🐛 bug 描述

以Button组件为例,封装成自定义组件后,createStyles可以获取到prefixCls的值。直接使用Button组件获取到的prefixCls就是默认值ant

screenshot-20241023-154712

💻 复现代码

import { Button } from 'antd'
import { createStyles, ThemeProvider } from 'antd-style'
import './App.css'

const useStyles = createStyles(({ token, css, prefixCls }) => {
  console.log('prefixCls: ', prefixCls);
  return {
    override: css`
      &.${prefixCls}-btn {
        background-color: ${token.colorWarning};
      }
    `,
  }
});

const Demo = ({ text }: { text?: string }) => {
  const { styles } = useStyles();

  return <Button className={styles.override}>{text ?? 'override to warning color'}</Button>;
};

function App() {
  const { styles } = useStyles();

  return (
    <ThemeProvider prefixCls={'abc'}>
      <Demo text={'prefixCls to abc'} />
      <Button className={styles.override}>abc</Button>
      {/* <ThemeProvider prefixCls={'efg'}>
        <Demo text={'prefixCls to efg'} />
        <Button className={styles.override}>qqq</Button>
      </ThemeProvider> */}
    </ThemeProvider>
  )
}

export default App

© 版本信息

  • antd-style 3.7.1
  • antd 5.21.5

🚑 其他信息

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant