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

fix: sx variant responsive #1273

Merged
merged 3 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## v0.5.0 UNRELEASED

- Fix sx prop variant responsive. Issue: #1030
## v0.5.0-alpha.0 2020-11-20

- BREAKING: Upgrade to Emotion 11, and `csstype` 3. PR #1261
Expand Down
18 changes: 8 additions & 10 deletions packages/css/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,10 @@ 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
}

Expand All @@ -280,19 +279,18 @@ export const css = (args: ThemeUIStyleObject = {}) => (
...('theme' in props ? props.theme : props),
}
let result: CSSObject = {}
const obj = typeof args === 'function' ? args(theme) : args
let obj = typeof args === 'function' ? args(theme) : args
// insert variant props before responsive styles, so they can be merged
if (obj['variant']) {
obj = { ...get(theme, obj['variant']), ...obj }
delete obj['variant'];
}
const styles = responsive(obj)(theme)

for (const key in styles) {
const x = styles[key as keyof typeof styles]
const val = typeof x === 'function' ? x(theme) : x

if (key === 'variant') {
const variant = css(get(theme, val as string))(theme)
result = { ...result, ...variant }
continue
}

if (val && typeof val === 'object') {
// TODO: val can also be an array here. Is this a bug? Can it be reproduced?
result[key] = css(val as ThemeUICSSObject)(theme)
Expand Down