Skip to content

Commit

Permalink
fix: use Theme TS type
Browse files Browse the repository at this point in the history
  • Loading branch information
TimKolberger committed Feb 11, 2021
1 parent d6808f0 commit 5a8d8c0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-otters-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chakra-ui/react": patch
---

The `extendTheme` function uses the type `Theme` again
8 changes: 4 additions & 4 deletions packages/react/src/extend-theme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import defaultTheme, { ChakraTheme, DefaultChakraTheme } from "@chakra-ui/theme"
import defaultTheme, { ChakraTheme, Theme } from "@chakra-ui/theme"
import { isFunction, mergeWith } from "@chakra-ui/utils"

type CloneKey<Target, Key> = Key extends keyof Target ? Target[Key] : unknown
Expand All @@ -20,19 +20,19 @@ type DeepThemeExtension<BaseTheme, ThemeType> = {
}

export type ThemeOverride = Partial<ChakraTheme> &
DeepThemeExtension<DefaultChakraTheme, ChakraTheme>
DeepThemeExtension<Theme, ChakraTheme>

/**
* Function to override or customize the Chakra UI theme conveniently
* @param overrides - Your custom theme object overrides
* @param baseTheme - theme to customize
*/
export function extendTheme<
BaseTheme extends ChakraTheme = DefaultChakraTheme,
BaseTheme extends ChakraTheme = Theme,
Overrides extends ThemeOverride = ThemeOverride
>(
overrides: Overrides,
baseTheme: BaseTheme = defaultTheme as BaseTheme,
baseTheme: BaseTheme = (defaultTheme as unknown) as BaseTheme,
): BaseTheme & Overrides {
function customizer(
source: unknown,
Expand Down
20 changes: 20 additions & 0 deletions packages/react/tests/extend-theme.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,24 @@ describe("extendTheme", () => {

expect((customTheme.breakpoints as any).customFunction).toBeUndefined()
})

it("should allow custom breakpoints", () => {
const override = {
breakpoints: createBreakpoints({
sm: "1px",
md: "2px",
lg: "3px",
xl: "4px",
phone: "5px",
}),
}

const customTheme = extendTheme(override)

expect(customTheme.breakpoints).toHaveProperty("sm")
expect(customTheme.breakpoints).toHaveProperty("md")
expect(customTheme.breakpoints).toHaveProperty("lg")
expect(customTheme.breakpoints).toHaveProperty("xl")
expect(customTheme.breakpoints).toHaveProperty("phone")
})
})

0 comments on commit 5a8d8c0

Please sign in to comment.