-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1069 from near/feat/navigation-rework
New Navigation Layout (Sidebar)
- Loading branch information
Showing
57 changed files
with
1,806 additions
and
157 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,27 @@ | ||
import styled from 'styled-components'; | ||
|
||
import { useBosComponents } from '@/hooks/useBosComponents'; | ||
import { useCookiePreferences } from '@/hooks/useCookiePreferences'; | ||
|
||
import { VmComponent } from './vm/VmComponent'; | ||
|
||
const Wrapper = styled.div` | ||
position: fixed; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
`; | ||
|
||
export const CookiePrompt = () => { | ||
const cookieData = useCookiePreferences(); | ||
const components = useBosComponents(); | ||
return ( | ||
<Wrapper> | ||
<VmComponent | ||
showLoadingSpinner={false} | ||
src={components.nearOrg.cookiePrompt} | ||
props={{ cookiesAcknowleged: cookieData }} | ||
/> | ||
</Wrapper> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,19 +1,96 @@ | ||
import type { ReactNode } from 'react'; | ||
import { useRouter } from 'next/router'; | ||
import { type ReactNode, useEffect, useState } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import { sidebarLayoutEnabled as sidebarLayoutFeatureFlagEnabled } from '@/utils/config'; | ||
|
||
import { BosLoaderBanner } from '../BosLoaderBanner'; | ||
import { Navigation } from '../navigation/Navigation'; | ||
import { MarketingNavigation } from '../marketing-navigation/MarketingNavigation'; | ||
import { LargeScreenHeader } from '../sidebar-navigation/LargeScreenHeader'; | ||
import { SidebarNavigation } from '../sidebar-navigation/SidebarNavigation'; | ||
import { useNavigationStore } from '../sidebar-navigation/store'; | ||
import { SMALL_SCREEN_LAYOUT_MAX_WIDTH } from '../sidebar-navigation/utils'; | ||
|
||
interface Props { | ||
children: ReactNode; | ||
} | ||
|
||
const Wrapper = styled.div<{ | ||
$animate: boolean; | ||
$sidebar: boolean; | ||
}>` | ||
--sidebar-expand-transition-speed: ${(p) => (p.$animate ? '300ms' : '0ms')}; | ||
--sidebar-width-expanded: 256px; | ||
--sidebar-width-collapsed: 68px; | ||
--header-height: 64px; | ||
display: flex; | ||
min-height: 100vh; | ||
min-width: 0; | ||
justify-content: stretch; | ||
align-items: stretch; | ||
flex-direction: ${(p) => (p.$sidebar ? 'row' : 'column')}; | ||
@media (max-width: ${SMALL_SCREEN_LAYOUT_MAX_WIDTH}px) { | ||
--sidebar-width-expanded: 100vw; | ||
flex-direction: column; | ||
} | ||
`; | ||
|
||
const Content = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
flex-grow: 1; | ||
justify-content: stretch; | ||
align-items: stretch; | ||
min-width: 0; | ||
`; | ||
|
||
export function DefaultLayout({ children }: Props) { | ||
const router = useRouter(); | ||
const [sidebarLayoutTestOverrideEnabled, setSidebarLayoutTestOverrideEnabled] = useState(false); | ||
const [sidebarLayoutShouldAnimate, setSidebarLayoutShouldAnimate] = useState(false); | ||
const sidebarLayoutEnabled = sidebarLayoutTestOverrideEnabled || sidebarLayoutFeatureFlagEnabled; | ||
const sidebarLayoutHasInitialized = useNavigationStore((store) => store.hasInitialized); | ||
|
||
useEffect(() => { | ||
/* | ||
This logic is only needed for short term testing. | ||
Add "?sidebar=true" to any URL to temporarily enable the sidebar layout. | ||
*/ | ||
|
||
if (router.query.sidebar === 'true') { | ||
setSidebarLayoutTestOverrideEnabled(true); | ||
} | ||
}, [router.query]); | ||
|
||
useEffect(() => { | ||
/* | ||
We need to temporarily disable transition animations for the sidebar | ||
until the expanded preference has resolved from local storage. Without | ||
this logic, the sidebar would animate to collapsed on page load if the | ||
user prefers the sidebar collapsed - the sidebar should initialize in | ||
its proper collapsed or expanded state with animating on page load. | ||
*/ | ||
|
||
if (sidebarLayoutHasInitialized) { | ||
setTimeout(() => { | ||
setSidebarLayoutShouldAnimate(true); | ||
}, 100); | ||
} | ||
}, [sidebarLayoutHasInitialized]); | ||
|
||
return ( | ||
<> | ||
<Navigation /> | ||
<BosLoaderBanner /> | ||
<Wrapper $animate={sidebarLayoutShouldAnimate} $sidebar={sidebarLayoutEnabled}> | ||
{sidebarLayoutEnabled ? <SidebarNavigation /> : <MarketingNavigation />} | ||
|
||
<Content> | ||
{sidebarLayoutEnabled && <LargeScreenHeader />} | ||
|
||
<BosLoaderBanner /> | ||
|
||
{children} | ||
</> | ||
{children} | ||
</Content> | ||
</Wrapper> | ||
); | ||
} |
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,15 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const RootContentContainer = styled.div` | ||
/* | ||
NOTE: We don't want to set max-width or padding on this root container. If we did, | ||
it would be impossible for application/component developers to have UI that bleeds | ||
to the edge for designs that require background colors or images. The developer of | ||
the components is responsible for setting an appropriate max-width and/or padding. | ||
*/ | ||
flex-grow: 1; | ||
width: 100%; | ||
position: relative; | ||
overflow: hidden; | ||
`; |
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 @@ | ||
export * from './Container'; |
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,84 @@ | ||
# Tooltip | ||
|
||
Implemented via Radix primitives: https://www.radix-ui.com/docs/primitives/components/tooltip | ||
|
||
_If the current props and Stitches style overrides aren't enough to cover your use case, feel free to implement your own component using the Radix primitives directly._ | ||
|
||
## Example | ||
|
||
Simply wrap the element you desire to have a tooltip with the `<Tooltip>` component: | ||
|
||
```tsx | ||
import { Tooltip } from '@/components/lib/Tooltip'; | ||
|
||
... | ||
|
||
<Tooltip content="I am the tooltip message."> | ||
<Button>Curious Button</Button> | ||
</Tooltip> | ||
``` | ||
|
||
## Props | ||
|
||
To simplify usage of the Radix tooltip primitives, the component abstracts away the need for using `Root`, `Trigger`, and `Content` - all you need to do is use the single `<Tooltip>` component as shown above. | ||
|
||
To pass a [Root](https://www.radix-ui.com/docs/primitives/components/tooltip#root) option, use the `root={{}}` property like so: | ||
|
||
```tsx | ||
<Tooltip | ||
content="I am the tooltip message." | ||
root={{ | ||
delayDuration: 500, | ||
}} | ||
> | ||
... | ||
</Tooltip> | ||
``` | ||
|
||
To pass a [Content](https://www.radix-ui.com/docs/primitives/components/tooltip#content) option, pass it as you normally would like so: | ||
|
||
```tsx | ||
<Tooltip content="I am the tooltip message." side="left" align="end"> | ||
... | ||
</Tooltip> | ||
``` | ||
|
||
## Content | ||
|
||
The `content` prop can be passed a string to render a default message: | ||
|
||
```tsx | ||
<Tooltip content="I am the tooltip message.">...</Tooltip> | ||
``` | ||
|
||
A `ReactNode` can also be passed if you want to use a custom set of elements for the message. | ||
|
||
```tsx | ||
<Tooltip | ||
content={ | ||
<> | ||
<FeatherIcon icon="eye" /> I have an icon. | ||
</> | ||
} | ||
> | ||
... | ||
</Tooltip> | ||
``` | ||
|
||
## Disabled | ||
|
||
Sometimes you might need to temporarily disable the tooltip from appearing. You can use the `disabled` prop to prevent the tooltip from showing while still letting the child element be interacted with: | ||
|
||
```tsx | ||
<Tooltip content="I am the tooltip message." disabled={shouldDisableTooltip}> | ||
<Button>Curious Button</Button> | ||
</Tooltip> | ||
``` | ||
|
||
You can also disable the tooltip for touch screens: | ||
|
||
```tsx | ||
<Tooltip content="I will not show on touch screen devices." disabledTouchScreen> | ||
<Button>Curious Button</Button> | ||
</Tooltip> | ||
``` |
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,42 @@ | ||
import * as Primitive from '@radix-ui/react-tooltip'; | ||
import type { ComponentProps, ReactElement, ReactNode } from 'react'; | ||
|
||
import * as S from './styles'; | ||
|
||
type RootProps = Omit<ComponentProps<typeof Primitive.Root>, 'children'>; | ||
type ContentProps = ComponentProps<typeof Primitive.Content>; | ||
|
||
type Props = ContentProps & { | ||
children: ReactElement; | ||
content: ReactNode; | ||
disabled?: boolean; | ||
root?: RootProps; | ||
}; | ||
|
||
export const Tooltip = ({ | ||
children, | ||
content, | ||
disabled, | ||
root = { disableHoverableContent: true }, | ||
side = 'top', | ||
sideOffset = 3, | ||
...props | ||
}: Props) => { | ||
const delayDuration = root?.delayDuration || 300; | ||
|
||
return ( | ||
<Primitive.Provider> | ||
<Primitive.Root delayDuration={delayDuration} open={disabled ? false : undefined} {...root}> | ||
<Primitive.Trigger asChild>{children}</Primitive.Trigger> | ||
|
||
<Primitive.Portal> | ||
<S.Content side={side} sideOffset={sideOffset} {...props} ref={undefined}> | ||
{content} | ||
<S.ArrowBorder /> | ||
<S.ArrowFill /> | ||
</S.Content> | ||
</Primitive.Portal> | ||
</Primitive.Root> | ||
</Primitive.Provider> | ||
); | ||
}; |
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 @@ | ||
export * from './Tooltip'; |
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,36 @@ | ||
import * as Primitive from '@radix-ui/react-tooltip'; | ||
import styled from 'styled-components'; | ||
|
||
export const Content = styled(Primitive.Content)` | ||
border-radius: 0.25rem; | ||
padding: 0.3rem 0.5rem; | ||
display: flex; | ||
align-items: center; | ||
gap: 0.5rem; | ||
color: var(--sand12); | ||
background-color: var(--white); | ||
z-index: 2000; | ||
max-width: 20rem; | ||
font-size: 0.8rem; | ||
line-height: 1.5; | ||
word-break: break-word; | ||
font-family: sans-serif; | ||
box-shadow: 0 0 0 1px var(--sand6), 0 1px 2px 0 rgba(0, 0, 0, 0.06); | ||
`; | ||
|
||
export const ArrowBorder = styled(Primitive.Arrow)` | ||
fill: var(--sand6); | ||
stroke: var(--sand6); | ||
stroke-width: 2px; | ||
margin-top: 1px; | ||
margin-right: 1px; | ||
[data-side='bottom'] &, | ||
[data-side='left'] & { | ||
margin-right: -1px; | ||
} | ||
`; | ||
|
||
export const ArrowFill = styled(Primitive.Arrow)` | ||
fill: var(--white); | ||
`; |
File renamed without changes.
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
1 change: 0 additions & 1 deletion
1
...ponents/navigation/NotificationButton.tsx → ...rketing-navigation/NotificationButton.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.