From 91ae412cbba770a8eb034b560bbbfbe71f7f6346 Mon Sep 17 00:00:00 2001 From: Jakub Biesiada Date: Fri, 23 Jul 2021 16:24:07 +0200 Subject: [PATCH] feat: add fallback icon to context --- src/components/Icon.tsx | 11 +++++++---- src/context.tsx | 21 ++++++++++++++++----- src/types/FontType.ts | 1 + 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/components/Icon.tsx b/src/components/Icon.tsx index e7535cf..b3198e1 100644 --- a/src/components/Icon.tsx +++ b/src/components/Icon.tsx @@ -7,10 +7,13 @@ import { getIconType } from '../helpers/getIconType' import type { Props } from '../types/Props' -export const Icon = ({ type, ...props }: Props & IconProps) => { - const contextFontType = useContext(NativeIconsContext) +// TODO? type for name optional when has context provided +export const Icon = ({ type, name, ...props }: Props & IconProps) => { + const iconsContext = useContext(NativeIconsContext) - const IconComponent = getIconType(type || contextFontType) + // TODO + const IconComponent = getIconType(type || iconsContext.type) - return + // TODO + return } diff --git a/src/context.tsx b/src/context.tsx index 64019cc..60be406 100644 --- a/src/context.tsx +++ b/src/context.tsx @@ -1,19 +1,30 @@ import React from 'react' +import { IconProps } from 'react-native-vector-icons/Icon' import type { FontType } from './types/FontType' import type { Props } from './types/Props' -export const NativeIconsContext = React.createContext( - undefined -) +// TODO refactor +export const NativeIconsContext = React.createContext<{ + readonly type?: FontType + readonly fallbackIcon?: IconProps['name'] +}>({ + type: undefined, + fallbackIcon: undefined, +}) NativeIconsContext.displayName = 'NativeIconsContext' export const NativeIconsProvider = ({ children, type, -}: Props & { readonly children: React.ReactNode }) => ( - + fallbackIcon, +}: Props & { + // TODO refactor + readonly children: React.ReactNode + readonly fallbackIcon?: IconProps['name'] +}) => ( + {children} ) diff --git a/src/types/FontType.ts b/src/types/FontType.ts index bf316df..60cb389 100644 --- a/src/types/FontType.ts +++ b/src/types/FontType.ts @@ -13,3 +13,4 @@ export type FontType = | 'octicons' | 'zocial' | 'simple-line-icons' +// | string // TODO