A tiny library for writing native css code in JavaScript.
VXV is powered by stylis, a fast css preprocessor.
- Tiny: VXV does not bloat you bundle
- Powered by tagged template literals
- Namespaced: VXV automatically namespaces your css
- Modular: Import css from js files
- Isomorphic: VXV works in node and in browsers, this is great for server side rendering
- Just CSS: VXV does not force you to learn anything new, it's just good old css.
$ 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);
You can use plain old JavaScript variables for dynamic styles. You could even build mixins using JavaScript functions.
const vxv = require('vxv');
const xou = require('xou');
const color = 'blue';
const styles = vxv`
font-family: sans-serif;
& h1 {
color: ${ color };
}
`;
const element = xou`<div class="${ styles }">
<h1>I am blue</h1>
</div>`;
Subelements have to be suffixed by an &
.
const vxv = require('vxv');
vxv`
& p {
text-align: center;
&.red {
color: red;
}
}
`;
Global elements have to be tagged by the global
statement.
const vxv = require('vxv');
vxv`
:global(body) {
background: red;
}
`;
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.
This is a monorepo, which means that there are multiple node modules in a single git repository, all the modules are in packages/
. Monorepos are used by many other oss projects including babel, react and meteor - Learn why.
MIT Β© Tobias Herber