-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add color blind themes #1474
Add color blind themes #1474
Changes from 2 commits
21da0ac
ae80110
25e7796
fd18dd1
56ed28a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@primer/components": minor | ||
--- | ||
|
||
Add `light_protanopia` and `dark_protanopia` color blind color schemes |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,58 +48,20 @@ const fontSizes = ['12px', '14px', '16px', '20px', '24px', '32px', '40px', '48px | |
|
||
const space = ['0', '4px', '8px', '16px', '24px', '32px', '40px', '48px', '64px', '80px', '96px', '112px', '128px'] | ||
|
||
const light = partitionColors(primitives.colors.light) | ||
const dark = partitionColors(primitives.colors.dark) | ||
const darkDimmed = partitionColors(primitives.colors['dark_dimmed']) | ||
const darkHighContrast = partitionColors(primitives.colors['dark_high_contrast']) | ||
|
||
// This file must be in vanilla JS to work with preval | ||
// but our temporary filter utils make it impossible for | ||
// our TypeScript to properly infer const object structure | ||
// so we need to use JSDoc comments. | ||
|
||
/** | ||
* @type Partial<typeof primitives.colors.light> | ||
*/ | ||
const lightColors = omitScale(light.colors) | ||
|
||
/** | ||
* @type Partial<typeof primitives.colors.light> | ||
*/ | ||
const lightShadows = omitScale(light.shadows) | ||
|
||
/** | ||
* @type Partial<typeof primitives.colors.dark> | ||
*/ | ||
const darkColors = omitScale(dark.colors) | ||
|
||
/** | ||
* @type Partial<typeof primitives.colors.dark> | ||
*/ | ||
const darkShadows = omitScale(dark.shadows) | ||
|
||
/** | ||
* @type Partial<typeof primitives.colors.dark_dimmed> | ||
*/ | ||
const darkDimmedColors = omitScale(darkDimmed.colors) | ||
|
||
/** | ||
* @type Partial<typeof primitives.colors.dark_dimmed> | ||
*/ | ||
const darkDimmedShadows = omitScale(darkDimmed.shadows) | ||
|
||
/** | ||
* @type Partial<typeof primitives.colors.dark_dimmed> | ||
*/ | ||
const darkHighContrastColors = omitScale(darkHighContrast.colors) | ||
|
||
/** | ||
* @type Partial<typeof primitives.colors.dark_high_contrast> | ||
* @type Record<keyof typeof primitives.colors, Record<'colors' | 'shadows', Partial<typeof primitives.colors.light>> | ||
*/ | ||
const darkHighContrastShadows = omitScale(darkHighContrast.shadows) | ||
const colorSchemes = Object.entries(primitives.colors) | ||
.map(([name, variables]) => { | ||
const {colors, shadows} = partitionColors(variables) | ||
return [name, {colors: omitScale(colors), shadows: omitScale(shadows)}] | ||
}) | ||
.reduce((acc, [name, variables]) => { | ||
acc[name] = variables | ||
return acc | ||
}, {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I refactored this part of the code to get all color schemes from Primer Primitives instead of hard-coding references to them. This means that when future color schemes are published in Primer Primitives, we only need to bump the Primer Primitives version number in Primer React to make the color schemes available to Primer React consumers. |
||
|
||
const theme = { | ||
// General | ||
animation, | ||
borderWidths, | ||
breakpoints, | ||
|
@@ -110,25 +72,7 @@ const theme = { | |
radii, | ||
sizes, | ||
space, | ||
colorSchemes: { | ||
light: { | ||
colors: lightColors, | ||
shadows: lightShadows | ||
}, | ||
dark: { | ||
colors: darkColors, | ||
shadows: darkShadows | ||
}, | ||
dark_dimmed: { | ||
colors: darkDimmedColors, | ||
shadows: darkDimmedShadows | ||
}, | ||
// eslint-disable-next-line camelcase | ||
dark_high_contrast: { | ||
colors: darkHighContrastColors, | ||
shadows: darkHighContrastShadows | ||
} | ||
} | ||
colorSchemes | ||
} | ||
|
||
module.exports = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: you could collapse this map into the reduce below, if you think it'd be more readable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. Good call. I'll do that