Skip to content

Commit 84dd45f

Browse files
committed
feat: updates icon component types for cross-package consistency
1 parent d5fa1dc commit 84dd45f

File tree

12 files changed

+155
-49
lines changed

12 files changed

+155
-49
lines changed

docs/migration.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ consider additional positioning prop support on a case-by-case basis.
3434

3535
#### @zendeskgarden/react-accordions
3636

37-
- Removed `IItem` type export. Use `ITimelineItemProps` instead.
37+
- The following React component prop types have changed:
38+
- Removed `IItem` type export. Use `ITimelineItemProps` instead.
39+
- `IStepperLabelProps['icon']`: `ReactNode` -> `ReactElement`
40+
- `ITimelineItemProps['icon']`: `ReactNode` -> `ReactElement`
3841

3942
#### @zendeskgarden/react-buttons
4043

@@ -44,7 +47,10 @@ consider additional positioning prop support on a case-by-case basis.
4447
#### @zendeskgarden/react-chrome
4548

4649
- Removed `PRODUCT` type export. Use `IHeaderItemProps['product']` instead.
47-
- Renamed `ICollapsibleSubNavItemProps` type export to `ISubNavCollapsibleItemProps`.
50+
- The following React component types have changed:
51+
- Renamed `ICollapsibleSubNavItemProps` type export to `ISubNavCollapsibleItemProps`.
52+
- `Header.ItemIcon`: `HTMLAttributes<HTMLElement>` -> `SVGAttributes<SVGElement>`
53+
- `Nav.ItemIcon`: `HTMLAttributes<HTMLElement>` -> `SVGAttributes<SVGElement>`
4854
- Subcomponent exports have been deprecated and will be removed in a future major version. Update
4955
to subcomponent properties:
5056
- `FooterItem` -> `Footer.Item`
@@ -100,6 +106,8 @@ consider additional positioning prop support on a case-by-case basis.
100106
- The following types have changed:
101107
- removed `IFieldProps`
102108
- removed `IIconProps`. Use `IFauxInputStartIconProps` or `IFauxInputEndIconProps` instead.
109+
- `IMediaInputProps['start']`: `any` -> `ReactElement`
110+
- `IMediaInputProps['end']`: `any` -> `ReactElement`
103111
- Subcomponent exports have been deprecated and will be removed in a future major version. Update
104112
to subcomponent properties:
105113
- `Hint` -> `Field.Hint`
@@ -170,6 +178,12 @@ consider additional positioning prop support on a case-by-case basis.
170178
- All subcomponent exports have been deprecated and will be removed in a future major version.
171179
Update to subcomponent properties (e.g., `Tooltip.Title`).
172180

181+
#### @zendeskgarden/react-typography
182+
183+
- The following React component types have changed:
184+
- `Span.Icon`: `HTMLAttributes<HTMLElement>` -> `SVGAttributes<SVGElement>`
185+
- `Span.StartIcon`: `HTMLAttributes<HTMLElement>` -> `SVGAttributes<SVGElement>`
186+
173187
#### @zendeskgarden/react-utilities
174188

