index.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import type {RouteComponentProps} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import {space} from 'sentry/styles/space';
  4. import EmptyStory from 'sentry/views/stories/emptyStory';
  5. import ErrorStory from 'sentry/views/stories/errorStory';
  6. import storiesContext from 'sentry/views/stories/storiesContext';
  7. import StoryFile from 'sentry/views/stories/storyFile';
  8. import StoryHeader from 'sentry/views/stories/storyHeader';
  9. import StoryTree from 'sentry/views/stories/storyTree';
  10. import type {StoriesQuery} from 'sentry/views/stories/types';
  11. import useStoriesLoader from 'sentry/views/stories/useStoriesLoader';
  12. type Props = RouteComponentProps<{}, {}, any, StoriesQuery>;
  13. export default function Stories({location}: Props) {
  14. const story = useStoriesLoader({filename: location.query.name});
  15. return (
  16. <Layout>
  17. <StoryHeader style={{gridArea: 'head'}} />
  18. <aside style={{gridArea: 'aside'}}>
  19. <StoryTree files={storiesContext().files()} />
  20. </aside>
  21. {story.error ? (
  22. <VerticalScroll style={{gridArea: 'body'}}>
  23. <ErrorStory error={story.error} />
  24. </VerticalScroll>
  25. ) : story.resolved ? (
  26. <Main style={{gridArea: 'body'}}>
  27. <StoryFile filename={story.filename} resolved={story.resolved} />
  28. </Main>
  29. ) : (
  30. <VerticalScroll style={{gridArea: 'body'}}>
  31. <EmptyStory />
  32. </VerticalScroll>
  33. )}
  34. </Layout>
  35. );
  36. }
  37. const Layout = styled('div')`
  38. --stories-grid-space: ${space(2)};
  39. display: grid;
  40. grid-template:
  41. 'head head' max-content
  42. 'aside body' auto/ ${p => p.theme.settings.sidebarWidth} 1fr;
  43. gap: var(--stories-grid-space);
  44. place-items: stretch;
  45. height: 100vh;
  46. padding: var(--stories-grid-space);
  47. `;
  48. const VerticalScroll = styled('main')`
  49. overflow-x: hidden;
  50. overflow-y: scroll;
  51. `;
  52. /**
  53. * Avoid <Panel> here because nested panels will have a modified theme.
  54. * Therefore stories will look different in prod.
  55. */
  56. const Main = styled(VerticalScroll)`
  57. background: ${p => p.theme.background};
  58. border-radius: ${p => p.theme.panelBorderRadius};
  59. border: 1px solid ${p => p.theme.border};
  60. padding: var(--stories-grid-space);
  61. overflow-x: hidden;
  62. overflow-y: scroll;
  63. position: relative;
  64. `;