-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
4,404 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"presets": ["env"], | ||
"plugins": [ | ||
["transform-react-jsx", { "pragma":"h" }], | ||
"transform-object-rest-spread" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
[*] | ||
# Change these settings to your own preference | ||
indent_style = space | ||
indent_size = 2 | ||
# We recommend you to keep these unchanged | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/dist | ||
/node_modules | ||
/npm-debug.log | ||
.DS_Store | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
language: node_js | ||
node_js: | ||
- 6 | ||
cache: | ||
directories: | ||
- node_modules | ||
notifications: | ||
email: false | ||
script: | ||
- yarn run test | ||
after_success: | ||
- npm install -g codecov | ||
- codecov | ||
branches: | ||
only: | ||
- master |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# preact-glam | ||
|
||
> A tiny glamorous implementation for preact | ||
[![Travis](https://img.shields.io/travis/vesparny/preact-glam.svg)](https://travis-ci.org/vesparny/preact-glam) | ||
[![David](https://img.shields.io/david/vesparny/preact-glam.svg)](https://david-dm.org/vesparny/preact-glam) | ||
[![npm](https://img.shields.io/npm/v/preact-glam.svg)](https://www.npmjs.com/package/preact-glam) | ||
[![npm](https://img.shields.io/npm/dm/preact-glam.svg)](https://npm-stat.com/charts.html?package=preact-glam&from=2017-04-01) | ||
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) | ||
[![MIT License](https://img.shields.io/npm/l/preact-glam.svg?style=flat-square)](https://github.com/vesparny/preact-glam/blob/master/LICENSE) | ||
|
||
## Install | ||
|
||
This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed. | ||
|
||
```sh | ||
$ yarn add preact-glam | ||
``` | ||
|
||
Then with a module bundler like [rollup](http://rollupjs.org/) or [webpack](https://webpack.js.org/), use as you would anything else: | ||
|
||
```javascript | ||
// using ES6 modules | ||
import glam from 'preact-glam' | ||
|
||
// using CommonJS modules | ||
var glam = require('preact-glam') | ||
``` | ||
|
||
The [UMD](https://github.com/umdjs/umd) build is also available on [unpkg](https://unpkg.com): | ||
|
||
```html | ||
<script src="https://unpkg.com/preact-glam/dist/preact-glam.umd.js"></script> | ||
``` | ||
|
||
You can find the library on `window.preactGlam`. | ||
|
||
## Usage | ||
|
||
Please refer to [glamorous-tiny](https://github.com/paypal/glamorous#size) | ||
|
||
## Tests | ||
|
||
```sh | ||
$ yarn run test | ||
``` | ||
|
||
|
||
[MIT License](LICENSE.md) © [Alessandro Arnodo](https://alessandro.arnodo.net/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
{ | ||
"name": "preact-glam", | ||
"amdName": "preactGlam", | ||
"version": "0.0.0", | ||
"description": "A tiny glamorous implementation for preact", | ||
"jsnext:main": "dist/preact-glam.es.js", | ||
"module": "dist/preact-glam.es.js", | ||
"main": "dist/preact-glam.cjs.js", | ||
"umd:main": "dist/preact-glam.umd.js", | ||
"scripts": { | ||
"precommit": "lint-staged", | ||
"bump": "standard-version", | ||
"testonly": "jest --coverage", | ||
"lint": "standard", | ||
"test": "npm run lint && npm run testonly", | ||
"build": "npm-run-all test clean rollup rollup:min size", | ||
"clean": "rimraf dist", | ||
"rollup": "rollup -c", | ||
"rollup:min": "cross-env MINIFY=minify rollup -c", | ||
"size": "echo \"Gzipped Size: $(cat dist/preact-glam.umd.min.js | gzip-size)\"", | ||
"release": "npm run build && npm run bump && git push --follow-tags origin master && npm publish" | ||
}, | ||
"repository": "vesparny/preact-glam", | ||
"keywords": [ | ||
"preact", | ||
"glamor", | ||
"glamorous", | ||
"glam", | ||
"css", | ||
"style" | ||
], | ||
"homepage": "https://github.com/vesparny/preact-glam", | ||
"authors": [ | ||
"Alessandro Arnodo <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"files": [ | ||
"dist", | ||
"src", | ||
"test" | ||
], | ||
"devDependencies": { | ||
"babel-core": "^6.24.1", | ||
"babel-eslint": "^7.2.2", | ||
"babel-plugin-transform-object-rest-spread": "^6.23.0", | ||
"babel-plugin-transform-react-jsx": "^6.24.1", | ||
"cross-env": "^4.0.0", | ||
"glamor": "^2.20.24", | ||
"gzip-size-cli": "^2.0.0", | ||
"husky": "^0.13.3", | ||
"jest": "^19.0.2", | ||
"lint-staged": "^3.4.0", | ||
"npm-run-all": "^4.0.2", | ||
"preact": "^8.1.0", | ||
"prettier": "^1.2.2", | ||
"rimraf": "^2.5.2", | ||
"rollup": "^0.41.4", | ||
"rollup-plugin-babel": "^2.7.1", | ||
"rollup-plugin-uglify": "^1.0.1", | ||
"standard": "^10.0.2", | ||
"standard-version": "^4.0.0" | ||
}, | ||
"dependencies": { | ||
"babel-preset-env": "^1.4.0" | ||
}, | ||
"peerDependencies": { | ||
"glamor": "^2.20.24", | ||
"preact": "^8.1.0" | ||
}, | ||
"jest": { | ||
"roots": [ | ||
"src" | ||
] | ||
}, | ||
"standard": { | ||
"parser": "babel-eslint", | ||
"globals": [ | ||
"jest", | ||
"expect", | ||
"it", | ||
"test", | ||
"describe" | ||
] | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"prettier --write --semi false", | ||
"standard --fix", | ||
"git add" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import babel from 'rollup-plugin-babel' | ||
import uglify from 'rollup-plugin-uglify' | ||
|
||
const minify = !!process.env.MINIFY | ||
|
||
export default { | ||
entry: 'src/index.js', | ||
moduleName: 'preactGlam', | ||
useStrict: false, | ||
sourceMap: minify, | ||
external: ['preact', 'glamor'], | ||
globals: { | ||
preact: 'preact', | ||
glamor: 'Glamor' | ||
}, | ||
plugins: [ | ||
babel({ | ||
exclude: 'node_modules/**', | ||
babelrc: false, | ||
presets: [ | ||
[ | ||
'env', | ||
{ | ||
modules: false | ||
} | ||
] | ||
], | ||
plugins: [ | ||
[ | ||
'transform-react-jsx', | ||
{ | ||
pragma: 'h' | ||
} | ||
], | ||
'transform-object-rest-spread' | ||
] | ||
}), | ||
minify ? uglify() : {} | ||
], | ||
targets: minify | ||
? [ | ||
{ | ||
dest: 'dist/preact-glam.umd.min.js', | ||
format: 'umd' | ||
}, | ||
{ | ||
dest: 'dist/preact-glam.cjs.min.js', | ||
format: 'cjs' | ||
} | ||
] | ||
: [ | ||
{ | ||
dest: 'dist/preact-glam.cjs.js', | ||
format: 'cjs' | ||
}, | ||
{ | ||
dest: 'dist/preact-glam.es.js', | ||
format: 'es' | ||
}, | ||
{ | ||
dest: 'dist/preact-glam.umd.js', | ||
format: 'umd' | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** @jsx h */ | ||
import glam from '../index' | ||
|
||
test('should pass glam object prop', () => { | ||
const Comp = glam('div')({ | ||
marginLeft: 1 | ||
}) | ||
expect(Comp).toBeDefined() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { css, styleSheet } from 'glamor' | ||
|
||
function extractGlamorStyles (className = '') { | ||
return className.toString().split(' ').reduce((groups, name) => { | ||
if (name.indexOf('css-') === 0) { | ||
const id = name.slice('css-'.length) | ||
const { style } = styleSheet.registered[id] | ||
groups.glamorStyles.push(style) | ||
} else { | ||
groups.glamorlessClassName = `${groups.glamorlessClassName} ${name}`.trim() | ||
} | ||
return groups | ||
}, { glamorlessClassName: '', glamorStyles: [] }) | ||
} | ||
|
||
export default getGlamorClassName | ||
|
||
function getGlamorClassName (styles, props) { | ||
const mappedArgs = styles.slice() | ||
for (let i = mappedArgs.length; i--;) { | ||
if (typeof mappedArgs[i] === 'function') { | ||
mappedArgs[i] = mappedArgs[i](props) | ||
} | ||
} | ||
const { | ||
glamorStyles: parentGlamorStyles, | ||
glamorlessClassName | ||
} = extractGlamorStyles(props.className) | ||
const glamorClassName = css(...mappedArgs, ...parentGlamorStyles).toString() | ||
return `${glamorlessClassName} ${glamorClassName}`.trim() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** @jsx h */ | ||
import { h } from 'preact' | ||
import getClassName from './get-classname' | ||
|
||
export default function glam (comp) { | ||
return function glamComponentFactory (...styles) { | ||
const GlamComponent = props => { | ||
const { className, glam, ...toForward } = props | ||
const fullClassName = getClassName(GlamComponent.styles, props) | ||
return <GlamComponent.comp {...toForward} className={fullClassName} /> | ||
} | ||
|
||
GlamComponent.comp = comp.comp ? comp.comp : comp | ||
GlamComponent.styles = comp.styles ? comp.styles.concat(styles) : styles | ||
return GlamComponent | ||
} | ||
} |
Oops, something went wrong.