import { ValueOf } from '@pluralsight/ps-design-system-util' import hoistNonReactStatics from 'hoist-non-react-statics' import React from 'react' import { defaultName, names } from '../vars/index' export { defaultName, names } type Names = typeof names export const ThemeContext = React.createContext>(defaultName) type ThemeProps = { name?: ValueOf } type ThemeStatics = { defaultName: typeof defaultName; names: Names } type ThemeComponent = React.FC & ThemeStatics const Theme: ThemeComponent = props => { const { name = defaultName } = props return ( {props.children} ) } Theme.names = names Theme.defaultName = defaultName export default Theme export function useTheme() { const themeName = React.useContext(ThemeContext) return themeName } function getDisplayName(Component: React.ComponentType) { if (typeof Component === 'string') return Component if (!Component) return return Component.displayName || Component.name || 'Component' } /** * @deprecated please use the useTheme hook to get theme information */ export function withTheme>( BaseComponent: React.ComponentType

) { const name = getDisplayName(BaseComponent) const Forwarded = React.forwardRef((props, ref) => { const themeName = useTheme() return }) Forwarded.displayName = `withTheme(${name})` return hoistNonReactStatics(Forwarded, BaseComponent) }