Skip to content

Commit 247cae4

Browse files
committed
refactor: TabGroup - refactored Tab Content into helper functions
1 parent 0368b73 commit 247cae4

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed

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

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { Link, NavLink } from 'react-router-dom'
22

3-
import { ReactComponent as ICErrorExclamation } from '@Icons/ic-error-exclamation.svg'
4-
import { ReactComponent as ICWarning } from '@Icons/ic-warning.svg'
53
import { ComponentSizeType } from '@Shared/constants'
64

75
import { TabGroupProps, TabProps } from './TabGroup.types'
86
import { getClassNameBySizeMap, tabGroupClassMap } from './TabGroup.utils'
7+
import { getTabBadge, getTabDescription, getTabIcon, getTabIndicator } from './TabGroup.helpers'
98

109
import './TabGroup.scss'
1110

@@ -14,7 +13,7 @@ const Tab = ({
1413
props,
1514
tabType,
1615
active,
17-
icon: Icon,
16+
icon,
1817
size,
1918
badge = null,
2019
alignActiveBorderWithContainer,
@@ -34,29 +33,12 @@ const Tab = ({
3433
const content = (
3534
<>
3635
<p className="m-0 flexbox dc__align-items-center dc__gap-6">
37-
{showError && <ICErrorExclamation className={`${iconClassName}`} />}
38-
{!showError && showWarning && <ICWarning className={`${iconClassName} warning-icon-y7`} />}
39-
{!showError && !showWarning && Icon && <Icon className={`${iconClassName} tab-group__tab__icon`} />}
36+
{getTabIcon({ className: iconClassName, icon, showError, showWarning })}
4037
{label}
41-
{badge !== null && (
42-
<div className={`tab-group__tab__badge bcn-1 cn-7 fw-6 flex px-4 ${badgeClassName}`}>
43-
{badge}
44-
</div>
45-
)}
46-
{showIndicator && <span className="tab-group__tab__indicator bcr-5 mt-4 dc__align-self-start" />}
38+
{getTabBadge(badge, badgeClassName)}
39+
{getTabIndicator(showIndicator)}
4740
</p>
48-
{description && (
49-
<ul className="tab-group__tab__description m-0 p-0 fs-12 lh-16 fw-4 cn-7 flexbox dc__align-items-center dc__gap-4">
50-
{Array.isArray(description)
51-
? description.map((desc, idx) => (
52-
<li key={desc} className="flex dc__gap-4">
53-
{!!idx && <span className="dc__bullet" />}
54-
{desc}
55-
</li>
56-
))
57-
: description}
58-
</ul>
59-
)}
41+
{getTabDescription(description)}
6042
</>
6143
)
6244

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ReactComponent as ICErrorExclamation } from '@Icons/ic-error-exclamation.svg'
2+
import { ReactComponent as ICWarning } from '@Icons/ic-warning.svg'
3+
4+
import { TabProps } from './TabGroup.types'
5+
6+
export const getTabIcon = ({
7+
icon: Icon,
8+
showError,
9+
showWarning,
10+
className,
11+
}: Pick<TabProps, 'showError' | 'showWarning' | 'icon'> & { className: string }) => (
12+
<>
13+
{showError && <ICErrorExclamation className={`${className}`} />}
14+
{!showError && showWarning && <ICWarning className={`${className} warning-icon-y7`} />}
15+
{!showError && !showWarning && Icon && <Icon className={`${className} tab-group__tab__icon`} />}
16+
</>
17+
)
18+
19+
export const getTabBadge = (badge: TabProps['badge'], className: string) =>
20+
badge !== null && <div className={`tab-group__tab__badge bcn-1 cn-7 fw-6 flex px-4 ${className}`}>{badge}</div>
21+
22+
export const getTabIndicator = (showIndicator: TabProps['showIndicator']) =>
23+
showIndicator && <span className="tab-group__tab__indicator bcr-5 mt-4 dc__align-self-start" />
24+
25+
export const getTabDescription = (description: TabProps['description']) =>
26+
description && (
27+
<ul className="tab-group__tab__description m-0 p-0 fs-12 lh-16 fw-4 cn-7 flexbox dc__align-items-center dc__gap-4">
28+
{Array.isArray(description)
29+
? description.map((desc, idx) => (
30+
<li key={desc} className="flex dc__gap-4">
31+
{!!idx && <span className="dc__bullet" />}
32+
{desc}
33+
</li>
34+
))
35+
: description}
36+
</ul>
37+
)

0 commit comments

Comments
 (0)