Monorepo containing core modules of Zeichen.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

207 rader
5.0 KiB

  1. import * as React from 'react'
  2. import styled from 'styled-components'
  3. import SecondaryNavItem from '../SecondaryNavItem/SecondaryNavItem'
  4. import PrimaryNavItem from '../PrimaryNavItem/PrimaryNavItem'
  5. const Base = styled('aside')({
  6. width: 360,
  7. height: '100%',
  8. position: 'fixed',
  9. top: 0,
  10. left: -360,
  11. backgroundColor: 'var(--color-fg)',
  12. color: 'var(--color-bg)',
  13. zIndex: 1,
  14. '@media (min-width: 1080px)': {
  15. width: `${100 / 3}%`,
  16. left: 0,
  17. },
  18. })
  19. const PrimaryNavItems = styled('nav')({
  20. width: '100%',
  21. height: '4rem',
  22. position: 'fixed',
  23. bottom: 0,
  24. left: 0,
  25. zIndex: 1,
  26. backgroundColor: 'var(--color-fg)',
  27. color: 'var(--color-bg)',
  28. justifyContent: 'center',
  29. '@media (min-width: 1080px)': {
  30. position: 'static',
  31. bottom: 'auto',
  32. left: 'auto',
  33. width: '4rem',
  34. height: '100%',
  35. },
  36. })
  37. const PrimaryNavItemsContainer = styled('div')({
  38. width: '100%',
  39. height: '100%',
  40. maxWidth: 720,
  41. display: 'flex',
  42. margin: '0 auto',
  43. '@media (min-width: 1080px)': {
  44. width: '100%',
  45. flexDirection: 'column',
  46. justifyContent: 'space-between',
  47. alignItems: 'stretch',
  48. },
  49. })
  50. const PrimaryNavItemGroup = styled('div')({
  51. display: 'contents',
  52. '@media (min-width: 1080px)': {
  53. display: 'block',
  54. },
  55. })
  56. const SecondaryNavItems = styled('nav')({
  57. height: '100%',
  58. position: 'relative',
  59. backgroundColor: 'var(--color-bg)',
  60. '::before': {
  61. content: "''",
  62. display: 'block',
  63. top: 0,
  64. left: 0,
  65. width: '100%',
  66. height: '100%',
  67. position: 'absolute',
  68. backgroundColor: 'black',
  69. opacity: 0.03125,
  70. },
  71. '@media (min-width: 1080px)': {
  72. flex: 'auto',
  73. },
  74. })
  75. const VisibleSecondaryNavItems = styled(SecondaryNavItems)({
  76. position: 'fixed',
  77. top: 0,
  78. left: 0,
  79. width: '100%',
  80. paddingBottom: '4rem',
  81. boxSizing: 'border-box',
  82. '@media (min-width: 1080px)': {
  83. position: 'relative',
  84. top: 'auto',
  85. left: 'auto',
  86. width: 'auto',
  87. paddingBottom: 0,
  88. },
  89. })
  90. const SecondaryNavItemsOverflow = styled('div')({
  91. overflow: 'auto',
  92. width: '100%',
  93. height: '100%',
  94. position: 'relative',
  95. })
  96. const NavbarItems = styled('div')({
  97. display: 'flex',
  98. width: '100%',
  99. height: '100%',
  100. })
  101. const NavbarContainer = styled('div')({
  102. display: 'block',
  103. width: '100%',
  104. height: '100%',
  105. margin: '0 0 0 auto',
  106. boxSizing: 'border-box',
  107. maxWidth: 360,
  108. })
  109. const Navbar = ({
  110. secondaryVisible,
  111. primaryItemsStart = [],
  112. primaryItemsEnd = [],
  113. secondaryItemsHeader = [],
  114. secondaryItems = [],
  115. }) => {
  116. const SecondaryNavItemsComponent = secondaryVisible ? VisibleSecondaryNavItems : SecondaryNavItems
  117. return (
  118. <Base>
  119. <NavbarContainer>
  120. <NavbarItems>
  121. <PrimaryNavItems>
  122. <PrimaryNavItemsContainer>
  123. <PrimaryNavItemGroup>
  124. {
  125. Array.isArray(primaryItemsStart!)
  126. && primaryItemsStart.map(i => (
  127. <PrimaryNavItem
  128. key={i.id}
  129. mobileOnly={i.mobileOnly}
  130. href={i.href}
  131. iconName={i.iconName}
  132. title={i.title}
  133. active={i.active}
  134. />
  135. ))
  136. }
  137. </PrimaryNavItemGroup>
  138. {
  139. Array.isArray(primaryItemsEnd!)
  140. && (
  141. <PrimaryNavItemGroup>
  142. {
  143. primaryItemsEnd.map(i => (
  144. <PrimaryNavItem
  145. key={i.id}
  146. href={i.href}
  147. iconName={i.iconName}
  148. title={i.title}
  149. active={i.active}
  150. />
  151. ))
  152. }
  153. </PrimaryNavItemGroup>
  154. )
  155. }
  156. </PrimaryNavItemsContainer>
  157. </PrimaryNavItems>
  158. <SecondaryNavItemsComponent>
  159. <SecondaryNavItemsOverflow>
  160. {
  161. secondaryItemsHeader.map(i => (
  162. <SecondaryNavItem
  163. key={i.id}
  164. active={i.active}
  165. href={i.href}
  166. replace={i.replace}
  167. iconName={i.iconName}
  168. title={i.title}
  169. subtitle={i.subtitle}
  170. actions={i.actions}
  171. />
  172. ))
  173. }
  174. {
  175. secondaryItems.map(i => (
  176. <SecondaryNavItem
  177. key={i.id}
  178. active={i.active}
  179. href={i.href}
  180. replace={i.replace}
  181. iconName={i.iconName}
  182. title={i.title}
  183. subtitle={i.subtitle}
  184. actions={i.actions}
  185. />
  186. ))
  187. }
  188. </SecondaryNavItemsOverflow>
  189. </SecondaryNavItemsComponent>
  190. </NavbarItems>
  191. </NavbarContainer>
  192. </Base>
  193. )
  194. }
  195. export default Navbar