-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
172 additions
and
108 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
58 changes: 58 additions & 0 deletions
58
packages/shared-ux/chrome/navigation/src/ui/components/header.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { EuiHeaderLogo, EuiLoadingSpinner } from '@elastic/eui'; | ||
import React from 'react'; | ||
import useObservable from 'react-use/lib/useObservable'; | ||
import { NavigationProps, NavigationServices } from '../../../types'; | ||
import { getI18nStrings } from '../../i18n_strings'; | ||
import { ElasticMark } from './elastic_mark'; | ||
import './header_logo.scss'; | ||
|
||
type Props = Pick<NavigationProps, 'homeHref'>; | ||
type Services = Pick< | ||
NavigationServices, | ||
'basePath' | 'navIsOpen' | 'navigateToUrl' | 'loadingCount$' | ||
>; | ||
|
||
export const NavHeader = (props: Props & Services) => { | ||
const strings = getI18nStrings(); | ||
const { basePath, navIsOpen, navigateToUrl, loadingCount$, homeHref } = props; | ||
|
||
const loadingCount = useObservable(loadingCount$, 0); | ||
const homeUrl = basePath.prepend(homeHref); | ||
const navigateHome = (event: React.MouseEvent) => { | ||
event.preventDefault(); | ||
navigateToUrl(homeUrl); | ||
}; | ||
const logo = | ||
loadingCount === 0 ? ( | ||
<EuiHeaderLogo | ||
iconType="logoElastic" | ||
aria-label={strings.headerLogoAriaLabel} | ||
onClick={navigateHome} | ||
data-test-subj="nav-header-logo" | ||
/> | ||
) : ( | ||
<a href={homeUrl} onClick={navigateHome}> | ||
<EuiLoadingSpinner | ||
size="l" | ||
aria-hidden={false} | ||
onClick={navigateHome} | ||
data-test-subj="nav-header-loading-spinner" | ||
/> | ||
</a> | ||
); | ||
|
||
return ( | ||
<> | ||
{logo} | ||
{navIsOpen ? <ElasticMark className="chrHeaderLogo__mark" aria-hidden={true} /> : null} | ||
</> | ||
); | ||
}; |
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
packages/shared-ux/chrome/navigation/src/ui/components/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { NavHeader } from './header'; | ||
export { LinkToCloud } from './link_to_cloud'; | ||
export { NavigationBucket } from './navigation_bucket'; | ||
export { RecentlyAccessed } from './recently_accessed'; |
45 changes: 45 additions & 0 deletions
45
packages/shared-ux/chrome/navigation/src/ui/components/link_to_cloud.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { EuiCollapsibleNavGroup, EuiLink } from '@elastic/eui'; | ||
import React from 'react'; | ||
import { NavigationProps } from '../../../types'; | ||
import { getI18nStrings } from '../../i18n_strings'; | ||
|
||
interface Props { | ||
linkToCloud?: NavigationProps['homeHref']; | ||
} | ||
|
||
export const LinkToCloud = (props: Props) => { | ||
const strings = getI18nStrings(); | ||
|
||
switch (props.linkToCloud) { | ||
case 'projects': | ||
return ( | ||
<EuiLink | ||
href="https://cloud.elastic.co/projects" | ||
color="text" | ||
data-test-subj="nav-header-link-to-projects" | ||
> | ||
<EuiCollapsibleNavGroup iconType="spaces" title={strings.linkToCloudProjects} /> | ||
</EuiLink> | ||
); | ||
case 'deployments': | ||
return ( | ||
<EuiLink | ||
href="https://cloud.elastic.co/deployments" | ||
color="text" | ||
data-test-subj="nav-header-link-to-deployments" | ||
> | ||
<EuiCollapsibleNavGroup iconType="spaces" title={strings.linkToCloudDeployments} /> | ||
</EuiLink> | ||
); | ||
default: | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/shared-ux/chrome/navigation/src/ui/components/recently_accessed.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { EuiCollapsibleNavGroup, EuiSideNav, EuiSideNavItemType } from '@elastic/eui'; | ||
import React from 'react'; | ||
import useObservable from 'react-use/lib/useObservable'; | ||
import { NavigationProps, NavigationServices } from '../../../types'; | ||
import { getI18nStrings } from '../../i18n_strings'; | ||
import { navigationStyles as styles } from '../../styles'; | ||
|
||
interface Props { | ||
recentlyAccessed$: Observable<RecentItem[]>; | ||
} | ||
|
||
export const RecentlyAccessed = (props: Props) => { | ||
const strings = getI18nStrings(); | ||
const recentlyAccessed = useObservable(props.recentlyAccessed$, []); | ||
if (recentlyAccessed.length > 0) { | ||
const navItems: Array<EuiSideNavItemType<unknown>> = [ | ||
{ | ||
name: '', // no list header title | ||
id: 'recents_root', | ||
items: recentlyAccessed.map(({ id, label, link }) => ({ | ||
id, | ||
name: label, | ||
href: link, | ||
})), | ||
}, | ||
]; | ||
|
||
return ( | ||
<EuiCollapsibleNavGroup | ||
title={strings.recentlyAccessed} | ||
iconType="clock" | ||
isCollapsible={true} | ||
initialIsOpen={true} | ||
data-test-subj={`nav-bucket-recentlyAccessed`} | ||
> | ||
<EuiSideNav items={navItems} css={styles.euiSideNavItems} /> | ||
</EuiCollapsibleNavGroup> | ||
); | ||
} | ||
|
||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters