import * as React from 'react' ; import get from 'lodash/get' ; import { ThemeContext } from '@emotion/core' ; import { defaultCanvasTheme , createCanvasTheme , EmotionCanvasTheme , PartialEmotionCanvasTheme , } from './index' ; const getFilledTheme = ( theme ) => ( { ... theme , canvas : createCanvasTheme ( theme . canvas ! ) , } ) ; param { Object = } theme export function useTheme ( theme ? ) { if ( theme && theme . canvas ) { return getFilledTheme ( theme ) ; } try { const contextTheme = React . useContext ( ThemeContext ) as EmotionCanvasTheme ; if ( contextTheme && contextTheme . canvas ) { return getFilledTheme ( contextTheme ) ; } } catch ( e ) { } const windowTheme = typeof window !== 'undefined' && get ( window , 'window.workday.canvas.theme' ) ; if ( windowTheme ) { return getFilledTheme ( { canvas : windowTheme } ) ; } return { canvas : defaultCanvasTheme } ; }