Add generalized button class

This commit is contained in:
André Wahlberg 2020-11-27 17:05:55 +01:00
parent 7e841cfaeb
commit c59f331965
4 changed files with 75 additions and 31 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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>
);
}
}

View File

@ -3,11 +3,18 @@ import './css/NavigationDrawer.css';
import globalData from '../GlobalData.js';
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
};
@ -31,9 +38,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="" />
@ -41,7 +62,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>