Skip to content

Commit baeb5a0

Browse files
author
Kubit
committed
Add disable state to IconHighlighted component
1 parent a20bc43 commit baeb5a0

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

src/components/iconHighlighted/__tests__/iconHighlighted.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ describe('IconHighlighted Component', () => {
3737
expect(results).toHaveNoViolations();
3838
});
3939

40+
it('Should render IconHighlighted with decorative icon and disabled=true', async () => {
41+
const { getByRole, container } = renderProvider(
42+
<IconHighlighted {...mockPropsInformative} disabled={true} />
43+
);
44+
45+
const iconHighlighted = getByRole('img', { name: 'icon label', hidden: false });
46+
47+
expect(iconHighlighted).toBeDefined();
48+
49+
const results = await axe(container);
50+
expect(container).toHTMLValidate();
51+
expect(results).toHaveNoViolations();
52+
});
53+
4054
it('Should render IconHighlighted with informative icon', async () => {
4155
const { getByRole, container } = renderProvider(<IconHighlighted {...mockPropsDecorative} />);
4256

src/components/iconHighlighted/iconHighlighted.styled.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ import { IconHighlightedSizePropsType } from './types';
77
type IconHighlightedStyledType = {
88
styles?: IconHighlightedSizePropsType;
99
backgroundColor?: string;
10+
disabled?: boolean;
1011
};
1112
export const IconHighlightedContainerStyled = styled.span<IconHighlightedStyledType>`
1213
display: flex;
1314
justify-content: center;
1415
align-items: center;
16+
${props =>
17+
props.disabled
18+
? getStyles(props.styles?.container?.disabled)
19+
: getStyles(props.styles?.container)}
1520
background-color: ${({ backgroundColor }) => backgroundColor};
16-
${props => getStyles(props.styles?.container)}
1721
`;

src/components/iconHighlighted/iconHighlightedStandAlone.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@ import { IIconHighlightedStandAlone } from './types/iconHighlighted';
77
import { IconHighlightedType } from './types/type';
88

99
const IconHighlightedStandAloneComponent = (
10-
{ ...props }: IIconHighlightedStandAlone,
10+
{ disabled = false, ...props }: IIconHighlightedStandAlone,
1111
ref: React.ForwardedRef<HTMLDivElement> | undefined | null
1212
): JSX.Element => {
1313
return (
1414
<IconHighlightedContainerStyled
1515
ref={ref}
1616
backgroundColor={props.backgroundColor}
1717
data-testid={props.dataTestId}
18+
disabled={disabled}
1819
styles={props.styles[props.size]}
1920
>
2021
<ElementOrIcon
2122
altText={props.type === IconHighlightedType.INFORMATIVE ? props.altText : undefined}
2223
color={props.color}
23-
customIconStyles={props.styles[props.size]?.icon}
24+
customIconStyles={
25+
!disabled ? props.styles[props.size]?.icon : props.styles[props.size]?.icon?.disabled
26+
}
2427
icon={props.icon}
2528
/>
2629
</IconHighlightedContainerStyled>

src/components/iconHighlighted/stories/argtypes.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ export const argtypes = (variants: IThemeObjectVariants, themeSelected: string):
9696
category: CATEGORY_CONTROL.MODIFIERS,
9797
},
9898
},
99+
disabled: {
100+
description: 'Specifies if the IconHighlighted element is disabled or not',
101+
type: { name: 'boolean' },
102+
control: { type: 'boolean' },
103+
table: {
104+
type: {
105+
summary: 'boolean',
106+
},
107+
defaultValue: { summary: false },
108+
category: CATEGORY_CONTROL.MODIFIERS,
109+
},
110+
},
99111
dataTestId: {
100112
description: 'String used for testing',
101113
control: { type: 'text' },

src/components/iconHighlighted/types/iconHighlighted.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { IconHighlightedType } from './type';
88
export interface IIconHighlightedStyled {
99
styles: IconHighlightedVariantStylesType;
1010
backgroundColor?: string;
11+
disabled?: boolean;
1112
}
1213

1314
export interface IIconHighlightedStandAlone extends IElementOrIcon, IIconHighlightedStyled {

src/components/iconHighlighted/types/iconHighlightedTheme.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import { CommonStyleType, IconTypes } from '@/types';
33
import { IconHighlightedSizeType } from './size';
44

55
export type IconHighlightedSizePropsType = {
6-
container?: CommonStyleType;
7-
icon?: IconTypes;
6+
container?: CommonStyleType & {
7+
disabled?: CommonStyleType;
8+
};
9+
icon?: IconTypes & {
10+
disabled?: IconTypes;
11+
};
812
};
913

1014
export type IconHighlightedVariantStylesType = {

0 commit comments

Comments
 (0)