index.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. <Sidebar style={{gridArea: 'aside'}}>
  19. <StoryTree files={storiesContext().files()} />
  20. </Sidebar>
  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 Sidebar = styled('aside')`
  49. overflow: auto;
  50. `;
  51. const VerticalScroll = styled('main')`
  52. overflow-x: hidden;
  53. overflow-y: scroll;
  54. `;
  55. /**
  56. * Avoid <Panel> here because nested panels will have a modified theme.
  57. * Therefore stories will look different in prod.
  58. */
  59. const Main = styled(VerticalScroll)`
  60. background: ${p => p.theme.background};
  61. border-radius: ${p => p.theme.panelBorderRadius};
  62. border: 1px solid ${p => p.theme.border};
  63. padding: var(--stories-grid-space);
  64. overflow-x: hidden;
  65. overflow-y: scroll;
  66. position: relative;
  67. `;