-
Notifications
You must be signed in to change notification settings - Fork 137
refactor: 重构collapse为details实现 #362
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
base: master
Are you sure you want to change the base?
Changes from all commits
3cfdc2e
5ffc99a
df7f09e
ce3ba4c
ff26366
925207f
5026c13
9f5873f
a834f41
3bd0abf
60430c7
4ddcf52
dba7f64
5ed0807
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,11 @@ | |||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
@import './motion.less'; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// ::view-transition-old(root), /* 旧视图*/ | ||||||||||||||||||||||||||||||
// ::view-transition-new(root) { /* 新视图*/ | ||||||||||||||||||||||||||||||
// animation-duration: 0.6s; | ||||||||||||||||||||||||||||||
// } | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
#arrow { | ||||||||||||||||||||||||||||||
.common() { | ||||||||||||||||||||||||||||||
width: 0; | ||||||||||||||||||||||||||||||
|
@@ -35,6 +40,20 @@ | |||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
& > &-item { | ||||||||||||||||||||||||||||||
border-top: @borderStyle; | ||||||||||||||||||||||||||||||
list-style-position: outside; | ||||||||||||||||||||||||||||||
interpolate-size: allow-keywords; | ||||||||||||||||||||||||||||||
overflow: hidden; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
&::details-content { | ||||||||||||||||||||||||||||||
block-size: 0; | ||||||||||||||||||||||||||||||
transition: block-size 0.6s, content-visibility 0.6s; | ||||||||||||||||||||||||||||||
transition-behavior: allow-discrete; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
&[open]::details-content { | ||||||||||||||||||||||||||||||
Comment on lines
+47
to
+53
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. The CSS pseudo-element
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||
block-size: auto; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
Comment on lines
+43
to
+55
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. 🛠️ Refactor suggestion 使用现代CSS特性实现动画过渡 代码引入了一些新的CSS特性来实现基于
这些CSS特性是比较新的,需要注意浏览器兼容性问题。与 建议添加一些注释说明这些属性的浏览器兼容性要求,或考虑为不支持这些特性的浏览器提供兼容性样式。 🤖 Prompt for AI Agents (early access)
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. 兼容性如何? 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.
这只是demo实现,ant实现上考虑下css兼容吧 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. 有方案么,最好提前考虑起来。 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.
你看下是不是可行, 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. 我尝试引入startTransition,编译报错,需要升级哪里吗? |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
&:first-child { | ||||||||||||||||||||||||||||||
border-top: none; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,7 +6,7 @@ import type { | |||||||||||||||||||||
|
||||||||||||||||||||||
const getCollapsedHeight: MotionEventHandler = () => ({ height: 0, opacity: 0 }); | ||||||||||||||||||||||
const getRealHeight: MotionEventHandler = (node) => ({ height: node.scrollHeight, opacity: 1 }); | ||||||||||||||||||||||
const getCurrentHeight: MotionEventHandler = (node) => ({ height: node.offsetHeight }); | ||||||||||||||||||||||
const getCurrentHeight: MotionEventHandler = (node) => ({ height: node?.offsetHeight ?? 0 }); | ||||||||||||||||||||||
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. 可选链可能触发 TS18048 编译错误
建议两种修复思路,任选其一:
-const getCurrentHeight: MotionEventHandler = (node) => ({ height: node?.offsetHeight ?? 0 });
+const getCurrentHeight: MotionEventHandler = (node) => ({ height: node ? node.offsetHeight : 0 });
-const getCurrentHeight: MotionEventHandler = (node) => ({ height: node?.offsetHeight ?? 0 });
+const getCurrentHeight: MotionEventHandler = (node?: HTMLElement | null) => ({
+ height: node?.offsetHeight ?? 0,
+}); 请根据实际调用情况选择,以确保通过 CI 并避免隐藏的空值问题。 📝 Committable suggestion
Suggested change
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||
const skipOpacityTransition: MotionEndEventHandler = (_, event) => | ||||||||||||||||||||||
(event as TransitionEvent).propertyName === 'height'; | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,11 +1,11 @@ | ||||||
import classNames from 'classnames'; | ||||||
import CSSMotion from '@rc-component/motion'; | ||||||
import KeyCode from '@rc-component/util/lib/KeyCode'; | ||||||
import CSSMotion from '@rc-component/motion'; | ||||||
import React from 'react'; | ||||||
import type { CollapsePanelProps } from './interface'; | ||||||
import PanelContent from './PanelContent'; | ||||||
|
||||||
const CollapsePanel = React.forwardRef<HTMLDivElement, CollapsePanelProps>((props, ref) => { | ||||||
const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((props, ref) => { | ||||||
const { | ||||||
showArrow = true, | ||||||
headerClass, | ||||||
|
@@ -33,8 +33,10 @@ const CollapsePanel = React.forwardRef<HTMLDivElement, CollapsePanelProps>((prop | |||||
const ifExtraExist = extra !== null && extra !== undefined && typeof extra !== 'boolean'; | ||||||
|
||||||
const collapsibleProps = { | ||||||
onClick: () => { | ||||||
onClick: (e: React.MouseEvent) => { | ||||||
onItemClick?.(panelKey); | ||||||
e.preventDefault(); | ||||||
e.stopPropagation(); | ||||||
}, | ||||||
onKeyDown: (e: React.KeyboardEvent) => { | ||||||
if (e.key === 'Enter' || e.keyCode === KeyCode.ENTER || e.which === KeyCode.ENTER) { | ||||||
|
@@ -79,16 +81,16 @@ const CollapsePanel = React.forwardRef<HTMLDivElement, CollapsePanelProps>((prop | |||||
); | ||||||
|
||||||
// ======================== HeaderProps ======================== | ||||||
const headerProps: React.HTMLAttributes<HTMLDivElement> = { | ||||||
const headerProps: React.HTMLAttributes<HTMLElement> = { | ||||||
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. [nitpick] Since
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
className: headerClassName, | ||||||
style: styles?.header, | ||||||
...(['header', 'icon'].includes(collapsible) ? {} : collapsibleProps), | ||||||
}; | ||||||
|
||||||
// ======================== Render ======================== | ||||||
return ( | ||||||
<div {...resetProps} ref={ref} className={collapsePanelClassNames}> | ||||||
<div {...headerProps}> | ||||||
<details {...resetProps} ref={ref} className={collapsePanelClassNames} open={isActive}> | ||||||
<summary {...headerProps}> | ||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
{showArrow && iconNode} | ||||||
<span | ||||||
className={classNames(`${prefixCls}-title`, customizeClassNames?.title)} | ||||||
|
@@ -98,7 +100,7 @@ const CollapsePanel = React.forwardRef<HTMLDivElement, CollapsePanelProps>((prop | |||||
{header} | ||||||
</span> | ||||||
{ifExtraExist && <div className={`${prefixCls}-extra`}>{extra}</div>} | ||||||
</div> | ||||||
</summary> | ||||||
<CSSMotion | ||||||
visible={isActive} | ||||||
leavedClassName={`${prefixCls}-panel-hidden`} | ||||||
|
@@ -124,7 +126,7 @@ const CollapsePanel = React.forwardRef<HTMLDivElement, CollapsePanelProps>((prop | |||||
); | ||||||
}} | ||||||
</CSSMotion> | ||||||
</div> | ||||||
</details> | ||||||
); | ||||||
}); | ||||||
|
||||||
|
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.
[nitpick] This commented-out view-transition snippet appears stale. Removing or relocating it behind a feature flag will keep the stylesheet clearer.
Copilot uses AI. Check for mistakes.