-
Notifications
You must be signed in to change notification settings - Fork 43
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
Document new functional color system #225
Merged
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
15d273d
Replace docs
colebemis 5109fea
Convert to TS
colebemis 30c63a7
Update theme context
colebemis 3ee0e78
Add descriptions
colebemis 5dadbff
Add color theme picker
colebemis 170cdbb
Update color theme picker
colebemis 5c6e6db
Add color scales
colebemis e08acb0
Tweak styles
colebemis f3c131d
Add content to homepage
colebemis fb24cd7
Merge remote-tracking branch 'origin/main' into update-docs
colebemis ad2f81f
Wrap with `var()`
colebemis 4e4823f
Update scale variables heading
colebemis cae954a
Update docs/gatsby-config.js
colebemis 2757a40
Merge remote-tracking branch 'origin/main' into update-docs
colebemis 799918e
Merge branch 'update-docs' of https://github.com/primer/primitives in…
colebemis b43bff2
Replace colors_v2 with colors directory
colebemis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,121 @@ | ||
--- | ||
title: Colors | ||
--- | ||
|
||
import colors from '../../dist/js/colors_v2' | ||
import deprecatedColors from '../../dist/deprecations/colors_v2.json' | ||
import filterObj from 'filter-obj' | ||
import flatten from 'flat' | ||
import {Box} from '@primer/components' | ||
import {SwatchGrid} from '../src/components/swatch-grid' | ||
import {ColorThemePicker} from '../src/components/color-theme-picker' | ||
import {ColorScales} from '../src/components/color-scales' | ||
|
||
## Themes | ||
|
||
Preview color variables in any of the available themes: | ||
|
||
<ColorThemePicker /> | ||
|
||
## Functional variables | ||
|
||
### Foreground | ||
|
||
<SwatchGrid names={Object.keys(flatten(colors.light)).filter(key => key.split('.')[0] === 'fg')} /> | ||
|
||
### Canvas | ||
|
||
<SwatchGrid names={Object.keys(flatten(colors.light)).filter(key => key.split('.')[0] === 'canvas')} /> | ||
|
||
### Border | ||
|
||
<SwatchGrid | ||
names={Object.keys(flatten(colors.light)).filter( | ||
key => key.split('.')[0] === 'border' && !Object.keys(deprecatedColors).includes(key) | ||
)} | ||
/> | ||
|
||
### Shadow | ||
|
||
<SwatchGrid | ||
names={Object.keys(flatten(colors.light)).filter( | ||
key => key.split('.')[0] === 'shadow' && !Object.keys(deprecatedColors).includes(key) | ||
)} | ||
/> | ||
|
||
### Neutral | ||
|
||
Use to highlight content without any added meaning. | ||
|
||
<SwatchGrid names={Object.keys(flatten(colors.light)).filter(key => key.split('.')[0] === 'neutral')} /> | ||
|
||
### Accent | ||
|
||
Use to draw attention to interactive elements. | ||
|
||
<SwatchGrid names={Object.keys(flatten(colors.light)).filter(key => key.split('.')[0] === 'accent')} /> | ||
|
||
### Success | ||
|
||
Use to expresses the completion or positive outcome of a task. | ||
|
||
<SwatchGrid names={Object.keys(flatten(colors.light)).filter(key => key.split('.')[0] === 'success')} /> | ||
|
||
### Attention | ||
|
||
Use to warn of pending tasks or highlight active content. | ||
|
||
<SwatchGrid names={Object.keys(flatten(colors.light)).filter(key => key.split('.')[0] === 'attention')} /> | ||
|
||
### Severe | ||
|
||
Use when there are more than 3 levels of states, for example in heatmaps. | ||
|
||
<SwatchGrid names={Object.keys(flatten(colors.light)).filter(key => key.split('.')[0] === 'severe')} /> | ||
|
||
### Danger | ||
|
||
Use to inform of error or another negative message. | ||
|
||
<SwatchGrid names={Object.keys(flatten(colors.light)).filter(key => key.split('.')[0] === 'danger')} /> | ||
|
||
### Done | ||
|
||
Completion color for productivity and code review workflows. | ||
|
||
<SwatchGrid names={Object.keys(flatten(colors.light)).filter(key => key.split('.')[0] === 'done')} /> | ||
|
||
### Sponsors | ||
|
||
Use for Sponsors-related interfaces. | ||
|
||
<SwatchGrid names={Object.keys(flatten(colors.light)).filter(key => key.split('.')[0] === 'sponsors')} /> | ||
|
||
## Scale variable | ||
|
||
<Note variant="warning"> | ||
Avoid referencing scale variables directly when building UI that needs to adapt to different color themes. Instead, | ||
use the functional variables listed above. In rare cases, you may need to use scale variables to define custom | ||
functional variables in your application. | ||
</Note> | ||
|
||
<ColorScales /> | ||
|
||
## Deprecated variables | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th>Deprecated variable</th> | ||
<th>Replacement variable(s)</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{Object.entries(deprecatedColors).map(([key, value]) => ( | ||
<tr> | ||
<td>{key}</td> | ||
<td>{value}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
title: Primer Primitives | ||
--- | ||
|
||
import {HeroLayout} from '@primer/gatsby-theme-doctocat' | ||
|
||
export default HeroLayout | ||
|
||
## Install | ||
|
||
```shell | ||
npm install @primer/primitives | ||
``` | ||
|
||
## Usage | ||
|
||
Primitive data is served in several formats from the [`dist/`](https://unpkg.com/browse/@primer/primitives/dist/) folder: | ||
|
||
- `dist/scss` contains [SCSS](https://sass-lang.com/) files that define CSS variables to be imported into other SCSS files | ||
- `dist/json` contains JSON files for each set of primitives | ||
- `dist/js` contains CommonJS-style JavaScript modules for each set of primitives, as well as an index file that loads all of the primitives for all primitive types. The JavaScript modules also include TypeScript typings files for use in TypeScript projects. |
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
19 changes: 19 additions & 0 deletions
19
docs/src/@primer/gatsby-theme-doctocat/components/wrap-page-element.js
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {BaseStyles} from '@primer/components' | ||
import SkipLink from '@primer/gatsby-theme-doctocat/src/components/skip-link' | ||
import React from 'react' | ||
import {ColorThemeProvider} from '../../../components/color-theme-context' | ||
|
||
// Shadowing this file to wrap the page in our custom ColorThemeProvider. | ||
|
||
function wrapPageElement({element}) { | ||
return ( | ||
<ColorThemeProvider> | ||
<BaseStyles> | ||
<SkipLink /> | ||
{element} | ||
</BaseStyles> | ||
</ColorThemeProvider> | ||
) | ||
} | ||
|
||
export default wrapPageElement |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- title: Colors | ||
url: /colors |
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import colors from '../../../dist/js/colors_v2' | ||
import React from 'react' | ||
import {useColorTheme} from './color-theme-context' | ||
import {Box, Text} from '@primer/components' | ||
import {readableColor} from 'color2k' | ||
|
||
export function ColorScales() { | ||
const [colorTheme] = useColorTheme() | ||
return ( | ||
<Box | ||
sx={{ | ||
display: 'grid', | ||
gridGap: 3, | ||
gridTemplateColumns: 'repeat(auto-fit, minmax(320px, 1fr))', | ||
p: 3, | ||
bg: colors[colorTheme].canvas.default, | ||
boxShadow: 'inset 0 0 0 1px rgba(0,0,0,0.1)', | ||
borderRadius: 2 | ||
}} | ||
> | ||
{Object.entries(colors[colorTheme].scale).map(([scaleName, scale]) => { | ||
return ( | ||
<Box sx={{overflow: 'hidden', borderRadius: 1}}> | ||
{Array.isArray(scale) ? ( | ||
scale.map((color, index) => { | ||
return ( | ||
<Box | ||
sx={{ | ||
color: readableColor(color), | ||
bg: color, | ||
p: 2, | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
fontFamily: 'mono', | ||
fontSize: 1 | ||
}} | ||
> | ||
<Text> | ||
scale.{scaleName}.{index} | ||
</Text> | ||
<Text>{color}</Text> | ||
</Box> | ||
) | ||
}) | ||
) : ( | ||
<Box | ||
sx={{ | ||
color: readableColor(scale), | ||
bg: scale, | ||
p: 2, | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
fontFamily: 'mono', | ||
fontSize: 1 | ||
}} | ||
> | ||
<Text>scale.{scaleName}</Text> | ||
<Text>{scale}</Text> | ||
</Box> | ||
)} | ||
</Box> | ||
) | ||
})} | ||
</Box> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react' | ||
import colors from '../../../dist/js/colors_v2' | ||
|
||
const ColorThemeContext = React.createContext< | ||
[keyof typeof colors, React.Dispatch<React.SetStateAction<keyof typeof colors>>] | ||
>(['light', () => {}]) | ||
|
||
export function ColorThemeProvider({children}) { | ||
const [colorTheme, setColorTheme] = React.useState<keyof typeof colors>('light') | ||
return <ColorThemeContext.Provider value={[colorTheme, setColorTheme]}>{children}</ColorThemeContext.Provider> | ||
} | ||
|
||
export function useColorTheme() { | ||
return React.useContext(ColorThemeContext) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Sponsors is it's own section?