All Projects → raphamorim → Native Css

raphamorim / Native Css

Licence: mit
Convert pure CSS to React Style or javascript literal objects.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Native Css

Division
Simple to use yet powerfull style widgets with syntax inspired by CSS.
Stars: ✭ 262 (-18.63%)
Mutual labels:  style
Semantic Ui Wordpress
This project incorporates Semantic UI into a starter (aka developer) theme for WordPress.
Stars: ✭ 276 (-14.29%)
Mutual labels:  semantic
Ropium
ROPium is a tool that helps you building ROP exploits by finding and chaining gadgets together
Stars: ✭ 288 (-10.56%)
Mutual labels:  semantic
React Magic
A collection of magic animations for react components.
Stars: ✭ 264 (-18.01%)
Mutual labels:  css-animations
Input Range Scss
Styling Cross-Browser Compatible Range Inputs with Sass
Stars: ✭ 272 (-15.53%)
Mutual labels:  style
You Need To Know Css
💄CSS tricks for web developers~
Stars: ✭ 3,777 (+1072.98%)
Mutual labels:  css-animations
C Code Style
Recommended C code style and coding rules for standard C99 or later
Stars: ✭ 252 (-21.74%)
Mutual labels:  style
All About Programming
Everything about programming!!
Stars: ✭ 314 (-2.48%)
Mutual labels:  css-animations
Parser Lib
Collection of parsers written in JavaScript
Stars: ✭ 274 (-14.91%)
Mutual labels:  style
Izmir
Izmir - An image hover mini CSS library
Stars: ✭ 283 (-12.11%)
Mutual labels:  css-animations
Opennars
OpenNARS for Research 3.0+
Stars: ✭ 264 (-18.01%)
Mutual labels:  semantic
Eslint Config Standard With Typescript
An extension of eslint-config-standard, made for TypeScript.
Stars: ✭ 269 (-16.46%)
Mutual labels:  style
Easydialog
通过封装DialogFragment实现的dialog,非自定义view,纯净原生!
Stars: ✭ 280 (-13.04%)
Mutual labels:  style
Focus Beamertheme
Focus: a minimalist presentation theme for LaTeX Beamer.
Stars: ✭ 263 (-18.32%)
Mutual labels:  style
Erfnet pytorch
Pytorch code for semantic segmentation using ERFNet
Stars: ✭ 304 (-5.59%)
Mutual labels:  semantic
Stylist
Define UI styles in a hot-reloadable yaml or json file
Stars: ✭ 260 (-19.25%)
Mutual labels:  style
Html5 Canvas Animation
🚀 3D lines animation with three.js
Stars: ✭ 278 (-13.66%)
Mutual labels:  css-animations
Bcdu Net
BCDU-Net : Medical Image Segmentation
Stars: ✭ 314 (-2.48%)
Mutual labels:  semantic
Rmq
RMQ - RubyMotionQuery
Stars: ✭ 311 (-3.42%)
Mutual labels:  style
Uber go guide cn
Uber Go 语言编码规范中文版. The Uber Go Style Guide .
Stars: ✭ 4,277 (+1228.26%)
Mutual labels:  style

native-css

Convert pure CSS to javascript literal objects or React Style.

NPM Version Build Status

Before Anything!

This tool believes in this semantic for CSS: HTML semantics and front-end architecture

'Cause of this, all ids and inheritance relationships are converted to classes.

Install

Verify if you have node and npm installed.

As CLI
$ npm install -g native-css
As Node Module
$ npm install native-css

CLI Usage

Params: input (required), output (optional)

$ native-css <input> <output>

Example

Input CSS Example:

.taxi {
  background-color: #F8F8F8;
  color: #999;
}

#car {
  color: blue;
}

Convert CSS to React Format

Using:

$ native-css <input> <output> --react

Generate this as output (JS format):

var styles = StyleSheet.create({
  taxi: {
    color: '#999',
    backgroundColor: '#F8F8F8'
  },
  car: {
	color: 'blue';
  }
});

Convert CSS to Literal JS object

Using, but without react flag:

$ native-css <input> <output>

Generate this as output (JS format):

styles: {
  taxi: {
    color: '#999',
    backgroundColor: '#F8F8F8'
  },
  car: {
	color: 'blue';
  }
}

Inherent and Parents

As stated, this tool believes and follows a specific semantic for CSS. Therefore in these cases, exists a change in nomenclature. Example:

Input File (style.css)

.any.element {
  color: red;
}

.parent .child {
  color: orange;
}

.parent  .child2 {
  color: blue;
}

Output File (style.js)

any_element: { 
  color: 'red' 
},
parent__child: { 
  color: 'orange' 
},
parent__child2: { 
  color: 'blue' 
}

Media Queries

Input File (style.css):

@media screen and (min-width: 1020px){
  body .container { 
    width: 1020px !important
  }
}

@media (min-width: 768px){
  body .container {
    width: 748px !important;
    box-sizing: 'all'
  }
}

Output File (style.js):

'@media screen and (min-width:1020px)': { 
  __expression__: 'screen and (min-width:1020px)',
  body__container: { 
    width: '1020px !important' 
  } 
},
'@media (min-width:768px)': { 
  __expression__: '(min-width:768px)',
  body__container: { 
    width: '748px !important',
    boxSizing: 'all'
  } 
}

Module Usage

supported input types: Path, Url, String, Buffer

var nativeCSS = require('native-css'),
	pathToCssFile = 'somePath/file.css';

// Generate JavaScript Object
var cssObject = nativeCSS.convert(pathToCssFile);

url support with async version:

var nativeCSS = require('native-css'),
  URL = 'http://raw.githubusercontent.com/raphamorim/native-css/master/test/fixtures/sample.css';

// Generate JavaScript Object
nativeCSS.convertAsync(URL || Path) // returns Promise
  .then(function(result) {
    // convert/validate data
    // return or throw
  })

webpack usage:

cssobjects-loader

Not supported CSS features

React Style does not support CSS selectors, pseudo-classes and CSS animation. Mostly because we try to avoid implicit behaviour and want the user to make layout decisions inside the render() function.

CSS selectors introduce implicit behaviour by not having a direct link with the elements on which they're applied. Therefore there is no way of knowing what the consequences are, and this easily leads to refactoring issues. Instead you should be using plain JavaScript variables.

Classes with pseudo-classes have a higher precedence then classes with no pseudo-classes, which results in issues if you want to override styling in "higher-level" components. In some cases(:before, after, etc.) a component is easily added, in others (active, focus, hover, etc) plain JavaScript will do the trick. In all, you don't need CSS for this. In some cases though you might want to use pseudo-classes (like styling a scrollbar) - which we do support.

Animations inside CSS also introduce implicit behaviour, as CSS animations are decoupled from logic. By being decoupled, the state of the component is split between the component and the CSS animation. We however believe state should be contained within a component. An example of solving this using JS is React Magician.

Contributing

Don't be shy, send a Pull Request! Here is how:

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

About

License: MIT ® Raphael Amorim

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].