diff --git a/src/components/Icon/Icon.tsx b/src/components/Icon/Icon.tsx index 5f02456c8c..0c39169093 100644 --- a/src/components/Icon/Icon.tsx +++ b/src/components/Icon/Icon.tsx @@ -1,5 +1,7 @@ import * as React from 'react'; +import type {ColorTextBaseProps} from '../Text/colorText/colorText'; +import {colorText} from '../Text/colorText/colorText'; import type {DOMProps, QAProps} from '../types'; import {block} from '../utils/cn'; import {a11yHiddenSvgProps} from '../utils/svg'; @@ -22,7 +24,7 @@ interface IconComposition { prefix?: string; } -export interface IconProps extends QAProps, DOMProps { +export interface IconProps extends QAProps, DOMProps, ColorTextBaseProps { data: IconData; width?: number | string; height?: number | string; @@ -36,7 +38,18 @@ const b = block('icon'); export const Icon: React.ForwardRefExoticComponent> & IconComposition = React.forwardRef( ( - {data, width, height, size, className, style, fill = 'currentColor', stroke = 'none', qa}, + { + data, + width, + height, + size, + className, + style, + color, + fill = 'currentColor', + stroke = 'none', + qa, + }, ref, ) => { // This component supports four different ways to load and use icons: @@ -91,12 +104,17 @@ export const Icon: React.ForwardRefExoticComponent = { options: Object.keys(icons), mapping: icons, }, + color: { + control: 'select', + options: TEXT_COLORS, + }, style: { control: 'object', }, diff --git a/src/components/Icon/__tests__/Icon.visual.test.tsx b/src/components/Icon/__tests__/Icon.visual.test.tsx index 1f6ad5e06e..f073fb5b42 100644 --- a/src/components/Icon/__tests__/Icon.visual.test.tsx +++ b/src/components/Icon/__tests__/Icon.visual.test.tsx @@ -3,7 +3,7 @@ import {smokeTest, test} from '~playwright/core'; import {createSmokeScenarios} from '../../../stories/tests-factory/create-smoke-scenarios'; import type {IconProps} from '../Icon'; -import {sizeCases} from './cases'; +import {colorCases, sizeCases, styleCases} from './cases'; import {TestIcon} from './helpersPlaywright'; test.describe('Icon', {tag: '@Icon'}, () => { @@ -12,6 +12,8 @@ test.describe('Icon', {tag: '@Icon'}, () => { {}, { size: sizeCases, + color: colorCases, + style: styleCases, }, ); diff --git a/src/components/Icon/__tests__/cases.tsx b/src/components/Icon/__tests__/cases.tsx index 744c0f3f03..078ddb0385 100644 --- a/src/components/Icon/__tests__/cases.tsx +++ b/src/components/Icon/__tests__/cases.tsx @@ -1,4 +1,10 @@ -import type {Cases} from '../../../stories/tests-factory/models'; +import type {Cases, CasesWithName} from '../../../stories/tests-factory/models'; import type {IconProps} from '../Icon'; export const sizeCases: Cases = [10, 20, 30]; + +export const colorCases: Cases = ['primary', 'danger']; + +export const styleCases: CasesWithName = [ + ['color: var(--g-color-text-positive)', {color: 'var(--g-color-text-positive)'}], +];