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

refactor: FloatButton support css var #45861

Merged
merged 3 commits into from
Nov 15, 2023

Conversation

JarvisArt
Copy link
Contributor

@JarvisArt JarvisArt commented Nov 14, 2023

[中文版模板 / 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

💡 Background and solution

📝 Changelog

Language Changelog
🇺🇸 English FloatButton support css variables.
🇨🇳 Chinese FloatButton 组件支持 css 变量。

☑️ 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 808dbd3

This pull request refactors the float button component and its group variant to use CSS variables for styling and customization. It introduces a new hook useCSSVar and a new function wrapCSSVar to register and apply the CSS variables. It also enhances the style and customization of the component by using the @ant-design/cssinjs library and the zIndexPopup token value. It adds a new file components/float-button/style/cssVar.ts to export the useCSSVar hook.

🔍 Walkthrough

🤖 Generated by Copilot at 808dbd3

  • Replace wrapSSR function with wrapCSSVar function and destructure hashId from useStyle hook in FloatButton and FloatButtonGroup components to use CSS variables (link,link,link,link)
  • Import useCSSVar hook from ./style/cssVar in FloatButton and FloatButtonGroup components to register and use CSS variables (link,link)
  • Add components/float-button/style/cssVar.ts file to export useCSSVar hook that uses genCSSVarRegister and prepareComponentToken functions to create a CSS variable provider and consumer for the float button component (link)
  • Use unit function from @ant-design/cssinjs to convert numeric token values to CSS unit strings in initFloatButtonGroupMotion and sharedFloatButtonStyle functions (link,link,link,link,link,link,link)
  • Use calc function from @ant-design/cssinjs to create CSS calc expressions for token values that accept custom CSS units or expressions in floatButtonGroupStyle, sharedFloatButtonStyle, and default export functions (link,link,link,link)
  • Use zIndexPopup token value instead of hard-coded 99 value for zIndex property of FloatButton and FloatButtonGroup components (link,link)
  • Add comments to ComponentToken interface to describe the meaning and usage of each token value (link)
  • Modify FloatButtonToken interface to make some token values accept either a number or a string, such as floatButtonIconSize, floatButtonBodySize, and badgeOffset (link)

Copy link

stackblitz bot commented Nov 14, 2023

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

Copy link
Contributor

github-actions bot commented Nov 14, 2023

Preview Is ready

@@ -32,7 +33,8 @@ const FloatButtonGroup: React.FC<FloatButtonGroupProps> = (props) => {

const { direction, getPrefixCls } = useContext<ConfigConsumerProps>(ConfigContext);
const prefixCls = getPrefixCls(floatButtonPrefixCls, customizePrefixCls);
const [wrapSSR, hashId] = useStyle(prefixCls);
const [, hashId] = useStyle(prefixCls);
const wrapCSSVar = useCSSVar(prefixCls);
Copy link
Member

Choose a reason for hiding this comment

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

用 useCSSVarCls 取一个 roolCls 吧,FloatButton 那里也是。
这里 prefixCls 不是最外层,不会作用到最外层元素

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done~

Copy link

codesandbox-ci bot commented Nov 14, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit de38f31:

Sandbox Source
antd reproduction template (forked) Configuration

Comment on lines 17 to 26
/**
* @desc 圆形按钮中徽章点的偏移量
* @descEN Offset of the badge dot in a circular button
*/
dotOffsetInCircle: number;
/**
* @desc 方形按钮中徽章点的偏移量
* @descEN Offset of the badge dot in a square button
*/
dotOffsetInSquare: number;
Copy link
Member

Choose a reason for hiding this comment

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

这两个打上 @internal 或者直接移到 FloatButtonToken 里吧,不对外透出

Copy link
Contributor Author

Choose a reason for hiding this comment

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

只能放ComponentToken了,因为涉及到的计算在css实现不了

Copy link

argos-ci bot commented Nov 14, 2023

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

Build Status Details Updated (UTC)
default (Inspect) 🧿 Changes detected (Review) 1 change Nov 14, 2023, 10:00 AM

Copy link

codecov bot commented Nov 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (4266517) 100.00% compared to head (de38f31) 100.00%.
Report is 13 commits behind head on feature.

Additional details and impacted files
@@            Coverage Diff            @@
##           feature    #45861   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          706       706           
  Lines        12052     12083   +31     
  Branches      3197      3197           
=========================================
+ Hits         12052     12083   +31     

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

} = token;
return {
[componentCls]: {
...resetComponent(token),
border: 'none',
position: 'fixed',
cursor: 'pointer',
zIndex: 99,
zIndex: token.zIndexPopup,
Copy link
Member

@MadCcc MadCcc Nov 14, 2023

Choose a reason for hiding this comment

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

这个建议不改,容易 break,其他的 zIndex 也是

Copy link
Contributor Author

Choose a reason for hiding this comment

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

要不把 zIndexPopup 删了?因为现在这个token也没用到。

@MadCcc
Copy link
Member

MadCcc commented Nov 14, 2023

https://codesandbox.io/s/antd-reproduction-template-forked-kn3jll?file=/index.js

@MadCcc MadCcc merged commit 0de7f06 into ant-design:feature Nov 15, 2023
53 of 54 checks passed
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

2 participants