indicators.stories.js 2.0 KB

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