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

(css): Allow injecting UserTheme and typecheck colors against scale #1090

Closed
wants to merge 97 commits into from
Closed
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
77eb36e
(css): Allow injecting UserTheme and typecheck colors against scale
hasparus Jul 26, 2020
2b167e9
(css): typecheck colors scale from the theme
hasparus Jul 26, 2020
7b5f850
(css): Support CSS.Globals alongside scale keys
hasparus Jul 26, 2020
faeeb8b
(css): update older test
hasparus Jul 26, 2020
734a60e
(theme-ui): reexport UserTheme
hasparus Aug 11, 2020
af3f76e
(css): move scales to separate file to colocate them with types
hasparus Aug 11, 2020
f5b18d1
(css): Add ResponsiveStyleTuple<T> interface
hasparus Aug 12, 2020
d28935f
WIP
hasparus Aug 17, 2020
6cef68d
add opacities, space (no comments yet)
nandorojo Sep 30, 2020
3b464be
let overwrite CSS properties supercede alias types
nandorojo Oct 1, 2020
cd0f14f
add remaining scales, make types optional
nandorojo Oct 1, 2020
7be1f96
add borders, sizes
nandorojo Oct 1, 2020
ecd2e0b
exclude array types
nandorojo Oct 1, 2020
1ccc26b
Merge pull request #1 from nandorojo/nandorojo/injection
hasparus Oct 1, 2020
bc3c96c
Update TypeScript to 4.0.3
hasparus Oct 1, 2020
65c179d
Test exact theme scales
hasparus Oct 1, 2020
3222d50
Fix errors-and-inference test
hasparus Oct 1, 2020
679d532
Reexport scales
hasparus Oct 1, 2020
35c87a2
Merge pull request #2 from hasparus/inject-exact-theme-2
hasparus Oct 1, 2020
cb17f20
added border widths, radii
nandorojo Oct 12, 2020
2be06c8
border styles
nandorojo Oct 12, 2020
c79e5d5
add missing border properties
nandorojo Oct 12, 2020
9973caf
fonts
nandorojo Oct 12, 2020
d869762
font weights
nandorojo Oct 12, 2020
b91688f
line heights
nandorojo Oct 12, 2020
f5f037b
add shadows, letter spacings, & optional fields
nandorojo Oct 12, 2020
94b2a4c
z indices
nandorojo Oct 12, 2020
4ef19ec
Add JSDoc comments to scale properties
hasparus Oct 16, 2020
ac8a4b1
Test exact theme scales
hasparus Oct 1, 2020
71fe2f1
Add JSDoc comments to SizesCSSProperties and BordersCSSProperties
hasparus Oct 16, 2020
ad12ae2
Annotate scales
hasparus Oct 16, 2020
30d65d9
Update comment
hasparus Oct 16, 2020
f3813f8
Accept number as fontFamily value in TypographyProps.value
hasparus Oct 16, 2020
bd15798
Add DottedPaths and ts-toolbelt
hasparus Nov 23, 2020
37dd31a
Merge branch 'master' into inject-exact-theme
hasparus Nov 23, 2020
e758c29
feat(css): support deep scale paths
hasparus Nov 23, 2020
3ee1a84
ref(css): clean up OverwritesCSSProperties
hasparus Nov 23, 2020
a6e6d5d
fix(css): add missing builtins values to scales
hasparus Nov 24, 2020
83283c2
wip: push scales work in progress in case my laptop explodes
hasparus Nov 29, 2020
7f88e52
chore: move each scale to separate file
hasparus Nov 30, 2020
63699f7
fix: rework borders scale types
hasparus Nov 30, 2020
806e2da
fix: change "as any" to "as ThemeUICSSObject"
hasparus Nov 30, 2020
17fa683
ref: remove todo comment
hasparus Nov 30, 2020
10a010e
feat: export scale value types in Scales namespace
hasparus Nov 30, 2020
083f994
feat: rename Theme to BaseTheme and FinalTheme to Theme
hasparus Nov 30, 2020
46688c3
feat: do not pass false, undefined and null to Emotion
hasparus Nov 30, 2020
a82ba6c
Merge branch 'master' into inject-exact-theme
hasparus Nov 30, 2020
6603ab4
wip: change allowStrings to noStrings
hasparus Dec 1, 2020
eabdae8
Merge branch 'master' into inject-exact-theme
hasparus Dec 1, 2020
3246314
Merge branch 'master' into inject-exact-theme
hasparus Dec 2, 2020
b84aa48
Bump ts-snippet to 5.0.1
hasparus Dec 2, 2020
f03a104
Allow holes in scales -- accept null and undefined as scale value
hasparus Dec 2, 2020
acc904e
Export makeTheme from @theme-ui/css
hasparus Dec 2, 2020
f22c7f4
Add more type-level tests for exact themes
hasparus Dec 2, 2020
74b1dd3
Import CSSObject from @emotion/react
hasparus Dec 3, 2020
6f1a6bf
Move multiples and aliases to separate files
hasparus Dec 3, 2020
a4cf32b
Always allow numbers
hasparus Dec 3, 2020
512bcdc
Colocate multiples with scales
hasparus Dec 3, 2020
5bc9b11
Add missing number to sizes scale
hasparus Dec 3, 2020
b915028
Update typography snapshots ('border: 0' to 'border: none')
hasparus Dec 3, 2020
544c270
GitHub Actions, why aren't you running?
hasparus Dec 3, 2020
7031547
This is why DevOps folks get paid so much
hasparus Dec 3, 2020
902e626
fix(editor): Add null | false to accepted props
hasparus Dec 3, 2020
c0e966e
Update TypeScript to next, because our getTypeFacts bug was fixed 8 d…
hasparus Dec 3, 2020
337efd1
Microbundle, why?
hasparus Dec 3, 2020
bb5aa05
fix: workflow/ci.yml
hasparus Dec 7, 2020
a6ede7b
Merge branch 'develop' into inject-exact-theme
hasparus Dec 22, 2020
d34e0dc
chore: update deps
hasparus Dec 23, 2020
6f94730
Merge branch 'develop' into inject-exact-theme
hasparus Dec 23, 2020
72ba710
Merge branch 'develop' into inject-exact-theme
hasparus Feb 25, 2021
4477a1f
chore: run husky install
hasparus Feb 25, 2021
db67443
fix(css): update options.ts to use BaseTheme
hasparus Feb 25, 2021
4c1747c
fix(css): fix merge conflict induced type errors
hasparus Feb 28, 2021
e86faba
fix(css): add transitions scale missing from merge
hasparus Feb 28, 2021
6328eb6
test(css): adapt tests to match new types
hasparus Feb 28, 2021
d3696a9
chore(tooling): install auto
hasparus Feb 28, 2021
e7b2560
chore: install auto
hasparus Mar 1, 2021
e4a8f01
docs: add all-contributors
hasparus Mar 1, 2021
8ce5809
docs: add @jxnblk as a contributor
hasparus Mar 1, 2021
5d3cea5
docs: add contributors
hasparus Mar 1, 2021
be693ac
chore: add all-contributors:add script
hasparus Mar 1, 2021
e20fb66
chore: add @auto-it/all-contributors plugin
hasparus Mar 1, 2021
6f63f36
chore: add @auto-it/conventional-commits plugin
hasparus Mar 1, 2021
1ecd5ec
chore: add @auto-it/first-time-contributor plugin
hasparus Mar 1, 2021
71c0226
chore: add @auto-it/released plugin
hasparus Mar 1, 2021
9b55d9a
chore: configure auto prerelease branches
hasparus Mar 1, 2021
9d1a251
Merge branch 'chores' into inject-exact-theme
hasparus Mar 1, 2021
c6760d1
chore: publish with deps on exact versions
hasparus Mar 1, 2021
823bff1
chore: add verifyAccess: false to omit 2FA on CI
hasparus Mar 1, 2021
9dbb0de
ci: run release job on GitHub Actions
hasparus Mar 1, 2021
9b02eb8
Merge branch 'chores' into inject-exact-theme
hasparus Mar 1, 2021
0ef947c
Merge branch 'develop' into inject-exact-theme
hasparus Mar 1, 2021
c5a716a
Merge branch 'develop' into inject-exact-theme
hasparus Mar 1, 2021
df2c70a
chore: canary version
hasparus Mar 1, 2021
410ac76
Merge branch 'chores' into inject-exact-theme
hasparus Mar 1, 2021
df21470
wip(css): leave todo comment
hasparus Mar 16, 2021
67fa03d
Merge branch 'develop' into inject-exact-theme
hasparus May 22, 2021
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
- `SxStyleProp`, an alias for `ThemeUIStyleObject` removed. Use `ThemeUIStyleObject` instead.
- Fix: Add `sx` props types to all props accepting `className`. PR #1308
- Fix WithPoorAsProp to work with ComponentProps utility type. PR #1308
- Don't pass `false`, `undefined` and `null` to Emotion. Allow them as style values in TypeScript. PR #1090
- Allow to inject user's exact theme type. PR #1090
- Add `theme.options.strictMode` object with configuration for Theme UI strict mode.
- TODO short excerpt from the docs on how to use it

