formatters.stories.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import React from 'react';
  2. // import {action} from '@storybook/addon-actions';
  3. import {withInfo} from '@storybook/addon-info';
  4. import {text, boolean} from '@storybook/addon-knobs';
  5. import FileSize from 'app/components/fileSize';
  6. import Duration from 'app/components/duration';
  7. import DateTime from 'app/components/dateTime';
  8. import Count from 'app/components/count';
  9. import Version from 'app/components/version';
  10. export default {
  11. title: 'Utility/Formatters',
  12. };
  13. export const _DateTime = withInfo(
  14. 'Formats number (in ms or seconds) into a datetime string'
  15. )(() => (
  16. <div>
  17. <div>
  18. <DateTime date={1500000000000} />
  19. </div>
  20. <div>
  21. <DateTime seconds={false} date={1500000000000} />
  22. </div>
  23. <div>
  24. <DateTime dateOnly date={1500000000000} />
  25. </div>
  26. <div>
  27. <DateTime timeOnly date={1500000000000} />
  28. </div>
  29. </div>
  30. ));
  31. _DateTime.story = {
  32. name: 'DateTime',
  33. };
  34. export const _FileSize = withInfo('Formats number of bytes to filesize string')(() => (
  35. <div>
  36. <div>
  37. <FileSize bytes={15} />
  38. </div>
  39. <div>
  40. <FileSize bytes={15000} />
  41. </div>
  42. <div>
  43. <FileSize bytes={1500000} />
  44. </div>
  45. <div>
  46. <FileSize bytes={15000000000} />
  47. </div>
  48. <div>
  49. <FileSize bytes={15000000000000} />
  50. </div>
  51. <div>
  52. <FileSize bytes={15000000000000000} />
  53. </div>
  54. </div>
  55. ));
  56. _FileSize.story = {
  57. name: 'FileSize',
  58. };
  59. export const _Duration = withInfo('Formats number of seconds into a duration string')(
  60. () => {
  61. const exact = boolean('exact', false);
  62. const abbreviation = boolean('abbreviation', false);
  63. return (
  64. <div>
  65. <div>
  66. <Duration seconds={15} exact={exact} abbreviation={abbreviation} />
  67. </div>
  68. <div>
  69. <Duration seconds={60} exact={exact} abbreviation={abbreviation} />
  70. </div>
  71. <div>
  72. <Duration seconds={15000} exact={exact} abbreviation={abbreviation} />
  73. </div>
  74. <div>
  75. <Duration seconds={86400} exact={exact} abbreviation={abbreviation} />
  76. </div>
  77. <div>
  78. <Duration seconds={186400} exact={exact} abbreviation={abbreviation} />
  79. </div>
  80. <div>
  81. <Duration seconds={604800} exact={exact} abbreviation={abbreviation} />
  82. </div>
  83. <div>
  84. <Duration seconds={1500000} exact={exact} abbreviation={abbreviation} />
  85. </div>
  86. </div>
  87. );
  88. }
  89. );
  90. export const _Count = withInfo('Formats numbers into a shorthand string')(() => (
  91. <div>
  92. <div>
  93. 5000000 =
  94. <Count value="5000000" />
  95. </div>
  96. <div>
  97. 500000000 =
  98. <Count value="500000000" />
  99. </div>
  100. <div>
  101. 50000 =
  102. <Count value="50000" />
  103. </div>
  104. </div>
  105. ));
  106. export const _Version = withInfo('Formats release version')(() => {
  107. const version = text('version', 'foo.bar.Baz@1.0.0+20200101');
  108. const anchor = boolean('anchor', true);
  109. const preserveGlobalSelection = boolean('preserveGlobalSelection', false);
  110. const tooltipRawVersion = boolean('tooltipRawVersion', true);
  111. const withPackage = boolean('withPackage', false);
  112. const truncate = boolean('truncate', false);
  113. const projectId = text('projectId', '');
  114. const className = text('className', 'asdsad');
  115. return (
  116. <div>
  117. {version} =
  118. <Version
  119. version={version}
  120. anchor={anchor}
  121. preserveGlobalSelection={preserveGlobalSelection}
  122. tooltipRawVersion={tooltipRawVersion}
  123. withPackage={withPackage}
  124. projectId={projectId}
  125. truncate={truncate}
  126. className={className}
  127. />
  128. </div>
  129. );
  130. });