Layout scaffolding for Web apps.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

95 lignes
1.9 KiB

  1. import * as React from 'react';
  2. import styled from 'styled-components';
  3. import TopBar from '../../widgets/TopBar';
  4. const LayoutBase = styled('div')({
  5. '--width-base': 'var(--width-base, 360px)',
  6. '--height-topbar': 'var(--height-topbar, 4rem)',
  7. })
  8. const ContentBase = styled('main')({
  9. boxSizing: 'border-box',
  10. '@media (min-width: 1080px)': {
  11. paddingRight: 'calc(50% - var(--width-base, 360px) * 0.5)',
  12. },
  13. })
  14. const SidebarBase = styled('div')({
  15. boxSizing: 'border-box',
  16. backgroundColor: 'var(--color-bg, white)',
  17. // prevent collapse of margin
  18. '::after': {
  19. content: "''",
  20. display: 'block',
  21. paddingBottom: 1,
  22. marginTop: -1,
  23. boxSizing: 'border-box',
  24. },
  25. '@media (prefers-color-scheme: dark)': {
  26. backgroundColor: 'var(--color-bg, black)',
  27. },
  28. '@media (min-width: 1080px)': {
  29. position: 'absolute',
  30. top: 0,
  31. right: 0,
  32. width: 'calc(50% - var(--width-base, 360px) * 0.5)',
  33. height: '100%',
  34. },
  35. })
  36. export const SidebarContainer = styled('div')({
  37. padding: '0 1rem',
  38. boxSizing: 'border-box',
  39. width: '100%',
  40. maxWidth: 'calc(var(--width-base, 360px) * 2)',
  41. margin: '0 auto',
  42. '@media (min-width: 1080px)': {
  43. width: 'var(--width-base, 360px)',
  44. marginLeft: 0,
  45. },
  46. })
  47. export const ContentContainer = styled('div')({
  48. padding: '0 1rem',
  49. boxSizing: 'border-box',
  50. width: '100%',
  51. maxWidth: 'calc(var(--width-base, 360px) * 2)',
  52. margin: '0 auto',
  53. '@media (min-width: 1080px)': {
  54. marginRight: 0,
  55. },
  56. })
  57. type Props = {
  58. brand?: React.ReactNode,
  59. sidebarMain: React.ReactChild,
  60. userLink?: React.ReactNode,
  61. topBarCenter?: React.ReactChild,
  62. }
  63. export const Layout: React.FC<Props> = ({
  64. brand,
  65. sidebarMain,
  66. userLink,
  67. topBarCenter,
  68. children,
  69. }) => {
  70. return (
  71. <LayoutBase>
  72. <TopBar
  73. wide
  74. brand={brand}
  75. userLink={userLink}
  76. >
  77. {topBarCenter}
  78. </TopBar>
  79. <ContentBase>
  80. {children}
  81. </ContentBase>
  82. <SidebarBase>
  83. {sidebarMain}
  84. </SidebarBase>
  85. </LayoutBase>
  86. )
  87. }