Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
1a0e35a0
Commit
1a0e35a0
authored
Oct 31, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redesigned nav link
parent
4f8801c7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
43 deletions
+28
-43
NavLink.tsx
ui/snippets/navigation/vertical/NavLink.tsx
+7
-18
NavLinkBase.tsx
ui/snippets/navigation/vertical/NavLinkBase.tsx
+16
-16
NavLinkRewards.tsx
ui/snippets/navigation/vertical/NavLinkRewards.tsx
+5
-9
No files found.
ui/snippets/navigation/vertical/NavLink.tsx
View file @
1a0e35a0
...
@@ -2,10 +2,6 @@ import React from 'react';
...
@@ -2,10 +2,6 @@ import React from 'react';
import
type
{
NavItem
}
from
'
types/client/navigation
'
;
import
type
{
NavItem
}
from
'
types/client/navigation
'
;
import
{
route
}
from
'
nextjs-routes
'
;
import
{
isInternalItem
}
from
'
lib/hooks/useNavItems
'
;
import
NavLinkBase
from
'
./NavLinkBase
'
;
import
NavLinkBase
from
'
./NavLinkBase
'
;
type
Props
=
{
type
Props
=
{
...
@@ -14,19 +10,12 @@ type Props = {
...
@@ -14,19 +10,12 @@ type Props = {
onClick
?:
()
=>
void
;
onClick
?:
()
=>
void
;
}
}
const
NavLink
=
({
item
,
isCollapsed
,
onClick
}:
Props
)
=>
{
const
NavLink
=
({
item
,
isCollapsed
,
onClick
}:
Props
)
=>
(
const
isInternalLink
=
isInternalItem
(
item
);
<
NavLinkBase
return
(
item=
{
item
}
<
NavLinkBase
onClick=
{
onClick
}
item=
{
item
}
isCollapsed=
{
isCollapsed
}
nextRoute=
{
'
nextRoute
'
in
item
?
item
.
nextRoute
:
undefined
}
/>
onClick=
{
onClick
}
);
href=
{
isInternalLink
?
route
(
item
.
nextRoute
)
:
item
.
url
}
isActive=
{
isInternalLink
&&
item
.
isActive
}
isExternal=
{
!
isInternalLink
}
isCollapsed=
{
isCollapsed
}
/>
);
};
export
default
React
.
memo
(
NavLink
);
export
default
React
.
memo
(
NavLink
);
ui/snippets/navigation/vertical/NavLinkBase.tsx
View file @
1a0e35a0
...
@@ -2,9 +2,12 @@ import { Link, Text, HStack, Tooltip, Box, useBreakpointValue } from '@chakra-ui
...
@@ -2,9 +2,12 @@ import { Link, Text, HStack, Tooltip, Box, useBreakpointValue } from '@chakra-ui
import
NextLink
from
'
next/link
'
;
import
NextLink
from
'
next/link
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
NavItem
,
NavItemExternal
,
NavItemInternal
}
from
'
types/client/navigation
'
;
import
type
{
NavItem
}
from
'
types/client/navigation
'
;
import
{
route
}
from
'
nextjs-routes
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
{
isInternalItem
}
from
'
lib/hooks/useNavItems
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
LightningLabel
,
{
LIGHTNING_LABEL_CLASS_NAME
}
from
'
../LightningLabel
'
;
import
LightningLabel
,
{
LIGHTNING_LABEL_CLASS_NAME
}
from
'
../LightningLabel
'
;
...
@@ -15,32 +18,29 @@ import { checkRouteHighlight } from '../utils';
...
@@ -15,32 +18,29 @@ import { checkRouteHighlight } from '../utils';
type
Props
=
{
type
Props
=
{
item
:
NavItem
;
item
:
NavItem
;
nextRoute
?:
NavItemInternal
[
'
nextRoute
'
]
;
onClick
?:
(
e
:
React
.
MouseEvent
)
=>
void
;
isCollapsed
?:
boolean
;
isCollapsed
?:
boolean
;
onClick
?:
()
=>
void
;
as
?:
'
a
'
|
'
button
'
;
href
?:
string
;
isExternal
?:
boolean
;
isActive
?:
boolean
;
isDisabled
?:
boolean
;
isDisabled
?:
boolean
;
}
}
const
NavLinkBase
=
({
item
,
nextRoute
,
isCollapsed
,
onClick
,
isExternal
,
as
=
'
a
'
,
href
,
isActive
,
isDisabled
}:
Props
)
=>
{
const
NavLinkBase
=
({
item
,
onClick
,
isCollapsed
,
isDisabled
}:
Props
)
=>
{
const
isMobile
=
useIsMobile
();
const
isMobile
=
useIsMobile
();
const
colors
=
useColors
();
const
colors
=
useColors
();
const
isInternalLink
=
isInternalItem
(
item
);
const
href
=
isInternalLink
?
route
(
item
.
nextRoute
)
:
item
.
url
;
const
isExpanded
=
isCollapsed
===
false
;
const
isExpanded
=
isCollapsed
===
false
;
const
styleProps
=
useNavLinkStyleProps
({
isCollapsed
,
isExpanded
,
isActive
});
const
styleProps
=
useNavLinkStyleProps
({
isCollapsed
,
isExpanded
,
isActive
:
isInternalLink
&&
item
.
isActive
});
const
isXLScreen
=
useBreakpointValue
({
base
:
false
,
xl
:
true
});
const
isXLScreen
=
useBreakpointValue
({
base
:
false
,
xl
:
true
});
const
isHighlighted
=
checkRouteHighlight
(
nextRoute
?
{
nextRoute
}
as
NavItemInternal
:
{}
as
NavItemExternal
);
const
isHighlighted
=
checkRouteHighlight
(
item
);
const
content
=
(
const
content
=
(
<
Link
<
Link
as=
{
as
}
href=
{
href
}
href=
{
href
}
target=
{
is
External
?
'
_blank
'
:
'
_self
'
}
target=
{
is
InternalLink
?
'
_self
'
:
'
_blank
'
}
{
...
styleProps
.
itemProps
}
{
...
styleProps
.
itemProps
}
w=
{
{
base
:
'
100%
'
,
lg
:
isExpanded
?
'
100%
'
:
'
60px
'
,
xl
:
isCollapsed
?
'
60px
'
:
'
100%
'
}
}
w=
{
{
base
:
'
100%
'
,
lg
:
isExpanded
?
'
100%
'
:
'
60px
'
,
xl
:
isCollapsed
?
'
60px
'
:
'
100%
'
}
}
display=
"flex"
display=
"flex"
...
@@ -62,14 +62,14 @@ const NavLinkBase = ({ item, nextRoute, isCollapsed, onClick, isExternal, as = '
...
@@ -62,14 +62,14 @@ const NavLinkBase = ({ item, nextRoute, isCollapsed, onClick, isExternal, as = '
placement=
"right"
placement=
"right"
variant=
"nav"
variant=
"nav"
gutter=
{
20
}
gutter=
{
20
}
color=
{
isActive
?
colors
.
text
.
active
:
colors
.
text
.
hover
}
color=
{
is
InternalLink
&&
item
.
is
Active
?
colors
.
text
.
active
:
colors
.
text
.
hover
}
margin=
{
0
}
margin=
{
0
}
>
>
<
HStack
spacing=
{
0
}
overflow=
"hidden"
>
<
HStack
spacing=
{
0
}
overflow=
"hidden"
>
<
NavLinkIcon
item=
{
item
}
/>
<
NavLinkIcon
item=
{
item
}
/>
<
Text
{
...
styleProps
.
textProps
}
as=
"span"
ml=
{
3
}
>
<
Text
{
...
styleProps
.
textProps
}
as=
"span"
ml=
{
3
}
>
<
span
>
{
item
.
text
}
</
span
>
<
span
>
{
item
.
text
}
</
span
>
{
isExternal
&&
<
IconSvg
name=
"link_external"
boxSize=
{
3
}
color=
"icon_link_external"
verticalAlign=
"middle"
/>
}
{
!
isInternalLink
&&
<
IconSvg
name=
"link_external"
boxSize=
{
3
}
color=
"icon_link_external"
verticalAlign=
"middle"
/>
}
</
Text
>
</
Text
>
{
isHighlighted
&&
(
{
isHighlighted
&&
(
<
LightningLabel
iconColor=
{
styleProps
.
itemProps
.
bgColor
}
isCollapsed=
{
isCollapsed
}
/>
<
LightningLabel
iconColor=
{
styleProps
.
itemProps
.
bgColor
}
isCollapsed=
{
isCollapsed
}
/>
...
@@ -81,8 +81,8 @@ const NavLinkBase = ({ item, nextRoute, isCollapsed, onClick, isExternal, as = '
...
@@ -81,8 +81,8 @@ const NavLinkBase = ({ item, nextRoute, isCollapsed, onClick, isExternal, as = '
return
(
return
(
<
Box
as=
"li"
listStyleType=
"none"
w=
"100%"
>
<
Box
as=
"li"
listStyleType=
"none"
w=
"100%"
>
{
nextRoute
?
(
{
isInternalLink
?
(
<
NextLink
href=
{
nextRoute
}
passHref
legacyBehavior
>
<
NextLink
href=
{
item
.
nextRoute
}
passHref
legacyBehavior
>
{
content
}
{
content
}
</
NextLink
>
</
NextLink
>
)
:
content
}
)
:
content
}
...
...
ui/snippets/navigation/vertical/NavLinkRewards.tsx
View file @
1a0e35a0
...
@@ -3,7 +3,6 @@ import React, { useCallback } from 'react';
...
@@ -3,7 +3,6 @@ import React, { useCallback } from 'react';
import
type
{
NavItem
}
from
'
types/client/navigation
'
;
import
type
{
NavItem
}
from
'
types/client/navigation
'
;
import
{
route
}
from
'
nextjs-routes
'
;
import
type
{
Route
}
from
'
nextjs-routes
'
;
import
type
{
Route
}
from
'
nextjs-routes
'
;
import
config
from
'
configs/app
'
;
import
config
from
'
configs/app
'
;
...
@@ -23,10 +22,9 @@ const NavLinkRewards = ({ isCollapsed, onClick }: Props) => {
...
@@ -23,10 +22,9 @@ const NavLinkRewards = ({ isCollapsed, onClick }: Props) => {
const
pathname
=
'
/account/rewards
'
;
const
pathname
=
'
/account/rewards
'
;
const
nextRoute
=
{
pathname
}
as
Route
;
const
nextRoute
=
{
pathname
}
as
Route
;
const
isLogedIn
=
isInitialized
&&
apiToken
;
const
handleClick
=
useCallback
((
e
:
React
.
MouseEvent
)
=>
{
const
handleClick
=
useCallback
(()
=>
{
if
(
isInitialized
&&
!
apiToken
)
{
if
(
isInitialized
&&
!
apiToken
)
{
e
.
preventDefault
();
openLoginModal
();
openLoginModal
();
}
}
onClick
?.();
onClick
?.();
...
@@ -41,14 +39,12 @@ const NavLinkRewards = ({ isCollapsed, onClick }: Props) => {
...
@@ -41,14 +39,12 @@ const NavLinkRewards = ({ isCollapsed, onClick }: Props) => {
item=
{
{
item=
{
{
text
:
'
Merits
'
,
text
:
'
Merits
'
,
icon
:
dailyRewardQuery
.
data
?.
available
?
'
merits_with_dot
'
:
'
merits
'
,
icon
:
dailyRewardQuery
.
data
?.
available
?
'
merits_with_dot
'
:
'
merits
'
,
nextRoute
:
nextRoute
,
isActive
:
router
.
pathname
===
pathname
,
}
as
NavItem
}
}
as
NavItem
}
nextRoute=
{
isLogedIn
?
nextRoute
:
undefined
}
onClick=
{
handleClick
}
onClick=
{
handleClick
}
as=
{
isLogedIn
?
'
a
'
:
'
button
'
}
href=
{
isLogedIn
?
route
(
nextRoute
)
:
undefined
}
isActive=
{
router
.
pathname
===
pathname
}
isDisabled=
{
!
isInitialized
}
isCollapsed=
{
isCollapsed
}
isCollapsed=
{
isCollapsed
}
isDisabled=
{
!
isInitialized
}
/>
/>
);
);
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment