Skip to content

Commit d062010

Browse files
authored
fix(theme): update types for ThemeProvider to accept output of createTheme (#3071)
1 parent c603730 commit d062010

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

.changeset/popular-pigs-glow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@aws-amplify/ui-react": patch
3+
"@aws-amplify/ui": patch
4+
---
5+
6+
fix(theme): update types for `ThemeProvider` to accept output of `createTheme`

packages/react/src/components/ThemeProvider/__tests__/ThemeProvider.test.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { render, screen } from '@testing-library/react';
2-
import { Theme } from '@aws-amplify/ui';
2+
import { renderHook } from '@testing-library/react-hooks';
3+
import { Theme, createTheme } from '@aws-amplify/ui';
34
import * as React from 'react';
45

56
import { ThemeProvider } from '../index';
67
import { Heading } from '../../../primitives';
8+
import { useTheme } from '../../../hooks';
79

810
const App = () => {
911
return <Heading>Howdy</Heading>;
@@ -21,6 +23,31 @@ describe('ThemeProvider', () => {
2123
expect(heading.nodeName).toBe('H6');
2224
});
2325

26+
it('should accept the output of createTheme to allow for extending themes', async () => {
27+
const studioTheme = createTheme();
28+
const extendedTheme = createTheme(
29+
{
30+
name: 'extended-theme',
31+
tokens: {
32+
colors: {
33+
font: {
34+
primary: { value: 'hotpink' },
35+
},
36+
},
37+
},
38+
},
39+
studioTheme
40+
);
41+
42+
const { result } = renderHook(() => useTheme(), {
43+
wrapper: ({ children }) => (
44+
<ThemeProvider theme={extendedTheme}>{children}</ThemeProvider>
45+
),
46+
});
47+
48+
expect(result.current.tokens.colors.font.primary.value).toBe('hotpink');
49+
});
50+
2451
it('wraps the App in [data-amplify-theme="default-theme"]', () => {
2552
const { container } = render(
2653
<ThemeProvider>

packages/react/src/components/ThemeProvider/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { DirectionProvider } from '@radix-ui/react-direction';
33

4-
import { createTheme, Theme } from '@aws-amplify/ui';
4+
import { createTheme, Theme, WebTheme } from '@aws-amplify/ui';
55

66
import { AmplifyContext } from './AmplifyContext';
77

@@ -28,7 +28,7 @@ interface ThemeProviderProps {
2828
/**
2929
* Custom theme
3030
*/
31-
theme?: Theme;
31+
theme?: Theme | WebTheme;
3232
}
3333

3434
export function AmplifyProvider({

packages/ui/src/theme/createTheme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const setupToken: SetupToken<WebDesignToken> = ({ token, path }) => {
3131
* const myOtherTheme = createTheme({}, myTheme);
3232
*/
3333
export function createTheme(
34-
theme?: Theme,
34+
theme?: Theme | WebTheme,
3535
DefaultTheme: DefaultTheme | WebTheme = defaultTheme
3636
): WebTheme {
3737
// merge theme and DefaultTheme to get a complete theme

0 commit comments

Comments
 (0)