indicators.stories.js 2.3 KB

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