license import React from 'react' ; import { ThemeContext } from './themeContext' ; export type ThemeValue = string ; export type ThemeType = Record < string , ThemeValue > ; returns overview-example export const useTheme = ( ) : ThemeType => { return React . useContext ( ThemeContext ) ; } ; /**
 * Service for working with Eva themes
 */ export class ThemeService { returns static create = ( theme ) : ThemeType => { return Object . keys ( theme ) . reduce ( ( acc , key ) : ThemeType => { return { ... acc , [ key ] : ThemeService . getValue ( key , theme , key ) } ; } , { } ) ; } ; returns static getValue = ( name , theme , fallback ? ) : ThemeValue | undefined => { if ( ThemeService . isReference ( name ) ) { const themeKey = ThemeService . createKeyFromReference ( name ) ; return ThemeService . findValue ( themeKey , theme ) || fallback ; } return ThemeService . findValue ( name , theme ) || fallback ; } ; returns private static findValue = ( name , theme ) : ThemeValue | undefined => { const value = theme [ name ] ; if ( ThemeService . isReference ( value ) ) { const themeKey = ThemeService . createKeyFromReference ( value ) ; return ThemeService . findValue ( themeKey , theme ) ; } return value ; } ; returns private static isReference = ( value ) : boolean => { return `${ value }` . startsWith ( '$' ) ; } ; /**
     * Transforms reference key to theme key
     */ private static createKeyFromReference = ( value ) : string => { return `${ value }` . substring ( 1 ) ; } ; }