Skip to content
/ vxv Public

πŸ‘“πŸ’„ A tiny library for writing native css code in JavaScript.

License

Notifications You must be signed in to change notification settings

herber/vxv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Build Status vxv

A tiny library for writing native css code in JavaScript.
VXV is powered by stylis, a fast css preprocessor.

Features

  • 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.

Install

$ npm install vxv

Usage

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);

Dynamic styles

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>`;

Styling subelements

Subelements have to be suffixed by an &.

const vxv = require('vxv');

vxv`
& p {
  text-align: center;

  &.red {
    color: red;
  }
}
`;

Styling global elements

Global elements have to be tagged by the global statement.

const vxv = require('vxv');

vxv`
:global(body) {
  background: red;
}
`;

Serverside rendering

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.

Monorepo

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.

Packages

License

MIT Β© Tobias Herber

About

πŸ‘“πŸ’„ A tiny library for writing native css code in JavaScript.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published