Skip to content

Commit 44c56ff

Browse files
authored
Merge pull request #679 from devtron-labs/uat/approval-policy-exceptions-1
feat: TabGroup - add support for icon to be rendered via Icon component
2 parents 4c22f0b + 22f9746 commit 44c56ff

File tree

6 files changed

+36
-12
lines changed

6 files changed

+36
-12
lines changed

src/Shared/Components/Icon/styles.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
.icon-component-color {
1818
&:not([data-style-override='false']) {
1919
:where([stroke^='#']:not([data-style-override='false'])) {
20-
stroke: var(--iconColor);
20+
stroke: var(--overrideIconColor, var(--iconColor));
21+
2122
}
2223
:where([fill^='#']:not([data-style-override='false'])) {
23-
fill: var(--iconColor);
24+
fill: var(--overrideIconColor, var(--iconColor));
2425
}
2526
}
2627
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const Tab = ({
6363
const content = (
6464
<>
6565
<p className="m-0 flexbox dc__align-items-center dc__gap-6">
66-
{getTabIcon({ className: iconClassName, icon, showError, showWarning })}
66+
{getTabIcon({ className: iconClassName, icon, showError, showWarning, size, active })}
6767
{label}
6868
{getTabBadge(badge, badgeClassName)}
6969
{getTabIndicator(showIndicator)}

src/Shared/Components/TabGroup/TabGroup.helpers.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,31 @@
1717
import { ReactComponent as ICErrorExclamation } from '@Icons/ic-error-exclamation.svg'
1818
import { ReactComponent as ICWarning } from '@Icons/ic-warning.svg'
1919

20-
import { TabProps } from './TabGroup.types'
20+
import { Icon } from '../Icon'
21+
import { TabGroupProps, TabProps } from './TabGroup.types'
22+
import { TAB_ICON_SIZE_MAP } from './TabGroup.utils'
2123

2224
export const getTabIcon = ({
23-
icon: Icon,
25+
icon,
2426
showError,
2527
showWarning,
2628
className,
27-
}: Pick<TabProps, 'showError' | 'showWarning' | 'icon'> & { className: string }) => {
29+
size,
30+
active,
31+
}: Pick<TabProps, 'showError' | 'showWarning' | 'icon' | 'active'> &
32+
Pick<TabGroupProps, 'size'> & { className: string }) => {
2833
if (showError) {
2934
return <ICErrorExclamation className={className} />
3035
}
3136
if (showWarning) {
3237
return <ICWarning className={`${className} warning-icon-y7`} />
3338
}
34-
if (Icon) {
35-
return <Icon className={`${className} tab-group__tab__icon`} />
39+
if (typeof icon === 'string') {
40+
return <Icon name={icon} color={active ? 'B500' : 'N700'} size={TAB_ICON_SIZE_MAP[size]} />
41+
}
42+
if (icon) {
43+
const RenderIcon = icon
44+
return <RenderIcon className={`${className} tab-group__tab__icon`} />
3645
}
3746
return null
3847
}

src/Shared/Components/TabGroup/TabGroup.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
&:hover:not(.tab-group__tab--block):not(.dc__disabled) {
5353
color: var(--B500);
5454
@include svg-styles(var(--B500));
55+
56+
svg.icon-component-color {
57+
--overrideIconColor: var(--B500);
58+
}
5559
}
5660

5761
&--active {
@@ -92,7 +96,7 @@
9296
color: var(--N900);
9397
}
9498

95-
&:hover:not([aria-disabled="true"]) {
99+
&:hover:not([aria-disabled='true']) {
96100
color: var(--B500);
97101
}
98102
}

src/Shared/Components/TabGroup/TabGroup.types.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { ComponentSizeType } from '@Shared/constants'
2020
import { DataAttributes } from '@Shared/types'
2121
import { TooltipProps } from '@Common/Tooltip/types'
2222

23+
import { IconName } from '../Icon'
24+
2325
type TabComponentProps<TabTypeProps> = TabTypeProps & DataAttributes
2426

2527
type ConditionalTabType =
@@ -106,10 +108,11 @@ export type TabProps = {
106108
*/
107109
description?: string | string[]
108110
/**
109-
* Icon component to be displayed in the tab.
110-
* This should be a functional component that renders an SVG.
111+
* Icon to be displayed in the tab.
112+
* This can either be a functional component that renders a SVG
113+
* or a string representing the name of the icon to be rendered by the Icon component.
111114
*/
112-
icon?: React.FunctionComponent<React.SVGProps<SVGSVGElement>>
115+
icon?: React.FunctionComponent<React.SVGProps<SVGSVGElement>> | IconName
113116
/**
114117
* Badge number to be displayed on the tab, typically for notifications.
115118
*/

src/Shared/Components/TabGroup/TabGroup.utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { ComponentSizeType } from '@Shared/constants'
1818

19+
import { IconsProps } from '../Icon'
1920
import { TabGroupProps } from './TabGroup.types'
2021

2122
export const getClassNameBySizeMap = ({
@@ -46,6 +47,12 @@ export const getClassNameBySizeMap = ({
4647
},
4748
})
4849

50+
export const TAB_ICON_SIZE_MAP: Record<TabGroupProps['size'], IconsProps['size']> = {
51+
[ComponentSizeType.medium]: 14,
52+
[ComponentSizeType.large]: 16,
53+
[ComponentSizeType.xl]: 16,
54+
}
55+
4956
export const tabGroupClassMap: Record<TabGroupProps['size'], string> = {
5057
[ComponentSizeType.medium]: 'dc__gap-12',
5158
[ComponentSizeType.large]: 'dc__gap-16',

0 commit comments

Comments
 (0)