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.
 
 
 

94 lines
1.8 KiB

  1. import * as React from 'react'
  2. import styled, {createGlobalStyle} from 'styled-components';
  3. import TopBar from '../../widgets/TopBar'
  4. import {applyBackgroundColor, 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. ...applyBackgroundColor(),
  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 SidebarContainer = 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. <TopBar
  72. wide
  73. brand={brand}
  74. userLink={userLink}
  75. >
  76. {topBarCenter}
  77. </TopBar>
  78. <ContentBase>
  79. {children}
  80. </ContentBase>
  81. <SidebarBase>
  82. {sidebarMain}
  83. </SidebarBase>
  84. </>
  85. )
  86. }