Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

Header.tsx 4.3 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  1. import { useState } from 'react'
  2. import cx from 'classnames'
  3. import { useRouter } from 'next/router'
  4. import { MarkGithubIcon, ThreeBarsIcon, XIcon } from '@primer/octicons-react'
  5. import { ButtonOutline } from '@primer/components'
  6. import { Link } from 'components/Link'
  7. import { useMainContext } from './context/MainContext'
  8. import { LanguagePicker } from './LanguagePicker'
  9. import { HeaderNotifications } from 'components/HeaderNotifications'
  10. import { ProductPicker } from 'components/ProductPicker'
  11. import { useTranslation } from 'components/hooks/useTranslation'
  12. import { HomepageVersionPicker } from 'components/landing/HomepageVersionPicker'
  13. import { Search } from 'components/Search'
  14. export const Header = () => {
  15. const router = useRouter()
  16. const { relativePath, currentLayoutName, error } = useMainContext()
  17. const { t } = useTranslation(['header', 'homepage'])
  18. const [isMenuOpen, setIsMenuOpen] = useState(false)
  19. const showVersionPicker =
  20. relativePath === 'index.md' ||
  21. currentLayoutName === 'product-landing' ||
  22. currentLayoutName === 'product-sublanding'
  23. return (
  24. <div className="border-bottom color-border-secondary no-print">
  25. {error !== '404' && <HeaderNotifications />}
  26. <header
  27. className="container-xl px-3 px-md-6 pt-3 pb-3 position-relative"
  28. style={{ zIndex: 2 }}
  29. >
  30. {/* desktop header */}
  31. <div className="d-none d-lg-flex flex-justify-end">
  32. {showVersionPicker && (
  33. <div className="py-2 mr-4">
  34. <HomepageVersionPicker />
  35. </div>
  36. )}
  37. <div className="py-2">
  38. <LanguagePicker />
  39. </div>
  40. {/* <!-- GitHub.com homepage and 404 page has a stylized search; Enterprise homepages do not --> */}
  41. {relativePath !== 'index.md' && error !== '404' && (
  42. <div className="d-inline-block ml-4">
  43. <Search />
  44. </div>
  45. )}
  46. </div>
  47. {/* mobile header */}
  48. <div className="d-lg-none">
  49. <div className="d-flex flex-justify-between">
  50. <div className="d-flex flex-items-center" id="github-logo-mobile" role="banner">
  51. <Link aria-hidden="true" tabIndex={-1} href={`/${router.locale}`}>
  52. <MarkGithubIcon size={32} className="color-icon-primary" />
  53. </Link>
  54. <Link
  55. href={`/${router.locale}`}
  56. className="h4-mktg color-text-primary no-underline no-wrap pl-2"
  57. >
  58. {t('github_docs')}
  59. </Link>
  60. </div>
  61. <div>
  62. <ButtonOutline
  63. css
  64. onClick={() => setIsMenuOpen(!isMenuOpen)}
  65. aria-label="Navigation Menu"
  66. >
  67. {isMenuOpen ? <XIcon size="small" /> : <ThreeBarsIcon size="small" />}
  68. </ButtonOutline>
  69. </div>
  70. </div>
  71. {/* mobile menu contents */}
  72. <div className="relative">
  73. <div
  74. className={cx(
  75. 'width-full position-absolute left-0 right-0 color-shadow-large color-bg-primary px-3 px-md-6 pb-3',
  76. isMenuOpen ? 'd-block' : 'd-none'
  77. )}
  78. >
  79. <div className="mt-3 mb-2">
  80. <h4 className="text-mono f5 text-normal color-text-secondary">
  81. {t('explore_by_product')}
  82. </h4>
  83. <ProductPicker />
  84. </div>
  85. {/* <!-- Versions picker that only appears in the header on landing pages --> */}
  86. {showVersionPicker && (
  87. <div className="border-top py-2">
  88. <HomepageVersionPicker variant="inline" />
  89. </div>
  90. )}
  91. {/* <!-- Language picker - 'English', 'Japanese', etc --> */}
  92. <div className="border-top py-2">
  93. <LanguagePicker variant="inline" />
  94. </div>
  95. {/* <!-- GitHub.com homepage and 404 page has a stylized search; Enterprise homepages do not --> */}
  96. {relativePath !== 'index.md' && error !== '404' && (
  97. <div className="pt-3 border-top">
  98. <Search />
  99. </div>
  100. )}
  101. </div>
  102. </div>
  103. </div>
  104. </header>
  105. </div>
  106. )
  107. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...