## v0.5.0-alpha.2 2020-11-30

Expand Down
4 changes: 1 addition & 3 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
"version": "0.6.0-alpha.1",
"npmClient": "yarn",
"useWorkspaces": true,
"packages": [
"packages/*"
]
"packages": ["packages/*"]
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"prettier": "^2.2.0",
"react-test-renderer": "^16.8.6",
"ts-jest": "^26.4.4",
"typescript": "^4"
"typescript": "^4.1.2",
"ts-snippet": "^5.0.1"
},
"jest": {
"preset": "ts-jest/presets/js-with-babel",
Expand Down Expand Up @@ -116,5 +117,8 @@
"hooks": {
"pre-commit": "lint-staged"
}
},
"resolutions": {
"typescript": "4.1.2"
}
}
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export type {
ThemeUIExtendedCSSProperties,
ThemeUIStyleObject,
VariantProperty,
BaseTheme,
UserTheme,
} from '@theme-ui/css'
export * from './types'

Expand Down
3 changes: 2 additions & 1 deletion packages/css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
},
"dependencies": {
"@emotion/react": "^11.1.1",
"csstype": "^3.0.5"
"csstype": "^3.0.5",
"ts-toolbelt": "^8.0.7"
},
"gitHead": "87e9ebb0cc66d8a5e1fcde7bb60f2077266aa437"
}
3 changes: 3 additions & 0 deletions packages/css/src/exact-theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { BaseTheme } from './types'

