From 1c07e7f4439ebdf4517aef0180b56435cde32ab2 Mon Sep 17 00:00:00 2001 From: Tabatha Zeitke Date: Thu, 27 Jan 2022 15:03:05 -0800 Subject: [PATCH] chore: override theme header correctly --- .../gatsby-theme-newrelic/GlobalHeader.js | 507 ------------------ src/layouts/QuickStartLayout.js | 7 +- 2 files changed, 5 insertions(+), 509 deletions(-) delete mode 100644 src/@newrelic/gatsby-theme-newrelic/GlobalHeader.js diff --git a/src/@newrelic/gatsby-theme-newrelic/GlobalHeader.js b/src/@newrelic/gatsby-theme-newrelic/GlobalHeader.js deleted file mode 100644 index 92263fb1..00000000 --- a/src/@newrelic/gatsby-theme-newrelic/GlobalHeader.js +++ /dev/null @@ -1,507 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import PropTypes from 'prop-types'; -import { css } from '@emotion/react'; -import { graphql, useStaticQuery, Link } from 'gatsby'; -import AnnouncementBanner from '@newrelic/gatsby-theme-newrelic/src/components/AnnouncementBanner'; -import DarkModeToggle from '@newrelic/gatsby-theme-newrelic/src/components/DarkModeToggle'; -import ExternalLink from '@newrelic/gatsby-theme-newrelic/src/components/ExternalLink'; -import Button from '@newrelic/gatsby-theme-newrelic/src/components/Button'; -import Dropdown from '@newrelic/gatsby-theme-newrelic/src/components/Dropdown'; -import NewRelicLogo from '@newrelic/gatsby-theme-newrelic/src/components/NewRelicLogo'; -import Icon from '@newrelic/gatsby-theme-newrelic/src/components/Icon'; -import GlobalNavLink from '@newrelic/gatsby-theme-newrelic/src/components/GlobalNavLink'; -import useMedia from 'use-media'; -import { useLocation } from '@reach/router'; -import useQueryParams from '@newrelic/gatsby-theme-newrelic/src/hooks/useQueryParams'; -import useLocale from '@newrelic/gatsby-theme-newrelic/src/hooks/useLocale'; -import useThemeTranslation from '@newrelic/gatsby-theme-newrelic/src/hooks/useThemeTranslation'; -import path from 'path'; -import { rgba } from 'polished'; -import SearchModal from '@newrelic/gatsby-theme-newrelic/src/components/SearchModal'; -import { useDebounce } from 'react-use'; -import useHasMounted from '@newrelic/gatsby-theme-newrelic/src/hooks/useHasMounted'; -import useTessen from '@newrelic/gatsby-theme-newrelic/src/hooks/useTessen'; -import SplitTextButton from '@newrelic/gatsby-theme-newrelic/src/components/SplitTextButton'; - -const action = css` - color: var(--secondary-text-color); - transition: all 0.2s ease-out; - - &:hover { - color: var(--secondary-text-hover-color); - } -`; - -export const NR_SITES = { - PLATFORM: 'PLATFORM', - PRICING: 'PRICING', - SOLUTIONS: 'SOLUTIONS', - DOCS: 'DOCS', - IO: 'IO', -}; - -const HEADER_LINKS = new Map(); - -HEADER_LINKS.set(NR_SITES.PLATFORM, { - text: 'Platform', - href: 'https://newrelic.com/platform', -}) - .set(NR_SITES.PRICING, { - text: 'Pricing', - href: 'https://newrelic.com/pricing', - }) - .set(NR_SITES.Solutions, { - text: 'Solutions', - href: 'https://newrelic.com/', - }) - .set(NR_SITES.DOCS, { - text: 'Docs', - href: 'https://docs.newrelic.com/', - }) - .set(NR_SITES.IO, { - text: 'Instant Observability', - href: 'https://newrelic.com/instant-observability', - }); - -const createNavList = (listType, activeSite = null) => { - const navList = []; - HEADER_LINKS.forEach(({ text, href }) => { - switch (listType) { - case 'main': - navList.push( -
  • - - {text} - -
  • - ); - break; - case 'dropdown': - navList.push( - - {text} - - ); - break; - } - }); - return navList; -}; - -// hides searchbar -const CONDENSED_BREAKPOINT = '815px'; - -// swaps out logo into collapsable nav -const NAV_BREAKPOINT = '770px'; - -// changes layout for mobile view -const MOBILE_BREAKPOINT = '600px'; - -const actionLink = css` - ${action}; - - display: flex; - align-items: center; -`; - -const actionIcon = css` - display: block; - cursor: pointer; -`; - -const useSearchQuery = () => { - const { queryParams, setQueryParam } = useQueryParams(); - const searchQueryParam = queryParams.get('q'); - const [searchTerm, setSearchTerm] = useState(searchQueryParam); - const hasQParam = queryParams.has('q'); - const tessen = useTessen(); - - useDebounce( - () => { - if (hasQParam) { - setQueryParam('q', searchTerm); - if (searchTerm && searchTerm.length > 2) { - tessen.track({ - eventName: 'swiftypeSearchInput', - category: 'GlobalSearch', - name: 'searchInput', - searchTerm, - }); - } - } - }, - 400, - [searchTerm, setQueryParam, hasQParam] - ); - - useEffect(() => { - setSearchTerm(searchQueryParam); - }, [searchQueryParam]); - - return [searchTerm, setSearchTerm]; -}; - -const GlobalHeader = ({ className, activeSite }) => { - const hasMounted = useHasMounted(); - const location = useLocation(); - const { queryParams, setQueryParam, deleteQueryParam } = useQueryParams(); - const [searchTerm, setSearchTerm] = useSearchQuery(); - const { t } = useThemeTranslation(); - - const { - allLocale: { nodes: locales }, - } = useStaticQuery(graphql` - query GlobalHeaderQuery2 { - allLocale(sort: { fields: [isDefault, locale], order: [DESC, ASC] }) { - nodes { - locale - localName - isDefault - } - } - } - `); - - const hideLogoText = useMedia({ maxWidth: '350px' }); - - const matchLocalePath = new RegExp( - `^\\/(${locales.map(({ locale }) => locale).join('|')})` - ); - - const locale = useLocale(); - - return ( - <> - setSearchTerm(searchTerm)} - onClose={() => { - deleteQueryParam('q'); - }} - isOpen={hasMounted && queryParams.has('q')} - /> - -
    -
    - - -
      li { - transition: all 0.2s ease-out; - color: var(--secondary-text-color); - - &:not(:first-of-type) { - margin-left: 0.5rem; - } - } - - @media screen and (max-width: ${CONDENSED_BREAKPOINT}) { - flex: unset; - } - `} - > -
    • - { - setQueryParam('q', ''); - }} - css={css` - ${actionLink} - - @media screen and (max-width: ${CONDENSED_BREAKPOINT}) { - display: block; - } - `} - > - - -
    • - {locales.length > 1 && ( -
    • - - - {locale.localName} - - - {locales.map(({ isDefault, locale, localName }) => ( - - {localName} - - ))} - - -
    • - )} - -
    • - -
    • -
    • - -
    • -
    • - -
    • -
    -
    -
    - - ); -}; - -GlobalHeader.propTypes = { - className: PropTypes.string, - activeSite: PropTypes.oneOf(Object.values(NR_SITES)), -}; - -export default GlobalHeader; diff --git a/src/layouts/QuickStartLayout.js b/src/layouts/QuickStartLayout.js index 16dfa679..ebc7e835 100644 --- a/src/layouts/QuickStartLayout.js +++ b/src/layouts/QuickStartLayout.js @@ -1,6 +1,9 @@ import React, { useEffect, useState } from 'react'; -import { Layout, NR_SITES } from '@newrelic/gatsby-theme-newrelic'; -import GlobalHeader from '../@newrelic/gatsby-theme-newrelic/GlobalHeader'; +import { + Layout, + GlobalHeader, + NR_SITES, +} from '@newrelic/gatsby-theme-newrelic'; import PropTypes from 'prop-types'; import { css } from '@emotion/react'; import '../components/styles.scss';