-
Notifications
You must be signed in to change notification settings - Fork 139
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 12 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; | ||||||||||||||||||||||||||||||
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. https://developer.mozilla.org/en-US/docs/Web/CSS/interpolate-size#browser_compatibility 浏览器兼容性有点差,这个会没办法在 antd 中使用。 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.
有什么好建议吗 |
||||||||||||||||||||||||||||||
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 | ||||
---|---|---|---|---|---|---|
@@ -1,11 +1,10 @@ | ||||||
import classNames from 'classnames'; | ||||||
import CSSMotion from '@rc-component/motion'; | ||||||
import KeyCode from '@rc-component/util/lib/KeyCode'; | ||||||
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 +32,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) { | ||||||
|
@@ -67,6 +68,8 @@ const CollapsePanel = React.forwardRef<HTMLDivElement, CollapsePanelProps>((prop | |||||
[`${prefixCls}-item-disabled`]: disabled, | ||||||
}, | ||||||
className, | ||||||
// ? 修改为details实现后动画是作用在details元素上 需要将motionName设置在details上 | ||||||
openMotion?.motionName, | ||||||
); | ||||||
|
||||||
const headerClassName = classNames( | ||||||
|
@@ -79,16 +82,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,33 +101,18 @@ const CollapsePanel = React.forwardRef<HTMLDivElement, CollapsePanelProps>((prop | |||||
{header} | ||||||
</span> | ||||||
{ifExtraExist && <div className={`${prefixCls}-extra`}>{extra}</div>} | ||||||
</div> | ||||||
<CSSMotion | ||||||
visible={isActive} | ||||||
leavedClassName={`${prefixCls}-panel-hidden`} | ||||||
{...openMotion} | ||||||
</summary> | ||||||
<PanelContent | ||||||
prefixCls={prefixCls} | ||||||
classNames={customizeClassNames} | ||||||
styles={styles} | ||||||
isActive={isActive} | ||||||
forceRender={forceRender} | ||||||
removeOnLeave={destroyOnHidden} | ||||||
role={accordion ? 'tabpanel' : undefined} | ||||||
> | ||||||
{({ className: motionClassName, style: motionStyle }, motionRef) => { | ||||||
return ( | ||||||
<PanelContent | ||||||
ref={motionRef} | ||||||
prefixCls={prefixCls} | ||||||
className={motionClassName} | ||||||
classNames={customizeClassNames} | ||||||
style={motionStyle} | ||||||
styles={styles} | ||||||
isActive={isActive} | ||||||
forceRender={forceRender} | ||||||
role={accordion ? 'tabpanel' : undefined} | ||||||
> | ||||||
{children} | ||||||
</PanelContent> | ||||||
); | ||||||
}} | ||||||
</CSSMotion> | ||||||
</div> | ||||||
{children} | ||||||
</PanelContent> | ||||||
</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.