export const makeTheme = <T extends BaseTheme>(t: T) => t
160 changes: 19 additions & 141 deletions packages/css/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import {
CSSObject,
ThemeUIStyleObject,
ThemeDerivedStyles,
Theme,
ThemeUICSSObject,
Theme,
} from './types'
import { scales, Scales } from './scales'

export { scales } from './scales'
export type { Scales } from './scales'

export * from './types'

Expand Down Expand Up @@ -58,139 +62,6 @@ export const multiples = {
size: ['width', 'height'],
}

export const scales = {
color: 'colors',
backgroundColor: 'colors',
borderColor: 'colors',
caretColor: 'colors',
columnRuleColor: 'colors',
opacity: 'opacities',
transition: 'transitions',
margin: 'space',
marginTop: 'space',
marginRight: 'space',
marginBottom: 'space',
marginLeft: 'space',
marginX: 'space',
marginY: 'space',
marginBlock: 'space',
marginBlockEnd: 'space',
marginBlockStart: 'space',
marginInline: 'space',
marginInlineEnd: 'space',
marginInlineStart: 'space',
padding: 'space',
paddingTop: 'space',
paddingRight: 'space',
paddingBottom: 'space',
paddingLeft: 'space',
paddingX: 'space',
paddingY: 'space',
paddingBlock: 'space',
paddingBlockEnd: 'space',
paddingBlockStart: 'space',
paddingInline: 'space',
paddingInlineEnd: 'space',
paddingInlineStart: 'space',
scrollPadding: 'space',
scrollPaddingTop: 'space',
scrollPaddingRight: 'space',
scrollPaddingBottom: 'space',
scrollPaddingLeft: 'space',
scrollPaddingX: 'space',
scrollPaddingY: 'space',
inset: 'space',
insetBlock: 'space',
insetBlockEnd: 'space',
insetBlockStart: 'space',
insetInline: 'space',
insetInlineEnd: 'space',
insetInlineStart: 'space',
top: 'space',
right: 'space',
bottom: 'space',
left: 'space',
gridGap: 'space',
gridColumnGap: 'space',
gridRowGap: 'space',
gap: 'space',
columnGap: 'space',
rowGap: 'space',
fontFamily: 'fonts',
fontSize: 'fontSizes',
fontWeight: 'fontWeights',
lineHeight: 'lineHeights',
letterSpacing: 'letterSpacings',
border: 'borders',
borderTop: 'borders',
borderRight: 'borders',
borderBottom: 'borders',
borderLeft: 'borders',
borderWidth: 'borderWidths',
borderStyle: 'borderStyles',
borderRadius: 'radii',
borderTopRightRadius: 'radii',
borderTopLeftRadius: 'radii',
borderBottomRightRadius: 'radii',
borderBottomLeftRadius: 'radii',
borderTopWidth: 'borderWidths',
borderTopColor: 'colors',
borderTopStyle: 'borderStyles',
borderBottomWidth: 'borderWidths',
borderBottomColor: 'colors',
borderBottomStyle: 'borderStyles',
borderLeftWidth: 'borderWidths',
borderLeftColor: 'colors',
borderLeftStyle: 'borderStyles',
borderRightWidth: 'borderWidths',
borderRightColor: 'colors',
borderRightStyle: 'borderStyles',
borderBlock: 'borders',
borderBlockEnd: 'borders',
borderBlockEndStyle: 'borderStyles',
borderBlockEndWidth: 'borderWidths',
borderBlockStart: 'borders',
borderBlockStartStyle: 'borderStyles',
borderBlockStartWidth: 'borderWidths',
borderBlockStyle: 'borderStyles',
borderBlockWidth: 'borderWidths',
borderEndEndRadius: 'radii',
borderEndStartRadius: 'radii',
borderInline: 'borders',
borderInlineEnd: 'borders',
borderInlineEndStyle: 'borderStyles',
borderInlineEndWidth: 'borderWidths',
borderInlineStart: 'borders',
borderInlineStartStyle: 'borderStyles',
borderInlineStartWidth: 'borderWidths',
borderInlineStyle: 'borderStyles',
borderInlineWidth: 'borderWidths',
borderStartEndRadius: 'radii',
borderStartStartRadius: 'radii',
outlineColor: 'colors',
boxShadow: 'shadows',
textShadow: 'shadows',
zIndex: 'zIndices',
width: 'sizes',
minWidth: 'sizes',
maxWidth: 'sizes',
height: 'sizes',
minHeight: 'sizes',
maxHeight: 'sizes',
flexBasis: 'sizes',
size: 'sizes',
blockSize: 'sizes',
inlineSize: 'sizes',
maxBlockSize: 'sizes',
maxInlineSize: 'sizes',
minBlockSize: 'sizes',
minInlineSize: 'sizes',
// svg
fill: 'colors',
stroke: 'colors',
} as const
type Scales = typeof scales

