indicators.stories.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import {
  2. addErrorMessage,
  3. addMessage,
  4. addSuccessMessage,
  5. } from 'sentry/actionCreators/indicator';
  6. import Button from 'sentry/components/button';
  7. import IndicatorContainer, {Indicators} from 'sentry/components/indicators';
  8. import IndicatorStore from 'sentry/stores/indicatorStore';
  9. export default {
  10. title: 'Components/Toast Indicators',
  11. };
  12. export const Static = ({type}) => {
  13. return (
  14. <div style={{backgroundColor: 'white', padding: 12}}>
  15. <Indicators
  16. items={[
  17. {
  18. id: '',
  19. type,
  20. message: 'Indicator message',
  21. },
  22. ]}
  23. />
  24. </div>
  25. );
  26. };
  27. Static.storyName = 'Static';
  28. Static.args = {
  29. type: 'success',
  30. };
  31. Static.argTypes = {
  32. type: {
  33. control: {
  34. type: 'select',
  35. options: ['success', 'error', 'loading'],
  36. },
  37. },
  38. };
  39. export const Interactive = () => {
  40. let success;
  41. let error;
  42. let loading;
  43. return (
  44. <div style={{backgroundColor: 'white', padding: 12}}>
  45. <Button
  46. onClick={() => {
  47. if (success) {
  48. IndicatorStore.remove(success);
  49. success = null;
  50. } else {
  51. success = addSuccessMessage('Success');
  52. }
  53. }}
  54. >
  55. Toggle Success
  56. </Button>
  57. <Button
  58. onClick={() => {
  59. if (loading) {
  60. IndicatorStore.remove(loading);
  61. loading = null;
  62. } else {
  63. loading = addMessage('Loading', 'loading');
  64. }
  65. }}
  66. >
  67. Toggle Loading
  68. </Button>
  69. <Button
  70. onClick={() => {
  71. if (error) {
  72. IndicatorStore.remove(error);
  73. error = null;
  74. } else {
  75. error = addErrorMessage('Error');
  76. }
  77. }}
  78. >
  79. Toggle Error
  80. </Button>
  81. <IndicatorContainer />
  82. </div>
  83. );
  84. };
  85. Interactive.storyName = 'Interactive';