Skip to content

Commit 162b576

Browse files
committed
refactor: TabGroup - moved utils func to separate file
1 parent d433191 commit 162b576

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

src/Shared/Components/TabGroup/TabGroup.component.tsx

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ComponentSizeType } from '@Shared/constants'
66

77
import { TabGroupProps, TabProps } from './TabGroup.types'
88
import './TabGroup.scss'
9+
import { getClassNameBySize, getIconColorClass } from './TabGroup.utils'
910

1011
const Tab = ({
1112
label,
@@ -23,44 +24,23 @@ const Tab = ({
2324
showWarning,
2425
disabled,
2526
}: TabProps & Pick<TabGroupProps, 'size' | 'alignActiveBorderWithContainer' | 'hideTopPadding'>) => {
26-
const getClassNameBySize = () => {
27-
switch (size) {
28-
case ComponentSizeType.medium:
29-
return {
30-
tabClassName: `fs-12 ${!hideTopPadding ? 'pt-6' : ''} ${alignActiveBorderWithContainer ? 'pb-5' : 'pb-6'}`,
31-
iconClassName: 'icon-dim-14',
32-
badgeClassName: 'fs-11 lh-18 tab-group__tab__badge--medium',
33-
}
34-
default:
35-
return {
36-
tabClassName: `fs-13 ${!hideTopPadding ? 'pt-8' : ''} ${alignActiveBorderWithContainer ? 'pb-7' : 'pb-8'}`,
37-
iconClassName: 'icon-dim-16',
38-
badgeClassName: 'fs-12 lh-20',
39-
}
40-
}
41-
}
42-
const { tabClassName, iconClassName, badgeClassName } = getClassNameBySize()
43-
44-
const getIconColorClass = () => {
45-
if (iconType === 'fill') {
46-
return `tab-group__tab__icon--fill ${active ? 'fcb-5' : 'fcn-7'}`
47-
}
48-
if (iconType === 'stroke') {
49-
return `tab-group__tab__icon--stroke ${active ? 'scb-5' : 'scn-7'}`
50-
}
51-
52-
return ''
53-
}
27+
const { tabClassName, iconClassName, badgeClassName } = getClassNameBySize({
28+
size,
29+
hideTopPadding,
30+
alignActiveBorderWithContainer,
31+
})
5432

5533
const getTabComponent = () => {
5634
const content = (
5735
<>
5836
{showError && <ICErrorExclamation className={`${iconClassName}`} />}
5937
{!showError && showWarning && <ICWarning className={`${iconClassName} warning-icon-y7`} />}
60-
{!showError && !showWarning && Icon && <Icon className={`${iconClassName} ${getIconColorClass()}`} />}
38+
{!showError && !showWarning && Icon && (
39+
<Icon className={`${iconClassName} ${getIconColorClass({ iconType, active })}`} />
40+
)}
6141
{label}
6242
{badge !== null && (
63-
<div className={`tab-group__tab__badge bcn-1 cn-7 flex px-4 ${badgeClassName}`}>{badge}</div>
43+
<div className={`tab-group__tab__badge bcn-1 cn-7 fw-6 flex px-4 ${badgeClassName}`}>{badge}</div>
6444
)}
6545
{showIndicator && <span className="tab-group__tab__indicator bcr-5 mt-4 dc__align-self-start" />}
6646
</>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { ComponentSizeType } from '@Shared/constants'
2+
import { TabGroupProps, TabProps } from './TabGroup.types'
3+
4+
export const getClassNameBySize = ({
5+
size,
6+
hideTopPadding,
7+
alignActiveBorderWithContainer,
8+
}: Pick<TabGroupProps, 'size' | 'hideTopPadding' | 'alignActiveBorderWithContainer'>) => {
9+
switch (size) {
10+
case ComponentSizeType.medium:
11+
return {
12+
tabClassName: `fs-12 ${!hideTopPadding ? 'pt-6' : ''} ${alignActiveBorderWithContainer ? 'pb-5' : 'pb-6'}`,
13+
iconClassName: 'icon-dim-14',
14+
badgeClassName: 'fs-11 lh-18 tab-group__tab__badge--medium',
15+
}
16+
default:
17+
return {
18+
tabClassName: `fs-13 ${!hideTopPadding ? 'pt-8' : ''} ${alignActiveBorderWithContainer ? 'pb-7' : 'pb-8'}`,
19+
iconClassName: 'icon-dim-16',
20+
badgeClassName: 'fs-12 lh-20',
21+
}
22+
}
23+
}
24+
25+
export const getIconColorClass = ({ iconType, active }: Pick<TabProps, 'iconType' | 'active'>) => {
26+
if (iconType === 'fill') {
27+
return `tab-group__tab__icon--fill ${active ? 'fcb-5' : 'fcn-7'}`
28+
}
29+
if (iconType === 'stroke') {
30+
return `tab-group__tab__icon--stroke ${active ? 'scb-5' : 'scn-7'}`
31+
}
32+
33+
return ''
34+
}

0 commit comments

Comments
 (0)