Code Monkey home page Code Monkey logo

fela's Introduction

Fela

Fela is a fast and modular library to handle styling in JavaScript.
It is dynamic by design and renders your styles depending on your application state.

It generates CSS and therefore supports all common CSS features such as media queries, pseudo classes, keyframes and font-faces. It also renders on server-side with ease and ships with a powerful plugin API adding e.g. automatic vendor prefixing or fallback value support.

Fela can be used with React or with any other view library. It even supports React Native.

TravisCI Test Coverage npm downloads gzipped size npm version Gitter

Try it on JSFiddle!

Installation

npm i --save fela

Assuming you are using npm as your package manager you can npm install all packages.
Otherwise we also provide UMD builds for each package within the dist folder. You can easily use them via unpkg.

<!-- Fela (Development): Unminified version including all warnings -->
<script src="https://unpkg.com/[email protected]/dist/fela.js"></script>
<!-- Fela (Production): Minified version -->
<script src="https://unpkg.com/[email protected]/dist/fela.min.js"></script>

Features

  • Dynamic styling
  • Universal rendering
  • Dead code elimination
  • High performance
  • Minimal CSS output
  • Framework-agnostic
  • Pseudo classes & Media queries
  • Child & Attribute selectors
  • Vendor prefixing
  • Component theming
  • Many useful plugins
  • Local namespace

The Gist

Fela is all about rendering styles, especially so called rules. A universal renderer will help us to render styles of all kind. Once rendered into a DOM node, a change listener will subscribe to changes and automatically add new rules.
The following example illustrates the key parts of Fela though it only shows the very basics.

import { createRenderer } from 'fela'
import { render } from 'fela-dom'

// rules are just plain functions of props
// returning a valid object of style declarations
const rule = props => ({
  fontSize: props.fontSize + 'px',
  marginTop: props.margin ? '15px' : 0,
  color: 'red',
  lineHeight: 1.4,
  ':hover': {
    color: 'blue',
    fontSize: props.fontSize + 2 + 'px'
  },
  // nest media queries and pseudo classes
  // inside the style object
  '@media (min-height: 300px)': {
    backgroundColor: 'gray',
    ':hover': {
      color: 'black'
    }
  }
})

// creates a new renderer to render styles
const renderer = createRenderer()

// rendering the rule returns a className reference
// which can be attached to any element
const className = renderer.renderRule(rule, { fontSize: 12 })

// it uses atomic css design to reuse styles
// on declaration base and to keep the markup minimal
console.log(className) // => a b c d e f h

// renders all styles into the DOM
render(renderer, mountNode)

Documentation

Posts

Examples

Community

  • Aesthetic - React style and theme layer with Fela support
  • cf-ui - Cloudflare UI Framework
  • Este - Starter kit for universal full–fledged React apps build with Fela
  • Tel Aviv - React Universal Rendering

Packages

This repository is made of several separate packages including the core package. For convenience sake, we keep the package versions in sync. Therefore every package gets updated along with the core package, even if nothing changed within a particular package.

The following list shows a quick overview of all existing packages.

 Package  Dependencies Downloads
 fela   npm downloads
 fela-dom   npm downloads
 fela-native   npm downloads
Bindings
 react-fela   npm downloads
 preact-fela   npm downloads
 inferno-fela   npm downloads
Tools
 fela-tools   npm downloads
Plugins
 fela-plugin-custom-property   npm downloads
 fela-plugin-dynamic-prefixer   npm downloads
 fela-plugin-extend   npm downloads
 fela-plugin-fallback-value   npm downloads
 fela-plugin-friendly-pseudo-class   npm downloads
 fela-plugin-isolation   npm downloads
 fela-plugin-logger   npm downloads
 fela-plugin-lvha   npm downloads
 fela-plugin-named-media-query   npm downloads
 fela-plugin-placeholder-prefixer   npm downloads
 fela-plugin-prefixer   npm downloads
 fela-plugin-remove-undefined   npm downloads
 fela-plugin-unit   npm downloads
 fela-plugin-validator   npm downloads
 Plugin presets    
 fela-preset-dev   npm downloads
 fela-preset-web   npm downloads
Enhancers
 fela-beautifier   npm downloads
 fela-font-renderer   npm downloads
 fela-layout-debugger   npm downloads
 fela-logger   npm downloads
 fela-monolithic   npm downloads
 fela-perf   npm downloads
 fela-statistics   npm downloads

Support

Join us on Gitter. We highly appreciate any contribution.
We also love to get feedback.

Who's using Fela?

License

Fela is licensed under the MIT License.
Documentation is licensed under Creative Common License.
Created with ♥ by @rofrischmann and all the great contributors.

fela's People

Contributors

alex-wilmer avatar balupton avatar benoneal avatar brian-gaffney avatar craga89 avatar dustin-h avatar electerious avatar fongandrew avatar gitter-badger avatar hansolsong avatar jakecoxon avatar janmarsicek avatar johanneslumpe avatar jrobber avatar milesj avatar npmcdn-to-unpkg-bot avatar pavelpz avatar rileyjshaw avatar rossolson avatar sejoker avatar steida avatar tajo avatar theultdev avatar tiagojsalmeida avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.