/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
import React from 'react';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Input, Label, Form, FormGroup } from 'seduo-ui';
class ModalExample extends React.Component<any, any> {
constructor(props) {
super(props);
this.state = {
modal: false,
backdrop: true,
};
this.toggle = this.toggle.bind(this);
this.changeBackdrop = this.changeBackdrop.bind(this);
}
toggle() {
this.setState({
modal: !this.state.modal,
});
}
changeBackdrop(e) {
let value = e.target.value;
if (value !== 'static') {
value = JSON.parse(value);
}
this.setState({
backdrop: value,
});
}
render() {
return (
<div>
<Form inline onSubmit={(e) => e.preventDefault()}>
<FormGroup>
<Label for="backdrop">Backdrop value</Label>{' '}
<Input type="select" name="backdrop" id="backdrop" onChange={this.changeBackdrop}>
<option value="true">true</option>
<option value="false">false</option>
<option value="static">"static"</option>
</Input>
</FormGroup>{' '}
<Button color="danger" onClick={this.toggle}>
{this.props.buttonLabel}
</Button>
</Form>
<Modal
isOpen={this.state.modal}
toggle={this.toggle}
className={this.props.className}
backdrop={this.state.backdrop}
>
<ModalHeader toggle={this.toggle}>Modal title</ModalHeader>
<ModalBody>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={this.toggle}>
Do Something
</Button>{' '}
<Button color="secondary" onClick={this.toggle}>
Cancel
</Button>
</ModalFooter>
</Modal>
</div>
);
}
}
export default ModalExample;
Modals with Custom Transition Timeouts
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
import React from 'react';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'seduo-ui';
class ModalExample extends React.Component<any, any> {
constructor(props) {
super(props);
this.state = {
modal: false,
};
this.toggle = this.toggle.bind(this);
}
toggle() {
this.setState({
modal: !this.state.modal,
});
}
render() {
return (
<div>
<Button color="danger" onClick={this.toggle}>
{this.props.buttonLabel}
</Button>
<Modal
isOpen={this.state.modal}
modalTransition={{
timeout: 20,
}}
backdropTransition={{
timeout: 10,
}}
toggle={this.toggle}
className={this.props.className}
>
<ModalHeader toggle={this.toggle}>Modal title</ModalHeader>
<ModalBody>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={this.toggle}>
Do Something
</Button>{' '}
<Button color="secondary" onClick={this.toggle}>
Cancel
</Button>
</ModalFooter>
</Modal>
</div>
);
}
}
export default ModalExample;
Modals without Fade Effect
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
import React from 'react';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'seduo-ui';
class ModalExample extends React.Component<any, any> {
constructor(props) {
super(props);
this.state = {
modal: false,
};
this.toggle = this.toggle.bind(this);
}
toggle() {
this.setState({
modal: !this.state.modal,
});
}
render() {
return (
<div>
<Button color="danger" onClick={this.toggle}>
{this.props.buttonLabel}
</Button>
<Modal isOpen={this.state.modal} fade={false} toggle={this.toggle} className={this.props.className}>
<ModalHeader toggle={this.toggle}>Modal title</ModalHeader>
<ModalBody>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={this.toggle}>
Do Something
</Button>{' '}
<Button color="secondary" onClick={this.toggle}>
Cancel
</Button>
</ModalFooter>
</Modal>
</div>
);
}
}
export default ModalExample;
Modals with custom close button
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
import React from 'react';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'seduo-ui';
class ModalExample extends React.Component<any, any> {
constructor(props) {
super(props);
this.state = {
modal: false,
};
this.toggle = this.toggle.bind(this);
}
toggle() {
this.setState({
modal: !this.state.modal,
});
}
render() {
const closeBtn = (
<button className="close" onClick={this.toggle}>
×
</button>
);
return (
<div>
<Button color="danger" onClick={this.toggle}>
{this.props.buttonLabel}
</Button>
<Modal isOpen={this.state.modal} toggle={this.toggle} className={this.props.className}>
<ModalHeader toggle={this.toggle} close={closeBtn}>
Modal title
</ModalHeader>
<ModalBody>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={this.toggle}>
Do Something
</Button>{' '}
<Button color="secondary" onClick={this.toggle}>
Cancel
</Button>
</ModalFooter>
</Modal>
</div>
);
}
}
export default ModalExample;
Focus after close
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
import React from 'react';
import { Button, Modal, ModalBody, ModalFooter, Label, Input, FormGroup, Form } from 'seduo-ui';
class ModalFocusAfterClose extends React.Component<any, any> {
constructor(props) {
super(props);
this.state = {
open: false,
focusAfterClose: true,
};
this.toggle = this.toggle.bind(this);
this.handleSelectChange = this.handleSelectChange.bind(this);
}
toggle() {
this.setState(({ open }) => ({
open: !open,
}));
}
handleSelectChange({ target: { value } }) {
this.setState({
focusAfterClose: JSON.parse(value),
});
}
render() {
return (
<div>
<Form inline onSubmit={(e) => e.preventDefault()}>
<FormGroup>
<Label for="focusAfterClose">Focus After Close</Label>
<Input className="mx-2" type="select" id="focusAfterClose" onChange={this.handleSelectChange}>
<option value="true">Yes</option>
<option value="false">No</option>
</Input>
</FormGroup>
<Button color="danger" onClick={this.toggle}>
Open
</Button>
</Form>
<Modal returnFocusAfterClose={this.state.focusAfterClose} isOpen={this.state.open}>
<ModalBody>
Observe the "Open" button. It will be focused after close when "returnFocusAfterClose" is true
and will not be focused if "returnFocusAfterClose" is false.
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={this.toggle}>
Close
</Button>
</ModalFooter>
</Modal>
</div>
);
}
}
export default ModalFocusAfterClose;
Modal without Header
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
import React from 'react';
import { Button, Modal, ModalBody, ModalFooter } from 'seduo-ui';
class ModalWithoutHeaderExample extends React.Component<any, any> {
constructor(props) {
super(props);
this.state = {
modal: false,
};
this.toggle = this.toggle.bind(this);
}
toggle() {
this.setState({
modal: !this.state.modal,
});
}
render() {
return (
<div>
<Button color="danger" onClick={this.toggle}>
{this.props.buttonLabel}
</Button>
<Modal isOpen={this.state.modal} toggle={this.toggle} className={this.props.className} withoutHeader>
<ModalBody>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={this.toggle}>
Do Something
</Button>{' '}
<Button color="secondary" onClick={this.toggle}>
Cancel
</Button>
</ModalFooter>
</Modal>
</div>
);
}
}
export default ModalWithoutHeaderExample;