Skip to content

Commit 2fba511

Browse files
committed
feat: Icon - add support for dataTestId, rotateBy and fillSpace props
1 parent 10f2024 commit 2fba511

2 files changed

Lines changed: 42 additions & 9 deletions

File tree

src/Shared/Components/Icon/IconBase.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@ const conditionalWrap = (tooltipProps: IconBaseProps['tooltipProps']) => (childr
2828
</Tooltip>
2929
)
3030

31-
export const IconBase = ({ name, iconMap, size = 16, tooltipProps, color }: IconBaseProps) => {
31+
export const IconBase = ({
32+
name,
33+
iconMap,
34+
size = 16,
35+
tooltipProps,
36+
color,
37+
dataTestId,
38+
rotateBy,
39+
fillSpace = false,
40+
}: IconBaseProps) => {
3241
const IconComponent = iconMap[name]
3342

3443
if (!IconComponent) {
@@ -38,12 +47,14 @@ export const IconBase = ({ name, iconMap, size = 16, tooltipProps, color }: Icon
3847
return (
3948
<ConditionalWrap condition={!!tooltipProps?.content} wrap={conditionalWrap(tooltipProps)}>
4049
<IconComponent
41-
className={`${size ? `icon-dim-${size}` : ''} ${color ? 'icon-component-color' : ''} ${ICON_STROKE_WIDTH_MAP[size] ? 'icon-component-stroke-width' : ''} dc__no-shrink`}
50+
data-testid={dataTestId}
51+
className={`${size ? `icon-dim-${size}` : ''} ${color ? 'icon-component-color' : ''} ${ICON_STROKE_WIDTH_MAP[size] ? 'icon-component-stroke-width' : ''} ${rotateBy ? 'rotate' : ''} ${fillSpace ? 'dc__fill-available-space' : ''} dc__no-shrink`}
4252
style={{
4353
...(color ? { ['--iconColor' as string]: `var(--${color})` } : {}),
4454
...(ICON_STROKE_WIDTH_MAP[size]
4555
? { ['--strokeWidth' as string]: ICON_STROKE_WIDTH_MAP[size] }
4656
: {}),
57+
...(rotateBy ? { ['--rotateBy' as string]: `${rotateBy}deg` } : {}),
4758
}}
4859
/>
4960
</ConditionalWrap>

src/Shared/Components/Icon/types.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,43 @@ import { IconBaseColorType, IconBaseSizeType } from '@Shared/index'
2222
type IconMap = Record<string, FC<SVGProps<SVGSVGElement>>>
2323

2424
export interface IconBaseProps {
25-
/** The name of the icon to render. */
25+
/**
26+
* The name of the icon to render.
27+
*/
2628
name: keyof IconMap
27-
/** The map containing all available icons. */
29+
/**
30+
* A map containing all available icons.
31+
*/
2832
iconMap: IconMap
2933
/**
30-
* The size of the icon in pixels.
34+
* The size of the icon in pixels. If not provided, the default size is `16px`.
35+
*
3136
* @default 16
3237
*/
3338
size?: IconBaseSizeType | null
34-
/** Props to configure the tooltip when hovering over the icon. */
39+
/**
40+
* Configuration for the tooltip displayed when hovering over the icon.
41+
*/
3542
tooltipProps?: TooltipProps
3643
/**
37-
* The color of the icon (color tokens). \
38-
* If `null`, the default color present in icon is used.
39-
* @example `'B500'`, `'N200'`, `'G50'`, `'R700'`
44+
* The color of the icon, specified using predefined color tokens.
45+
* If set to `null`, the icon's default color will be used.
46+
*
47+
* @example 'B500', 'N200', 'G50', 'R700'
4048
*/
4149
color: IconBaseColorType
50+
/**
51+
* A unique identifier for testing purposes, typically used in test automation.
52+
*/
53+
dataTestId?: string
54+
/**
55+
* Rotates the icon by the specified number of degrees.
56+
*
57+
* @example 90, 180, 270
58+
*/
59+
rotateBy?: number
60+
/**
61+
* If true, the icon will expand to fill the available space of its container.
62+
*/
63+
fillSpace?: boolean
4264
}

0 commit comments

Comments
 (0)