indicators.stories.js 2.2 KB

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