【问题标题】:I want to change the default style of the chakra ui button我想更改脉轮 ui 按钮的默认样式
【发布时间】:2023-03-15 22:05:01
【问题描述】:

我正在使用脉轮用户界面。
我想将按钮颜色更改为#2477b3。 我可以通过传递props中的值来改变它,但是每次传递props中的值都需要花费很多时间和精力,所以我想改变默认的Button颜色等。
我想使用 A 按钮的样式。
我更改了theme.ts并创建了一个BButton,但样式没有改变。 我尝试更改 theme.ts 中的值,但颜色没有改变。

  <Button
      size={'sm'}
      bg="#2B6CB0"
      _hover={{ bg: '#2477b3' }}
      _active={{
        bg: '#2477b3',
        transform: 'scale(0.98)',
        borderColor: '#2477b3',
      }}
      color={'#ffffff'}
    >
     AButton
    </Button>

  <Button>BButton</Button>

主题.ts

import { extendTheme } from '@chakra-ui/react';
export const theme = extendTheme({
  components: {
    Button: {
      baseStyle: {
        fontWeight: 'bold',
        _hover: {
          _disabled: {
            bg: '#2477b3',
          },
        },
      },
      variants: {
        bg: '#2B6CB0',
        _active: {
          bg: '#2477b3',
          transform: 'scale(0.98)',
          borderColor: '#2477b3',
        },
      },
    },
  },
});

【问题讨论】:

    标签: reactjs next.js chakra-ui


    【解决方案1】:

    您需要先正确定义主题覆盖,方法是设置一个变体,然后将默认值设置为该变体

    import { extendTheme } from '@chakra-ui/react';
    export const theme = extendTheme({
      components: {
        Button: {
          baseStyle: {
            // ...define your base styles
          },
          variants: {
            // Make a variant, we'll call it `base` here and leave it empty
            base: {},
            secondary: {
              //...define other variants        
            }
          },
          defaultProps: {
            // Then here we set the base variant as the default
            variant: 'base'
          }
        },
      },
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-10
      • 1970-01-01
      • 2016-01-18
      • 1970-01-01
      • 2018-06-22
      • 2020-07-02
      • 1970-01-01
      • 2012-10-24
      相关资源
      最近更新 更多