Skip to content

Commit f260866

Browse files
committed
feat: 增加extra
1 parent d998708 commit f260866

File tree

7 files changed

+53
-6
lines changed

7 files changed

+53
-6
lines changed

assets/index/Dialog.less

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
font-weight: bold;
2323
}
2424

25+
&-extra {
26+
padding-right: 36px;
27+
}
28+
2529
&-section {
2630
position: relative;
2731
background-color: #ffffff;
@@ -43,15 +47,15 @@
4347
color: #000;
4448
text-shadow: 0 1px 0 #fff;
4549
filter: alpha(opacity=20);
46-
opacity: .2;
50+
opacity: 0.2;
4751
text-decoration: none;
4852

4953
&:disabled {
5054
pointer-events: none;
5155
}
5256

5357
&-x:after {
54-
content: '×'
58+
content: '×';
5559
}
5660

5761
&:hover {
@@ -67,6 +71,9 @@
6771
background: #fff;
6872
color: #666;
6973
border-bottom: 1px solid #e9e9e9;
74+
display: flex;
75+
align-items: center;
76+
justify-content: space-between;
7077
}
7178

7279
&-body {
@@ -85,7 +92,8 @@
8592
animation-fill-mode: both;
8693
}
8794

88-
&-zoom-enter, &-zoom-appear {
95+
&-zoom-enter,
96+
&-zoom-appear {
8997
opacity: 0;
9098
.effect();
9199
animation-timing-function: cubic-bezier(0.08, 0.82, 0.17, 1);
@@ -98,7 +106,8 @@
98106
animation-play-state: paused;
99107
}
100108

101-
&-zoom-enter&-zoom-enter-active, &-zoom-appear&-zoom-appear-active {
109+
&-zoom-enter&-zoom-enter-active,
110+
&-zoom-appear&-zoom-appear-active {
102111
animation-name: rcDialogZoomIn;
103112
animation-play-state: running;
104113
}
@@ -120,7 +129,6 @@
120129
}
121130
@keyframes rcDialogZoomOut {
122131
0% {
123-
124132
transform: scale(1, 1);
125133
}
126134
100% {

docs/examples/ant-design.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const MyControl: React.FC = () => {
9696
onClose={onClose}
9797
style={style}
9898
title="dialog1"
99+
extra={<a onClick={onClick}>click me</a>}
99100
mousePosition={mousePosition}
100101
destroyOnHidden={destroyOnHidden}
101102
closeIcon={useIcon ? getSvg(clearPath, {}, true) : undefined}

src/Dialog/Content/Panel.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const Panel = React.forwardRef<PanelRef, PanelProps>((props, ref) => {
5454
height,
5555
classNames: modalClassNames,
5656
styles: modalStyles,
57+
extra,
5758
} = props;
5859

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

101+
const extraNode = extra ? (
102+
<div
103+
style={{ ...modalStyles?.extra }}
104+
className={classNames(`${prefixCls}-extra`, modalClassNames?.extra)}
105+
>
106+
{extra}
107+
</div>
108+
) : null;
109+
100110
const headerNode = title ? (
101111
<div
102112
className={classNames(`${prefixCls}-header`, modalClassNames?.header)}
@@ -109,8 +119,16 @@ const Panel = React.forwardRef<PanelRef, PanelProps>((props, ref) => {
109119
>
110120
{title}
111121
</div>
122+
{extraNode}
112123
</div>
113-
) : null;
124+
) : (
125+
<div
126+
className={classNames(`${prefixCls}-header`, modalClassNames?.header)}
127+
style={{ ...modalStyles?.header }}
128+
>
129+
{extraNode}
130+
</div>
131+
);
114132

115133
const closableObj = useMemo(() => {
116134
if (typeof closable === 'object' && closable !== null) {

src/Dialog/Content/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,19 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
3030
ariaId,
3131
onVisibleChanged,
3232
mousePosition,
33+
extra,
3334
} = props;
3435

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

3738
const panelRef = useRef<PanelRef>(null);
3839

40+
const hasExtra =
41+
extra !== null &&
42+
extra !== undefined &&
43+
typeof extra !== 'boolean' &&
44+
!(typeof extra === 'string' && extra.trim() === '');
45+
3946
// ============================== Refs ==============================
4047
React.useImperativeHandle(ref, () => ({
4148
...panelRef.current,
@@ -77,6 +84,7 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
7784
<Panel
7885
{...props}
7986
ref={panelRef}
87+
extra={hasExtra ? extra : null}
8088
title={title}
8189
ariaId={ariaId}
8290
prefixCls={prefixCls}

src/Dialog/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const Dialog: React.FC<IDialogPropTypes> = (props) => {
4343
rootStyle,
4444
classNames: modalClassNames,
4545
styles: modalStyles,
46+
extra,
4647
} = props;
4748

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

59+
const hasExtra =
60+
extra !== null &&
61+
extra !== undefined &&
62+
typeof extra !== 'boolean' &&
63+
!(typeof extra === 'string' && extra.trim() === '');
64+
5865
const lastOutSideActiveElementRef = useRef<HTMLElement>(null);
5966
const wrapperRef = useRef<HTMLDivElement>(null);
6067
const contentRef = useRef<ContentRef>(null);

src/IDialogPropTypes.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ export type IDialogPropTypes = {
5555

5656
// Refs
5757
panelRef?: React.Ref<HTMLDivElement>;
58+
59+
extra?: ReactNode;
5860
};

tests/__snapshots__/index.spec.tsx.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ exports[`dialog add rootClassName and rootStyle should render correct 1`] = `
3535
class="rc-dialog-close-x"
3636
/>
3737
</button>
38+
<div
39+
class="rc-dialog-header"
40+
/>
3841
<div
3942
class="rc-dialog-body"
4043
/>

0 commit comments

Comments
 (0)