mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-18 04:21:12 +02:00
add portals for modal
This commit is contained in:
@@ -55,6 +55,7 @@
|
|||||||
"firebase": "^5.0.4",
|
"firebase": "^5.0.4",
|
||||||
"preact": "^8.2.6",
|
"preact": "^8.2.6",
|
||||||
"preact-compat": "^3.17.0",
|
"preact-compat": "^3.17.0",
|
||||||
|
"preact-portal": "^1.1.3",
|
||||||
"preact-router": "^2.5.7",
|
"preact-router": "^2.5.7",
|
||||||
"split.js": "^1.3.5"
|
"split.js": "^1.3.5"
|
||||||
},
|
},
|
||||||
|
@@ -37,6 +37,11 @@ export default class CssSettingsModal extends Component {
|
|||||||
onBlur={cm => this.props.onChange(cm.getValue())}
|
onBlur={cm => this.props.onChange(cm.getValue())}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex flex-h-end">
|
||||||
|
<button class="btn" onClick={this.props.closeHandler}>
|
||||||
|
Apply and Close
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
|
import Portal from 'preact-portal';
|
||||||
|
|
||||||
export default class Modal extends Component {
|
export default class Modal extends Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@@ -18,18 +19,23 @@ export default class Modal extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
|
if (this.props.show != prevProps.show) {
|
||||||
document.body.classList[this.props.show ? 'add' : 'remove'](
|
document.body.classList[this.props.show ? 'add' : 'remove'](
|
||||||
'overlay-visible'
|
'overlay-visible'
|
||||||
);
|
);
|
||||||
|
if (this.props.show) {
|
||||||
if (this.props.show && !prevProps.show) {
|
// HACK: refs will evaluate on next tick due to portals
|
||||||
|
setTimeout(() => {
|
||||||
this.overlayEl.querySelector('.js-modal__close-btn').focus();
|
this.overlayEl.querySelector('.js-modal__close-btn').focus();
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
if (!this.props.show) return null;
|
if (!this.props.show) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<Portal into="body">
|
||||||
<div
|
<div
|
||||||
class={`${this.props.extraClasses || ''} modal is-modal-visible`}
|
class={`${this.props.extraClasses || ''} modal is-modal-visible`}
|
||||||
ref={el => (this.overlayEl = el)}
|
ref={el => (this.overlayEl = el)}
|
||||||
@@ -48,6 +54,7 @@ export default class Modal extends Component {
|
|||||||
{this.props.children}
|
{this.props.children}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</Portal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,7 @@ import KeyboardShortcutsModal from './KeyboardShortcutsModal';
|
|||||||
import { takeScreenshot } from '../takeScreenshot';
|
import { takeScreenshot } from '../takeScreenshot';
|
||||||
import AskToImportModal from './AskToImportModal';
|
import AskToImportModal from './AskToImportModal';
|
||||||
import { Alerts } from './Alerts';
|
import { Alerts } from './Alerts';
|
||||||
|
import Portal from 'preact-portal';
|
||||||
|
|
||||||
if (module.hot) {
|
if (module.hot) {
|
||||||
require('preact/debug');
|
require('preact/debug');
|
||||||
@@ -342,10 +343,6 @@ export default class App extends Component {
|
|||||||
window.searchInput.focus();
|
window.searchInput.focus();
|
||||||
} else {
|
} else {
|
||||||
window.searchInput.value = '';
|
window.searchInput.value = '';
|
||||||
// Give last focused editor, focus again
|
|
||||||
// if (editorWithFocus) {
|
|
||||||
// editorWithFocus.focus();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
document.body.classList[this.state.isSavedItemPaneOpen ? 'add' : 'remove'](
|
document.body.classList[this.state.isSavedItemPaneOpen ? 'add' : 'remove'](
|
||||||
'overlay-visible'
|
'overlay-visible'
|
||||||
@@ -413,12 +410,15 @@ export default class App extends Component {
|
|||||||
this.setState({ isAddLibraryModalOpen: true });
|
this.setState({ isAddLibraryModalOpen: true });
|
||||||
}
|
}
|
||||||
closeSavedItemsPane() {
|
closeSavedItemsPane() {
|
||||||
if (this.editorWithFocus) {
|
document.body.classList[this.state.isSavedItemPaneOpen ? 'add' : 'remove'](
|
||||||
this.editorWithFocus.focus();
|
'overlay-visible'
|
||||||
}
|
);
|
||||||
this.setState({
|
this.setState({
|
||||||
isSavedItemPaneOpen: false
|
isSavedItemPaneOpen: false
|
||||||
});
|
});
|
||||||
|
if (this.editorWithFocus) {
|
||||||
|
this.editorWithFocus.focus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
document.body.style.height = `${window.innerHeight}px`;
|
document.body.style.height = `${window.innerHeight}px`;
|
||||||
@@ -1095,7 +1095,9 @@ export default class App extends Component {
|
|||||||
dontAskBtnClickHandler={this.dontAskToImportAnymore.bind(this)}
|
dontAskBtnClickHandler={this.dontAskToImportAnymore.bind(this)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Portal into="body">
|
||||||
<div class="modal-overlay" />
|
<div class="modal-overlay" />
|
||||||
|
</Portal>
|
||||||
|
|
||||||
<svg
|
<svg
|
||||||
version="1.1"
|
version="1.1"
|
||||||
|
@@ -15,7 +15,8 @@ body {
|
|||||||
font-size: 87.5%;
|
font-size: 87.5%;
|
||||||
/* speocifically for mobile when keyboard is open */
|
/* speocifically for mobile when keyboard is open */
|
||||||
position: relative;
|
position: relative;
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Segoe UI Emoji', 'Segoe UI Symbol';
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial,
|
||||||
|
sans-serif, 'Segoe UI Emoji', 'Segoe UI Symbol';
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
@@ -196,7 +197,8 @@ textarea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.btn--primary {
|
.btn--primary {
|
||||||
background: var(--color-button) linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0px, transparent);
|
background: var(--color-button)
|
||||||
|
linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0px, transparent);
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,7 +568,11 @@ body>#demo-frame {
|
|||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
padding: 0px 8px;
|
padding: 0px 8px;
|
||||||
border: 1px solid rgba(0, 0, 0, 0.9);
|
border: 1px solid rgba(0, 0, 0, 0.9);
|
||||||
background: linear-gradient( 180deg, rgba(0, 0, 0, 0.5) 0, rgba(255, 255, 255, 0.1) 100%);
|
background: linear-gradient(
|
||||||
|
180deg,
|
||||||
|
rgba(0, 0, 0, 0.5) 0,
|
||||||
|
rgba(255, 255, 255, 0.1) 100%
|
||||||
|
);
|
||||||
/*text-shadow: 0px 1px 1px rgba(0,0,0,1);*/
|
/*text-shadow: 0px 1px 1px rgba(0,0,0,1);*/
|
||||||
box-shadow: 0 -1px 0px 0 rgba(255, 255, 255, 0.15);
|
box-shadow: 0 -1px 0px 0 rgba(255, 255, 255, 0.15);
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
@@ -832,6 +838,7 @@ body>#demo-frame {
|
|||||||
transform: translateX(0);
|
transform: translateX(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.overlay-visible .modal-overlay,
|
||||||
.is-modal-visible ~ .modal-overlay,
|
.is-modal-visible ~ .modal-overlay,
|
||||||
.saved-items-pane.is-open ~ .modal-overlay {
|
.saved-items-pane.is-open ~ .modal-overlay {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
@@ -1440,7 +1447,8 @@ body:not(.is-app) .show-when-app {
|
|||||||
width: 80px;
|
width: 80px;
|
||||||
height: 80px;
|
height: 80px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background: white url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="width:32px;height:32px" viewBox="0 0 24 24"><path fill="limegreen" d="M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2M11,16.5L18,9.5L16.59,8.09L11,13.67L7.91,10.59L6.5,12L11,16.5Z" /></svg>');
|
background: white
|
||||||
|
url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="width:32px;height:32px" viewBox="0 0 24 24"><path fill="limegreen" d="M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2M11,16.5L18,9.5L16.59,8.09L11,13.67L7.91,10.59L6.5,12L11,16.5Z" /></svg>');
|
||||||
}
|
}
|
||||||
|
|
||||||
.bookmarklet {
|
.bookmarklet {
|
||||||
|
@@ -7597,6 +7597,10 @@ preact-compat@^3.14.3, preact-compat@^3.17.0:
|
|||||||
prop-types "^15.5.8"
|
prop-types "^15.5.8"
|
||||||
standalone-react-addons-pure-render-mixin "^0.1.1"
|
standalone-react-addons-pure-render-mixin "^0.1.1"
|
||||||
|
|
||||||
|
preact-portal@^1.1.3:
|
||||||
|
version "1.1.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/preact-portal/-/preact-portal-1.1.3.tgz#22cdd3ecf6ad9aaa3f830607a9c6591de90aedb7"
|
||||||
|
|
||||||
preact-render-spy@^1.2.1:
|
preact-render-spy@^1.2.1:
|
||||||
version "1.3.0"
|
version "1.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/preact-render-spy/-/preact-render-spy-1.3.0.tgz#f64b83f4de33d9696e69e5b08c4ae5e29decd6d1"
|
resolved "https://registry.yarnpkg.com/preact-render-spy/-/preact-render-spy-1.3.0.tgz#f64b83f4de33d9696e69e5b08c4ae5e29decd6d1"
|
||||||
|
Reference in New Issue
Block a user