diff --git a/src-docs/src/views/emotion/canopy.tsx b/src-docs/src/views/emotion/canopy.tsx index 2b683e320c2..abec3dcdc0c 100644 --- a/src-docs/src/views/emotion/canopy.tsx +++ b/src-docs/src/views/emotion/canopy.tsx @@ -30,6 +30,7 @@ import { computed, euiThemeDefault, buildTheme, + EuiThemeModifications, } from '../../../../src/services'; const View = () => { @@ -76,7 +77,7 @@ const View3 = () => { const overrides = { colors: { light: { euiColorPrimary: '#8A07BD' }, - dark: { euiColorPrimary: '#bd07a5' }, + dark: { euiColorPrimary: '#BD07A5' }, }, }; return ( @@ -84,7 +85,7 @@ const View3 = () => { - + Overriding primary @@ -98,16 +99,16 @@ const View2 = () => { light: { euiColorSecondary: computed( ['colors.euiColorPrimary'], - () => '#85e89d' + () => '#85E89d' ), }, - dark: { euiColorSecondary: '#f0fff4' }, + dark: { euiColorSecondary: '#F0FFF4' }, }, }; return ( <> - + Overriding secondary @@ -176,15 +177,95 @@ export default () => { 'CUSTOM' ); + // Difference is due to automatic colorMode reduction during value computation. + // Makes typing slightly inconvenient, but makes consuming values very convenient. + type ExtensionsUncomputed = { + colors: { light: { myColor: string }; dark: { myColor: string } }; + custom: { + colors: { + light: { customColor: string }; + dark: { customColor: string }; + }; + mySize: number; + }; + }; + type ExtensionsComputed = { + colors: { myColor: string }; + custom: { colors: { customColor: string }; mySize: number }; + }; + + // Type (EuiThemeModifications) only necessary if you want IDE autocomplete support here + const extend: EuiThemeModifications = { + colors: { + light: { + euiColorPrimary: '#F56407', + myColor: computed(['colors.euiColorPrimary'], ([primary]) => primary), + }, + dark: { + euiColorPrimary: '#FA924F', + myColor: computed(['colors.euiColorPrimary'], ([primary]) => primary), + }, + }, + custom: { + colors: { + light: { customColor: '#080AEF' }, + dark: { customColor: '#087EEF' }, + }, + mySize: 5, + }, + }; + + const Extend = () => { + // Generic type (ExtensionsComputed) necessary if accessing extensions/custom properties + const [{ colors, custom }, colorMode] = useEuiTheme(); + return ( +
+
+ {colorMode} +
+            {JSON.stringify({ colors, custom }, null, 2)}
+          
+
+
+

+

+

+

+

+

+
+
+ ); + }; + return ( <> + modify={overrides}>