Skip to content

Is there any way to style the components without using the prop "style" (inline-style)? #48999

Answered by zombieJ
sawa-ko asked this question in Q&A
Discussion options

You must be logged in to vote

Ant Design provides the theme for preset token usage. But not provide the shortcut prop since antd has much complex token with its design system:

import { theme } from 'ant-design';

const { token } = theme.useToken();

// You can wrap the component if needed
const wrapComponent = (Component) => {
  const ProxyComponent = ({ pt, style, ...props }) => {
    const { token } = theme.useToken();

    return <Component style={{...style, paddingTop: token[pt]}} {...props} />
  };
};

const MyButton = wrapComponent(Button);

<MyButton pt="paddingXL" />

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sawa-ko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants