Skip to content

Commit 14817d4

Browse files
fix(react-native): align Icon props with SVG types
1 parent 815ba13 commit 14817d4

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

packages/design-system-react-native/MIGRATION.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@ The intermediate `Box` wrapper around the `BoxRow` in the left section has been
7575

7676
No changes to visual appearance or API.
7777

78+
#### Icon: prop types now align with SVG usage
79+
80+
**What Changed:**
81+
82+
- `IconProps` now extends `Omit<SvgProps, 'color' | 'name'>` instead of `ViewProps`.
83+
- The component now forwards `hitSlop` as `hitSlop ?? undefined` to satisfy strict SVG prop typing.
84+
85+
**Migration:**
86+
87+
If TypeScript now flags props you were previously passing to `Icon`, those props were `View`-specific and are no longer part of the `Icon` public type. Move those props to a wrapper `View` and keep SVG-compatible props on `Icon`.
88+
89+
```tsx
90+
// Before
91+
<Icon name={IconName.Lock} onLayout={handleLayout} />
92+
93+
// After
94+
<View onLayout={handleLayout}>
95+
<Icon name={IconName.Lock} />
96+
</View>
97+
```
98+
7899
---
79100

80101
### From version 0.16.0 to 0.17.0

packages/design-system-react-native/src/components/Icon/Icon.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@ export const Icon = ({
1717
}: IconProps) => {
1818
const tw = useTailwind();
1919
const SVG = assetByIconName[name];
20+
const { hitSlop, ...svgProps } = props;
2021
const twStyle = tw.style(
2122
color,
2223
TWCLASSMAP_ICON_SIZE_DIMENSION[size],
2324
twClassName,
2425
);
2526

2627
return (
27-
<SVG name={name} fill="currentColor" style={[twStyle, style]} {...props} />
28+
<SVG
29+
name={name}
30+
fill="currentColor"
31+
style={[twStyle, style]}
32+
hitSlop={hitSlop ?? undefined}
33+
{...svgProps}
34+
/>
2835
);
2936
};

packages/design-system-react-native/src/components/Icon/Icon.types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type React from 'react';
2-
import type { ViewProps } from 'react-native';
32
import type { SvgProps } from 'react-native-svg';
43

54
import type { IconColor, IconName, IconSize } from '../../types';
@@ -29,7 +28,7 @@ export type IconProps = {
2928
* Optional prop to add twrnc overriding classNames.
3029
*/
3130
twClassName?: string;
32-
} & ViewProps;
31+
} & Omit<SvgProps, 'color' | 'name'>;
3332

3433
/**
3534
* Asset stored by icon name

0 commit comments

Comments
 (0)