-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hypostyle v2): update hypostyle to v2
BREAKING CHANGE: customization now requires user to pass an entire hypostyle instance and interact with hypostyle directly, otherwise API is pretty similar
- Loading branch information
1 parent
7c59494
commit e846567
Showing
4 changed files
with
95 additions
and
186 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -1,117 +1,71 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
const { h } = require('hyposcript') | ||
const { Box, configure, flush, injectGlobal } = require('../') | ||
const { hypostyle } = require('hypostyle') | ||
const presets = require('hypostyle/presets') | ||
|
||
const { Box, configure } = require('../') | ||
|
||
module.exports = (test, assert) => { | ||
test('no styles', () => { | ||
const html = <Box /> | ||
assert(/class=""/.test(html)) | ||
}) | ||
|
||
test('base', () => { | ||
const html = <Box o={1} style={{ background: 'blue' }} /> | ||
const css = flush() | ||
const hypo = hypostyle() | ||
|
||
assert(/order:1/.test(css)) | ||
assert(/style.+background/.test(html)) | ||
}) | ||
|
||
test('configure custom tokens', () => { | ||
configure({ | ||
tokens: { | ||
color: { | ||
r: 'red' // custom value | ||
} | ||
} | ||
}) | ||
;<div> | ||
<Box c='blue' /> | ||
<Box c='r' /> | ||
</div> | ||
configure(hypo) | ||
|
||
const css = flush() | ||
const html = <Box /> | ||
|
||
assert(/color:blue/.test(css)) | ||
assert(/color:red/.test(css)) | ||
assert(/class=""/.test(html)) | ||
}) | ||
|
||
test('macros', () => { | ||
configure({ | ||
macros: { | ||
short: { | ||
color: '#ff4567' | ||
} | ||
} | ||
}) | ||
;<Box f short /> | ||
|
||
const css = flush() | ||
|
||
assert(/display:flex/.test(css)) | ||
assert(/color:#ff4567/.test(css)) | ||
}) | ||
test('base, pick', () => { | ||
const hypo = hypostyle(presets) | ||
|
||
test('variants', () => { | ||
configure({ | ||
variants: { | ||
type: { | ||
primary: { | ||
color: '#ff4567' | ||
} | ||
} | ||
} | ||
}) | ||
;<Box type='primary' /> | ||
configure(hypo) | ||
|
||
const css = flush() | ||
const html = <Box o={1} style={{ background: 'blue' }} /> | ||
const sheet = hypo.flush() | ||
|
||
assert(/color:#ff4567/.test(css)) | ||
assert(/order:1/.test(sheet)) | ||
assert(/style.+background/.test(html)) | ||
}) | ||
|
||
test('with as', () => { | ||
const html = <Box as='img' src='' /> | ||
|
||
assert(/img.+src/.test(html)) | ||
}) | ||
|
||
test('css', () => { | ||
;<Box css={{ c: 'blue' }} /> | ||
|
||
const css = flush() | ||
assert(/color:blue/.test(css)) | ||
}) | ||
|
||
test('css with media query', () => { | ||
;<Box css={{ maxWidth: [1, 1 / 2, 1 / 3] }} /> | ||
const hypo = hypostyle(presets) | ||
|
||
const css = flush() | ||
assert(/@media(.|\n)+max-width:33.33/.test(css)) | ||
}) | ||
configure(hypo) | ||
|
||
test('css as fn', () => { | ||
;<Box css={tokens => ({ pt: tokens.space[1] + 'px' })} /> | ||
const html = <Box as='img' src='' /> | ||
|
||
const css = flush() | ||
assert(/padding-top:4px/.test(css)) | ||
assert(/img.+src/.test(html)) | ||
}) | ||
|
||
test('class', () => { | ||
const html = <Box class='foo' w={10} /> | ||
test('className', () => { | ||
const hypo = hypostyle(presets) | ||
|
||
assert(/foo\s/.test(html)) | ||
}) | ||
configure(hypo) | ||
|
||
test('className', () => { | ||
const html = <Box className='foo' w={10} /> | ||
|
||
assert(/foo\s/.test(html)) | ||
}) | ||
|
||
test('injectGlobal', () => { | ||
injectGlobal({ '.global': { c: 'blue' } }) | ||
test('configure', () => { | ||
const hypo = hypostyle({ | ||
...presets, | ||
tokens: { | ||
color: { | ||
b: 'blue' | ||
} | ||
} | ||
}) | ||
|
||
hypo.css(tokens => ({ | ||
color: tokens.color.blue | ||
})) | ||
|
||
const css = flush() | ||
configure(hypo) | ||
;<Box className='foo' c='blue' /> | ||
const sheet = hypo.flush() | ||
|
||
assert(/global(.|\n)+color:blue/.test(css)) | ||
assert(/color:blue/.test(sheet)) | ||
}) | ||
} |