Skip to content
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

Merged
merged 5 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silly-students-visit.md
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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"license": "MIT",
"dependencies": {
"@primer/octicons-react": "^13.0.0",
"@primer/primitives": "4.7.1",
"@primer/primitives": "4.8.1",
"@react-aria/ssr": "3.1.0",
"@styled-system/css": "5.1.5",
"@styled-system/props": "5.1.5",
Expand Down
78 changes: 11 additions & 67 deletions src/theme-preval.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Copy link
Contributor

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?

Copy link
Contributor Author

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

const {colors, shadows} = partitionColors(variables)
return [name, {colors: omitScale(colors), shadows: omitScale(shadows)}]
})
.reduce((acc, [name, variables]) => {
acc[name] = variables
return acc
}, {})
Copy link
Contributor Author

@colebemis colebemis Sep 28, 2021

Choose a reason for hiding this comment

The 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,
Expand All @@ -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 = {
Expand Down