This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
token aliases and new surface token (#77)
* rename background to surface, add new background, add general use token aliases * remove console.log * correct background token uses to surface
- Loading branch information
1 parent
5ee8dc0
commit 0e7b691
Showing
13 changed files
with
194 additions
and
39 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
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
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
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
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,68 @@ | ||
import React from 'react'; | ||
import { css } from 'styled-components'; | ||
import { readableColor } from 'polished'; | ||
|
||
import { Text } from '../../../typography'; | ||
|
||
import { core } from '../../core'; | ||
import { Card, Canvas } from '../../storybook'; | ||
import { tx } from '../../util'; | ||
|
||
export function Tokens() { | ||
return ( | ||
<> | ||
<Canvas> | ||
<Card grade={400} styles={styles}> | ||
<span> | ||
<Text>color-surface-primary</Text> | ||
<br /> | ||
<Text>color-surface-400</Text> | ||
</span> | ||
</Card> | ||
<Card grade={600} styles={styles}> | ||
<span> | ||
<Text>color-surface-secondary</Text> | ||
<br /> | ||
<Text>color-surface-600</Text> | ||
</span> | ||
</Card> | ||
<Card grade={800} styles={styles}> | ||
<span> | ||
<Text>color-surface-secondary</Text> | ||
<br /> | ||
<Text>color-surface-800</Text> | ||
</span> | ||
</Card> | ||
</Canvas> | ||
|
||
<hr /> | ||
|
||
<Canvas> | ||
{[...new Array(11)].map((_, key) => { | ||
const grade = key * 100; | ||
|
||
return ( | ||
<Card key={key} grade={grade} styles={styles}> | ||
<Text>color-surface-{grade}</Text> | ||
</Card> | ||
); | ||
})} | ||
</Canvas> | ||
</> | ||
); | ||
} | ||
|
||
Tokens.storyName = 'surface'; | ||
|
||
function styles({ theme, grade }) { | ||
const surface = tx(theme, core.color.surface(grade)); | ||
const color = readableColor(surface); | ||
|
||
return css` | ||
background: ${surface}; | ||
> span { | ||
color: ${color}; | ||
} | ||
`; | ||
} |
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,23 @@ | ||
import { grayscale, slate, white } from '../../../color'; | ||
|
||
import { Token, readToken, TokenValue, clamp } from '../../util'; | ||
|
||
export const surface = (grade: number) => readToken(token, grade); | ||
|
||
const token: Token = { | ||
default: 'light', | ||
type: 'COLOR', | ||
modes: { dark, light }, | ||
}; | ||
|
||
function dark(grade: number): TokenValue { | ||
return grayscale(clamp(-1 * (grade / 5 - 1000))); | ||
} | ||
|
||
function light(grade: number): TokenValue { | ||
return grade >= 300 ? white : slate(clamp(-1 * (grade / 2 - 150))); | ||
} | ||
|
||
surface.primary = surface(400); | ||
surface.secondary = surface(600); | ||
surface.secondary = surface(800); |
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