1
- import React , { ReactNode , useState } from "react"
2
- import styled from "@emotion/styled"
3
-
4
- const TabList = styled . ul `
5
- display: flex;
6
- margin: 0;
7
- list-style-type: none;
8
- list-style-image: none;
9
- `
10
-
11
- const Tab = styled . li `
12
- border-bottom: 1px solid ${ ( props ) => props . theme . colors . primary } ;
13
- margin: 0;
14
- `
15
-
16
- const TabButton = styled . button < { selected : boolean } > `
17
- display: block;
18
- cursor: pointer;
19
- color: ${ ( { theme, selected } ) =>
20
- selected ? theme . colors . background : theme . colors . text } ;
21
- background-color: ${ ( { selected, theme } ) =>
22
- selected ? theme . colors . primary : "transparent" } ;
23
- border: 0;
24
- border-top-left-radius: 0.3rem;
25
- border-top-right-radius: 0.3rem;
26
- padding: 0.3rem 1rem;
27
- `
28
-
29
- const TabPanel = styled . div `
30
- background: ${ ( props ) => props . theme . colors . ednBackground } ;
31
- border-radius: 0.5rem;
32
- border: 1px solid ${ ( props ) => props . theme . colors . lightBorder } ;
33
- margin-top: 1rem;
34
- padding: 1.5rem;
35
- `
1
+ import React , { ReactNode } from "react"
2
+ import {
3
+ Tabs as ChakraTabs ,
4
+ TabList ,
5
+ Tab ,
6
+ TabPanels ,
7
+ TabPanel ,
8
+ } from "@chakra-ui/react"
36
9
37
10
interface Tab {
38
11
title : string
@@ -44,38 +17,28 @@ export interface IProps {
44
17
onTabClick ?: ( tabIndex : number ) => void
45
18
}
46
19
47
- /**
48
- * Minimal & temp Tab component until we migrate over a UI lib
49
- */
50
20
const Tabs : React . FC < IProps > = ( { tabs, onTabClick } ) => {
51
- const [ selectedIndex , setSelectedIndex ] = useState ( 0 )
52
- const selectedTab = tabs [ selectedIndex ]
53
-
54
21
const handleTabClick = ( index : number ) => {
55
- setSelectedIndex ( index )
56
-
57
22
if ( onTabClick ) {
58
23
onTabClick ( index )
59
24
}
60
25
}
61
26
62
27
return (
63
- < div >
64
- < nav >
65
- < TabList >
66
- { tabs . map ( ( tab , index ) => (
67
- < Tab key = { index } onClick = { ( ) => handleTabClick ( index ) } >
68
- < TabButton selected = { index === selectedIndex } >
69
- { tab . title }
70
- </ TabButton >
71
- </ Tab >
72
- ) ) }
73
- </ TabList >
74
- </ nav >
75
- < main >
76
- < TabPanel > { selectedTab . content } </ TabPanel >
77
- </ main >
78
- </ div >
28
+ < ChakraTabs as = "nav" >
29
+ < TabList >
30
+ { tabs . map ( ( tab , index ) => (
31
+ < Tab key = { index } onClick = { ( ) => handleTabClick ( index ) } >
32
+ { tab . title }
33
+ </ Tab >
34
+ ) ) }
35
+ </ TabList >
36
+ < TabPanels as = "main" >
37
+ { tabs . map ( ( tab , index ) => (
38
+ < TabPanel key = { index } > { tab . content } </ TabPanel >
39
+ ) ) }
40
+ </ TabPanels >
41
+ </ ChakraTabs >
79
42
)
80
43
}
81
44
0 commit comments