175189
- This package has been removed.

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/accordions/demo/stories/StepperStory.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const StepperStory: Story<IArgs> = ({ steps, ...args }) => (
2323
{steps.map((step, index) => (
2424
<Stepper.Step key={index}>
2525
<Stepper.Label
26-
icon={args.hasIcon && <Icon />}
26+
icon={args.hasIcon ? <Icon /> : undefined}
2727
isHidden={args.isLabelHidden}
2828
iconProps={args.iconProps}
2929
>

packages/accordions/demo/stories/TimelineStory.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export const TimelineStory: Story<IArgs> = ({ items, ...args }) => (
2323
<div style={{ backgroundColor: args.surfaceColor }}>
2424
<Timeline {...args}>
2525
{items.map((item, index) => (
26-
<Timeline.Item key={index} icon={args.hasIcon && <Icon />} surfaceColor={args.surfaceColor}>
26+
<Timeline.Item
27+
key={index}
28+
icon={args.hasIcon ? <Icon /> : undefined}
29+
surfaceColor={args.surfaceColor}
30+
>
2731
{args.hasOppositeContent && (
2832
<Timeline.OppositeContent>
2933
<Span hue="grey">{item.description}</Span>

packages/accordions/src/types/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
import { IUseAccordionProps } from '@zendeskgarden/container-accordion';
99
import {
10-
ReactNode,
1110
SVGAttributes,
1211
HTMLAttributes,
1312
LiHTMLAttributes,
14-
OlHTMLAttributes
13+
OlHTMLAttributes,
14+
ReactElement
1515
} from 'react';
1616

1717
export interface IAccordionProps<Value = any>
@@ -49,7 +49,7 @@ export interface IStepperProps extends OlHTMLAttributes<HTMLOListElement> {
4949

5050
export interface IStepperLabelProps extends HTMLAttributes<HTMLDivElement> {
5151
/** Replaces the label number with an icon */
52-
icon?: ReactNode;
52+
icon?: ReactElement;
5353
/** Passes props to the default check icon */
5454
iconProps?: SVGAttributes<SVGElement>;
5555
/** Hides the label text */
@@ -63,7 +63,7 @@ export interface ITimelineProps extends OlHTMLAttributes<HTMLOListElement> {
6363

6464
export interface ITimelineItemProps extends LiHTMLAttributes<HTMLLIElement> {
6565
/** Replaces the dot with an icon */
66-
icon?: ReactNode;
66+
icon?: ReactElement;
6767
/** Provides surface color for an icon placed on a non-white background */
6868
surfaceColor?: string;
6969
}

packages/breadcrumbs/src/styled/StyledChevronIcon.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,19 @@
55
* found at http://www.apache.org/licenses/LICENSE-2.0.
66
*/
77

8-
import React, { HTMLAttributes } from 'react';
9-
import styled, { ThemeProps, DefaultTheme } from 'styled-components';
8+
import React from 'react';
9+
import styled from 'styled-components';
1010
import { em } from 'polished';
1111
import { DEFAULT_THEME, getColorV8 } from '@zendeskgarden/react-theming';
1212
import ChevronRightStrokeIcon from '@zendeskgarden/svg-icons/src/12/chevron-right-stroke.svg';
1313

14-
/**
15-
* styled-components injects a theme prop that is rendered as an attribute
16-
* of the SVG icon in the browser. This function removes the `theme` prop injected
17-
* by styled-components.
18-
*/
19-
const ValidChevronIcon: React.FC<HTMLAttributes<SVGElement> & ThemeProps<DefaultTheme>> = props => {
20-
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
21-
const { theme, ...validProps } = props;
22-
23-
return <ChevronRightStrokeIcon {...validProps} />;
24-
};
25-
2614
/**
2715
* Accepts all `<svg>` props
2816
*/
29-
export const StyledChevronIcon = styled(ValidChevronIcon).attrs({
17+
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
18+
export const StyledChevronIcon = styled(({ children, theme, ...props }) => (
19+
<ChevronRightStrokeIcon {...props} />
20+
)).attrs({
3021
role: 'presentation',
3122
'aria-hidden': 'true'
3223
})`

packages/chrome/src/elements/header/HeaderItemIcon.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@
88
import React, {
99
Children,
1010
cloneElement,
11-
HTMLAttributes,
1211
isValidElement,
1312
PropsWithChildren,
14-
ReactHTMLElement
13+
SVGAttributes,
14+
ReactSVGElement
1515
} from 'react';
1616
import { DefaultTheme, ThemeProps } from 'styled-components';
1717
import { StyledHeaderItemIcon } from '../../styled';
1818

1919
/**
2020
* @deprecated use `Header.ItemIcon` instead
2121
*
22-
* @extends HTMLAttributes<HTMLElement>
22+
* @extends SVGAttributes<SVGElement>
2323
*/
2424
export const HeaderItemIcon = ({
2525
children,
2626
...props
27-
}: PropsWithChildren<HTMLAttributes<HTMLElement>>) => {
28-
const element = Children.only(children) as ReactHTMLElement<HTMLElement>;
27+
}: PropsWithChildren<SVGAttributes<SVGElement>>) => {
28+
const element = Children.only(children) as ReactSVGElement;
2929

3030
if (isValidElement(element)) {
3131
const Icon = ({
3232
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3333
theme,
3434
...iconProps
35-
}: ThemeProps<DefaultTheme> & HTMLAttributes<HTMLElement>) =>
36-
cloneElement<HTMLAttributes<HTMLElement>, HTMLElement>(element, { ...props, ...iconProps });
35+
}: ThemeProps<DefaultTheme> & SVGAttributes<SVGElement>) =>
36+
cloneElement<SVGAttributes<SVGElement>, SVGElement>(element, { ...props, ...iconProps });
3737

3838
return <StyledHeaderItemIcon as={Icon} {...props} />;
3939
}

packages/chrome/src/elements/nav/NavItemIcon.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@
88
import React, {
99
Children,
1010
cloneElement,
11-
HTMLAttributes,
11+
SVGAttributes,
1212
isValidElement,
1313
PropsWithChildren,
14-
ReactHTMLElement
14+
ReactSVGElement
1515
} from 'react';
1616
import { DefaultTheme, ThemeProps } from 'styled-components';
1717
import { StyledNavItemIcon } from '../../styled';
1818

1919
/**
2020
* @deprecated use `Nav.ItemIcon` instead
2121
*
22-
* @extends HTMLAttributes<HTMLElement>
22+
* @extends SVGAttributes<SVGElement>
2323
*/
2424
export const NavItemIcon = ({
2525
children,
2626
...props
27-
}: PropsWithChildren<HTMLAttributes<HTMLElement>>) => {
28-
const element = Children.only(children) as ReactHTMLElement<HTMLElement>;
27+
}: PropsWithChildren<SVGAttributes<SVGElement>>) => {
28+
const element = Children.only(children) as ReactSVGElement;
2929

3030
if (isValidElement(element)) {
3131
const Icon = ({
3232
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3333
theme,
3434
...iconProps
35-
}: ThemeProps<DefaultTheme> & HTMLAttributes<HTMLElement>) =>
36-
cloneElement<HTMLAttributes<HTMLElement>, HTMLElement>(element, { ...props, ...iconProps });
35+
}: ThemeProps<DefaultTheme> & SVGAttributes<SVGElement>) =>
36+
cloneElement<SVGAttributes<SVGElement>, SVGElement>(element, { ...props, ...iconProps });
3737

3838
return <StyledNavItemIcon as={Icon} {...props} />;
3939
}

packages/forms/src/elements/MediaInput.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ MediaInput.propTypes = {
133133
isBare: PropTypes.bool,
134134
focusInset: PropTypes.bool,
135135
validation: PropTypes.oneOf(VALIDATION),
136-
start: PropTypes.node,
137-
end: PropTypes.node,
136+
start: PropTypes.any,
137+
end: PropTypes.any,
138138
wrapperProps: PropTypes.object,
139139
wrapperRef: PropTypes.any
140140
};

packages/forms/src/types/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
HTMLAttributes,
1111
InputHTMLAttributes,
1212
LabelHTMLAttributes,
13+
ReactElement,
1314
SelectHTMLAttributes,
1415
SVGAttributes,
1516
TextareaHTMLAttributes
@@ -85,9 +86,9 @@ export interface IInputProps extends IRadioProps {
8586

8687
export interface IMediaInputProps extends IInputProps {
8788
/** Accepts a "start" icon to display */
88-
start?: any;
89+
start?: ReactElement;
8990
/** Accepts an "end" icon to display */
90-
end?: any;
91+
end?: ReactElement;
9192
/** Applies props to the wrapping [FauxInput](#fauxinput) element */
9293
wrapperProps?: any;
9394
/** Applies a ref to the wrapping [FauxInput](#fauxinput) element */

0 commit comments

Comments
 (0)