From 133c3d7e6937a56f62d0c28aefe64ff667b5f3e3 Mon Sep 17 00:00:00 2001 From: Matyas Szabo Date: Mon, 11 Nov 2024 17:34:49 +0100 Subject: [PATCH] refactor(emotion,theme-registry,ui-themes): docs, tests --- docs/guides/using-theme-overrides.md | 154 ++++++++++-------- packages/__docs__/components.js | 7 +- packages/__docs__/src/Theme/index.tsx | 2 +- .../emotion/src/__tests__/useTheme.test.tsx | 111 ++++++++++++- packages/theme-registry/src/ThemeRegistry.ts | 24 ++- .../src/__tests__/ThemeRegistry.test.ts | 2 +- packages/ui-themes/README.md | 18 +- .../src/__new-tests__/themes.test.tsx | 19 ++- packages/ui-themes/src/themes/canvas/index.ts | 6 +- .../src/themes/canvasHighContrast/index.ts | 6 + 10 files changed, 266 insertions(+), 83 deletions(-) diff --git a/docs/guides/using-theme-overrides.md b/docs/guides/using-theme-overrides.md index a7e6dad751..a72157cb95 100644 --- a/docs/guides/using-theme-overrides.md +++ b/docs/guides/using-theme-overrides.md @@ -27,23 +27,7 @@ type: embed ### How theming works in InstUI -The theming system in InstUI has three levels: - -**The global theme** - -Global themes are useful when you have multiple React Application trees and you want to set up themes and overrides on a more global level than application level theming. -This basically means you don't necessarily have to wrap each application tree with an [InstUISettingsProvider](/#InstUISettingsProvider) to use themes. -InstUI leverages the [ThemeRegistry](/#ThemeRegistry) package to achieve global theming. - -```jsx ---- -type: code ---- -// app/init sets the global theme -import canvas from '@instructure/ui-themes' - -canvas.use() -``` +The theming system in InstUI has these levels: **The application level theme** @@ -95,42 +79,28 @@ const generateStyle = (componentTheme) => { } ``` -### Global theme overrides +### Application level theme overrides -In order to globally register and override themes, simply import the theme you wish to use and call `.use({ overrides })` on it: +`` accepts full theme objects and override objects too. ```js --- -type: code +type: example --- -import ReactDOM from "react-dom" -import { canvas } from "@instructure/ui-themes" - -canvas.use({ - overrides: { - colors: { - primitives: { - green45: "red" - } +
- ...your application code goes here... + + I should have monospace font family from the override +
-) +
``` -**Note**: globally overriding themes like this means that every InstUI component will use that theme, unless they are wrapped inside an ``. - -You can see more examples [here](/#using-theme-overrides/#using-theme-overrides-examples). - -### Application level theme overrides - -`` accepts full theme objects and override objects too. - #### Full themes By nesting the `InstUISettingsProvider` you can apply different themes to some sections of you app. @@ -214,27 +184,27 @@ const Example = () => { return (

Common variables

- - + + setIcBrandPrimary(v)} - messages={[{text:'used for border/background/shadow/focus colors in many places',type:'hint'}]} /> + messages={[{text:'used for border/background/focus/shadow/.. colors in many places',type:'hint'}]} /> - + setIcBrandFontColorDark(v)} messages={[{text:'used in lots of places for text color',type:'hint'}]} />

Button branding

- - + + setIcBrandButtonPrimaryBgd(v)} messages={[{text:"Used by 'primary' color buttons for background",type:'hint'}]} />
setIcBrandButtonPrimaryText(v)} messages={[{text:"Used by 'primary' color buttons for text color",type:'hint'}]} />
- + setIcBrandButtonSecondaryBgd(v)} messages={[{text:'Unused in InstUI',type:'hint'}]} />
@@ -260,13 +230,17 @@ const Example = () => { 'ic-brand-global-nav-menu-item__text-color--active': icBrandGlobalNavMenuItemTextColorActive }}}>
- - - + + + + + - - + + + +