Skip to content

Commit 2190e56

Browse files
authored
feat: adds StyledBaseIcon to various icon components (#1792)
1 parent ff81ed3 commit 2190e56

File tree

36 files changed

+263
-186
lines changed

36 files changed

+263
-186
lines changed

package-lock.json

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/buttons/src/elements/IconButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const IconButton = forwardRef<HTMLButtonElement, IIconButtonProps>(
2020

2121
return (
2222
<StyledIconButton ref={ref} {...otherProps} focusInset={otherProps.focusInset || focusInset}>
23-
<StyledIcon isRotated={isRotated}>{children}</StyledIcon>
23+
<StyledIcon $isRotated={isRotated}>{children}</StyledIcon>
2424
</StyledIconButton>
2525
);
2626
}

packages/buttons/src/elements/components/EndIcon.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import React from 'react';
99
import { IButtonIconProps } from '../../types';
1010
import { StyledIcon } from '../../styled';
1111

12-
const EndIconComponent = (props: IButtonIconProps) => <StyledIcon position="end" {...props} />;
12+
const EndIconComponent = ({ isRotated, ...props }: IButtonIconProps) => (
13+
<StyledIcon $position="end" $isRotated={isRotated} {...props} />
14+
);
1315

1416
EndIconComponent.displayName = 'Button.EndIcon';
1517

packages/buttons/src/elements/components/StartIcon.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import React from 'react';
99
import { IButtonIconProps } from '../../types';
1010
import { StyledIcon } from '../../styled';
1111

12-
const StartIconComponent = (props: IButtonIconProps) => <StyledIcon position="start" {...props} />;
12+
const StartIconComponent = ({ isRotated, ...props }: IButtonIconProps) => (
13+
<StyledIcon $position="start" $isRotated={isRotated} {...props} />
14+
);
1315

1416
StartIconComponent.displayName = 'Button.StartIcon';
1517

packages/buttons/src/styled/StyledIcon.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('StyledIcon', () => {
3333

3434
it('renders rotated styling if provided', () => {
3535
const { container } = render(
36-
<StyledIcon isRotated>
36+
<StyledIcon $isRotated>
3737
<TestIcon />
3838
</StyledIcon>
3939
);
@@ -43,7 +43,7 @@ describe('StyledIcon', () => {
4343

4444
it('renders expected RTL styling', () => {
4545
const { container } = renderRtl(
46-
<StyledIcon isRotated>
46+
<StyledIcon $isRotated>
4747
<TestIcon />
4848
</StyledIcon>
4949
);

packages/buttons/src/styled/StyledIcon.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@
66
*/
77

88
import styled, { css, ThemeProps, DefaultTheme } from 'styled-components';
9-
import React, { Children } from 'react';
10-
import { DEFAULT_THEME, retrieveComponentStyles } from '@zendeskgarden/react-theming';
9+
import {
10+
DEFAULT_THEME,
11+
StyledBaseIcon,
12+
retrieveComponentStyles
13+
} from '@zendeskgarden/react-theming';
1114

1215
const COMPONENT_ID = 'buttons.icon';
1316

1417
interface IStyledIconProps {
15-
isRotated: boolean;
16-
position?: 'start' | 'end';
18+
$isRotated: boolean;
19+
$position?: 'start' | 'end';
1720
}
1821

1922
const sizeStyles = (props: IStyledIconProps & ThemeProps<DefaultTheme>) => {
2023
let marginProperty;
2124

22-
if (props.position === 'start') {
25+
if (props.$position === 'start') {
2326
marginProperty = `margin-${props.theme.rtl ? 'left' : 'right'}`;
24-
} else if (props.position === 'end') {
27+
} else if (props.$position === 'end') {
2528
marginProperty = `margin-${props.theme.rtl ? 'right' : 'left'}`;
2629
}
2730

@@ -33,14 +36,11 @@ const sizeStyles = (props: IStyledIconProps & ThemeProps<DefaultTheme>) => {
3336
);
3437
};
3538

36-
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
37-
export const StyledIcon = styled(({ children, isRotated, theme, ...props }) =>
38-
React.cloneElement(Children.only(children), props)
39-
).attrs({
39+
export const StyledIcon = styled(StyledBaseIcon).attrs({
4040
'data-garden-id': COMPONENT_ID,
4141
'data-garden-version': PACKAGE_VERSION
4242
})<IStyledIconProps>`
43-
transform: ${props => props.isRotated && `rotate(${props.theme.rtl ? '-' : '+'}180deg)`};
43+
transform: ${props => props.$isRotated && `rotate(${props.theme.rtl ? '-' : '+'}180deg)`};
4444
transition:
4545
transform 0.25s ease-in-out,
4646
color 0.25s ease-in-out;

packages/dropdowns/src/elements/combobox/Combobox.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export const Combobox = forwardRef<HTMLDivElement, IComboboxProps>(
274274
<StyledTrigger {...triggerProps}>
275275
<StyledContainer>
276276
{startIcon && (
277-
<StyledInputIcon isLabelHovered={isLabelHovered} isCompact={isCompact}>
277+
<StyledInputIcon $isLabelHovered={isLabelHovered} $isCompact={isCompact}>
278278
{startIcon}
279279
</StyledInputIcon>
280280
)}
@@ -322,10 +322,10 @@ export const Combobox = forwardRef<HTMLDivElement, IComboboxProps>(
322322
</StyledInputGroup>
323323
{(hasChevron || endIcon) && (
324324
<StyledInputIcon
325-
isCompact={isCompact}
326-
isEnd
327-
isLabelHovered={isLabelHovered}
328-
isRotated={hasChevron && isExpanded}
325+
$isCompact={isCompact}
326+
$isEnd
327+
$isLabelHovered={isLabelHovered}
328+
$isRotated={hasChevron && isExpanded}
329329
>
330330
{hasChevron ? <ChevronIcon /> : endIcon}
331331
</StyledInputIcon>

packages/dropdowns/src/elements/combobox/OptGroup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const OptGroup = forwardRef<HTMLLIElement, IOptGroupProps>(
5353
{(content || legend) && (
5454
<StyledOption as="div" isCompact={isCompact} $type="header">
5555
{icon && (
56-
<StyledOptionTypeIcon isCompact={isCompact} type="header">
56+
<StyledOptionTypeIcon $isCompact={isCompact} $type="header">
5757
{icon}
5858
</StyledOptionTypeIcon>
5959
)}

packages/dropdowns/src/elements/combobox/Option.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const OptionComponent = forwardRef<HTMLLIElement, IOptionProps>(
7373
{...props}
7474
{...optionProps}
7575
>
76-
<StyledOptionTypeIcon isCompact={isCompact} type={type}>
76+
<StyledOptionTypeIcon $isCompact={isCompact} $type={type}>
7777
{renderActionIcon(type)}
7878
</StyledOptionTypeIcon>
7979
{icon && <StyledOptionIcon>{icon}</StyledOptionIcon>}

packages/dropdowns/src/elements/menu/Item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const ItemComponent = forwardRef<HTMLLIElement, IItemProps>(
9090
{...itemProps}
9191
ref={mergeRefs([_itemRef, ref])}
9292
>
93-
<StyledItemTypeIcon isCompact={isCompact} type={type}>
93+
<StyledItemTypeIcon $isCompact={isCompact} $type={type}>
9494
{renderActionIcon(type)}
9595
</StyledItemTypeIcon>
9696
{icon && <StyledItemIcon>{icon}</StyledItemIcon>}

0 commit comments

Comments
 (0)