Skip to content

Commit e21a3db

Browse files
committed
fix: custom prop typing fixes
1 parent 0440d6a commit e21a3db

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

src/components/primitives/Box/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
PlatformProps,
66
ResponsiveValue,
77
ColorType,
8+
CustomProps,
89
} from '../../types';
910
import type { ITextProps } from './../Text/types';
1011

@@ -17,7 +18,7 @@ export interface ILinearGradientProps {
1718
};
1819
}
1920

20-
export interface IBoxProps<T = null>
21+
interface BoxProps<T = null>
2122
extends ViewProps,
2223
SafeAreaProps,
2324
PlatformProps<T extends null ? IBoxProps<any> : T>,
@@ -44,3 +45,5 @@ export interface IBoxProps<T = null>
4445
>;
4546
// gap?: ResponsiveValue<number | string>;
4647
}
48+
49+
export type IBoxProps<T = null> = BoxProps<T> | CustomProps<'Box'>;

src/components/primitives/Button/types.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,28 @@ import type { IStackProps } from '../Stack';
44
import type { ResponsiveValue } from '../../types';
55
import type { MutableRefObject } from 'react';
66
import type { ISizes } from '../../../theme/base/sizes';
7-
import type { VariantType } from '../../../components/types/utils';
7+
import type {
8+
CustomProps,
9+
VariantType,
10+
// VariantType,
11+
// VariantTypeTest,
12+
} from '../../../components/types/utils';
813
import type { ISpinnerProps } from '../Spinner/types';
914

15+
// const myFunction = ({ a, b }) => {
16+
// return { a: a, b: b };
17+
// };
18+
19+
// type returnType = ReturnType<typeof myFunction>;
20+
// type parameter = Parameters<typeof myFunction>[0];
21+
22+
// type newparameter = keyof parameter;
23+
// const a: parameter =
24+
// type parameter = Para<typeof myFunction>;
25+
// type buttonVariant = VariantTypeTest<'Button'>;
1026
// Todo: Create underscore Props section on docs.
1127
// _hover?: IButtonProps;
12-
export interface IButtonProps extends IPressableProps<IButtonProps> {
28+
interface ButtonProps extends IPressableProps<IButtonProps> {
1329
/**
1430
* The color of the radio when it's checked. This should be one of the color keys in the theme (e.g."green", "red").
1531
* @default 'primary'
@@ -153,3 +169,5 @@ export type IButtonComponentType = ((
153169
(props: IButtonGroupProps & { ref?: MutableRefObject<any> }) => JSX.Element
154170
>;
155171
};
172+
173+
export type IButtonProps = ButtonProps | CustomProps<'Button'>;

src/components/types/utils.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,39 @@ export type SizeType = ResponsiveValue<
2121
export type ColorType = ResponsiveValue<
2222
Leaves<ITheme['colors']> | (string & {})
2323
>;
24+
25+
type ComponentType<T extends keyof ITheme['components']> = {
26+
[Property in keyof ITheme['components'][T]]: ITheme['components'][T][Property];
27+
};
28+
29+
type ParametersOf<T> = {
30+
[Key in keyof T]: T[Key] extends (...args: any) => void
31+
? Parameters<T[Key]>[0] extends {}
32+
? Parameters<T[Key]>[0]
33+
: never
34+
: never;
35+
}[keyof T];
36+
37+
// type VariantParams<T extends keyof ITheme['components']> = ParametersOf<
38+
// //@ts-ignore
39+
// ComponentType<T>['variants']
40+
// >;
41+
42+
// type PickedVariantParams<T extends keyof ITheme['components']> = Pick<
43+
// VariantParams<T>,
44+
// keyof VariantParams<T>
45+
// >;
46+
type ParameterType<T, Key> = ParametersOf<
47+
//@ts-ignore
48+
ComponentType<T>[Key]
49+
>;
50+
type CustomPropType<T extends keyof ITheme['components'], Key> = Extract<
51+
ParameterType<T, Key>,
52+
Pick<ParameterType<T, Key>, keyof ParameterType<T, Key>>
53+
>;
54+
55+
export type CustomProps<T extends keyof ITheme['components']> =
56+
| CustomPropType<T, 'variants'>
57+
| CustomPropType<T, 'baseStyle'>
58+
| CustomPropType<T, 'sizes'>
59+
| CustomPropType<T, 'defaultProps'>;

0 commit comments

Comments
 (0)