Skip to content

Instantly share code, notes, and snippets.

@Wxh16144
Created July 16, 2025 07:44
Show Gist options
  • Select an option

  • Save Wxh16144/48cf1f67a40530c73375449d8a6b1b2b to your computer and use it in GitHub Desktop.

Select an option

Save Wxh16144/48cf1f67a40530c73375449d8a6b1b2b to your computer and use it in GitHub Desktop.
可视化 Ant Design Token
import { Typography, List, theme } from "antd";
import { FastColor } from "@ant-design/fast-color";
import { createGlobalStyle, ThemeProvider, type ThemeMode } from "antd-style";
import { NuqsAdapter } from "nuqs/adapters/react";
import type { PropsWithChildren } from "react";
import { parseAsStringEnum, useQueryState } from "nuqs";
export const setupInstructions = `
# Create a new directory for your project
mkdir hi-antd-token && cd hi-antd-token
# Create a new React project
npm create vite@latest . --template react-ts
# Install dependencies
npm install antd antd-style @ant-design/fast-color nuqs
`;
const Demo = () => {
const { token } = theme.useToken();
const color = {
text: token.colorText,
background: token.colorBgContainer,
error: token.colorError,
primary: token.colorPrimary,
success: token.colorSuccess,
warning: token.colorWarning,
info: token.colorInfo,
link: token.colorLink,
border: token.colorBorder,
borderSecondary: token.colorBorderSecondary,
} as const;
const hexColor = Object.entries(color).reduce((acc, [key, value]) => {
acc[key] = new FastColor(value).toHexString();
return acc;
}, {} as Record<string, string>);
return (
<List>
{Object.entries(hexColor).map(([key, value]) => (
<List.Item key={key}>
<Typography.Text style={{ color: value }}>
{key}: {value}
</Typography.Text>
</List.Item>
))}
</List>
);
};
const GlobalStyle = createGlobalStyle`
body {
color: ${({ theme }) => theme.colorBgBase};
background-color: ${({ theme }) => theme.colorBgContainer};
}
`;
const Theme = ({ children }: PropsWithChildren) => {
const [themeMode] = useQueryState<ThemeMode>(
"theme",
parseAsStringEnum(["auto", "light", "dark"])
.withDefault("auto")
.withOptions({
clearOnDefault: true,
})
);
return (
<ThemeProvider themeMode={themeMode}>
<GlobalStyle />
{children}
</ThemeProvider>
);
};
const App = () => {
return (
<NuqsAdapter>
<Theme>
<Demo />
</Theme>
</NuqsAdapter>
);
};
export default App;
@Wxh16144
Copy link
Author

ScreenShot

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment