-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds ability for theming via static.json file
- Loading branch information
1 parent
6232a8b
commit 827c256
Showing
4 changed files
with
124 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,98 @@ | ||
import { extendTheme } from "@chakra-ui/react"; | ||
import { STATIC } from "../static"; | ||
|
||
import { extendTheme, withDefaultColorScheme } from "@chakra-ui/react"; | ||
|
||
import "@fontsource/ibm-plex-mono"; | ||
import "@fontsource/ibm-plex-sans"; | ||
|
||
const theme = extendTheme({ | ||
fonts: { | ||
heading: `'IBM Plex Sans', sans-serif`, | ||
body: `'IBM Plex Sans', sans-serif`, | ||
mono: `'IBM Plex Mono', monospace`, | ||
}, | ||
colors: { | ||
brand: { | ||
"50": "#E5F2FF", | ||
"100": "#B8DBFF", | ||
"200": "#8AC4FF", | ||
"300": "#5CADFF", | ||
"400": "#2E96FF", | ||
"500": "#007FFF", | ||
"600": "#0066CC", | ||
"700": "#004C99", | ||
"800": "#00264c", | ||
"900": "#001933", | ||
export type ColorDefinition = | ||
| { | ||
50: string; | ||
100: string; | ||
200: string; | ||
300: string; | ||
400: string; | ||
500: string; | ||
600: string; | ||
700: string; | ||
800: string; | ||
900: string; | ||
} | ||
| string; | ||
|
||
export type ThemeSettings = { | ||
/** | ||
* Apply a default color scheme to all components. | ||
* This supports all Chakra UI color schemes and is not provided by default. | ||
* @see https://v2.chakra-ui.com/docs/styled-system/theme#colors for available color schemes. | ||
*/ | ||
colorScheme?: string; | ||
/** | ||
* Specific color definitions to use in the theme. | ||
* The most common use case is to define a `brand` color. | ||
* @example | ||
* ```json | ||
* { | ||
* "colors": { | ||
* "brand": { | ||
* "50": "#E5F2FF", | ||
* "100": "#B8DBFF", | ||
* "200": "#8AC4FF", | ||
* "300": "#5CADFF", | ||
* "400": "#2E96FF", | ||
* "500": "#007FFF", | ||
* "600": "#0066CC", | ||
* "700": "#004C99", | ||
* "800": "#00264c", | ||
* "900": "#001933" | ||
* } | ||
* } | ||
* } | ||
* ``` | ||
* @see https://v2.chakra-ui.com/docs/styled-system/theme#colors | ||
*/ | ||
colors?: Record<string, ColorDefinition>; | ||
/** | ||
* Extend the Chakra UI theme. | ||
* @see https://v2.chakra-ui.com/docs/styled-system/customize-theme#using-theme-extensions | ||
*/ | ||
extendTheme?: Parameters<typeof extendTheme>[0]; | ||
}; | ||
|
||
const brand: ColorDefinition = { | ||
"50": "#E5F2FF", | ||
"100": "#B8DBFF", | ||
"200": "#8AC4FF", | ||
"300": "#5CADFF", | ||
"400": "#2E96FF", | ||
"500": "#007FFF", | ||
"600": "#0066CC", | ||
"700": "#004C99", | ||
"800": "#00264c", | ||
"900": "#001933", | ||
}; | ||
|
||
let colorScheme = {}; | ||
if (STATIC.data.attributes.theme?.colorScheme) { | ||
colorScheme = withDefaultColorScheme({ | ||
colorScheme: STATIC.data.attributes.theme?.colorScheme, | ||
}); | ||
} | ||
|
||
const theme = extendTheme( | ||
{ | ||
fonts: { | ||
heading: `'IBM Plex Sans', sans-serif`, | ||
body: `'IBM Plex Sans', sans-serif`, | ||
mono: `'IBM Plex Mono', monospace`, | ||
}, | ||
colors: { | ||
brand, | ||
...(STATIC.data.attributes.theme?.colors || {}), | ||
}, | ||
}, | ||
}); | ||
colorScheme, | ||
STATIC.data.attributes.theme?.extendTheme || {}, | ||
); | ||
|
||
export default theme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters