Skip to content

Commit

Permalink
fix: custom media overrides
Browse files Browse the repository at this point in the history
fixes #7
  • Loading branch information
estrattonbailey committed Dec 21, 2021
1 parent d2b4162 commit ba1a813
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
21 changes: 20 additions & 1 deletion lib/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ test('flush', () => {
})

test('injectGlobal', () => {
const { injectGlobal, flush } = hypostyle()
const { injectGlobal, flush } = hypostyle({})
injectGlobal({ html: { color: 'blue' } })
const sheet = flush()
assert.ok(sheet.includes('color:blue'))
Expand Down Expand Up @@ -495,4 +495,23 @@ test('prefix', () => {
assert.equal(/hypo/.test(sheet), true)
})

/**
* @see https://github.com/sure-thing/hypostyle/issues/7
*/
test('issue #7', async () => {
const { style } = hypostyle(defaults)

const styles = style({
color: ['blue', 'red'],
[`@media (min-width: ${defaults.breakpoints[0]})`]: {
background: 'tomato',
},
})

assert.equal(styles, {
color: 'blue',
'@media (min-width: 400px)': { color: 'red', background: 'tomato' },
})
})

test.run()
11 changes: 8 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,14 @@ function style(props: HypostyleObject, theme: Theme): CssLikeObject {

props[prop] = arr
} else {
// continue, nested style object
styles[prop] = style(mixedObject, theme)
continue // continue main loop
/*
* Safely merge in nested prop — there may be duplicate keys, like
* after shorthand expansion or a custom media query block
*/
var nested = {}
nested[prop] = style(mixedObject, theme)
merge(styles, nested)
continue // continue, nested style object
}
}

Expand Down

0 comments on commit ba1a813

Please sign in to comment.