Skip to content

Commit

Permalink
Rename export fn, includeEndslerpEnds, default mode → lrgb
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonmcconnell committed Jul 7, 2022
1 parent d750270 commit 7333f3f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = {
includeLegacy: false,
lerpEnds: true,
interval: 25,
mode: 'rgb',
mode: 'lrgb',
})
},
}
Expand Down Expand Up @@ -85,7 +85,7 @@ theme: {
includeLegacy: false,
lerpEnds: true,
interval: 25,
mode: 'rgb',
mode: 'lrgb',
})
}
```
Expand All @@ -105,9 +105,9 @@ Every option in the options object is entirely optional and falls back to its re

** *`includeBase` must be set to true in order for `includeLegacy` to work*

* `includeEnds` (`boolean`) will include interpolation past the bounds of the colors included in the provided palette. For example, assuming a color `brown` is included in Tailwind config colors, where `brown-50` is the lightest shade and `brown-900` is the darkest shade, the function—when enabled—would interpolate between white (`#fff`) and `brown-50` and between black (`#000`) and `brown-900` to expose lighter and darker shades of every color than those included in the palette.
* `lerpEnds` (`boolean`) will include interpolation past the bounds of the colors included in the provided palette. For example, assuming a color `brown` is included in Tailwind config colors, where `brown-50` is the lightest shade and `brown-900` is the darkest shade, the function—when enabled—would interpolate between white (`#fff`) and `brown-50` and between black (`#000`) and `brown-900` to expose lighter and darker shades of every color than those included in the palette.

* `interval` (`number`, positive integer) sets the interval at which to interpolate colors. For example, with the default value of `25`, between `red-100` and `red-200`, it would interpolate the additional values `red-125`, `red-150`, and `red-175`. To include only the “halfway” values and not “quarter” values, you could pass an `interval` value of `50` which would only interpolate `red-150` between `red-100` and `red-200`. To interpolate every single value between each shade, you can pass a value of `1`, which would expose `red-101`, `red-102`, `red-103`, …, `red-899` per the default colors (including `red-0` and `red-1000` if `includeEnds` is enabled).
* `interval` (`number`, positive integer) sets the interval at which to interpolate colors. For example, with the default value of `25`, between `red-100` and `red-200`, it would interpolate the additional values `red-125`, `red-150`, and `red-175`. To include only the “halfway” values and not “quarter” values, you could pass an `interval` value of `50` which would only interpolate `red-150` between `red-100` and `red-200`. To interpolate every single value between each shade, you can pass a value of `1`, which would expose `red-101`, `red-102`, `red-103`, …, `red-899` per the default colors (including `red-0` and `red-1000` if `lerpEnds` is enabled).

It's important to note that each color's default intervals must be evenly divisible by the interval passed in this function, so it's recommended to use a naming convention similar to the one included in Tailwind by default:
```
Expand Down Expand Up @@ -137,18 +137,18 @@ Every option in the options object is entirely optional and falls back to its re
What this means at a larger scale is you can create beautiful palettes of colors using as few as two colors and letting `tailwind-lerp-colors` do the heavy lifting, interpolating between them.

The accepted values for mode are:
* rgb
* lab
* lch
* lrgb
* hcl
* num
* hcg
* oklch
* hsi
* hsl
* hsv
* oklab
* `lrgb` (default)
* `rgb`
* `lab`
* `lch`
* `hcl`
* `num`
* `hcg`
* `oklch`
* `hsi`
* `hsl`
* `hsv`
* `oklab`

## Roadmap
I have a few improvements planned already, and I am always open to feature requests and bug reports.
Expand Down
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const interpolateColors = (colorsObj, options = {}) => {
const lerpColors = (colorsObj, options = {}) => {
const chroma = require('chroma-js');
const builtInColors = require('tailwindcss/colors');
const legacyNames = ['lightBlue', 'warmGray', 'trueGray', 'coolGray', 'blueGray'];
Expand All @@ -8,7 +8,7 @@ const interpolateColors = (colorsObj, options = {}) => {
includeLegacy: false,
lerpEnds: true,
interval: 25,
mode: 'rgb',
mode: 'lrgb',
};

const validColorModes = [
Expand All @@ -29,8 +29,8 @@ const interpolateColors = (colorsObj, options = {}) => {
throw new Error('tailwind-lerp-colors option `includeBase` must be a boolean.');
if (isOptionInvalid('includeLegacy', v => typeof v === 'boolean'))
throw new Error('tailwind-lerp-colors option `includeLegacy` must be a boolean.');
if (isOptionInvalid('includeEnds', v => typeof v === 'boolean'))
throw new Error('tailwind-lerp-colors option `includeEnds` must be a boolean.');
if (isOptionInvalid('lerpEnds', v => typeof v === 'boolean'))
throw new Error('tailwind-lerp-colors option `lerpEnds` must be a boolean.');
if (isOptionInvalid('interval', v => Number.isInteger(v) && v > 0))
throw new Error('tailwind-lerp-colors option `interval` must be a positive integer greater than 0.');
if (isOptionInvalid('mode', v => validColorModes.includes(v)))
Expand All @@ -43,7 +43,7 @@ const interpolateColors = (colorsObj, options = {}) => {
return [base, legacy];
}, [{}, {}]
);
const { includeBase, includeLegacy, includeEnds, interval, mode } = {
const { includeBase, includeLegacy, lerpEnds, interval, mode } = {
...defaultOptions,
...options,
};
Expand Down Expand Up @@ -80,7 +80,7 @@ const interpolateColors = (colorsObj, options = {}) => {
})
.sort(sortByNumericFirstIndex)
);
if (includeEnds) {
if (lerpEnds) {
shadesArray.unshift([0, '#ffffff']);
shadesArray.push([1000, '#000000']);
}
Expand Down Expand Up @@ -114,4 +114,4 @@ const interpolateColors = (colorsObj, options = {}) => {
return finalColors;
};

module.exports = interpolateColors;
module.exports = lerpColors;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tailwind-lerp-colors",
"version": "1.1.3",
"version": "1.1.4",
"description": "Interpolate between defined colors in Tailwind config for additional color stops",
"main": "index.js",
"publishConfig": {
Expand Down

0 comments on commit 7333f3f

Please sign in to comment.