Toasts
import React from 'react';
import { Toast, ToastBody, ToastHeader } from 'reactstrap';
const Example = (props) => {
return (
<div>
<div className="p-3 my-2 rounded">
<Toast>
<ToastHeader>
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast on a white background — check it out!
</ToastBody>
</Toast>
</div>
<div className="p-3 my-2 rounded bg-docs-transparent-grid">
<Toast>
<ToastHeader>
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast on a gridded background — check it out!
</ToastBody>
</Toast>
</div>
<div className="p-3 bg-primary my-2 rounded">
<Toast>
<ToastHeader>
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast on a primary background — check it out!
</ToastBody>
</Toast>
</div>
<div className="p-3 bg-secondary my-2 rounded">
<Toast>
<ToastHeader>
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast on a secondary background — check it out!
</ToastBody>
</Toast>
</div>
<div className="p-3 bg-success my-2 rounded">
<Toast>
<ToastHeader>
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast on a success background — check it out!
</ToastBody>
</Toast>
</div>
<div className="p-3 bg-danger my-2 rounded">
<Toast>
<ToastHeader>
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast on a danger background — check it out!
</ToastBody>
</Toast>
</div>
<div className="p-3 bg-warning my-2 rounded">
<Toast>
<ToastHeader>
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast on a warning background — check it out!
</ToastBody>
</Toast>
</div>
<div className="p-3 bg-info my-2 rounded">
<Toast>
<ToastHeader>
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast on an info background — check it out!
</ToastBody>
</Toast>
</div>
<div className="p-3 bg-dark my-2 rounded">
<Toast>
<ToastHeader>
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast on a dark background — check it out!
</ToastBody>
</Toast>
</div>
<div className="p-3 my-2 rounded" style={{ background: 'black' }}>
<Toast>
<ToastHeader>
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast on a black background — check it out!
</ToastBody>
</Toast>
</div>
</div>
);
};
export default Example;
Properties
Toast.propTypes = {
className: PropTypes.string,
color: PropTypes.string, // default: 'success'
isOpen: PropTypes.bool, // default: true
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
// Controls the transition of the toast fading in and out
// See Fade for more details
transition: PropTypes.shape(Fade.propTypes),
}
Header icons
import React from 'react';
import { Toast, ToastBody, ToastHeader, Spinner } from 'reactstrap';
const Example = (props) => {
return (
<div>
<Toast>
<ToastHeader icon="primary">
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast with a primary icon — check it out!
</ToastBody>
</Toast>
<Toast>
<ToastHeader icon="secondary">
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast with a secondary icon — check it out!
</ToastBody>
</Toast>
<Toast>
<ToastHeader icon="success">
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast with a success icon — check it out!
</ToastBody>
</Toast>
<Toast>
<ToastHeader icon="danger">
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast with a danger icon — check it out!
</ToastBody>
</Toast>
<Toast>
<ToastHeader icon="warning">
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast with a warning icon — check it out!
</ToastBody>
</Toast>
<Toast>
<ToastHeader icon="info">
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast with an info icon — check it out!
</ToastBody>
</Toast>
<Toast>
<ToastHeader icon="light">
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast with a light icon — check it out!
</ToastBody>
</Toast>
<Toast>
<ToastHeader icon="dark">
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast with a dark icon — check it out!
</ToastBody>
</Toast>
<Toast>
<ToastHeader icon={<Spinner size="sm" />}>
Reactstrap
</ToastHeader>
<ToastBody>
This is a toast with a custom icon — check it out!
</ToastBody>
</Toast>
</div>
);
};
export default Example;
Dismissing
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
import React from 'react';
import { Button, Toast, ToastBody, ToastHeader } from 'reactstrap';
class ToastDismissExample extends React.Component {
constructor(props) {
super(props);
this.state = {
show: false
};
this.toggle = this.toggle.bind(this);
}
toggle() {
this.setState({
show: !this.state.show
});
}
render() {
return (
<div>
<Button color="primary" onClick={this.toggle}>{this.props.buttonLabel}</Button>
<br />
<br />
<Toast isOpen={this.state.show}>
<ToastHeader toggle={this.toggle}>Toast title</ToastHeader>
<ToastBody>
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.
</ToastBody>
</Toast>
</div>
);
}
}
export default ToastDismissExample;
当前内容版权归 reactstrap 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 reactstrap .