Skip to content
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

feat: component token support algorithm #43810

Merged
merged 13 commits into from Jul 27, 2023
Merged

Conversation

MadCcc
Copy link
Member

@MadCcc MadCcc commented Jul 26, 2023

  • feat: component theme
  • feat: component token support algorith,

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Workflow
  • Other (about what?)

🔗 Related issue link

#43638

💡 Background and solution

https://preview-43810-ant-design.surge.sh/components/config-provider-cn#components-config-provider-demo-theme

Kapture.2023-07-26.at.12.03.11.mp4

📝 Changelog

Language Changelog
🇺🇸 English Component Token support algorithm to calculate derivative tokens same as global.
🇨🇳 Chinese 组件 Token 支持配置 algorithm,和全局 Token 一样可用算法计算派生。

☑️ Self-Check before Merge

⚠️ Please check all items below before requesting a reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

🚀 Summary

🤖 Generated by Copilot at 5121402

This pull request enhances the theme customization feature of the ConfigProvider component. It allows users to specify different theme tokens and derivation logic for individual components using the theme prop. It also updates the related hooks, context, interface, and demo files to support the new feature. It requires a newer version of @ant-design/cssinjs dependency.

🔍 Walkthrough

🤖 Generated by Copilot at 5121402

  • Add and update imports of theme-related types and functions from @ant-design/cssinjs and components/theme in several files (link, link, link, link)
  • Update the ThemeConfig interface and the theme prop of the ConfigProvider component to support component-specific theme tokens and algorithms (link, link, link, link, link, link)
  • Implement the getComputedToken function and the useTheme hook to apply the theme derivation logic to the global and component themes (link, link, link, link)
  • Update the DesignTokenContext.Provider component to pass the component-specific theme tokens and themes to the context consumers (link)
  • Update the package.json file to use the latest version of @ant-design/cssinjs dependency (link)
  • Add a demo file components/config-provider/demo/theme.tsx to showcase the new theme customization features for different components (link, link, link, link)

@stackblitz
Copy link

stackblitz bot commented Jul 26, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 26, 2023

@socket-security
Copy link

socket-security bot commented Jul 26, 2023

No top level dependency changes detected. Learn more about Socket for GitHub ↗︎

@github-actions
Copy link
Contributor

github-actions bot commented Jul 26, 2023

size-limit report 📦

Path Size
./dist/antd.min.js 383.35 KB (+425 B 🔺)
./dist/antd-with-locales.min.js 442.87 KB (+384 B 🔺)

@argos-ci
Copy link

argos-ci bot commented Jul 26, 2023

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) 👍 Changes approved 3 changes Jul 27, 2023, 2:01 AM

@codecov
Copy link

codecov bot commented Jul 26, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (425e6ce) 100.00% compared to head (642b4eb) 100.00%.
Report is 3 commits behind head on feature.

Additional details and impacted files
@@            Coverage Diff            @@
##           feature    #43810   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          658       658           
  Lines        11118     11143   +25     
  Branches      3009      3017    +8     
=========================================
+ Hits         11118     11143   +25     
Files Changed Coverage Δ
components/config-provider/context.ts 100.00% <ø> (ø)
components/config-provider/hooks/useTheme.ts 100.00% <100.00%> (ø)
components/config-provider/index.tsx 100.00% <100.00%> (ø)
components/theme/context.ts 100.00% <100.00%> (ø)
components/theme/useToken.ts 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MadCcc MadCcc marked this pull request as ready for review July 26, 2023 12:51

const parsedComponents: any = {};
Object.entries(components || {}).forEach(([componentName, componentToken]) => {
parsedComponents[componentName] = { ...componentToken };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parsedComponents[componentName] 到处都是,这里提个变量出来

};

// Format if needed
mergedDerivativeToken = formatToken(mergedDerivativeToken);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatToken 下面也调用了一次,这个确定是要这么做的么?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只有这里调用了。cssinjs 里会被这个 getComputedToken 完全覆盖逻辑

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所以理论上 useCacheToken 是可以不传 formatToken 的

@MadCcc MadCcc merged commit 94b3d03 into feature Jul 27, 2023
87 checks passed
@MadCcc MadCcc deleted the feat/component-algorithm branch July 27, 2023 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants