Toasts

Toasts - 图1

  1. import React from 'react';
  2. import { Toast, ToastBody, ToastHeader } from 'reactstrap';
  3. const Example = (props) => {
  4. return (
  5. <div>
  6. <div className="p-3 my-2 rounded">
  7. <Toast>
  8. <ToastHeader>
  9. Reactstrap
  10. </ToastHeader>
  11. <ToastBody>
  12. This is a toast on a white background check it out!
  13. </ToastBody>
  14. </Toast>
  15. </div>
  16. <div className="p-3 my-2 rounded bg-docs-transparent-grid">
  17. <Toast>
  18. <ToastHeader>
  19. Reactstrap
  20. </ToastHeader>
  21. <ToastBody>
  22. This is a toast on a gridded background check it out!
  23. </ToastBody>
  24. </Toast>
  25. </div>
  26. <div className="p-3 bg-primary my-2 rounded">
  27. <Toast>
  28. <ToastHeader>
  29. Reactstrap
  30. </ToastHeader>
  31. <ToastBody>
  32. This is a toast on a primary background check it out!
  33. </ToastBody>
  34. </Toast>
  35. </div>
  36. <div className="p-3 bg-secondary my-2 rounded">
  37. <Toast>
  38. <ToastHeader>
  39. Reactstrap
  40. </ToastHeader>
  41. <ToastBody>
  42. This is a toast on a secondary background check it out!
  43. </ToastBody>
  44. </Toast>
  45. </div>
  46. <div className="p-3 bg-success my-2 rounded">
  47. <Toast>
  48. <ToastHeader>
  49. Reactstrap
  50. </ToastHeader>
  51. <ToastBody>
  52. This is a toast on a success background check it out!
  53. </ToastBody>
  54. </Toast>
  55. </div>
  56. <div className="p-3 bg-danger my-2 rounded">
  57. <Toast>
  58. <ToastHeader>
  59. Reactstrap
  60. </ToastHeader>
  61. <ToastBody>
  62. This is a toast on a danger background check it out!
  63. </ToastBody>
  64. </Toast>
  65. </div>
  66. <div className="p-3 bg-warning my-2 rounded">
  67. <Toast>
  68. <ToastHeader>
  69. Reactstrap
  70. </ToastHeader>
  71. <ToastBody>
  72. This is a toast on a warning background check it out!
  73. </ToastBody>
  74. </Toast>
  75. </div>
  76. <div className="p-3 bg-info my-2 rounded">
  77. <Toast>
  78. <ToastHeader>
  79. Reactstrap
  80. </ToastHeader>
  81. <ToastBody>
  82. This is a toast on an info background check it out!
  83. </ToastBody>
  84. </Toast>
  85. </div>
  86. <div className="p-3 bg-dark my-2 rounded">
  87. <Toast>
  88. <ToastHeader>
  89. Reactstrap
  90. </ToastHeader>
  91. <ToastBody>
  92. This is a toast on a dark background check it out!
  93. </ToastBody>
  94. </Toast>
  95. </div>
  96. <div className="p-3 my-2 rounded" style={{ background: 'black' }}>
  97. <Toast>
  98. <ToastHeader>
  99. Reactstrap
  100. </ToastHeader>
  101. <ToastBody>
  102. This is a toast on a black background check it out!
  103. </ToastBody>
  104. </Toast>
  105. </div>
  106. </div>
  107. );
  108. };
  109. export default Example;

Properties

  1. Toast.propTypes = {
  2. className: PropTypes.string,
  3. color: PropTypes.string, // default: 'success'
  4. isOpen: PropTypes.bool, // default: true
  5. tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
  6. // Controls the transition of the toast fading in and out
  7. // See Fade for more details
  8. transition: PropTypes.shape(Fade.propTypes),
  9. }

Header icons

Toasts - 图2

  1. import React from 'react';
  2. import { Toast, ToastBody, ToastHeader, Spinner } from 'reactstrap';
  3. const Example = (props) => {
  4. return (
  5. <div>
  6. <Toast>
  7. <ToastHeader icon="primary">
  8. Reactstrap
  9. </ToastHeader>
  10. <ToastBody>
  11. This is a toast with a primary icon check it out!
  12. </ToastBody>
  13. </Toast>
  14. <Toast>
  15. <ToastHeader icon="secondary">
  16. Reactstrap
  17. </ToastHeader>
  18. <ToastBody>
  19. This is a toast with a secondary icon check it out!
  20. </ToastBody>
  21. </Toast>
  22. <Toast>
  23. <ToastHeader icon="success">
  24. Reactstrap
  25. </ToastHeader>
  26. <ToastBody>
  27. This is a toast with a success icon check it out!
  28. </ToastBody>
  29. </Toast>
  30. <Toast>
  31. <ToastHeader icon="danger">
  32. Reactstrap
  33. </ToastHeader>
  34. <ToastBody>
  35. This is a toast with a danger icon check it out!
  36. </ToastBody>
  37. </Toast>
  38. <Toast>
  39. <ToastHeader icon="warning">
  40. Reactstrap
  41. </ToastHeader>
  42. <ToastBody>
  43. This is a toast with a warning icon check it out!
  44. </ToastBody>
  45. </Toast>
  46. <Toast>
  47. <ToastHeader icon="info">
  48. Reactstrap
  49. </ToastHeader>
  50. <ToastBody>
  51. This is a toast with an info icon check it out!
  52. </ToastBody>
  53. </Toast>
  54. <Toast>
  55. <ToastHeader icon="light">
  56. Reactstrap
  57. </ToastHeader>
  58. <ToastBody>
  59. This is a toast with a light icon check it out!
  60. </ToastBody>
  61. </Toast>
  62. <Toast>
  63. <ToastHeader icon="dark">
  64. Reactstrap
  65. </ToastHeader>
  66. <ToastBody>
  67. This is a toast with a dark icon check it out!
  68. </ToastBody>
  69. </Toast>
  70. <Toast>
  71. <ToastHeader icon={<Spinner size="sm" />}>
  72. Reactstrap
  73. </ToastHeader>
  74. <ToastBody>
  75. This is a toast with a custom icon check it out!
  76. </ToastBody>
  77. </Toast>
  78. </div>
  79. );
  80. };
  81. export default Example;

Dismissing

Toasts - 图3

  1. /* eslint react/no-multi-comp: 0, react/prop-types: 0 */
  2. import React from 'react';
  3. import { Button, Toast, ToastBody, ToastHeader } from 'reactstrap';
  4. class ToastDismissExample extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. show: false
  9. };
  10. this.toggle = this.toggle.bind(this);
  11. }
  12. toggle() {
  13. this.setState({
  14. show: !this.state.show
  15. });
  16. }
  17. render() {
  18. return (
  19. <div>
  20. <Button color="primary" onClick={this.toggle}>{this.props.buttonLabel}</Button>
  21. <br />
  22. <br />
  23. <Toast isOpen={this.state.show}>
  24. <ToastHeader toggle={this.toggle}>Toast title</ToastHeader>
  25. <ToastBody>
  26. 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.
  27. </ToastBody>
  28. </Toast>
  29. </div>
  30. );
  31. }
  32. }
  33. export default ToastDismissExample;