diff --git a/docs/demo/pure.md b/docs/demo/pure.md new file mode 100644 index 00000000..fa2582e8 --- /dev/null +++ b/docs/demo/pure.md @@ -0,0 +1,3 @@ +## pure-debug + + diff --git a/docs/examples/pure.tsx b/docs/examples/pure.tsx new file mode 100644 index 00000000..3a34c190 --- /dev/null +++ b/docs/examples/pure.tsx @@ -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 () => ( + + Hello World! + +); diff --git a/src/Dialog/Content/Panel.tsx b/src/Dialog/Content/Panel.tsx new file mode 100644 index 00000000..53004f23 --- /dev/null +++ b/src/Dialog/Content/Panel.tsx @@ -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 { + prefixCls: string; + ariaId?: string; + onMouseDown?: React.MouseEventHandler; + onMouseUp?: React.MouseEventHandler; + holderRef?: React.Ref; +} + +export type ContentRef = { + focus: () => void; + changeActive: (next: boolean) => void; +}; + +const Panel = React.forwardRef((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(); + const sentinelEndRef = useRef(); + + 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 =
{footer}
; + } + + let headerNode: React.ReactNode; + if (title) { + headerNode = ( +
+
+ {title} +
+
+ ); + } + + let closer: React.ReactNode; + if (closable) { + closer = ( + + ); + } + + const content = ( +
+ {closer} + {headerNode} +
+ {children} +
+ {footerNode} +
+ ); + + return ( +
+