Skip to content

Commit cf372cc

Browse files
author
Kubit
committed
Improve iconHost and iconHighleted
1 parent f61df8c commit cf372cc

File tree

8 files changed

+92
-31
lines changed

8 files changed

+92
-31
lines changed

src/components/elementOrIllustration/elementOrIllustration.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import { IllustrationBasic as Illustration } from '../illustration/illustration';
3+
import { IllustrationHost as Illustration } from '../illustration/illustrationHost';
44
import { IElementOrillustration } from './types/elementOrIllustration';
55

66
const ElementOrIllustrationComponent = (

src/components/icon/iconHost.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,4 @@ const IconHostComponent = (
5252
);
5353
};
5454

55-
/**
56-
* @deprecated This component has been deprecated and will be removed in the next MAJOR release.
57-
*
58-
* IconHost is a component that serves as a host for icons.
59-
* @param {React.PropsWithChildren<IIconHost>} props
60-
* @returns {JSX.Element}
61-
*/
6255
export const IconHost = React.forwardRef(IconHostComponent);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,18 @@ describe('IconHighlighted Component', () => {
6262
expect(container).toHTMLValidate();
6363
expect(results).toHaveNoViolations();
6464
});
65+
66+
it('Should render IconHighlighted with custom content', async () => {
67+
const { getByText, container } = renderProvider(
68+
<IconHighlighted {...mockPropsDecorative} customContent={'customContent'} />
69+
);
70+
71+
const customContent = getByText('customContent');
72+
73+
expect(customContent).toBeDefined();
74+
75+
const results = await axe(container);
76+
expect(container).toHTMLValidate();
77+
expect(results).toHaveNoViolations();
78+
});
6579
});
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
import styled from 'styled-components';
22

3-
import { getStyles } from '@/utils/getStyles/getStyles';
3+
import { getStyles, getTypographyStyles } from '@/utils/getStyles/getStyles';
44

55
import { IconHighlightedSizePropsType } from './types/iconHighlightedTheme';
66

77
type IconHighlightedStyledType = {
88
styles?: IconHighlightedSizePropsType;
99
backgroundColor?: string;
1010
disabled?: boolean;
11+
selected?: boolean;
1112
};
13+
export const ParentContainerStyled = styled.span<IconHighlightedStyledType>`
14+
${props => getStyles(props.styles?.parentContainer)}
15+
`;
16+
1217
export const IconHighlightedContainerStyled = styled.span<IconHighlightedStyledType>`
1318
display: flex;
1419
justify-content: center;
1520
align-items: center;
16-
${props =>
17-
props.disabled
18-
? getStyles(props.styles?.container?.disabled)
19-
: getStyles(props.styles?.container)}
21+
${props => getStyles(props.styles?.container)}
22+
${props => props.selected && getStyles(props.styles?.container?.selected)}
23+
${props => props.disabled && getStyles(props.styles?.container?.disabled)}
2024
background-color: ${({ backgroundColor }) => backgroundColor};
2125
`;
26+
27+
export const CustomContentContainerStyled = styled.span<IconHighlightedStyledType>`
28+
${props => getStyles(props.styles?.customContentContainer)}
29+
${props => getTypographyStyles(props.styles?.customContentContainer)}
30+
${props => props.selected && getStyles(props.styles?.customContentContainer?.selected)}
31+
${props => props.selected && getTypographyStyles(props.styles?.customContentContainer?.selected)}
32+
${props => props.disabled && getStyles(props.styles?.customContentContainer?.disabled)}
33+
${props => props.disabled && getTypographyStyles(props.styles?.customContentContainer?.disabled)}
34+
`;

src/components/iconHighlighted/iconHighlightedStandAlone.tsx

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,50 @@
11
import React from 'react';
22

33
import { ElementOrIcon } from '../elementOrIcon/elementOrIcon';
4-
import { IconHighlightedContainerStyled } from './iconHighlighted.styled';
4+
import {
5+
CustomContentContainerStyled,
6+
IconHighlightedContainerStyled,
7+
ParentContainerStyled,
8+
} from './iconHighlighted.styled';
59
import { IIconHighlightedStandAlone } from './types/iconHighlighted';
610
import { IconHighlightedType } from './types/type';
711

