You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All use-cases will use the getFilledTheme utility function or fall back to the default Canvas theme if no theme was found.
There is actually 2 distinct functions: A hook that can access the ThemeContext and a utility function. At the moment, the way it is implemented shouldn't cause any real issues, but every use of the CK styled function that doesn't have a predefined theme is throwing a silently-ignored error which isn't very efficient.
I propose useTheme is broken out to 2 distinct functions:
functionisCanvasTheme(input: object): input is EmotionCanvasTheme{returninput.hasOwnProperty('canvas');}functiongetThemeFromWindow(): any{// should we do any validation here? The shape could be anything... We're returning `any` and pretending things will be okayreturntypeofwindow!=='undefined'&&get(window,'window.workday.canvas.theme');}// to be used in `styled` and class componentsexportfunctiongetTheme(theme?: PartialEmotionCanvasTheme): EmotionCanvasTheme{if(theme&&isCanvasTheme(theme)){returngetFilledTheme(theme);}constwindowTheme=getThemeFromWindow();if(windowTheme){returngetFilledTheme({canvas: windowTheme});}return{canvas: defaultCanvasTheme};}// to be used in functional componentsexportfunctionuseTheme(theme?: PartialEmotionCanvasTheme): EmotionCanvasTheme{constcontextTheme=React.useContext(ThemeContext);if(theme&&isCanvasTheme(theme)){returngetFilledTheme(theme);}if(isCanvasTheme(contextTheme)){returngetFilledTheme(contextTheme);}constwindowTheme=getThemeFromWindow();if(windowTheme){returngetFilledTheme({canvas: windowTheme});}return{canvas: defaultCanvasTheme};}
AC
Update components that current useTheme to use the new methods
Deprecate old useTheme methods
Document changes
Review current usage & plan for migration
look into #864 and if that can be somewhat addressed here
The text was updated successfully, but these errors were encountered:
Fixes: #923
- We've added `getTheme` so that you can have access to theme inside of `styled` function or class components.
- We've updated `useTheme` to add a warning if being used outside of a context.
- We've removed `getCanvasTheme` and `useCanvasTheme`.
[category:Components]
### BREAKING CHANGES
- We've removed `getCanvasTheme` and `useCanvasTheme`.
- Use `useTheme` when you have a `CanvasProvider` or you're inside of a functional component
- Use `getTheme` when inside a styled component and you need access to theme.
Co-authored-by: @mannycarrera4 <[email protected]>
🐛 Bug Report
The
useTheme
hook is used in 3 distinct ways:styled
functionAll use-cases will use the
getFilledTheme
utility function or fall back to the default Canvas theme if no theme was found.There is actually 2 distinct functions: A hook that can access the
ThemeContext
and a utility function. At the moment, the way it is implemented shouldn't cause any real issues, but every use of the CKstyled
function that doesn't have a predefined theme is throwing a silently-ignored error which isn't very efficient.I propose
useTheme
is broken out to 2 distinct functions:AC
look into #864 and if that can be somewhat addressed here
The text was updated successfully, but these errors were encountered: