indicators.stories.js 1.9 KB

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