-
Notifications
You must be signed in to change notification settings - Fork 673
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
Adopt TS in theme-ui/color #672
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4e29968
refactor(@theme-ui/color): adopt TypeScript
hasparus 030d71c
chore(@theme-ui/color): rename index.js
hasparus 8e0fbf1
docs(@theme-ui/color): add grayscale to README
hasparus 481406f
chore(@theme-ui/color): stop building tests to dist
hasparus 9404cc6
test(@theme-ui/color): assert as Theme in tests
hasparus 8328017
chore(@theme-ui/color): move core to deps
hasparus ca9c226
refactor: move Theme to @theme-ui/css
hasparus 8e4680a
chore(@theme-ui/custom-properties): import Theme from css
hasparus 00f811e
chore(@theme-ui/color): import Theme from css
hasparus 5c13bd1
refactor(@theme-ui/core): stop depending on styled-system
hasparus abe38f4
chore(@theme-ui/css): revert stylelint format
hasparus 65e7b29
chore(@theme-ui/custom-properties): add @types/pluralize dependency
hasparus 78777ee
fix(docs): fix import to @theme-ui/css source code
hasparus 7a5104b
Update package.json
hasparus 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
This file was deleted.
Oops, something went wrong.
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,85 @@ | ||
import * as P from 'polished' | ||
import { get, Theme } from '@theme-ui/css' | ||
|
||
const g = (t: Theme, c: string) => | ||
get(t, `colors.${c}`, c) | ||
.replace(/^var\(--(\w+)(.*?), /, '') | ||
.replace(/\)/, '') | ||
|
||
/** | ||
* Darken a color by an amount 0–1 | ||
*/ | ||
export const darken = (c: string, n: number) => (t: Theme) => | ||
P.darken(n, g(t, c)) | ||
/** | ||
* Lighten a color by an amount 0–1 | ||
*/ | ||
export const lighten = (c: string, n: number) => (t: Theme) => | ||
P.lighten(n, g(t, c)) | ||
/** | ||
* Rotate the hue of a color by an amount 0–360 | ||
*/ | ||
export const rotate = (c: string, d: number) => (t: Theme) => | ||
P.adjustHue(d, g(t, c)) | ||
|
||
/** | ||
* Set the hue of a color to a degree 0–360 | ||
*/ | ||
export const hue = (c: string, h: number) => (t: Theme) => P.setHue(h, g(t, c)) | ||
/** | ||
* Set the saturation of a color to an amount 0–1 | ||
*/ | ||
export const saturation = (c: string, s: number) => (t: Theme) => | ||
P.setSaturation(s, g(t, c)) | ||
/** | ||
* Set the lightness of a color to an amount 0–1 | ||
*/ | ||
export const lightness = (c: string, l: number) => (t: Theme) => | ||
P.setLightness(l, g(t, c)) | ||
/** | ||
* Desaturate a color by an amount 0–1 | ||
*/ | ||
export const desaturate = (c: string, n: number) => (t: Theme) => | ||
P.desaturate(n, g(t, c)) | ||
/** | ||
* Saturate a color by an amount 0–1 | ||
*/ | ||
export const saturate = (c: string, n: number) => (t: Theme) => | ||
P.saturate(n, g(t, c)) | ||
|
||
/** | ||
* Shade a color by an amount 0–1 | ||
*/ | ||
export const shade = (c: string, n: number) => (t: Theme) => P.shade(n, g(t, c)) | ||
/** | ||
* Tint a color by an amount 0–1 | ||
*/ | ||
export const tint = (c: string, n: number) => (t: Theme) => P.tint(n, g(t, c)) | ||
|
||
export const transparentize = (c: string, n: number) => (t: Theme) => | ||
P.transparentize(n, g(t, c)) | ||
/** | ||
* Set the transparency of a color to an amount 0-1 | ||
*/ | ||
export const alpha = (c: string, n: number) => (t: Theme) => P.rgba(g(t, c), n) | ||
|
||
/** | ||
* Mix two colors by a specific ratio | ||
*/ | ||
export const mix = (a: string, b: string, n = 0.5) => (t: Theme) => | ||
P.mix(n, g(t, a), g(t, b)) | ||
|
||
/** | ||
* Get the complement of a color | ||
*/ | ||
export const complement = (c: string) => (t: Theme) => P.complement(g(t, c)) | ||
|
||
/** | ||
* Get the inverted color | ||
*/ | ||
export const invert = (c: string) => (t: Theme) => P.invert(g(t, c)) | ||
|
||
/** | ||
* Desaturate the color to grayscale | ||
*/ | ||
export const grayscale = (c: string) => desaturate(c, 1) |
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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
|
||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"moduleResolution": "node" | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts"] | ||
} |
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
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.
Did you run into issues without that explicit
include
?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, tests get built.
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.
Makes sense! Might want to add that to other files in a follow-up PR then
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.
Since this is a monorepo, we could add
tsconfig.json
to the root with all base compiler options (likemoduleResolution node
and noresolveJsonModule
) and then use"extends"
to inherit them. The tsconfig in root would be useful when you open the entire repo in an IDE.I'm not sure for 100%, but I think "include" is inherited literally (relative to the new config, not to the parent), so most tsconfigs in packages could look like
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.
Yes we should totally do this! 👍