Skip to content

Instantly share code, notes, and snippets.

@justinobney
Last active August 27, 2018 20:43
Show Gist options
  • Select an option

  • Save justinobney/4a0261c0c10af8f687e3252fc62ed078 to your computer and use it in GitHub Desktop.

Select an option

Save justinobney/4a0261c0c10af8f687e3252fc62ed078 to your computer and use it in GitHub Desktop.
BetterSemanticConfirm.js
import React, { Component } from "react";
import { Button, Modal } from "semantic-ui-react";
export class Confirm extends Component {
state = { open: false };
static defaultProps = {
onClose: () => {}
};
_handleClose = () => {
this.setState({ open: false });
this.props.onClose();
};
render() {
const { trigger, ...props } = this.props;
return (
<React.Fragment>
{React.cloneElement(trigger, {
onClick: e => {
this.setState({ open: true });
}
})}
<div
onClick={e => {
e.stopPropagation();
}}
>
<Modal open={this.state.open} onClose={this._handleClose} {...props}>
<Modal.Header>Confirm</Modal.Header>
<Modal.Content>Are you sure?</Modal.Content>
<Modal.Actions>
<Button primary>Yes</Button>
<Button onClick={this._handleClose} basic>
No
</Button>
</Modal.Actions>
</Modal>
</div>
</React.Fragment>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment