Skip to content
This repository has been archived by the owner on May 21, 2020. It is now read-only.

Commit

Permalink
feat(example): add more modifiers to example
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmega committed Apr 2, 2018
1 parent 54b64c8 commit 431974c
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 12 deletions.
96 changes: 86 additions & 10 deletions example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,59 @@ import Drawer from "../../lib/drawer.jsx";
import React, { Component } from "react";
import image from "url-loader!../planurahuette.jpg";

const style = {
background: "#F9F9F9",
boxShadow: "rgba(0, 0, 0, 0.188235) 0px 10px 20px, rgba(0, 0, 0, 0.227451) 0px 6px 6px"
};

export default class App extends Component {
state = {
openLeft: false,
openRight: false,
drawerStyle: `
{
"background": "#F9F9F9",
"boxShadow": "rgba(0, 0, 0, 0.188235) 0px 10px 20px, rgba(0, 0, 0, 0.227451) 0px 6px 6px"
}`,
relativeWidth: false,
width: 300
width: 300,
noTouchOpen: false,
noTouchClose: false,
};

setWidth = e => {
this.setState({
width: Number(e.target.value) || e.target.value
});
};

setTouch = e => {
this.setState({
[e.target.name]: !e.target.checked
})
}

setDrawerStyle = e => {
e.preventDefault()
this.setState({
drawerStyle: this.drawerStyleRef.value
})
}

render() {
const { openLeft, openRight } = this.state;
const {
drawerStyle: stringDrawerStyle,
openLeft,
openRight,
noTouchOpen,
noTouchClose
} = this.state;

let drawerStyle = {}
try {
drawerStyle = JSON.parse(stringDrawerStyle)
} catch (err) {
console.error('Error parsing JSON: ', err)
}

const drawerProps = {
overlayColor: "rgba(255,255,255,0.6)",
drawerStyle: style
drawerStyle
};

return (
Expand All @@ -33,9 +63,11 @@ export default class App extends Component {
<Drawer
{...drawerProps}
width={this.state.width}
fadeOut={true}
fadeOut
open={openLeft}
onChange={open => this.setState({ openLeft: open })}
noTouchOpen={noTouchOpen}
noTouchClose={noTouchClose}
>
<div style={{ width: "100%" }}>
<img src={image} />
Expand All @@ -46,11 +78,13 @@ export default class App extends Component {
</Drawer>}
{!openLeft &&
<Drawer
right={true}
right
width={this.state.width}
{...drawerProps}
open={openRight}
onChange={open => this.setState({ openRight: open })}
noTouchOpen={noTouchOpen}
noTouchClose={noTouchClose}
>
{val => {
var per = val / 300;
Expand Down Expand Up @@ -98,6 +132,7 @@ export default class App extends Component {
</div>
<div className="options">
<form className="row">
<h5>Size Controls</h5>
<p className="col s4">
<label htmlFor="width">Set width</label>
<input
Expand All @@ -108,6 +143,47 @@ export default class App extends Component {
/>
</p>
</form>
<form className="row">
<h5>Touch Controls</h5>
<p className="col s4">
<input
name="noTouchOpen"
id="noTouchOpen"
type="checkbox"
onChange={this.setTouch}
checked={!noTouchOpen}
/>
<label htmlFor="noTouchOpen">Touch open</label>
</p>
<p className="col s4" >
<input
name="noTouchClose"
id="noTouchClose"
type="checkbox"
onChange={this.setTouch}
checked={!noTouchClose}
/>
<label htmlFor="noTouchClose">Touch close</label>
</p>
</form>
<form className="row">
<h5>Custom Styles <small style={{ fontSize: 'small', color: '#777' }}>Must be JSON for the example</small></h5>
<p className="col s8 input-field">
<textarea
id="drawerStyle"
className="materialize-textarea"
ref={ref => this.drawerStyleRef = ref}
defaultValue={stringDrawerStyle}
/>
<label htmlFor="drawerStyle">drawerStyle</label>
<button
className="waves-effect waves-light btn"
onClick={this.setDrawerStyle}
>
Set drawerStyle
</button>
</p>
</form>
</div>
</div>
);
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"scripts": {
"build": "babel lib --out-dir ./",
"build-example": "webpack --config example/webpack.config.js",
"serve": "webpack-dev-server --config example/webpack.config.js",
"dev": "run-p \"build --watch\" serve",
"serve": "npm run build-example && webpack-dev-server --config example/webpack.config.js",
"open": "opn http://localhost:8888/example/index.html",
"lint": "eslint lib",
"patch-release": "npm version patch && npm publish && git push --follow-tags",
Expand Down Expand Up @@ -51,6 +52,7 @@
"eslint": "^4.9.0",
"eslint-plugin-react": "^7.4.0",
"file-loader": "^1.1.5",
"npm-run-all": "^4.1.2",
"opn-cli": "^3.1.0",
"react": "^16.0.0",
"react-dom": "^16.0.0",
Expand Down
Loading

0 comments on commit 431974c

Please sign in to comment.