A tiny library for writing native css code in JavaScript.
VXV is powered by stylis, a fast css preprocessor.
$ npm install vxv
VXV supports standard css(with some extras). It returns a simple class name that you can use to access the styles.
const vxv = require('vxv');
const xou = require('xou');
const styles = vxv`
font-family: sans-serif;
// Nested elements have to be tagged by an &.
& h1 {
color: red;
}
& p {
color: blue;
}
`;
const element = xou`<div class="${ styles }">
<h1>I am red.</h1>
<p>I am blue.</p>
</div>`;
document.body.appendChild(element);
For serverside rendering you need the vxv-server module.
VXV-Server processes your styles just like VXV does including hash prefixing. server()
will return a simple string containing all your styles - you can now save those styles somewhere or send them directly to the user.
const vxv = require('vxv');
const server = require('vxv-server');
const mainStyles = vxv`
h1 { font-size: 2rem }
h2 { font-size: 1.5rem }
h3 { font-size: 1.25rem }
h4 { font-size: 1rem }
h5 { font-size: .875rem }
h6 { font-size: .75rem }
`;
const otherStyles = vxv`
p, dl, ol, ul, pre, blockquote {
margin-top: 1em;
margin-bottom: 1em;
}
`;
server();
// => All styles even those used in other files -
// => prefixed and concatenated into single string,
// => that you can use for serverside rendering.