Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions assets/index/Dialog.less
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
font-weight: bold;
}

&-extra {
padding-right: 36px;
}

&-section {
position: relative;
background-color: #ffffff;
Expand All @@ -43,15 +47,15 @@
color: #000;
text-shadow: 0 1px 0 #fff;
filter: alpha(opacity=20);
opacity: .2;
opacity: 0.2;
text-decoration: none;

&:disabled {
pointer-events: none;
}

&-x:after {
content: '×'
content: '×';
}

&:hover {
Expand All @@ -67,6 +71,9 @@
background: #fff;
color: #666;
border-bottom: 1px solid #e9e9e9;
display: flex;
align-items: center;
justify-content: space-between;
}

&-body {
Expand All @@ -85,7 +92,8 @@
animation-fill-mode: both;
}

&-zoom-enter, &-zoom-appear {
&-zoom-enter,
&-zoom-appear {
opacity: 0;
.effect();
animation-timing-function: cubic-bezier(0.08, 0.82, 0.17, 1);
Expand All @@ -98,7 +106,8 @@
animation-play-state: paused;
}

&-zoom-enter&-zoom-enter-active, &-zoom-appear&-zoom-appear-active {
&-zoom-enter&-zoom-enter-active,
&-zoom-appear&-zoom-appear-active {
animation-name: rcDialogZoomIn;
animation-play-state: running;
}
Expand All @@ -120,7 +129,6 @@
}
@keyframes rcDialogZoomOut {
0% {

transform: scale(1, 1);
}
100% {
Expand Down
1 change: 1 addition & 0 deletions docs/examples/ant-design.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const MyControl: React.FC = () => {
onClose={onClose}
style={style}
title="dialog1"
extra={<a onClick={onClick}>click me</a>}
mousePosition={mousePosition}
destroyOnHidden={destroyOnHidden}
closeIcon={useIcon ? getSvg(clearPath, {}, true) : undefined}
Expand Down
20 changes: 19 additions & 1 deletion src/Dialog/Content/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const Panel = React.forwardRef<PanelRef, PanelProps>((props, ref) => {
height,
classNames: modalClassNames,
styles: modalStyles,
extra,
} = props;

// ================================= Refs =================================
Expand Down Expand Up @@ -97,6 +98,15 @@ const Panel = React.forwardRef<PanelRef, PanelProps>((props, ref) => {
</div>
) : null;

const extraNode = extra ? (
<div
style={{ ...modalStyles?.extra }}
Copy link
Member

Choose a reason for hiding this comment

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

这里不用解构,直接放进去即可

className={classNames(`${prefixCls}-extra`, modalClassNames?.extra)}
>
{extra}
</div>
) : null;

const headerNode = title ? (
<div
className={classNames(`${prefixCls}-header`, modalClassNames?.header)}
Expand All @@ -109,8 +119,16 @@ const Panel = React.forwardRef<PanelRef, PanelProps>((props, ref) => {
>
{title}
</div>
{extraNode}
</div>
) : null;
) : (
<div
className={classNames(`${prefixCls}-header`, modalClassNames?.header)}
Copy link
Member

Choose a reason for hiding this comment

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

这里有点重复了,如果要做 header 始终保留效果,可以提一个 headerContent 变量进行填充

style={{ ...modalStyles?.header }}
>
{extraNode}
</div>
);

const closableObj = useMemo(() => {
if (typeof closable === 'object' && closable !== null) {
Expand Down
8 changes: 8 additions & 0 deletions src/Dialog/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,19 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
ariaId,
onVisibleChanged,
mousePosition,
extra,
} = props;

const dialogRef = useRef<{ nativeElement: HTMLElement } & CSSMotionStateRef>(null);

const panelRef = useRef<PanelRef>(null);

const hasExtra =
extra !== null &&
extra !== undefined &&
typeof extra !== 'boolean' &&
!(typeof extra === 'string' && extra.trim() === '');

// ============================== Refs ==============================
React.useImperativeHandle(ref, () => ({
...panelRef.current,
Expand Down Expand Up @@ -77,6 +84,7 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
<Panel
{...props}
ref={panelRef}
extra={hasExtra ? extra : null}
title={title}
ariaId={ariaId}
prefixCls={prefixCls}
Expand Down
7 changes: 7 additions & 0 deletions src/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const Dialog: React.FC<IDialogPropTypes> = (props) => {
rootStyle,
classNames: modalClassNames,
styles: modalStyles,
extra,
} = props;

if (process.env.NODE_ENV !== 'production') {
Expand All @@ -55,6 +56,12 @@ const Dialog: React.FC<IDialogPropTypes> = (props) => {
}
}

const hasExtra =
extra !== null &&
extra !== undefined &&
typeof extra !== 'boolean' &&
!(typeof extra === 'string' && extra.trim() === '');

const lastOutSideActiveElementRef = useRef<HTMLElement>(null);
const wrapperRef = useRef<HTMLDivElement>(null);
const contentRef = useRef<ContentRef>(null);
Expand Down
2 changes: 2 additions & 0 deletions src/IDialogPropTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ export type IDialogPropTypes = {

// Refs
panelRef?: React.Ref<HTMLDivElement>;

extra?: ReactNode;
};
3 changes: 3 additions & 0 deletions tests/__snapshots__/index.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ exports[`dialog add rootClassName and rootStyle should render correct 1`] = `
class="rc-dialog-close-x"
/>
</button>
<div
class="rc-dialog-header"
/>
<div
class="rc-dialog-body"
/>
Expand Down