-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: export dialog panel * fix: props pass
- Loading branch information
Showing
6 changed files
with
169 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## pure-debug | ||
|
||
<code src="../examples/pure.tsx"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint no-console:0 */ | ||
import * as React from 'react'; | ||
import 'rc-select/assets/index.less'; | ||
import { Panel } from 'rc-dialog'; | ||
import '../../assets/index.less'; | ||
|
||
export default () => ( | ||
<Panel prefixCls="rc-dialog" title="Title" closable> | ||
Hello World! | ||
</Panel> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import React, { useRef } from 'react'; | ||
import classNames from 'classnames'; | ||
import type { IDialogChildProps } from '..'; | ||
import MemoChildren from './MemoChildren'; | ||
|
||
const sentinelStyle = { width: 0, height: 0, overflow: 'hidden', outline: 'none' }; | ||
|
||
export interface PanelProps extends Omit<IDialogChildProps, 'getOpenCount'> { | ||
prefixCls: string; | ||
ariaId?: string; | ||
onMouseDown?: React.MouseEventHandler; | ||
onMouseUp?: React.MouseEventHandler; | ||
holderRef?: React.Ref<HTMLDivElement>; | ||
} | ||
|
||
export type ContentRef = { | ||
focus: () => void; | ||
changeActive: (next: boolean) => void; | ||
}; | ||
|
||
const Panel = React.forwardRef<ContentRef, PanelProps>((props, ref) => { | ||
const { | ||
prefixCls, | ||
className, | ||
style, | ||
title, | ||
ariaId, | ||
footer, | ||
closable, | ||
closeIcon, | ||
onClose, | ||
children, | ||
bodyStyle, | ||
bodyProps, | ||
modalRender, | ||
onMouseDown, | ||
onMouseUp, | ||
holderRef, | ||
visible, | ||
forceRender, | ||
width, | ||
height, | ||
} = props; | ||
|
||
// ================================= Refs ================================= | ||
const sentinelStartRef = useRef<HTMLDivElement>(); | ||
const sentinelEndRef = useRef<HTMLDivElement>(); | ||
|
||
React.useImperativeHandle(ref, () => ({ | ||
focus: () => { | ||
sentinelStartRef.current?.focus(); | ||
}, | ||
changeActive: (next) => { | ||
const { activeElement } = document; | ||
if (next && activeElement === sentinelEndRef.current) { | ||
sentinelStartRef.current.focus(); | ||
} else if (!next && activeElement === sentinelStartRef.current) { | ||
sentinelEndRef.current.focus(); | ||
} | ||
}, | ||
})); | ||
|
||
// ================================ Style ================================= | ||
const contentStyle: React.CSSProperties = {}; | ||
|
||
if (width !== undefined) { | ||
contentStyle.width = width; | ||
} | ||
if (height !== undefined) { | ||
contentStyle.height = height; | ||
} | ||
// ================================ Render ================================ | ||
let footerNode: React.ReactNode; | ||
if (footer) { | ||
footerNode = <div className={`${prefixCls}-footer`}>{footer}</div>; | ||
} | ||
|
||
let headerNode: React.ReactNode; | ||
if (title) { | ||
headerNode = ( | ||
<div className={`${prefixCls}-header`}> | ||
<div className={`${prefixCls}-title`} id={ariaId}> | ||
{title} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
let closer: React.ReactNode; | ||
if (closable) { | ||
closer = ( | ||
<button type="button" onClick={onClose} aria-label="Close" className={`${prefixCls}-close`}> | ||
{closeIcon || <span className={`${prefixCls}-close-x`} />} | ||
</button> | ||
); | ||
} | ||
|
||
const content = ( | ||
<div className={`${prefixCls}-content`}> | ||
{closer} | ||
{headerNode} | ||
<div className={`${prefixCls}-body`} style={bodyStyle} {...bodyProps}> | ||
{children} | ||
</div> | ||
{footerNode} | ||
</div> | ||
); | ||
|
||
return ( | ||
<div | ||
key="dialog-element" | ||
role="dialog" | ||
aria-labelledby={title ? ariaId : null} | ||
aria-modal="true" | ||
ref={holderRef} | ||
style={{ | ||
...style, | ||
...contentStyle, | ||
}} | ||
className={classNames(prefixCls, className)} | ||
onMouseDown={onMouseDown} | ||
onMouseUp={onMouseUp} | ||
> | ||
<div tabIndex={0} ref={sentinelStartRef} style={sentinelStyle} aria-hidden="true" /> | ||
<MemoChildren shouldUpdate={visible || forceRender}> | ||
{modalRender ? modalRender(content) : content} | ||
</MemoChildren> | ||
<div tabIndex={0} ref={sentinelEndRef} style={sentinelStyle} aria-hidden="true" /> | ||
</div> | ||
); | ||
}); | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
Panel.displayName = 'Panel'; | ||
} | ||
|
||
export default Panel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import DialogWrap from './DialogWrap'; | ||
import { IDialogPropTypes as DialogProps } from './IDialogPropTypes'; | ||
import Panel from './Dialog/Content/Panel'; | ||
import type { IDialogPropTypes as DialogProps } from './IDialogPropTypes'; | ||
|
||
export { DialogProps }; | ||
export type { DialogProps }; | ||
export { Panel }; | ||
|
||
export default DialogWrap; |
79649e1
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.
Successfully deployed to the following URLs:
dialog – ./
dialog-amber.vercel.app
dialog-react-component.vercel.app
dialog-git-master-react-component.vercel.app