Skip to content

Commit 5405d97

Browse files
author
刘欢
committed
feat: add className *-mask-blur
1 parent acf2569 commit 5405d97

File tree

6 files changed

+34
-10
lines changed

6 files changed

+34
-10
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ReactDOM.render(
6565
| title | String\|React.Element | | Title of the dialog | |
6666
| footer | React.Element | | footer of the dialog | |
6767
| closable | Boolean \| ({ closeIcon?: React.ReactNode; disabled?: boolean, afterClose:function } & React.AriaAttributes) | true | whether show close button | |
68-
| mask | Boolean | true | whether show mask | |
68+
| mask | Boolean \| `blur` | true | whether show mask | |
6969
| maskClosable | Boolean | true | whether click mask to close | |
7070
| keyboard | Boolean | true | whether support press esc to close | |
7171
| mousePosition | {x:number,y:number} | | set pageX and pageY of current mouse(it will cause transform origin to be set). | |
@@ -104,8 +104,7 @@ open coverage/ dir
104104

105105
rc-dialog is released under the MIT license.
106106

107-
108-
## 🤝 Contributing
107+
## 🤝 Contributing
109108

110109
<a href="https://openomy.app/github/react-component/dialog" target="_blank" style="display: block; width: 100%;" align="center">
111110
<img src="https://www.openomy.app/svg?repo=react-component/dialog&chart=bubble&latestMonth=24" target="_blank" alt="Contribution Leaderboard" style="display: block; width: 100%;" />

assets/index/Mask.less

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
height: 100%;
1111
filter: alpha(opacity=50);
1212
z-index: 1050;
13-
13+
&&-blur {
14+
backdrop-filter: blur(4px);
15+
}
1416
&-hidden {
1517
display: none;
1618
}
@@ -22,7 +24,8 @@
2224
animation-timing-function: cubic-bezier(0.55, 0, 0.55, 0.2);
2325
}
2426

25-
&-fade-enter,&-fade-appear {
27+
&-fade-enter,
28+
&-fade-appear {
2629
opacity: 0;
2730
.fade-effect();
2831
animation-play-state: paused;
@@ -33,7 +36,8 @@
3336
animation-play-state: paused;
3437
}
3538

36-
&-fade-enter&-fade-enter-active,&-fade-appear&-fade-appear-active {
39+
&-fade-enter&-fade-enter-active,
40+
&-fade-appear&-fade-appear-active {
3741
animation-name: rcDialogFadeIn;
3842
animation-play-state: running;
3943
}

src/Dialog/Mask.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ export type MaskProps = {
99
style?: React.CSSProperties;
1010
maskProps?: React.HTMLAttributes<HTMLDivElement>;
1111
className?: string;
12+
mask?: boolean | 'blur';
1213
};
1314

1415
const Mask: React.FC<MaskProps> = (props) => {
15-
const { prefixCls, style, visible, maskProps, motionName, className } = props;
16+
const { prefixCls, style, visible, maskProps, motionName, className, mask } = props;
1617
return (
1718
<CSSMotion
1819
key="mask"
@@ -24,7 +25,12 @@ const Mask: React.FC<MaskProps> = (props) => {
2425
<div
2526
ref={ref}
2627
style={{ ...motionStyle, ...style }}
27-
className={classNames(`${prefixCls}-mask`, motionClassName, className)}
28+
className={classNames(
29+
`${prefixCls}-mask`,
30+
motionClassName,
31+
className,
32+
mask === 'blur' && `${prefixCls}-mask-blur`,
33+
)}
2834
{...maskProps}
2935
/>
3036
)}

src/Dialog/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ const Dialog: React.FC<IDialogPropTypes> = (props) => {
198198
style={{ zIndex, ...maskStyle, ...modalStyles?.mask }}
199199
maskProps={maskProps}
200200
className={modalClassNames?.mask}
201+
mask={mask}
201202
/>
202203
<div
203204
tabIndex={-1}

src/IDialogPropTypes.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import type { GetContainer } from '@rc-component/util/lib/PortalWrapper';
22
import type { CSSProperties, ReactNode, SyntheticEvent } from 'react';
33

4-
export type SemanticName = 'header' | 'body' | 'footer' | 'container' | 'title' | 'wrapper' | 'mask';
4+
export type SemanticName =
5+
| 'header'
6+
| 'body'
7+
| 'footer'
8+
| 'container'
9+
| 'title'
10+
| 'wrapper'
11+
| 'mask';
512

613
export type ModalClassNames = Partial<Record<SemanticName, string>>;
714

@@ -18,7 +25,7 @@ export type IDialogPropTypes = {
1825
keyboard?: boolean;
1926
style?: CSSProperties;
2027
rootStyle?: CSSProperties;
21-
mask?: boolean;
28+
mask?: boolean | 'blur';
2229
children?: React.ReactNode;
2330
afterClose?: () => any;
2431
afterOpenChange?: (open: boolean) => void;

tests/index.spec.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,4 +752,11 @@ describe('dialog', () => {
752752
expect(document.querySelector('.rc-dialog')).toBeTruthy();
753753
expect(document.querySelector('.rc-dialog-close')).toBeFalsy();
754754
});
755+
756+
it('Dialog mask blur', () => {
757+
render(<Dialog mask="blur" visible/>);
758+
jest.runAllTimers();
759+
expect(document.querySelector('.rc-dialog-root')).toBeTruthy();
760+
expect(document.querySelector('.rc-dialog-mask-blur')).toBeTruthy();
761+
});
755762
});

0 commit comments

Comments
 (0)