const positiveOrNegative = (scale: object, value: string | number) => {
if (typeof value !== 'number' || value >= 0) {
if (typeof value === 'string' && value.startsWith('-')) {
Expand Down Expand Up @@ -234,7 +105,7 @@ const transforms = [

const responsive = (
styles: Exclude<ThemeUIStyleObject, ThemeDerivedStyles>
) => (theme?: Theme) => {
) => (theme: Theme) => {
const next: Exclude<ThemeUIStyleObject, ThemeDerivedStyles> = {}
const breakpoints =
(theme && (theme.breakpoints as string[])) || defaultBreakpoints
Expand All @@ -247,7 +118,7 @@ const responsive = (
const key = k as keyof typeof styles
let value = styles[key]
if (typeof value === 'function') {
value = value(theme || {})
value = value(theme)
}

if (value == null) continue
Expand All @@ -262,22 +133,22 @@ const responsive = (
continue
}
next[media] = next[media] || {}
if (value[i] == null) continue;
(next[media] as Record<string, any>)[key] = value[i]
if (value[i] == null) continue
;(next[media] as Record<string, any>)[key] = value[i]
}
}
return next
}

type CssPropsArgument = { theme: Theme } | Theme
type CssPropsArgument = { theme?: Theme } | Theme

export const css = (args: ThemeUIStyleObject = {}) => (
props: CssPropsArgument = {}
): CSSObject => {
const theme: Theme = {
const theme = {
...defaultTheme,
...('theme' in props ? props.theme : props),
}
} as Theme
let obj = typeof args === 'function' ? args(theme) : args
let result: CSSObject = {}

Expand All @@ -298,10 +169,17 @@ export const css = (args: ThemeUIStyleObject = {}) => (
} else {
result = obj as CSSObject ;
}

const styles = responsive(result as ThemeUICSSObject)(theme)
result = {}

for (const key in styles) {
const x = styles[key as keyof typeof styles]

if (x === false || x == null) {
continue
}

const val = typeof x === 'function' ? x(theme) : x

if (val && typeof val === 'object') {
Expand Down
81 changes: 81 additions & 0 deletions packages/css/src/scales/borderStyles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import * as CSS from 'csstype'

import { Theme } from '../types'

import { ScaleProperty } from './scales-utility-types'

export const borderStyles: Record<
keyof BorderStylesCSSProperties,
'borderStyles'
> = {
borderStyle: 'borderStyles',
borderTopStyle: 'borderStyles',
borderBottomStyle: 'borderStyles',
borderLeftStyle: 'borderStyles',
borderRightStyle: 'borderStyles',
borderBlockEndStyle: 'borderStyles',
borderBlockStartStyle: 'borderStyles',
borderBlockStyle: 'borderStyles',
borderInlineEndStyle: 'borderStyles',
borderInlineStartStyle: 'borderStyles',
borderInlineStyle: 'borderStyles',
}
export type BorderStyle = ScaleProperty<Theme['borderStyles']>

export interface BorderStylesCSSProperties {
borderStyle?: BorderStyle | CSS.Property.BorderStyle
/**
* The **`border-top-style`** CSS property sets the line style of an element's top `border`.
*
* **Initial value**: `none`
*
* | Chrome | Firefox | Safari | Edge | IE |
* | :----: | :-----: | :----: | :----: | :-----: |
* | **1** | **1** | **1** | **12** | **5.5** |
*
* @see https://developer.mozilla.org/docs/Web/CSS/border-top-style
*/
borderTopStyle?: BorderStyle
/**
* The **`border-bottom-style`** CSS property sets the line style of an element's bottom `border`.
*
* **Initial value**: `none`
*
* | Chrome | Firefox | Safari | Edge | IE |
* | :----: | :-----: | :----: | :----: | :-----: |
* | **1** | **1** | **1** | **12** | **5.5** |
*
* @see https://developer.mozilla.org/docs/Web/CSS/border-bottom-style
*/
borderBottomStyle?: BorderStyle | CSS.Property.BorderBottomStyle
/**
* The **`border-left-style`** CSS property sets the line style of an element's left `border`.
*
* **Initial value**: `none`
*
* | Chrome | Firefox | Safari | Edge | IE |
* | :----: | :-----: | :----: | :----: | :-----: |
* | **1** | **1** | **1** | **12** | **5.5** |
*
* @see https://developer.mozilla.org/docs/Web/CSS/border-left-style
*/
borderLeftStyle?: BorderStyle | CSS.Property.BorderLeftStyle
/**
* The **`border-right-style`** CSS property sets the line style of an element's right `border`.
*
* **Initial value**: `none`
*
* | Chrome | Firefox | Safari | Edge | IE |
* | :----: | :-----: | :----: | :----: | :-----: |
* | **1** | **1** | **1** | **12** | **5.5** |
*
* @see https://developer.mozilla.org/docs/Web/CSS/border-right-style
*/
borderRightStyle?: BorderStyle | CSS.Property.BorderRightStyle
borderBlockEndStyle?: BorderStyle | CSS.Property.BorderBlockEndStyle
borderBlockStartStyle?: BorderStyle | CSS.Property.BorderBlockStartStyle
borderBlockStyle?: BorderStyle | CSS.Property.BorderBlockStyle
borderInlineEndStyle?: BorderStyle | CSS.Property.BorderInlineEndStyle
borderInlineStartStyle?: BorderStyle | CSS.Property.BorderInlineStartStyle
borderInlineStyle?: BorderStyle | CSS.Property.BorderInlineStyle
}
Loading