Monorepo containing core modules of Zeichen.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

113 líneas
2.1 KiB

  1. import * as React from 'react'
  2. import * as PropTypes from 'prop-types'
  3. import Link from 'next/link'
  4. import styled from 'styled-components'
  5. import Icon from '../Icon/Icon'
  6. const Base = styled('div')({
  7. width: 0,
  8. height: '4rem',
  9. flex: 'auto',
  10. padding: '0.25rem',
  11. boxSizing: 'border-box',
  12. position: 'relative',
  13. '@media (min-width: 1080px)': {
  14. width: '4rem',
  15. height: '4rem',
  16. },
  17. })
  18. const ClickArea = styled('a')({
  19. display: 'grid',
  20. color: 'inherit',
  21. placeContent: 'center',
  22. width: '100%',
  23. height: '100%',
  24. position: 'absolute',
  25. top: 0,
  26. left: 0,
  27. textDecoration: 'none',
  28. })
  29. const ClickAreaContent = styled('span')({
  30. display: 'block',
  31. textAlign: 'center',
  32. lineHeight: 1,
  33. })
  34. const Highlight = styled('div')({
  35. width: '100%',
  36. height: '100%',
  37. backgroundColor: 'var(--color-primary)',
  38. opacity: 0.5,
  39. borderRadius: '0.25rem',
  40. [`+ ${ClickArea}`]: {
  41. opacity: 0.75,
  42. },
  43. })
  44. const Title = styled('small')({
  45. display: 'block',
  46. fontWeight: 'bolder',
  47. '@media (min-width: 1080px)': {
  48. display: 'none',
  49. },
  50. })
  51. const MobileBase = styled(Base)({
  52. '@media (min-width: 1080px)': {
  53. display: 'none',
  54. },
  55. })
  56. const propTypes = {
  57. href: PropTypes.oneOfType([PropTypes.object, PropTypes.string]).isRequired,
  58. iconName: PropTypes.string.isRequired,
  59. title: PropTypes.string,
  60. mobileOnly: PropTypes.bool,
  61. active: PropTypes.bool,
  62. }
  63. type Props = PropTypes.InferProps<typeof propTypes>
  64. const PrimaryNavItem: React.FC<Props> = ({
  65. href,
  66. iconName,
  67. title,
  68. mobileOnly = false,
  69. active = false,
  70. }) => {
  71. const BaseComponent = mobileOnly ? MobileBase : Base
  72. return (
  73. <BaseComponent>
  74. {
  75. active
  76. && (
  77. <Highlight />
  78. )
  79. }
  80. <Link
  81. href={href}
  82. passHref
  83. >
  84. <ClickArea
  85. title={title}
  86. >
  87. <ClickAreaContent>
  88. <Icon
  89. name={iconName}
  90. />
  91. <Title>
  92. {title}
  93. </Title>
  94. </ClickAreaContent>
  95. </ClickArea>
  96. </Link>
  97. </BaseComponent>
  98. )
  99. }
  100. PrimaryNavItem.propTypes = propTypes
  101. export default PrimaryNavItem