Skip to content

Commit 9b6ac4e

Browse files
authored
Fix tab props
1 parent 1b06746 commit 9b6ac4e

File tree

1 file changed

+82
-76
lines changed

1 file changed

+82
-76
lines changed

src/components/tabs/Tabs.tsx

Lines changed: 82 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ import { Box } from "../box";
77
import { Button } from "../button";
88

99
interface TabProps {
10-
className?:string;
10+
className?: string;
1111
wizard?: boolean;
1212
step?: number;
1313
heading?: string;
14-
caption?:string;
15-
activeTab: number;
14+
caption?: string;
15+
activeTab?: number;
1616
children?: React.ReactNode;
1717
onClick?: (e: any) => void;
1818
onChange?: (e: any) => void;
1919
props?: any;
20-
styleActive?:boolean;
21-
index: number;
20+
styleActive?: boolean;
21+
index?: number;
2222
disabled?: boolean;
23-
buttons?:React.ReactNode;
23+
buttons?: React.ReactNode;
2424
}
2525

2626
interface TabsProps {
@@ -42,18 +42,18 @@ interface ButtonNextProps {
4242

4343
const TabsContent = styled(Box)`
4444
background-color: ${theme.colors.snowwhite};
45-
border-top:${theme.borders.grey};
46-
border-top-left-radius:0;
47-
border-top-right-radius:0;
48-
box-shadow:none;
45+
border-top: ${theme.borders.grey};
46+
border-top-left-radius: 0;
47+
border-top-right-radius: 0;
48+
box-shadow: none;
4949
padding: ${theme.spacing.spacing07} ${theme.spacing.spacing04};
5050
p {
5151
line-height: 1.5rem;
5252
&:first-child {
53-
margin-top:0;
53+
margin-top: 0;
5454
}
5555
&:last-child {
56-
margin-bottom:0;
56+
margin-bottom: 0;
5757
}
5858
}
5959
`;
@@ -62,71 +62,70 @@ const TabContainer: any = styled.li<TabProps>`
6262
display: inline-block;
6363
list-style: none;
6464
margin-bottom: -1px;
65-
padding:${theme.spacing.spacing04};
66-
background-color:${theme.colors.white};
67-
border-bottom:${theme.borders.grey};
68-
border-right:${theme.borders.grey};
65+
padding: ${theme.spacing.spacing04};
66+
background-color: ${theme.colors.white};
67+
border-bottom: ${theme.borders.grey};
68+
border-right: ${theme.borders.grey};
6969
min-width: 15.625rem;
7070
&:last-child {
71-
border-right:none;
71+
border-right: none;
7272
&.tab-active {
73-
border-right:${theme.borders.grey};
73+
border-right: ${theme.borders.grey};
7474
}
7575
}
7676
7777
&:hover {
78-
cursor: ${({ disabled }) =>
79-
disabled ? `auto` : `pointer`};
80-
background-color:${({ disabled }) =>
81-
disabled ? `${theme.colors.white}` : `${theme.colors.lights[1]}`};
78+
cursor: ${({ disabled }) => (disabled ? `auto` : `pointer`)};
79+
background-color: ${({ disabled }) =>
80+
disabled ? `${theme.colors.white}` : `${theme.colors.lights[1]}`};
8281
}
8382
8483
h5 {
85-
margin:0;
86-
font-weight:${theme.fontWeights.medium};
84+
margin: 0;
85+
font-weight: ${theme.fontWeights.medium};
8786
color: ${theme.colors.darks[2]};
8887
}
8988
p {
90-
margin:${theme.spacing.spacing01} 0 0;
89+
margin: ${theme.spacing.spacing01} 0 0;
9190
}
9291
&.tab-active {
93-
background-color:${theme.colors.snowwhite};
94-
border-bottom:1px solid transparent;
92+
background-color: ${theme.colors.snowwhite};
93+
border-bottom: 1px solid transparent;
9594
}
9695
`;
9796

9897
const TabsList = styled.ol`
99-
padding:0;
100-
margin:0;
98+
padding: 0;
99+
margin: 0;
101100
`;
102101

103102
const TabsWrapper = styled(Box)`
104-
padding:0;
103+
padding: 0;
105104
`;
106105

107106
const Step = styled(Box)`
108-
padding:0;
109-
display:flex;
110-
align-items:center;
111-
justify-content:center;
112-
width:2rem;
113-
height:2rem;
114-
box-shadow:none;
107+
padding: 0;
108+
display: flex;
109+
align-items: center;
110+
justify-content: center;
111+
width: 2rem;
112+
height: 2rem;
113+
box-shadow: none;
115114
margin-bottom: ${theme.spacing.spacing04};
116115
background-color: ${theme.colors.lights[2]};
117116
color: ${theme.colors.darks[3]};
118117
119118
&.dark {
120-
background:${theme.colors.primary};
121-
color:${theme.colors.white};
119+
background: ${theme.colors.primary};
120+
color: ${theme.colors.white};
122121
}
123122
`;
124123

125124
const TabsStatusButtons = styled.div`
126125
padding: ${theme.spacing.spacing04};
127126
border-top: ${theme.borders.grey};
128-
display:flex;
129-
position:relative;
127+
display: flex;
128+
position: relative;
130129
`;
131130

132131
const TabsCover = styled.div`
@@ -136,31 +135,32 @@ const TabsCover = styled.div`
136135
`;
137136

138137
const PreviousButton = styled(Button)`
139-
position: absolute;
140-
border:none;
138+
border: none;
141139
`;
142140
const NextButton = styled(Button)`
143-
margin-left:auto;
144-
margin-right:auto;
141+
margin-left: auto;
142+
margin-right: auto;
145143
`;
146144

147-
export const ButtonPrevious: FunctionComponent<ButtonPreviousProps> = ({
145+
export const ButtonPrevious: FunctionComponent<ButtonPreviousProps> = ({
148146
onClick,
149-
children
147+
children,
150148
}) => {
151149
return (
152-
<PreviousButton outline onClick={onClick}>{children}</PreviousButton>
153-
)};
150+
<PreviousButton outline onClick={onClick}>
151+
{children}
152+
</PreviousButton>
153+
);
154+
};
154155

155-
export const ButtonNext: FunctionComponent<ButtonNextProps> = ({
156+
export const ButtonNext: FunctionComponent<ButtonNextProps> = ({
156157
onClick,
157-
children
158+
children,
158159
}) => {
159-
return (
160-
<NextButton onClick={onClick}>{children}</NextButton>
161-
)};
160+
return <NextButton onClick={onClick}>{children}</NextButton>;
161+
};
162162

163-
export const Tab: FunctionComponent<TabProps> = ({
163+
export const Tab: FunctionComponent<TabProps> = ({
164164
wizard,
165165
step,
166166
heading,
@@ -169,23 +169,32 @@ export const Tab: FunctionComponent<TabProps> = ({
169169
index,
170170
disabled,
171171
onClick,
172-
buttons
172+
buttons,
173173
}) => {
174-
const className = (activeTab === index) ? "tab-active" : "tab";
174+
const className = activeTab === index ? "tab-active" : "tab";
175175
return (
176-
<TabContainer className={className} onClick={onClick} key={index} disabled={disabled} buttons={buttons}>
177-
{wizard ? <Step {...(index <= activeTab && {className: "dark"})}>{step}</Step> : null}
176+
<TabContainer
177+
className={className}
178+
onClick={onClick}
179+
key={index}
180+
disabled={disabled}
181+
buttons={buttons}
182+
>
183+
{wizard && activeTab && index && (
184+
<Step {...(index <= activeTab && { className: "dark" })}>{step}</Step>
185+
)}
178186
<Heading level={5}>{heading}</Heading>
179187
<Text small>{caption}</Text>
180188
</TabContainer>
181-
)};
189+
);
190+
};
182191

183-
export const Tabs: FunctionComponent<TabsProps> = ({
192+
export const Tabs: FunctionComponent<TabsProps> = ({
184193
name,
185194
wizard,
186195
children,
187196
handleTab,
188-
step
197+
step,
189198
}) => {
190199
return (
191200
<TabsWrapper>
@@ -208,19 +217,16 @@ export const Tabs: FunctionComponent<TabsProps> = ({
208217
<TabsCover>
209218
{children.map((child, key) => {
210219
if (key !== step) return undefined;
211-
return (
212-
<React.Fragment>
213-
<TabsContent>
214-
{child.props.children}
215-
</TabsContent>
216-
{wizard &&
217-
<TabsStatusButtons>
218-
{child.props.buttons}
219-
</TabsStatusButtons>
220-
}
221-
</React.Fragment>
222-
)
223-
})}
220+
return (
221+
<React.Fragment>
222+
<TabsContent>{child.props.children}</TabsContent>
223+
{wizard && (
224+
<TabsStatusButtons>{child.props.buttons}</TabsStatusButtons>
225+
)}
226+
</React.Fragment>
227+
);
228+
})}
224229
</TabsCover>
225230
</TabsWrapper>
226-
)};
231+
);
232+
};

0 commit comments

Comments
 (0)