react-native-vector-icons: allow omitting variant

This commit is contained in:
Omar Diab
2018-08-15 00:02:12 +09:00
parent 18f5c76069
commit a7340f9be3
2 changed files with 5 additions and 4 deletions

View File

@@ -16,14 +16,14 @@ type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
export type FontAwesome5IconVariants = keyof Omit<typeof FA5Style, "regular">;
// borrowed from https://stackoverflow.com/a/49725198/1105281
type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Omit<T, Keys> &
// modified from https://stackoverflow.com/a/49725198/1105281
type AllowOnlyOne<T, Keys extends keyof T = keyof T> = Omit<T, Keys> &
{
[K in Keys]-?: Required<Pick<T, K>> &
[K in Keys]-?: Partial<Pick<T, K>> &
Partial<Record<Exclude<Keys, K>, undefined>>
}[Keys];
export type FontAwesome5IconProps = RequireOnlyOne<
export type FontAwesome5IconProps = AllowOnlyOne<
{ [K in FontAwesome5IconVariants]?: boolean } & IconProps,
FontAwesome5IconVariants
>;

View File

@@ -29,6 +29,7 @@ class Example extends React.Component {
<View>
{/* Normal Icon */}
<MaterialIcon size={30} color="red" name="exit" />
<FontAwesome5Icon size={10} name="handshake" />
<FontAwesome5Icon size={10} name="handshake" solid />
<FontAwesome5ProIcon size={10} name="parachute-box" light />