UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

21 lines (16 loc) 680 B
import * as React from 'react'; import {ThemeContext} from '@emotion/react'; import {EmotionCanvasTheme, ContentDirection, PartialEmotionCanvasTheme} from './types'; function useDefaultTheme<T, C>(theme: T | undefined, config: C, fn: (config: C) => T) { return theme || fn(config); } /** * This is a small hook to support right-to-left logic. * It returns a boolean * @example * const isRTL = useIsRTL(); */ export const useIsRTL = (partialTheme?: PartialEmotionCanvasTheme) => { const theme = useDefaultTheme(partialTheme, ThemeContext, React.useContext) as EmotionCanvasTheme; return (theme && theme.canvas && theme.canvas.direction) === ContentDirection.RTL; };