Skip to content
This repository has been archived by the owner on Nov 25, 2019. It is now read-only.

Commit

Permalink
prettier !!!1!!1!
Browse files Browse the repository at this point in the history
  • Loading branch information
RafalFilipek committed Jun 7, 2017
1 parent 5107405 commit 7b8962d
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 92 deletions.
24 changes: 12 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module.exports = {
"parser": "babel-eslint",
"extends": "airbnb",
"plugins": [
"react",
"jsx-a11y",
"import",
"flowtype-errors"
],
"rules": {
"flowtype-errors/show-errors": 2
}
};
parser: 'babel-eslint',
extends: 'eslint:recommended',
plugins: ['react', 'jsx-a11y', 'import', 'flowtype-errors'],
env: {
browser: true,
es6: true,
node: true,
},
rules: {
'flowtype-errors/show-errors': 2,
},
};
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Greenkeeper badge](https://badges.greenkeeper.io/RafalFilipek/styled-props.svg)](https://greenkeeper.io/)
[![Build Status](https://travis-ci.org/RafalFilipek/styled-props.svg?branch=master)](https://travis-ci.org/RafalFilipek/styled-props)
[![Code Coverage](https://img.shields.io/codecov/c/github/RafalFilipek/styled-props/master.svg)](https://codecov.io/gh/RafalFilipek/styled-props)
[![Code Style](https://img.shields.io/badge/codestyle-airbnb-brightgreen.svg)](https://github.com/airbnb/javascript)
[![Code Style](https://img.shields.io/badge/codestyle-%C2%AF%5C____(%E3%83%84)____%2F%C2%AF%20%20-brightgreen.svg)](prettier.github.io/prettier/)

Simple lib that allows you to set *styled props* in your [*styled-components*](https://styled-components.com) without stress. Let's take `Button` component from styled-components web page. Here it is:

Expand Down
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"compile": "babel -d lib src",
"compile:watch": "babel -w -d lib src",
"clean": "rm -rf lib",
"prepublish": "npm run clean && npm test && npm run compile"
"prepublish": "npm run clean && npm test && npm run compile",
"precommit": "lint-staged",
"format": "prettier --single-quote --trailing-comma=es5 --parser=flow --write \"src/**/*.js\""
},
"files": [
"*.md",
Expand All @@ -32,6 +34,12 @@
"css",
"css-in-js"
],
"lint-staged": {
"*.js": [
"prettier --single-quote --trailing-comma=es5 --parser=babylon --write",
"git add"
]
},
"jest": {
"collectCoverage": true,
"coverageDirectory": "./.coverage",
Expand All @@ -54,7 +62,10 @@
"eslint-plugin-jsx-a11y": "^5.0.0",
"eslint-plugin-react": "^7.0.1",
"flow-bin": "^0.47.0",
"husky": "^0.13.4",
"jest": "^20.0.1",
"lint-staged": "^3.6.0",
"prettier": "^1.4.2",
"publish-please": "^2.3.1",
"react": "^15.5.4",
"react-addons-test-utils": "^15.5.1",
Expand All @@ -63,4 +74,4 @@
"styled-components": "^2.0.0"
},
"dependencies": {}
}
}
13 changes: 6 additions & 7 deletions src/bind.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import styledProps from './styledProps';

type PropsLike = { [key:string]: any };
type StyledPropsMap = { [key:string]: typeof styledProps };
type BindFunction = (map:PropsLike) => StyledPropsMap;
type PropsLike = { [key: string]: any };
type StyledPropsMap = { [key: string]: typeof styledProps };
type BindFunction = (map: PropsLike) => StyledPropsMap;

const bind:BindFunction = map => (
Object.keys(map).reduce((memo:StyledPropsMap, key:string) => {
const bind: BindFunction = map =>
Object.keys(map).reduce((memo: StyledPropsMap, key: string) => {
// eslint-disable-next-line no-param-reassign
memo[key] = styledProps(map[key], key);
return memo;
}, {})
);
}, {});

export default bind;
25 changes: 17 additions & 8 deletions src/styledProps.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
// @flow

type PropsLike = { [key:string]: any };
type MapperFunction = (props:PropsLike) => any;
export type StyledPropsFunction = (map:PropsLike, fallback?:string) => MapperFunction;
type PropsLike = { [key: string]: any };
type MapperFunction = (props: PropsLike) => any;
export type StyledPropsFunction = (
map: PropsLike,
fallback?: string
) => MapperFunction;

const styledProps:StyledPropsFunction = (map, fallback) => ((props) => {
const keysFromProps:string[] = Object.keys(map).filter(key => props[key] !== undefined);
const styledProps: StyledPropsFunction = (map, fallback) => props => {
const keysFromProps: string[] = Object.keys(map).filter(
key => props[key] !== undefined
);
if (keysFromProps.length > 1) {
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console
console.error(`[styledProps] Multiple props provided: ${keysFromProps.join(', ')}.`);
console.error(
`[styledProps] Multiple props provided: ${keysFromProps.join(', ')}.`
);
}
}
const keyFromProps = keysFromProps[0];
Expand All @@ -22,10 +29,12 @@ const styledProps:StyledPropsFunction = (map, fallback) => ((props) => {
}
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console
console.error(`[styledProps] Unknown fallback prop provided: ${fallback}.`);
console.error(
`[styledProps] Unknown fallback prop provided: ${fallback}.`
);
}
}
return undefined;
});
};

export default styledProps;
Loading

0 comments on commit 7b8962d

Please sign in to comment.