Skip to content

Commit

Permalink
fix: should not clean token when token change
Browse files Browse the repository at this point in the history
  • Loading branch information
MadCcc committed Feb 21, 2025
1 parent f433802 commit 372a110
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/examples/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useToken } from './theme';

interface ButtonToken extends DerivativeToken {
buttonPadding: string;
buttonBorderBottomWidth: string;
}

// 通用框架
Expand Down Expand Up @@ -62,6 +63,7 @@ const genDefaultButtonStyle = (
genSolidButtonStyle(prefixCls, token, () => ({
backgroundColor: token.componentBackgroundColor,
color: token.textColor,
borderWidth: token.buttonBorderBottomWidth,

'&:hover': {
borderColor: token.primaryColor,
Expand Down Expand Up @@ -137,6 +139,7 @@ const Button = ({ className, type, ...restProps }: ButtonProps) => {
},
() => ({
buttonPadding: '4px 8px',
buttonBorderBottomWidth: `calc(${token.borderWidth} * 2)`,
}),
);

Expand Down
6 changes: 4 additions & 2 deletions docs/examples/css-var.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const Demo = () => (

export default function App() {
const [show, setShow] = React.useState(true);

const [, forceUpdate] = React.useState({});
const [color, setColor] = React.useState('royalblue');
React.useEffect(() => {
forceUpdate({});
}, []);
Expand All @@ -30,13 +30,15 @@ export default function App() {
Show Components
</label>

<button onClick={() => { setColor((prev) => prev === 'royalblue' ? 'mediumslateblue' : 'royalblue')}}>Change theme</button>

{show && (
<div>
<Demo />
<br />
<DesignTokenProvider
value={{
token: { primaryColor: 'green' },
token: { primaryColor: color },
}}
>
<Demo />
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useCacheToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default function useCacheToken<
) as [any, string];
tokenWithCssVar._hashId = hashId;

recordCleanToken(hashId);
recordCleanToken(cssVar.key);
return [tokenWithCssVar, hashCls, actualToken, cssVarsStr, cssVar.key];
},
([, , , , themeKey]) => {
Expand Down

0 comments on commit 372a110

Please sign in to comment.