Skip to content

Commit a048424

Browse files
committed
feat: add blur() effect for <Modal>
This allows to do frosted glass effect
1 parent a2e8a8b commit a048424

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

src/Modal/__story__/story.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ storiesOf('UI/Modal', module)
5858
<Toggle>{({on, toggle}) =>
5959
<div>
6060
<button onClick={toggle}>Open dialog</button>
61-
{on && <Modal color='tomato' onClick={toggle} onEsc={toggle}>
61+
{on && <Modal color='rgba(0,0,0,.3)' onClick={toggle} onEsc={toggle}>
6262
<div
6363
style={{
6464
width: 300,

src/Modal/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let id = 0;
99
const ESC = 27;
1010

1111
export interface IModalProps extends IOverlayProps {
12+
blur?: number;
1213
dontLockFocus?: boolean;
1314
onEsc?: (event: KeyboardEvent) => void;
1415
onClose?: () => void;
@@ -21,6 +22,10 @@ export interface IModalState {
2122
}
2223

2324
export class Modal extends Component<IModalProps, IModalState> {
25+
static defaultProps = {
26+
blur: 5
27+
};
28+
2429
id: number;
2530
el: HTMLElement = null;
2631
activeEl: Element; // Previous active element;
@@ -67,8 +72,9 @@ export class Modal extends Component<IModalProps, IModalState> {
6772
const lock = sib.__libreact_lock;
6873

6974
sib.inert = lock.inert;
70-
sibling.style.setProperty('pointer-events', lock.pointerEvents),
71-
sibling.style.setProperty('user-select', lock.userSelect),
75+
sibling.style.setProperty('pointer-events', lock.pointerEvents);
76+
sibling.style.setProperty('user-select', lock.userSelect);
77+
sibling.style.setProperty('filter', lock.filter || 'none');
7278

7379
sibling.removeAttribute('aria-hidden');
7480
delete sib.__libreact_lock;
@@ -108,17 +114,25 @@ export class Modal extends Component<IModalProps, IModalState> {
108114
}
109115

110116
const sib = sibling as any;
117+
let filter = sibling.style.getPropertyValue('filter');
118+
119+
if (filter === 'none') {
120+
filter = '';
121+
}
111122

112123
sib.__libreact_lock = {
113124
owner: this,
114125
inert: sib.inert,
115126
pointerEvents: sibling.style.getPropertyValue('pointer-events'),
116127
userSelect: sibling.style.getPropertyValue('user-select'),
128+
filter
117129
};
118130

119131
sib.inert = true;
120132
sibling.style.setProperty('pointer-events', 'none');
121133
sibling.style.setProperty('user-select', 'none');
134+
console.log('F', 'filter', (filter ? filter + ',' : '') + `blur(${this.props.blur}px)`);
135+
sibling.style.setProperty('filter', (filter ? filter + ',' : '') + `blur(${this.props.blur}px)`);
122136
sibling.setAttribute('aria-hidden', 'true');
123137
}
124138

src/Overlay/__story__/story.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ storiesOf('UI/Overlay', module)
99
.add('Documentation', () => h(ShowDocs, {md: require('../../../docs/en/Overlay.md')}))
1010
.add('Basic example', () =>
1111
<div>
12+
<div style={{width: 100, height: 100, background: 'tomato'}} />
1213
<Overlay>
1314
foobar
1415
</Overlay>

src/Overlay/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export class Overlay extends Component<IOverlayProps, IOverlayState> {
4040
style.background = this.props.color;
4141
style.transition = this.props.time + 'ms opacity';
4242
style.opacity = 0;
43-
4443
style.display = 'flex';
4544
style.alignItems = 'center';
4645
style.justifyContent = 'center';

0 commit comments

Comments
 (0)