1
1
import styled from 'styled-components' ;
2
- import { LayoutGroup , motion } from 'framer-motion' ;
3
2
4
3
import { spacingsPx , zIndices } from '@trezor/theme' ;
5
- import { motionEasing , variables } from '@trezor/components' ;
4
+ import { Tabs } from '@trezor/components' ;
6
5
import { Route } from '@suite-common/suite-types' ;
7
6
8
7
import { useSelector } from 'src/hooks/suite' ;
9
8
import { selectRouteName } from 'src/reducers/suite/routerReducer' ;
10
- import { SUBPAGE_NAV_HEIGHT } from 'src/constants/suite/layout' ;
11
- import { selectIsLoggedOut } from 'src/reducers/suite/suiteReducer' ;
9
+ import { HEADER_HEIGHT } from 'src/constants/suite/layout' ;
12
10
13
- import { HoverAnimation } from '../../HoverAnimation' ;
14
11
import { AppNavigationTooltip } from '../../AppNavigation/AppNavigationTooltip' ;
15
12
16
- const Container = styled . div < { $isFullWidth : boolean } > `
13
+ const Container = styled . div `
17
14
position: sticky;
18
- top: 64px;
19
- display: flex;
20
- justify-content: flex-start;
21
- gap: ${ spacingsPx . sm } ;
22
- min-height: ${ SUBPAGE_NAV_HEIGHT } ;
15
+ top: ${ HEADER_HEIGHT } ;
23
16
background: ${ ( { theme } ) => theme . backgroundSurfaceElevation0 } ;
24
- padding: ${ spacingsPx . xs } 0 ${ spacingsPx . sm } ;
25
17
border-bottom: 1px solid ${ ( { theme } ) => theme . borderElevation1 } ;
26
- overflow: auto hidden;
27
18
z-index: ${ zIndices . pageHeader } ;
28
19
width: 100%;
29
- padding-left: ${ spacingsPx . md } ;
30
- padding-right: ${ spacingsPx . md } ;
31
- ` ;
32
-
33
- const MenuElement = styled . div < { $isActive : boolean } > `
34
- position: relative;
35
- display: flex;
36
- align-items: center;
37
- color: ${ ( { $isActive, theme } ) => ! $isActive && theme . textOnTertiary } ;
38
- white-space: nowrap;
39
-
40
- @media (max-width: ${ variables . SCREEN_SIZE . SM } ) {
41
- margin-right: ${ spacingsPx . md } ;
42
- }
43
- ` ;
44
-
45
- const Underline = styled ( motion . div ) `
46
- position: absolute;
47
- bottom: -${ spacingsPx . sm } ;
48
- left: 0;
49
- right: 0;
50
- height: 2px;
51
- background: ${ ( { theme } ) => theme . iconDefault } ;
52
- ` ;
53
-
54
- const StyledNavLink = styled . div < { $isActive : boolean ; $isNavigationDisabled : boolean } > `
55
- padding: ${ spacingsPx . xs } ${ spacingsPx . sm } ;
56
- opacity: ${ ( { $isActive, $isNavigationDisabled } ) =>
57
- ! $isActive && $isNavigationDisabled && '.5' } ;
58
- cursor: ${ ( { $isActive, $isNavigationDisabled } ) =>
59
- $isActive || $isNavigationDisabled ? 'default' : 'pointer' } ;
20
+ padding: ${ spacingsPx . md } ${ spacingsPx . md } 0;
60
21
` ;
61
22
62
23
type TabRoute = Route [ 'name' ] | undefined ;
@@ -70,62 +31,37 @@ export type NavigationItem = {
70
31
activeRoutes ?: TabRoute [ ] ;
71
32
} ;
72
33
73
- interface SubpageNavigationProps {
34
+ type SubpageNavigationProps = {
74
35
items : NavigationItem [ ] ;
75
- className ?: string ;
76
- }
36
+ } ;
77
37
78
- export const SubpageNavigation = ( { items, className } : SubpageNavigationProps ) => {
38
+ export const SubpageNavigation = ( { items } : SubpageNavigationProps ) => {
79
39
const routeName = useSelector ( selectRouteName ) ;
80
40
const selectedAccount = useSelector ( state => state . wallet . selectedAccount ) ;
81
- const isLoggedOut = useSelector ( selectIsLoggedOut ) ;
82
41
83
42
const isAccountLoading = selectedAccount . status === 'loading' ;
84
-
85
- const visibleItems = items . filter ( item => ! item . isHidden ) ;
43
+ const activeItemdId = items . find (
44
+ ( { id, activeRoutes } ) => activeRoutes ?. includes ( routeName ) || id === routeName ,
45
+ ) ?. id ;
86
46
87
47
return (
88
- < Container $isFullWidth = { isLoggedOut } className = { className } >
89
- < LayoutGroup id = { items [ 0 ] . id } >
90
- { visibleItems . map ( item => {
91
- const { id, title, activeRoutes } = item ;
92
-
93
- const isActive = activeRoutes
94
- ? activeRoutes . includes ( routeName )
95
- : routeName === id ;
96
- const isHoverable = ! isActive && ! isAccountLoading ;
97
- const onClick = isAccountLoading ? undefined : item . callback ;
98
-
99
- return (
100
- < MenuElement key = { id } $isActive = { isActive } >
101
- < HoverAnimation isHoverable = { isHoverable } >
102
- < AppNavigationTooltip isActiveTab = { isActive } >
103
- < StyledNavLink
104
- $isActive = { isActive }
105
- $isNavigationDisabled = { isAccountLoading }
106
- onClick = { onClick }
107
- data-testid = { item [ 'data-testid' ] }
108
- >
109
- { title }
110
- </ StyledNavLink >
111
- </ AppNavigationTooltip >
112
- </ HoverAnimation >
113
-
114
- { isActive && (
115
- < Underline
116
- // TODO: get rid of the weird jump when switching tabs on the account page before enabling this
117
- // layoutId="underline"
118
- transition = { {
119
- layout : {
120
- ease : motionEasing . transition ,
121
- } ,
122
- } }
123
- />
124
- ) }
125
- </ MenuElement >
126
- ) ;
127
- } ) }
128
- </ LayoutGroup >
48
+ < Container >
49
+ < AppNavigationTooltip >
50
+ < Tabs
51
+ hasBorder = { false }
52
+ size = "large"
53
+ isDisabled = { isAccountLoading }
54
+ activeItemId = { activeItemdId }
55
+ >
56
+ { items
57
+ . filter ( item => ! item . isHidden )
58
+ . map ( ( { id, callback, title, 'data-testid' : dataTestId } ) => (
59
+ < Tabs . Item key = { id } id = { id } onClick = { callback } data-testid = { dataTestId } >
60
+ { title }
61
+ </ Tabs . Item >
62
+ ) ) }
63
+ </ Tabs >
64
+ </ AppNavigationTooltip >
129
65
</ Container >
130
66
) ;
131
67
} ;
0 commit comments