1
1
import React from 'react' ;
2
- import styled from 'styled-components' ;
2
+ import styled , { css } from 'styled-components' ;
3
3
import { Link } from 'react-router-dom' ;
4
4
import palette from '../../lib/styles/palette' ;
5
5
import { useSpring , animated } from 'react-spring' ;
@@ -10,13 +10,17 @@ export type HorizontalTabProps = {
10
10
children : React . ReactElement < TabItemProps > [ ] ;
11
11
activeTab : string ;
12
12
tabWidth : number ;
13
+ align : 'center' | 'left' ;
14
+ theme : 'teal' | 'gray' ;
13
15
} ;
14
16
15
17
function HorizontalTab ( {
16
18
className,
17
19
children,
18
20
activeTab,
19
21
tabWidth,
22
+ align,
23
+ theme,
20
24
} : HorizontalTabProps ) {
21
25
const activeIndex = React . Children . toArray ( children ) . findIndex (
22
26
tab => tab . props . name === activeTab ,
@@ -34,22 +38,25 @@ function HorizontalTab({
34
38
} ) ;
35
39
36
40
return (
37
- < Block className = { className } >
41
+ < Block className = { className } align = { align } >
38
42
< div className = "tab-wrapper" >
39
43
{ React . Children . map ( children , tab => {
40
44
return React . cloneElement ( tab , {
41
45
active : tab . props . name === activeTab ,
42
46
width : `${ tabWidth } rem` ,
47
+ theme,
43
48
} ) ;
44
49
} ) }
45
- < Indicator style = { springStyle } />
50
+ < Indicator style = { springStyle } theme = { theme } />
46
51
</ div >
47
52
</ Block >
48
53
) ;
49
54
}
50
55
51
56
HorizontalTab . defaultProps = {
52
57
tabWidth : 8 ,
58
+ align : 'center' ,
59
+ theme : 'teal' ,
53
60
} ;
54
61
55
62
export type TabItemProps = {
@@ -58,42 +65,62 @@ export type TabItemProps = {
58
65
to : string ;
59
66
active ?: boolean ;
60
67
width ?: string ;
68
+ theme : 'teal' | 'gray' ;
61
69
} ;
62
70
63
- function TabItem ( { name, text, to, active, width } : TabItemProps ) {
71
+ function TabItem ( { name, text, to, active, width, theme } : TabItemProps ) {
64
72
return (
65
- < StyledLink to = { to } className = { active ? 'active' : '' } style = { { width } } >
73
+ < StyledLink
74
+ to = { to }
75
+ className = { active ? 'active' : '' }
76
+ style = { { width } }
77
+ theme = { theme }
78
+ >
66
79
{ text }
67
80
</ StyledLink >
68
81
) ;
69
82
}
70
83
71
- const Block = styled . div `
84
+ TabItem . defaultProps = {
85
+ theme : 'teal' ,
86
+ } ;
87
+
88
+ const Block = styled . div < { align : 'center' | 'left' } > `
72
89
display: flex;
73
- justify-content: center;
90
+ ${ props =>
91
+ props . align === 'center' &&
92
+ css `
93
+ justify-content : center;
94
+ ` }
74
95
.tab-wrapper {
75
96
display: flex;
76
97
position: relative;
77
98
}
78
99
` ;
79
100
80
- const Indicator = styled ( animated . div ) `
101
+ const Indicator = styled ( animated . div ) < { theme : 'teal' | 'gray' } > `
81
102
height: 2px;
82
103
display: block;
83
104
position: absolute;
84
105
bottom: 0px;
85
106
background: ${ palette . teal5 } ;
107
+ ${ props =>
108
+ props . theme === 'gray' &&
109
+ css `
110
+ background : ${ palette . gray8 } ;
111
+ ` }
86
112
` ;
87
113
88
- const StyledLink = styled ( Link ) `
114
+ const StyledLink = styled ( Link ) < {
115
+ theme : 'teal' | 'gray' ;
116
+ } > `
89
117
width: 8rem;
90
118
height: 3rem;
91
- font-size: 1.3125rem ;
119
+ font-size: 1.125rem ;
92
120
${ media . small } {
93
- height: 2.5rem;
94
121
font-size: 1rem;
95
122
}
96
- color: ${ palette . gray7 } ;
123
+ color: ${ palette . gray6 } ;
97
124
display: flex;
98
125
align-items: center;
99
126
justify-content: center;
@@ -102,6 +129,11 @@ const StyledLink = styled(Link)`
102
129
&.active {
103
130
font-weight: bold;
104
131
color: ${ palette . teal5 } ;
132
+ ${ props =>
133
+ props . theme === 'gray' &&
134
+ css `
135
+ color : ${ palette . gray8 } ;
136
+ ` }
105
137
}
106
138
` ;
107
139
0 commit comments