support remcalc('i i')

This commit is contained in:
Sérgio Ramos 2017-02-27 17:38:43 +00:00
parent 961a06f46a
commit e78a9d2d28
3 changed files with 11 additions and 5 deletions

View File

@ -75,6 +75,7 @@
"eslint-plugin-react": "^6.10.0",
"eslint-plugin-standard": "^2.0.1",
"jsdom": "^9.11.0",
"lodash.flatten": "^4.4.0",
"memory-fs": "^0.4.1",
"node-hook": "^0.4.0",
"nyc": "^10.1.2",

View File

@ -1,6 +1,7 @@
import { css } from 'styled-components';
import calc from 'reduce-css-calc';
import randomNatural from 'random-natural';
import flatten from 'lodash.flatten';
const remBase = 16;
const unitBase = 6;
@ -18,12 +19,16 @@ const rndId = (_code) => {
: lastDigit;
};
const remcalc = (...values) => values.map((value) => (
`${String(value).replace('px', '') / remBase}rem`
const remcalc = (...values) => flatten(
values.map((value) => String(value).split(/\s/img))
).map((value) => (
`${value.replace('px', '') / remBase}rem`
)).join(' ');
const unitcalc = (...values) => values.map(
(value) => remcalc(value * unitBase)
const unitcalc = (...values) => flatten(
values.map((value) => String(value).split(/\s/img))
).map((value) =>
remcalc(Number(value) * unitBase)
);
const cssCalc = (str) => calc(`calc(${str})`);

View File

@ -4252,7 +4252,7 @@ lodash.first@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash.first/-/lodash.first-3.0.0.tgz#5dae180d7f818ee65fc5b210b104a7bbef98a16a"
lodash.flatten@^4.2.0, lodash.flatten@^4.4.0:
lodash.flatten, lodash.flatten@^4.2.0, lodash.flatten@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.flatten/-/lodash.flatten-4.4.0.tgz#f31c22225a9632d2bbf8e4addbef240aa765a61f"