Layout scaffolding for Web apps.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

103 lines
1.9 KiB

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