autoSizedText.stories.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import JSXNode from 'sentry/components/stories/jsxNode';
  4. import SizingWindow from 'sentry/components/stories/sizingWindow';
  5. import storyBook from 'sentry/stories/storyBook';
  6. import {AutoSizedText} from 'sentry/views/dashboards/widgetCard/autoSizedText';
  7. export default storyBook(AutoSizedText, story => {
  8. story('Getting Started', () => {
  9. return (
  10. <Fragment>
  11. <p>
  12. <JSXNode name="AutoSizedText" /> is a helper component that automatically sizes
  13. a piece of text (single line only!) against its parent. It iteratively measures
  14. the size of the parent element, and chooses a font size for the child element to
  15. fit it perfectly (within reason) inside the parent. For example:
  16. </p>
  17. <SmallSizingWindow>
  18. <AutoSizedText>
  19. <OneLineSpan>NEWSFLASH, y'all!</OneLineSpan>
  20. </AutoSizedText>
  21. </SmallSizingWindow>
  22. <p>
  23. This was built for the "Big Number" widget in our Dashboards product. It's not
  24. possible to <i>perfectly</i> size the text using only CSS and HTML!
  25. </p>
  26. <p>
  27. To use <JSXNode name="AutoSizedText" />, set it as the child of positioned
  28. element of known dimensions. Pass the content you want to size as the{' '}
  29. <strong>
  30. <code>children</code>
  31. </strong>
  32. prop. <JSXNode name="AutoSizedText" /> will set the font size of its children to
  33. fit into the parent.
  34. </p>
  35. </Fragment>
  36. );
  37. });
  38. });
  39. const SmallSizingWindow = styled(SizingWindow)`
  40. width: 300px;
  41. height: 200px;
  42. `;
  43. const OneLineSpan = styled('span')`
  44. white-space: nowrap;
  45. `;