0

this is my custom button component, antd i want use all buttons with color and variant, but this is not working for color="primary" and variant="text". And i wonder why antd button ha no succcess, info, secondary buttons

import {Button as AntdButton, theme, ConfigProvider} from "antd";
import PropTypes from "prop-types";

export const Button = ({color, children, ...rest}) => {
    const {token} = theme.useToken();

    const colorMap = {
        success: token.colorSuccess,
        warning: token.colorWarning,
        info: token.colorInfo,
        error: token.colorError,
        secondary: "#3577f1",
    };

    const colorPrimary = colorMap[color];

    const button = <AntdButton color={color === 'error' ? "danger" : "primary"} {...rest}>{children}</AntdButton>;

    return colorPrimary ? (
        <ConfigProvider
            theme={{
                token: {
                    colorPrimary,
                },
            }}
        >
            {button}
        </ConfigProvider>
    ) : (
        button
    );
};

Button.propTypes = {
    color: PropTypes.string,
    children: PropTypes.node,
};
1
  • Welcome to Stack Overflow! In what way is your code not working as expected? Please elaborate on the specific problem you are observing and what debugging you have done. To learn more about this community and how we can help you, please start with the tour and read How to Ask and its linked resources. Commented Apr 18 at 13:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.