-
Notifications
You must be signed in to change notification settings - Fork 80
chore: master merge next #236
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
Changes from all commits
456a1ce
7fc269b
296d730
fcb0e28
afc4b67
db73b8d
d5c0ad1
f433802
cdd6675
c13639f
80f1368
9de2638
9e0b3d7
d0ec3f5
079f152
eb0170f
2b33bea
b5cab9b
aad3356
4b65240
c3d906a
02d35a3
c6283f7
5949a1b
1d9867a
68e4fed
a4da2e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| title: First Render | ||
| nav: | ||
| title: Demo | ||
| path: /demo | ||
| --- | ||
|
|
||
| <code src="../examples/first-render.tsx"></code> |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { | ||
| autoPrefixTransformer, | ||
| createTheme, | ||
| StyleProvider, | ||
| useStyleRegister, | ||
| } from '@ant-design/cssinjs'; | ||
| import React from 'react'; | ||
|
|
||
| const Demo = () => { | ||
| useStyleRegister( | ||
| { theme: createTheme(() => ({})), token: {}, path: ['.auto-prefix-box'] }, | ||
| () => ({ | ||
| '.auto-prefix-box': { | ||
| width: '200px', | ||
| height: '200px', | ||
| backgroundColor: '#f0f0f0', | ||
| border: '1px solid #d9d9d9', | ||
| borderRadius: '8px', | ||
| // Properties that will get vendor prefixes | ||
| transform: 'translateX(50px) scale(1.1)', | ||
| transition: 'all 0.3s ease', | ||
| userSelect: 'none', | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| backdropFilter: 'blur(10px)', | ||
| '&:hover': { | ||
| transform: 'translateX(50px) scale(1.2)', | ||
| backgroundColor: '#e6f7ff', | ||
| }, | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| return ( | ||
| <div className="auto-prefix-box"> | ||
| <h3>Auto Prefix Demo</h3> | ||
| <p>Hover to see effect</p> | ||
| <p style={{ fontSize: '12px', color: '#666' }}> | ||
| Check DevTools to see vendor prefixes in CSS | ||
| </p> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default () => ( | ||
| <StyleProvider transformers={[autoPrefixTransformer]}> | ||
| <Demo /> | ||
| </StyleProvider> | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import type { CSSObject, Theme } from '@ant-design/cssinjs'; | ||
| import { createTheme, useCacheToken } from '@ant-design/cssinjs'; | ||
| import { TinyColor } from '@ctrl/tinycolor'; | ||
| import React from 'react'; | ||
| import React, { PropsWithChildren } from 'react'; | ||
|
|
||
| export type GetStyle = (prefixCls: string, token: DerivativeToken) => CSSObject; | ||
|
|
||
|
|
@@ -61,32 +61,68 @@ export const DesignTokenContext = React.createContext<{ | |
| token: defaultDesignToken, | ||
| }); | ||
|
|
||
| export const DesignTokenProvider: React.FC< | ||
| PropsWithChildren<{ | ||
| value?: { | ||
| token?: Partial<DesignToken>; | ||
| hashed?: string | boolean; | ||
| cssVar?: { | ||
| key?: string; | ||
| prefix?: string; | ||
| }; | ||
| }; | ||
| }> | ||
| > = ({ children, value }) => { | ||
| const { token, hashed, cssVar } = value || {}; | ||
| const themeKey = React.useId(); | ||
| const cssVarKey = `css-var-${themeKey.replace(/:/g, '')}`; | ||
| return ( | ||
| <DesignTokenContext.Provider | ||
| value={{ | ||
| token, | ||
| hashed, | ||
| cssVar: { | ||
| ...cssVar, | ||
| key: cssVar?.key || cssVarKey, | ||
| }, | ||
| }} | ||
| > | ||
| {children} | ||
| </DesignTokenContext.Provider> | ||
| ); | ||
| }; | ||
|
Comment on lines
+64
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainDesignTokenProvider 实现良好,但需注意 React 版本依赖。
根据 PR 摘要,此版本已移除 React 18 以下版本的兼容性支持,因此使用 🏁 Script executed: #!/bin/bash
# 检查 package.json 中的 React 版本要求
cat package.json | jq -r '.peerDependencies.react, .devDependencies.react, .dependencies.react' | head -3Length of output: 21 需要进一步验证 React.useId() 在代码库中的使用范围和这是否是一个新的breaking change。让我检查相关信息。 Length of output: 614 🏁 Script executed: #!/bin/bash
# 检查 package.json 中是否有 breaking changes 的说明或版本号变化
cat package.json | jq -r '.version'Length of output: 13 更新 package.json 中的 React peerDependencies 版本要求。
在 🤖 Prompt for AI Agents |
||
|
|
||
| export function useToken(): [ | ||
| Theme<any, any>, | ||
| DerivativeToken, | ||
| string, | ||
| string | undefined, | ||
| string, | ||
| DerivativeToken, | ||
| ] { | ||
| const { | ||
| token: rootDesignToken = {}, | ||
| hashed, | ||
| cssVar, | ||
| cssVar: ctxCssVar, | ||
| } = React.useContext(DesignTokenContext); | ||
| const theme = React.useContext(ThemeContext); | ||
|
|
||
| const [token, hashId] = useCacheToken<DerivativeToken, DesignToken>( | ||
| theme, | ||
| [defaultDesignToken, rootDesignToken], | ||
| { | ||
| salt: typeof hashed === 'string' ? hashed : '', | ||
| cssVar: cssVar && { | ||
| prefix: 'rc', | ||
| key: cssVar.key, | ||
| unitless: { | ||
| lineHeight: true, | ||
| }, | ||
| const cssVar = { | ||
| key: ctxCssVar?.key || 'css-var-root', | ||
| }; | ||
|
|
||
| const [token, hashId, actualToken] = useCacheToken< | ||
| DerivativeToken, | ||
| DesignToken | ||
| >(theme, [defaultDesignToken, rootDesignToken], { | ||
| salt: typeof hashed === 'string' ? hashed : '', | ||
| cssVar: { | ||
| prefix: 'rc', | ||
| key: cssVar?.key || 'css-var-root', | ||
| unitless: { | ||
| lineHeight: true, | ||
| }, | ||
| hashed: !!hashed, | ||
| }, | ||
| ); | ||
| return [theme, token, hashed ? hashId : '', cssVar?.key]; | ||
| }); | ||
| return [theme, token, hashed ? hashId : '', cssVar.key, actualToken]; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
anyformergedTokenweakens type safety. A more specific type can be used here to ensure themergedTokenobject conforms to the expected shape, which appears to beButtonToken.