Skip to content

Commit

Permalink
Fixes 978 (#1342)
Browse files Browse the repository at this point in the history
Should fix 978, and add support for set-udelement, get-udelement, hide-udelement.
Note: remove-udelement shouldn't work (haven't tested)
  • Loading branch information
BoSen29 authored and adamdriscoll committed Dec 2, 2019
1 parent 6b828cb commit b4bff54
Showing 1 changed file with 55 additions and 8 deletions.
63 changes: 55 additions & 8 deletions src/UniversalDashboard.Materialize/Components/ud-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import {Button} from 'react-materialize';
import UdIcon from './ud-icon';

export default class UDButton extends React.Component {
constructor(props) {
super(props);

this.state = {
backgroundColor: this.props.backgroundColor,
fontColor: this.props.fontColor,
floating: this.props.floating,
flat: this.props.flat,
icon: this.props.icon,
text: this.props.text,
disabled: this.props.disabled,
hidden: this.props.hidden
}
}

onClick() {
if (this.props.onClick) {
Expand All @@ -15,29 +29,62 @@ export default class UDButton extends React.Component {
}
}

onIncomingEvent(eventName, event) {
if (event.type === "requestState") {
var data = {
attributes: this.state
}
UniversalDashboard.post(`/api/internal/component/element/sessionState/${event.requestId}`, data);
}
else if (event.type === "setState") {
this.setState(event.state.attributes);
}
else if (event.type === "clearElement") {
this.setState({
content: null
});
}
else if (event.type === "removeElement") {
this.setState({
hidden:true
});
}
}

componentWillMount() {
this.pubSubToken = UniversalDashboard.subscribe(this.props.id, this.onIncomingEvent.bind(this));
}

componentWillUnmount() {
UniversalDashboard.unsubscribe(this.pubSubToken);
}

render() {
if(this.state.hidden) {
return null;
}

var style = {
backgroundColor: this.props.backgroundColor,
color: this.props.fontColor
backgroundColor: this.state.backgroundColor,
color: this.state.fontColor
}

var icon = null;
if (this.props.icon) {
icon = <UdIcon icon={this.props.icon} style={{marginRight: this.props.floating || !this.props.text ? 'unset' : '5px'}}/>
if (this.state.icon) {
icon = <UdIcon icon={this.state.icon} style={{marginRight: this.state.floating || !this.state.text ? 'unset' : '5px'}}/>
}

return <Button
className="ud-button"
onClick={this.onClick.bind(this)}
id={this.props.id}
flat={this.props.flat}
disabled={this.props.disabled}
floating={this.props.floating}
flat={this.state.flat}
disabled={this.state.disabled}
floating={this.state.floating}
style={style}
>
{icon}
{this.props.text}
{this.state.text}
</Button>
}
}

0 comments on commit b4bff54

Please sign in to comment.