import React, { createContext, useContext } from 'react'; type ContextType = { colors: RequiredColors; }; const Context = createContext({} as ContextType); type RequiredColors = { gray50: string; gray100: string; gray200: string; gray300: string; gray400: string; gray500: string; gray600: string; gray700: string; gray800: string; gray900: string; primary50: string; primary100: string; primary200: string; primary300: string; primary400: string; primary500: string; primary600: string; primary700: string; primary800: string; primary900: string; }; const Provider = function (props: { children: React.ReactNode; colors: Colors; }) { return ( {props.children} ); }; export const useColors = () => { const context = useContext(Context); if (context.colors === undefined) { throw new Error( 'react-native-components requires all components to be surrounding by Provider' ); } function getColor(color: string) { if (context.colors[color as 'gray50'] === undefined) { throw new Error(`The color ${color} was not given to the Provider`); } return context.colors[color as 'gray50']; } return { getColor }; }; export default Provider;