Skip to content

Commit 973ee86

Browse files
fix: bloated lib/**/*.d.ts files
1 parent f7fe59d commit 973ee86

File tree

8 files changed

+62
-12
lines changed

8 files changed

+62
-12
lines changed

src/components/Appbar/AppbarAction.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import color from 'color';
55

66
import { useInternalTheme } from '../../core/theming';
77
import { black } from '../../styles/themes/v2/colors';
8+
import { forwardRef } from '../../utils/forwardRef';
89
import type { IconSource } from '../Icon';
910
import IconButton from '../IconButton/IconButton';
1011

@@ -68,7 +69,7 @@ export type Props = React.ComponentPropsWithoutRef<typeof IconButton> & {
6869
* export default MyComponent;
6970
* ```
7071
*/
71-
const AppbarAction = React.forwardRef<View, Props>(
72+
const AppbarAction = forwardRef<View, Props>(
7273
(
7374
{
7475
size = 24,

src/components/Appbar/AppbarBackAction.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
View,
77
} from 'react-native';
88

9+
import { forwardRef } from '../../utils/forwardRef';
910
import type { $Omit } from './../../types';
1011
import AppbarAction from './AppbarAction';
1112
import AppbarBackIcon from './AppbarBackIcon';
@@ -60,7 +61,7 @@ export type Props = $Omit<
6061
* export default MyComponent;
6162
* ```
6263
*/
63-
const AppbarBackAction = React.forwardRef<View, Props>(
64+
const AppbarBackAction = forwardRef<View, Props>(
6465
({ accessibilityLabel = 'Back', ...rest }: Props, ref) => (
6566
<AppbarAction
6667
accessibilityLabel={accessibilityLabel}

src/components/Card/Card.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
ViewStyle,
1010
} from 'react-native';
1111

12+
import type { ThemedComponent } from '@callstack/react-theme-provider';
13+
1214
import { withInternalTheme } from '../../core/theming';
1315
import type { InternalTheme } from '../../types';
1416
import Surface from '../Surface';
@@ -39,7 +41,7 @@ type HandlePressType = 'in' | 'out';
3941

4042
type Mode = 'elevated' | 'outlined' | 'contained';
4143

42-
export type Props = React.ComponentProps<typeof Surface> & {
44+
export type CardProps = React.ComponentProps<typeof Surface> & {
4345
/**
4446
* Mode of the Card.
4547
* - `elevated` - Card with elevation.
@@ -82,6 +84,13 @@ export type Props = React.ComponentProps<typeof Surface> & {
8284
accessible?: boolean;
8385
};
8486

87+
export type Props = (
88+
| OutlinedCardProps
89+
| ElevatedCardProps
90+
| ContainedCardProps
91+
) &
92+
CardProps;
93+
8594
/**
8695
* A card is a sheet of material that serves as an entry point to more detailed information.
8796
*
@@ -137,7 +146,7 @@ const Card = ({
137146
testID = 'card',
138147
accessible,
139148
...rest
140-
}: (OutlinedCardProps | ElevatedCardProps | ContainedCardProps) & Props) => {
149+
}: Props) => {
141150
const isMode = React.useCallback(
142151
(modeToCompare: Mode) => {
143152
return cardMode === modeToCompare;
@@ -314,4 +323,9 @@ const styles = StyleSheet.create({
314323
},
315324
});
316325

317-
export default withInternalTheme(Card);
326+
export default withInternalTheme(Card) as ThemedComponent<unknown, Props> & {
327+
Content: typeof CardContent;
328+
Actions: typeof CardActions;
329+
Cover: typeof CardCover;
330+
Title: typeof CardTitle;
331+
};

src/components/FAB/FAB.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import {
99
ViewStyle,
1010
} from 'react-native';
1111

12+
import type { ThemedComponent } from '@callstack/react-theme-provider';
13+
1214
import { withInternalTheme } from '../../core/theming';
1315
import type { $RemoveChildren, InternalTheme } from '../../types';
16+
import { forwardRef } from '../../utils/forwardRef';
1417
import ActivityIndicator from '../ActivityIndicator';
1518
import CrossFadeIcon from '../CrossFadeIcon';
1619
import Icon, { IconSource } from '../Icon';
@@ -154,7 +157,7 @@ export type Props = $RemoveChildren<typeof Surface> & {
154157
* export default MyComponent;
155158
* ```
156159
*/
157-
const FAB = React.forwardRef<View, Props>(
160+
const FAB = forwardRef<View, Props>(
158161
(
159162
{
160163
icon,
@@ -335,9 +338,14 @@ const styles = StyleSheet.create({
335338
},
336339
});
337340

338-
export default withInternalTheme(FAB);
341+
export type ThemedFAB = ThemedComponent<
342+
unknown,
343+
React.ComponentProps<typeof FAB>
344+
>;
345+
346+
export default withInternalTheme(FAB) as ThemedFAB;
339347

340348
// @component-docs ignore-next-line
341-
const FABWithTheme = withInternalTheme(FAB);
349+
const FABWithTheme: ThemedFAB = withInternalTheme(FAB);
342350
// @component-docs ignore-next-line
343351
export { FABWithTheme as FAB };

src/components/IconButton/IconButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99

1010
import { useInternalTheme } from '../../core/theming';
1111
import type { $RemoveChildren, ThemeProp } from '../../types';
12+
import { forwardRef } from '../../utils/forwardRef';
1213
import CrossFadeIcon from '../CrossFadeIcon';
1314
import Icon, { IconSource } from '../Icon';
1415
import Surface from '../Surface';
@@ -112,7 +113,7 @@ export type Props = $RemoveChildren<typeof TouchableRipple> & {
112113
*
113114
* @extends TouchableRipple props https://callstack.github.io/react-native-paper/touchable-ripple.html
114115
*/
115-
const IconButton = React.forwardRef<View, Props>(
116+
const IconButton = forwardRef<View, Props>(
116117
(
117118
{
118119
icon,

src/components/Searchbar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import color from 'color';
1717

1818
import { withInternalTheme } from '../core/theming';
1919
import type { InternalTheme } from '../types';
20+
import { forwardRef } from '../utils/forwardRef';
2021
import ActivityIndicator from './ActivityIndicator';
2122
import type { IconSource } from './Icon';
2223
import IconButton from './IconButton/IconButton';
@@ -119,7 +120,7 @@ type TextInputHandles = Pick<
119120
120121
* ```
121122
*/
122-
const Searchbar = React.forwardRef<TextInputHandles, Props>(
123+
const Searchbar = forwardRef<TextInputHandles, Props>(
123124
(
124125
{
125126
clearAccessibilityLabel = 'clear',

src/components/TextInput/TextInput.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import {
88
ViewStyle,
99
} from 'react-native';
1010

11+
import type { ThemedComponent } from '@callstack/react-theme-provider';
12+
1113
import { withInternalTheme } from '../../core/theming';
1214
import type { InternalTheme } from '../../types';
15+
import { forwardRef } from '../../utils/forwardRef';
1316
import TextInputAffix, {
1417
Props as TextInputAffixProps,
1518
} from './Adornment/TextInputAffix';
@@ -220,7 +223,7 @@ type TextInputHandles = Pick<
220223
* @extends TextInput props https://reactnative.dev/docs/textinput#props
221224
*/
222225

223-
const TextInput = React.forwardRef<TextInputHandles, Props>(
226+
const TextInput = forwardRef<TextInputHandles, Props>(
224227
(
225228
{
226229
mode = 'flat',
@@ -513,4 +516,10 @@ TextInput.Icon = TextInputIcon;
513516
// @ts-ignore Types of property 'theme' are incompatible.
514517
TextInput.Affix = TextInputAffix;
515518

516-
export default withInternalTheme(TextInput);
519+
export default withInternalTheme(TextInput) as ThemedComponent<
520+
unknown,
521+
Props
522+
> & {
523+
Icon: typeof TextInputIcon;
524+
Affix: typeof TextInputAffix;
525+
};

src/utils/forwardRef.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {
2+
forwardRef as reactForwardRef,
3+
ForwardRefRenderFunction,
4+
PropsWithoutRef,
5+
RefAttributes,
6+
ForwardRefExoticComponent,
7+
} from 'react';
8+
9+
export type ForwarRefComponent<T, P = {}> = ForwardRefExoticComponent<
10+
PropsWithoutRef<P> & RefAttributes<T>
11+
>;
12+
13+
export const forwardRef: <T, P = {}>(
14+
render: ForwardRefRenderFunction<T, P>
15+
) => ForwarRefComponent<T, P> = reactForwardRef;

0 commit comments

Comments
 (0)