Skip to content

Commit 1e3d176

Browse files
committed
feat: refactor InfoBlock component to use size-based class mappings for container and icon
1 parent c05bbd0 commit 1e3d176

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/Shared/Components/InfoBlock/InfoBlock.component.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { ComponentSizeType } from '@Shared/constants'
2-
import { cloneElement } from 'react'
32
import { deriveBorderClassFromConfig, deriveBorderRadiusClassFromConfig } from '@Shared/Helpers'
43
import { InfoBlockProps } from './types'
5-
import { VARIANT_TO_BG_MAP, VARIANT_TO_ICON_MAP } from './constants'
4+
import {
5+
CONTAINER_SIZE_TO_CLASS_MAP,
6+
SIZE_TO_ICON_CLASS_MAP,
7+
VARIANT_TO_BG_MAP,
8+
VARIANT_TO_ICON_MAP,
9+
} from './constants'
610
import { Button } from '../Button'
711

812
const InfoBlock = ({
@@ -15,15 +19,12 @@ const InfoBlock = ({
1519
description,
1620
borderRadiusConfig,
1721
borderConfig,
18-
fullWidth = true,
1922
}: InfoBlockProps) => {
20-
const baseContainerClass = `${size === ComponentSizeType.large ? 'px-12' : 'px-8'} ${VARIANT_TO_BG_MAP[variant]} ${deriveBorderRadiusClassFromConfig(borderRadiusConfig)} ${deriveBorderClassFromConfig(borderConfig)} ${fullWidth ? 'w-100' : ''} py-8 br-4 bw-1`
21-
const Icon = customIcon ?? VARIANT_TO_ICON_MAP[variant]
23+
const baseContainerClass = `${CONTAINER_SIZE_TO_CLASS_MAP[size]} ${VARIANT_TO_BG_MAP[variant]} ${deriveBorderRadiusClassFromConfig(borderRadiusConfig)} ${deriveBorderClassFromConfig(borderConfig)} w-100 py-8 br-4 bw-1`
24+
const iconClass = `dc__no-shrink flex dc__fill-available-space ${SIZE_TO_ICON_CLASS_MAP[size]}`
25+
const icon = customIcon ?? VARIANT_TO_ICON_MAP[variant]
2226

23-
const renderIcon = () =>
24-
cloneElement(Icon, {
25-
className: `${Icon.props?.className ?? ''} ${size === ComponentSizeType.large ? 'icon-dim-20' : 'icon-dim-18'} dc__no-shrink`,
26-
})
27+
const renderIcon = () => <span className={iconClass}>{icon}</span>
2728

2829
const renderHeading = () => {
2930
if (!heading) {

src/Shared/Components/InfoBlock/constants.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ReactComponent as ICError } from '@Icons/ic-error.svg'
33
import { ReactComponent as ICSuccess } from '@Icons/ic-success.svg'
44
import { ReactComponent as ICWarningY5 } from '@Icons/ic-warning-y5.svg'
55
import { ReactComponent as ICHelp } from '@Icons/ic-help.svg'
6+
import { ComponentSizeType } from '@Shared/constants'
67
import { InfoBlockProps } from './types'
78

89
export const VARIANT_TO_BG_MAP: Record<InfoBlockProps['variant'], string> = {
@@ -20,3 +21,13 @@ export const VARIANT_TO_ICON_MAP: Record<InfoBlockProps['variant'], InfoBlockPro
2021
success: <ICSuccess />,
2122
warning: <ICWarningY5 />,
2223
}
24+
25+
export const CONTAINER_SIZE_TO_CLASS_MAP: Record<InfoBlockProps['size'], string> = {
26+
[ComponentSizeType.large]: 'px-12',
27+
[ComponentSizeType.medium]: 'px-8',
28+
}
29+
30+
export const SIZE_TO_ICON_CLASS_MAP: Record<InfoBlockProps['size'], string> = {
31+
[ComponentSizeType.large]: 'icon-dim-20',
32+
[ComponentSizeType.medium]: 'icon-dim-18',
33+
}

src/Shared/Components/InfoBlock/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ export type InfoBlockProps = {
2323
buttonProps?: ButtonProps
2424
borderConfig?: BorderConfigType
2525
borderRadiusConfig?: BorderConfigType
26-
/**
27-
* @default true
28-
*/
29-
fullWidth?: boolean
3026
} & (
3127
| {
3228
/**

0 commit comments

Comments
 (0)