-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Header
component adjustements (#357)
Ref: #355 ## Goal: To adjust `Header` component following latest design changes ## Done: - Implement generic `Link` and `NavLink` components, a fusion of Chakra's and Router's `Link` component - Implement `Navigation` component with animated active item indicator - Added conditional rendering for `ConnectWallet` component with presence animation
- Loading branch information
Showing
13 changed files
with
210 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from "react" | ||
import { Box, BoxProps, HStack, List } from "@chakra-ui/react" | ||
import { NavigationItemType } from "#/types/navigation" | ||
import NavigationItem from "./NavigationItem" | ||
|
||
type NavigationProps = BoxProps & { | ||
items: NavigationItemType[] | ||
} | ||
|
||
function Navigation(props: NavigationProps) { | ||
const { items, ...restProps } = props | ||
|
||
return ( | ||
<Box as="nav" {...restProps}> | ||
<HStack as={List} spacing={5} ml={12}> | ||
{items.map((item) => ( | ||
<NavigationItem key={item.href} {...item} /> | ||
))} | ||
</HStack> | ||
</Box> | ||
) | ||
} | ||
|
||
export default Navigation |
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,38 @@ | ||
import React from "react" | ||
import { | ||
Box, | ||
ListItem, | ||
ListItemProps, | ||
useMultiStyleConfig, | ||
} from "@chakra-ui/react" | ||
import { motion } from "framer-motion" | ||
import { NavigationItemType } from "#/types/navigation" | ||
import { NavLink } from "../../shared/NavLink" | ||
|
||
type NavigationItemProps = ListItemProps & NavigationItemType | ||
|
||
function NavigationItem(props: NavigationItemProps) { | ||
const { label, href, ...restProps } = props | ||
const styles = useMultiStyleConfig("Link", { variant: "navigation" }) | ||
|
||
return ( | ||
<ListItem pos="relative" {...restProps}> | ||
<NavLink to={href} sx={styles.container}> | ||
{({ isActive }) => ( | ||
<> | ||
{label} | ||
{isActive && ( | ||
<Box | ||
as={motion.span} | ||
layoutId="active-route-indicator" | ||
sx={styles.indicator} | ||
/> | ||
)} | ||
</> | ||
)} | ||
</NavLink> | ||
</ListItem> | ||
) | ||
} | ||
|
||
export default NavigationItem |
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 { default as Navigation } from "./Navigation" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from "react" | ||
import { | ||
Link as ChakraLink, | ||
LinkProps as ChakraLinkProps, | ||
} from "@chakra-ui/react" | ||
import { | ||
Link as RouterLink, | ||
LinkProps as RouterLinkProps, | ||
} from "react-router-dom" | ||
|
||
type LinkProps = Omit<ChakraLinkProps, "as" | "href"> & | ||
Pick<RouterLinkProps, "to"> | ||
|
||
export function Link(props: LinkProps) { | ||
return <ChakraLink as={RouterLink} {...props} /> | ||
} |
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,21 @@ | ||
import React from "react" | ||
import { | ||
Link as ChakraLink, | ||
LinkProps as ChakraLinkProps, | ||
} from "@chakra-ui/react" | ||
import { | ||
NavLink as RouterNavLink, | ||
NavLinkProps as RouterNavLinkProps, | ||
} from "react-router-dom" | ||
|
||
type NavLinkProps = Omit<ChakraLinkProps, "as" | "href" | "children"> & | ||
Pick<RouterNavLinkProps, "to" | "children"> | ||
|
||
export function NavLink(props: NavLinkProps) { | ||
const { children, ...restProps } = props | ||
return ( | ||
<ChakraLink as={RouterNavLink} {...restProps}> | ||
{children as React.ReactNode} | ||
</ChakraLink> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./useIsActiveRoute" |
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,10 @@ | ||
import { routerPath } from "#/router/path" | ||
import { useLocation } from "react-router-dom" | ||
|
||
export const useIsActiveRoute = (route: string) => { | ||
const location = useLocation() | ||
|
||
return location.pathname === route | ||
} | ||
|
||
export const useIsHomeRouteActive = () => useIsActiveRoute(routerPath.home) |
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
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,4 @@ | ||
export type NavigationItemType = { | ||
label: string | ||
href: string | ||
} |