812
const IconHighlightedStandAloneComponent = (
9-
{ disabled = false, dataTestId = 'icon-highlighted', ...props }: IIconHighlightedStandAlone,
13+
{
14+
disabled = false,
15+
selected = false,
16+
dataTestId = 'icon-highlighted',
17+
...props
18+
}: IIconHighlightedStandAlone,
1019
ref: React.ForwardedRef<HTMLDivElement> | undefined | null
1120
): JSX.Element => {
1221
return (
13-
<IconHighlightedContainerStyled
14-
ref={ref}
15-
backgroundColor={props.backgroundColor}
16-
data-testid={dataTestId}
17-
disabled={disabled}
18-
styles={props.styles[props.size]}
19-
>
20-
<ElementOrIcon
21-
altText={props.type === IconHighlightedType.INFORMATIVE ? props.altText : undefined}
22-
color={props.color}
23-
customIconStyles={
24-
!disabled ? props.styles[props.size]?.icon : props.styles[props.size]?.icon?.disabled
25-
}
26-
icon={props.icon}
27-
/>
28-
</IconHighlightedContainerStyled>
22+
<ParentContainerStyled ref={ref} data-testid={dataTestId} styles={props.styles[props.size]}>
23+
<IconHighlightedContainerStyled
24+
backgroundColor={props.backgroundColor}
25+
disabled={disabled}
26+
selected={selected}
27+
styles={props.styles[props.size]}
28+
>
29+
<ElementOrIcon
30+
altText={props.type === IconHighlightedType.INFORMATIVE ? props.altText : undefined}
31+
color={props.color}
32+
customIconStyles={
33+
!disabled ? props.styles[props.size]?.icon : props.styles[props.size]?.icon?.disabled
34+
}
35+
icon={props.icon}
36+
/>
37+
</IconHighlightedContainerStyled>
38+
{props.customContent && (
39+
<CustomContentContainerStyled
40+
disabled={disabled}
41+
selected={selected}
42+
styles={props.styles[props.size]}
43+
>
44+
{props.customContent}
45+
</CustomContentContainerStyled>
46+
)}
47+
</ParentContainerStyled>
2948
);
3049
};
3150

src/components/iconHighlighted/stories/argtypes.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ export const argtypes = (variants: IThemeObjectVariants, themeSelected: string):
109109
category: CATEGORY_CONTROL.MODIFIERS,
110110
},
111111
},
112+
selected: {
113+
description: 'Applies selected styles',
114+
type: { name: 'boolean' },
115+
control: { type: 'boolean' },
116+
table: {
117+
type: {
118+
summary: 'boolean',
119+
},
120+
defaultValue: { summary: false },
121+
category: CATEGORY_CONTROL.MODIFIERS,
122+
},
123+
},
112124
dataTestId: {
113125
description: 'String used for testing',
114126
control: { type: 'text' },

src/components/iconHighlighted/types/iconHighlighted.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ export interface IIconHighlightedStyled {
99
styles: IconHighlightedVariantStylesType;
1010
backgroundColor?: string;
1111
disabled?: boolean;
12+
selected?: boolean;
1213
}
1314

1415
export interface IIconHighlightedStandAlone extends IElementOrIcon, IIconHighlightedStyled {
1516
size: IconHighlightedSizeType;
1617
type?: IconHighlightedType;
18+
customContent?: React.ReactNode;
1719
}
1820

1921
export interface IIconHighlighted<V = undefined extends string ? unknown : string>

src/components/iconHighlighted/types/iconHighlightedTheme.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import { CommonStyleType } from '@/types/styles/commonStyle';
22
import { IconTypes } from '@/types/styles/icon';
3+
import { TypographyTypes } from '@/types/styles/typography';
34

45
import { IconHighlightedSizeType } from './size';
56

67
export type IconHighlightedSizePropsType = {
8+
parentContainer?: CommonStyleType;
79
container?: CommonStyleType & {
810
disabled?: CommonStyleType;
11+
selected?: CommonStyleType;
912
};
1013
icon?: IconTypes & {
1114
disabled?: IconTypes;
1215
};
16+
customContentContainer?: CommonStyleType &
17+
TypographyTypes & {
18+
disabled?: CommonStyleType & TypographyTypes;
19+
selected?: CommonStyleType & TypographyTypes;
20+
};
1321
};
1422

1523
export type IconHighlightedVariantStylesType = {

0 commit comments

Comments
 (0)