Skip to content

Commit 4e09919

Browse files
committed
feat(emotion): asd
1 parent b2cf930 commit 4e09919

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

packages/emotion/src/EmotionTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ type Overrides = {
104104

105105
type BaseThemeOrOverride = Theme | PartialTheme | Overrides
106106

107-
type ThemeOrOverride =
107+
type ThemeOrLegacyOverride =
108108
| BaseThemeOrOverride
109109
| ((theme: BaseTheme) => BaseThemeOrOverride)
110110

@@ -147,7 +147,7 @@ export interface StyleObject {
147147

148148
export type {
149149
BaseThemeOrOverride,
150-
ThemeOrOverride,
150+
ThemeOrLegacyOverride,
151151
Overrides,
152152
ComponentOverride,
153153
SpecificThemeOverride,

packages/emotion/src/InstUISettingsProvider/index.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { DeterministicIdContextProvider } from '@instructure/ui-react-utils'
3030

3131
import { getTheme } from '../getTheme'
3232

33-
import type { ThemeOrOverride } from '../EmotionTypes'
33+
import type { ThemeOrLegacyOverride } from '../EmotionTypes'
3434
import type { DeterministicIdProviderValue } from '@instructure/ui-react-utils'
3535
import { mergeDeep } from '@instructure/ui-utils'
3636
import { Theme } from '@instructure/ui-themes'
@@ -41,7 +41,7 @@ type InstUIProviderProps = {
4141
/**
4242
* A full theme or an override object
4343
*/
44-
theme?: ThemeOrOverride
44+
theme?: ThemeOrLegacyOverride
4545

4646
// TODO-theme-types: fix override typing
4747
/**
@@ -92,18 +92,29 @@ function InstUISettingsProvider({
9292
)
9393
}
9494

95-
let providedTheme = theme
96-
if (typeof theme !== 'function') {
97-
const override = (theme as Theme).themeOverride!
98-
providedTheme = {
99-
...theme,
100-
themeOverride: mergeDeep(override, themeOverride)
101-
}
102-
}
95+
/**
96+
* new pattern: if you wanna replace a theme inside an InstUISettigsProvider, provide it via the theme prop. It'll
97+
* override everything, replacing the otherwise used theme.
98+
* if you wanna apply an override, use the themeOverride prop.
99+
*/
100+
101+
// let providedThemeOverride = themeOverride
102+
// if (typeof themeOverride === 'function') {
103+
// providedThemeOverride = themeOverride(useTheme())
104+
// }
105+
106+
// let providedTheme = theme
107+
// if (typeof theme !== 'function') {
108+
// const override = (theme as Theme).themeOverride!
109+
// providedTheme = {
110+
// ...theme,
111+
// themeOverride: mergeDeep(override, themeOverride)
112+
// }
113+
// }
103114

104115
let providers = (
105116
<DeterministicIdContextProvider instanceCounterMap={instanceCounterMap}>
106-
<ThemeProvider theme={getTheme(providedTheme)}>
117+
<ThemeProvider theme={getTheme(theme, themeOverride)}>
107118
<TextDirectionContext.Provider value={finalDir}>
108119
{children}
109120
</TextDirectionContext.Provider>

packages/emotion/src/__tests__/useTheme.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ import '@testing-library/jest-dom'
2929

3030
import { useTheme } from '../useTheme'
3131
import { InstUISettingsProvider } from '../InstUISettingsProvider'
32-
import type { ThemeOrOverride } from '../EmotionTypes'
32+
import type { ThemeOrLegacyOverride } from '../EmotionTypes'
3333

3434
type Props = {
35-
callback(theme: ThemeOrOverride): void
35+
callback(theme: ThemeOrLegacyOverride): void
3636
}
3737

3838
const ExampleComponent = (props: Props) => {

packages/emotion/src/getComponentThemeOverride.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
import type {
26-
ThemeOrOverride,
26+
ThemeOrLegacyOverride,
2727
Overrides,
2828
ComponentOverride
2929
} from './EmotionTypes'
@@ -48,7 +48,7 @@ type ComponentName = keyof ComponentOverride | undefined
4848
* @returns The calculated theme override object
4949
*/
5050
const getComponentThemeOverride = (
51-
theme: ThemeOrOverride,
51+
theme: ThemeOrLegacyOverride,
5252
displayName: string,
5353
componentId?: string,
5454
// ThemeOverrideProp is the old type, ThemeOverrideValue is the new one

packages/emotion/src/getTheme.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type { BaseTheme } from '@instructure/shared-types'
2828

2929
import type {
3030
Overrides,
31-
ThemeOrOverride,
31+
ThemeOrLegacyOverride,
3232
SpecificThemeOverride
3333
} from './EmotionTypes'
3434

@@ -43,13 +43,13 @@ import type {
4343
* If an override object is given, it returns the ancestor theme and
4444
* the overrides merged together.
4545
*
46-
* @param themeOrOverride - A full theme or an override object
46+
* @param themeOrLegacyOverride - A full theme or an override object
4747
* @returns A function that returns with the theme object for the [ThemeProvider](https://emotion.sh/docs/theming#themeprovider-reactcomponenttype)
4848
* This function is called by Emotion on theme provider creation, where
4949
* `ancestorTheme` is a theme object from an ancestor `ThemeProvider`
5050
*/
5151
const getTheme =
52-
(themeOrOverride: ThemeOrOverride) =>
52+
(themeOrLegacyOverride: ThemeOrLegacyOverride, themeOverride: any) =>
5353
(ancestorTheme = {} as BaseTheme) => {
5454
// we need to clone the ancestor theme not to override it
5555
let currentTheme
@@ -67,7 +67,7 @@ const getTheme =
6767
currentTheme = ancestorTheme
6868
}
6969

70-
let resolvedThemeOrOverride = themeOrOverride
70+
let resolvedThemeOrOverride = themeOrLegacyOverride
7171

7272
if (typeof resolvedThemeOrOverride === 'function') {
7373
resolvedThemeOrOverride = resolvedThemeOrOverride(currentTheme)

0 commit comments

Comments
 (0)