Add generalized button class
This commit is contained in:
parent
f86b9ee220
commit
66dbc66ec4
@ -1,14 +1,31 @@
|
||||
import React, { Component } from 'react';
|
||||
|
||||
class Button extends Component {
|
||||
render() {
|
||||
// Multiple onClick functions
|
||||
onClick = () => {
|
||||
console.log(this.props.onClick);
|
||||
|
||||
if (this.props.onClick !== null
|
||||
&& this.props.onClick !== undefined) {
|
||||
if (Array.isArray(this.props.onClick)) {
|
||||
this.props.onClick.forEach(func => {
|
||||
func();
|
||||
});
|
||||
} else {
|
||||
console.log("Error when parsing Button onClick functions.");
|
||||
}
|
||||
} else {
|
||||
console.log("Error when parsing Button onClick functions.");
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<a href={this.props.destination}>
|
||||
{this.props.title}
|
||||
</a>
|
||||
<button onClick={this.onClick}>
|
||||
{this.props.children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
}
|
||||
// TODO Add css
|
||||
export default Button
|
||||
|
||||
export default Button;
|
@ -1,9 +1,11 @@
|
||||
import addNotification from "react-push-notification";
|
||||
|
||||
import Button from './Button.js';
|
||||
import disruptIcon from '../img/flash.svg';
|
||||
|
||||
const DisruptionButton = () => {
|
||||
const genDisrupt = () => {
|
||||
|
||||
class DisruptionButton extends Button {
|
||||
genDisrupt = () => {
|
||||
addNotification({
|
||||
title: "Warning",
|
||||
subtitle: "This is a subtitle",
|
||||
@ -11,14 +13,17 @@ const DisruptionButton = () => {
|
||||
theme: "blue",
|
||||
native: true, // when using native, your OS will handle theming.
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<button onClick={genDisrupt} className="disruptBtn">
|
||||
<Button onClick={this.props.onClick.concat([this.genDisrupt])} className="disruptBtn">
|
||||
<img src={disruptIcon} alt="" />
|
||||
Generera Störning
|
||||
</button>
|
||||
<span>Generera Störning</span>
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default DisruptionButton;
|
||||
|
@ -1,20 +1,21 @@
|
||||
import React, { Component } from 'react';
|
||||
import Button from './Button.js';
|
||||
|
||||
class MenuButton extends Component {
|
||||
|
||||
class MenuButton extends Button {
|
||||
render() {
|
||||
if (this.props.childOrderReverse) {
|
||||
return (
|
||||
<button>
|
||||
<Button>
|
||||
<span>{this.props.label}</span>
|
||||
<img src={this.props.icon} alt="" />
|
||||
</button>
|
||||
</Button>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<button>
|
||||
<Button>
|
||||
<img src={this.props.icon} alt="" />
|
||||
<span>{this.props.label}</span>
|
||||
</button>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,18 @@ import React, { Component } from 'react';
|
||||
import './css/NavigationDrawer.css';
|
||||
|
||||
import DisruptionButton from "./DisruptionButton.js";
|
||||
import Popup from './Popup.js';
|
||||
import Button from './Button.js';
|
||||
|
||||
import userIcon from '../img/user.svg';
|
||||
|
||||
|
||||
class NavigationDrawer extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.popupElem = React.createRef();
|
||||
}
|
||||
|
||||
state = {
|
||||
open: false
|
||||
};
|
||||
@ -30,9 +37,23 @@ class NavigationDrawer extends Component {
|
||||
});
|
||||
};
|
||||
|
||||
showPopup = () => {
|
||||
this.popupElem.current.show();
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<>
|
||||
<Popup ref={this.popupElem}>
|
||||
<h3>Välj hållplats:</h3>
|
||||
<ul>
|
||||
<li><Button>Hållplats 1</Button></li>
|
||||
<li><Button>Hållplats 2</Button></li>
|
||||
<li><Button>Hållplats 3</Button></li>
|
||||
<li><Button>Hållplats 4</Button></li>
|
||||
</ul>
|
||||
</Popup>
|
||||
|
||||
<div id="navDrawer" className={`${this.state.open ? "open" : ""}`}>
|
||||
<header>
|
||||
<img src={userIcon} alt="" />
|
||||
@ -40,7 +61,7 @@ class NavigationDrawer extends Component {
|
||||
<span>example@gmail.com</span>
|
||||
</header>
|
||||
<div id="navList">
|
||||
<DisruptionButton />
|
||||
<DisruptionButton onClick={[this.showPopup, this.close]} />
|
||||
</div>
|
||||
<hr />
|
||||
<span id="version">Projektgrupp 3 - Utmaning 7</span>
|
||||
|
Loading…
Reference in New Issue
Block a user