Skip to content

Commit

Permalink
Merge branch 'main' into repo-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Octomerger authored Aug 19, 2021
2 parents f23f454 + 9d1bd54 commit d2e084a
Show file tree
Hide file tree
Showing 63 changed files with 167 additions and 146 deletions.
57 changes: 41 additions & 16 deletions components/lib/getThemeProps.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
export const defaultCSSThemeProps = {
type ThemeT = { name: string; color_mode: string }

const defaultCSSThemeProps = {
colorMode: 'auto', // light, dark, auto
nightScheme: 'dark',
dayScheme: 'light',
nightTheme: 'dark',
dayTheme: 'light',
}
export const defaultThemeProps = {

export const defaultComponentThemeProps = {
colorMode: 'auto', // day, night, auto
nightScheme: 'dark',
dayScheme: 'light',
nightTheme: 'dark',
dayTheme: 'light',
}

const cssColorModeToJs: Record<string, string> = {
const cssColorModeToComponentColorMode: Record<string, string> = {
auto: 'auto',
light: 'day',
dark: 'night',
}

const supportedThemes = ['light', 'dark', 'dark_dimmed']

/*
* Our version of primer/css is out of date, so we can only support known themes.
* For the least jarring experience possible, we fallback to the color_mode (light / dark) if provided by the theme, otherwise our own defaults
*/
function getSupportedTheme(theme: ThemeT | undefined, fallbackTheme: string) {
if (!theme) {
return fallbackTheme
}

return supportedThemes.includes(theme.name) ? theme.name : theme.color_mode
}

/*
* Returns theme props for consumption by either primer/css or primer/components
* based on the cookie and/or fallback values
*/
export function getThemeProps(req: any, mode?: 'css') {
let cookieValue: {
color_mode?: 'auto' | 'light' | 'dark'
dark_theme?: { name: string }
light_theme?: { name: string }
dark_theme?: ThemeT
light_theme?: ThemeT
} = {}
const defaultProps = mode === 'css' ? defaultCSSThemeProps : defaultThemeProps
const defaultThemeProps = mode === 'css' ? defaultCSSThemeProps : defaultComponentThemeProps

if (req.cookies?.color_mode) {
try {
Expand All @@ -31,12 +52,16 @@ export function getThemeProps(req: any, mode?: 'css') {
}
}

// The cookie value is a primer/css color_mode. sometimes we need to convert that to a primer/components compatible version
const colorMode =
(mode === 'css'
? cookieValue.color_mode
: cssColorModeToComponentColorMode[cookieValue.color_mode || '']) ||
defaultThemeProps.colorMode

return {
// the cookie uses primer/css color_mode, sometimes we need to convert that to a primer/components compatible version
colorMode:
(mode === 'css' ? cookieValue.color_mode : cssColorModeToJs[cookieValue.color_mode || '']) ||
defaultProps.colorMode,
nightScheme: cookieValue.dark_theme?.name || defaultProps.nightScheme,
dayScheme: cookieValue.light_theme?.name || defaultProps.dayScheme,
colorMode,
nightTheme: getSupportedTheme(cookieValue.dark_theme, defaultThemeProps.nightTheme),
dayTheme: getSupportedTheme(cookieValue.light_theme, defaultThemeProps.dayTheme),
}
}
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-2.22-cn-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-2.22-cn.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-2.22-de-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-2.22-de.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-2.22-en-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-2.22-en.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-2.22-es-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-2.22-es.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-2.22-ja-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-2.22-ja.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-2.22-pt-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-2.22-pt.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.0-cn-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.0-cn.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.0-de-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.0-de.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.0-en-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.0-en.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.0-es-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.0-es.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.0-ja-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.0-ja.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.0-pt-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.0-pt.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.1-cn-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.1-cn.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.1-de-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.1-de.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.1-en-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.1-en.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.1-es-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.1-es.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.1-ja-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.1-ja.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.1-pt-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-3.1-pt.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-dotcom-cn-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-dotcom-cn.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-dotcom-de-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-dotcom-de.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-dotcom-en-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-dotcom-en.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-dotcom-es-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-dotcom-es.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-dotcom-ja-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-dotcom-ja.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-dotcom-pt-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-dotcom-pt.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-ghae-cn-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-ghae-cn.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-ghae-de-records.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-ghae-de.json.br
Git LFS file not shown
4 changes: 2 additions & 2 deletions lib/search/indexes/github-docs-ghae-en-records.json.br
Git LFS file not shown
Loading

0 comments on commit d2e084a

Please sign in to comment.