forked from newthuhole/hole_thu_frontend
add pressure
This commit is contained in:
5
package-lock.json
generated
5
package-lock.json
generated
@@ -8505,6 +8505,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/preserve/-/preserve-0.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/preserve/-/preserve-0.2.0.tgz",
|
||||||
"integrity": "sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks="
|
"integrity": "sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks="
|
||||||
},
|
},
|
||||||
|
"pressure": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/pressure/-/pressure-2.1.2.tgz",
|
||||||
|
"integrity": "sha512-ZSargPrrtyDGsWKFQvk3e5i/JM24pRTlb7Wu6RNtQiSzSAwdNw7hmB4+tQ/V2AhC3u4YGx3q2kMYEgtr/6ctXQ=="
|
||||||
|
},
|
||||||
"pretty-bytes": {
|
"pretty-bytes": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-4.0.2.tgz",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"load-script": "^1.0.0",
|
"load-script": "^1.0.0",
|
||||||
|
"pressure": "^2.1.2",
|
||||||
"react": "^16.4.2",
|
"react": "^16.4.2",
|
||||||
"react-dom": "^16.4.2",
|
"react-dom": "^16.4.2",
|
||||||
"react-lazyload": "latest",
|
"react-lazyload": "latest",
|
||||||
|
|||||||
19
src/App.js
19
src/App.js
@@ -2,14 +2,15 @@ import React, {Component} from 'react';
|
|||||||
import {Flow} from './Flows';
|
import {Flow} from './Flows';
|
||||||
import {Title} from './Title';
|
import {Title} from './Title';
|
||||||
import {Sidebar} from './Sidebar';
|
import {Sidebar} from './Sidebar';
|
||||||
|
import {PressureHelper} from './PressureHelper';
|
||||||
import {TokenCtx} from './UserAction';
|
import {TokenCtx} from './UserAction';
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state={
|
this.state={
|
||||||
sidebar_title: null,
|
sidebar_title: '',
|
||||||
sidebar_content: null,
|
sidebar_content: null, // determine status of sidebar
|
||||||
mode: 'list', // list, single, search, attention
|
mode: 'list', // list, single, search, attention
|
||||||
search_text: null,
|
search_text: null,
|
||||||
flow_render_key: +new Date(),
|
flow_render_key: +new Date(),
|
||||||
@@ -17,6 +18,17 @@ class App extends Component {
|
|||||||
};
|
};
|
||||||
this.show_sidebar_bound=this.show_sidebar.bind(this);
|
this.show_sidebar_bound=this.show_sidebar.bind(this);
|
||||||
this.set_mode_bound=this.set_mode.bind(this);
|
this.set_mode_bound=this.set_mode.bind(this);
|
||||||
|
this.on_pressure_bound=this.on_pressure.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
on_pressure() {
|
||||||
|
if(this.state.sidebar_content)
|
||||||
|
this.setState({
|
||||||
|
sidebar_title: '',
|
||||||
|
sidebar_content: null,
|
||||||
|
});
|
||||||
|
else
|
||||||
|
this.set_mode('list',null);
|
||||||
}
|
}
|
||||||
|
|
||||||
show_sidebar(title,content) {
|
show_sidebar(title,content) {
|
||||||
@@ -45,7 +57,7 @@ class App extends Component {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
}}>
|
}}>
|
||||||
<div>
|
<PressureHelper callback={this.on_pressure_bound} />
|
||||||
<div className="bg-img" style={{
|
<div className="bg-img" style={{
|
||||||
backgroundImage: 'url('+(localStorage['REPLACE_ERIRI_WITH_URL'] || 'static/eriri_bg.jpg')+')'
|
backgroundImage: 'url('+(localStorage['REPLACE_ERIRI_WITH_URL'] || 'static/eriri_bg.jpg')+')'
|
||||||
}} />
|
}} />
|
||||||
@@ -63,7 +75,6 @@ class App extends Component {
|
|||||||
sidebar_content: null,
|
sidebar_content: null,
|
||||||
});
|
});
|
||||||
}} content={this.state.sidebar_content} title={this.state.sidebar_title} />
|
}} content={this.state.sidebar_content} title={this.state.sidebar_title} />
|
||||||
</div>
|
|
||||||
</TokenCtx.Provider>
|
</TokenCtx.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/PressureHelper.css
Normal file
17
src/PressureHelper.css
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
.pressure-box {
|
||||||
|
border: 500px /* also change js! */ solid orange;
|
||||||
|
position: fixed;
|
||||||
|
margin: auto;
|
||||||
|
z-index: 100;
|
||||||
|
pointer-events: none;
|
||||||
|
transition:
|
||||||
|
top 100ms linear,
|
||||||
|
bottom 100ms linear,
|
||||||
|
left 100ms linear,
|
||||||
|
right 100ms linear;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pressure-box-fired {
|
||||||
|
border-color: orangered;
|
||||||
|
pointer-events: initial !important;
|
||||||
|
}
|
||||||
73
src/PressureHelper.js
Normal file
73
src/PressureHelper.js
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import React, {Component} from 'react';
|
||||||
|
import Pressure from 'pressure';
|
||||||
|
|
||||||
|
import './PressureHelper.css';
|
||||||
|
|
||||||
|
const THRESHOLD=.4;
|
||||||
|
const MULTIPLIER=25;
|
||||||
|
const BORDER_WIDTH=500; // also change css!
|
||||||
|
|
||||||
|
export class PressureHelper extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state={
|
||||||
|
level: 0,
|
||||||
|
fired: false,
|
||||||
|
};
|
||||||
|
this.callback=props.callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
do_fire() {
|
||||||
|
this.setState({
|
||||||
|
level: 1,
|
||||||
|
fired: true,
|
||||||
|
});
|
||||||
|
this.callback();
|
||||||
|
window.setTimeout(()=>{
|
||||||
|
this.setState({
|
||||||
|
level: 0,
|
||||||
|
fired: false,
|
||||||
|
});
|
||||||
|
},300);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
Pressure.set(document.body, {
|
||||||
|
change: (force)=>{
|
||||||
|
if(!this.state.fired) {
|
||||||
|
this.setState({
|
||||||
|
level: force,
|
||||||
|
});
|
||||||
|
if(force===1)
|
||||||
|
this.do_fire();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
end: ()=>{
|
||||||
|
this.setState({
|
||||||
|
level: 0,
|
||||||
|
fired: false,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
polyfill: false,
|
||||||
|
only: 'touch',
|
||||||
|
preventSelect: false,
|
||||||
|
});
|
||||||
|
document.body.addEventListener('selectstart',(event)=>{
|
||||||
|
if(this.state.level>THRESHOLD)
|
||||||
|
event.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const pad=MULTIPLIER*(this.state.level-THRESHOLD)-BORDER_WIDTH;
|
||||||
|
return (
|
||||||
|
<div className={'pressure-box '+(this.state.fired ? 'pressure-box-fired' : '')} style={{
|
||||||
|
left: pad,
|
||||||
|
right: pad,
|
||||||
|
top: pad,
|
||||||
|
bottom: pad,
|
||||||
|
}} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user