random-gradient
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -8,10 +8,32 @@ 'use strict' | ||
const res = gradient('new gradient') | ||
t.truthy(res.includes('to top right')) | ||
t.truthy(typeof res, 'string') | ||
}) | ||
test('return gradient diagonal', t => { | ||
const res = gradient('new gradient', 'diagonal') | ||
t.truthy(res.includes('to top right')) | ||
t.truthy(typeof res, 'string') | ||
}) | ||
test('return gradient radial', t => { | ||
const res = gradient('new gradient', 'radial') | ||
t.truthy(res.includes('radial')) | ||
t.truthy(typeof res, 'string') | ||
}) | ||
test('return gradient horizontal', t => { | ||
const res = gradient('new gradient', 'horizontal') | ||
t.truthy(typeof res, 'string') | ||
}) | ||
test('return gradient vertical', t => { | ||
const res = gradient('new gradient', 'vertical') | ||
t.truthy(res.includes('to right')) | ||
t.truthy(typeof res, 'string') | ||
}) | ||
test('return different gradient with different uid', t => { | ||
const res = gradient('new gradient') | ||
const res2 = gradient('another gradient') | ||
t.not(res, res2) | ||
@@ -24,6 +46,6 @@ t.truthy(typeof res, 'string') | ||
const error = t.throws(() => { | ||
gradient() | ||
}, TypeError) | ||
gradient() | ||
}, TypeError) | ||
t.is(error.message, 'uid is required') | ||
}) |
19
index.js
@@ -7,3 +7,3 @@ | ||
module.exports = uid => { | ||
module.exports = (uid, type = 'diagonal') => { | ||
if (uid) { | ||
@@ -15,3 +15,18 @@ const n = hash(uid) | ||
return `linear-gradient(45deg, ${c1_} 10%, ${c2} 100%)` | ||
switch (type) { | ||
case 'diagonal': | ||
return `linear-gradient(to top right, ${c1_}, ${c2})` | ||
case 'radial': | ||
return `radial-gradient(circle, ${c1_}, ${c2})` | ||
case 'horizontal': | ||
return `linear-gradient(${c1_}, ${c2})` | ||
case 'vertical': | ||
return `linear-gradient(to right, ${c1_}, ${c2})` | ||
default: | ||
return `linear-gradient(to top right, ${c1_}, ${c2})` | ||
} | ||
} | ||
@@ -18,0 +33,0 @@ |
{ | ||
"name": "random-gradient", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Generate beautiful random gradients", | ||
@@ -23,7 +23,4 @@ "main": "index.js", | ||
"esnext": true, | ||
"space": true, | ||
"ignores": [ | ||
"__tests__/index.js" | ||
] | ||
"space": true | ||
} | ||
} |
@@ -15,10 +15,19 @@ # random-gradient [![Build Status](https://travis-ci.org/bukinoshita/random-gradient.svg?branch=master)](https://travis-ci.org/bukinoshita/random-gradient) | ||
```js | ||
// with React | ||
import gradient from 'random-gradient' | ||
gradient(uid) | ||
// => linear-gradient(45deg, #d4f906 10%, #06d4f9 100%) | ||
export default ({ name }) => { | ||
const bgGradient = { background: gradient(name) } | ||
return ( | ||
<div style={bgGradient}> | ||
<h2>{name}</h2> | ||
</div> | ||
) | ||
} | ||
``` | ||
## API | ||
### randomGradient(uid) | ||
### randomGradient(uid, type) | ||
@@ -29,2 +38,7 @@ #### uid | ||
#### type | ||
Type: `string`<br/> | ||
Default: `diagonal`<br/> | ||
Options: `diagonal`, `vertical`, `horizontal`, `radial`<br/> | ||
## Related | ||
@@ -31,0 +45,0 @@ |
127039
64
49