Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import tinycolor from 'tinycolor2';
import generate from './generate';

export interface PalettesProps {
Expand Down Expand Up @@ -43,8 +44,13 @@ const purple = presetPalettes.purple;
const magenta = presetPalettes.magenta;
const grey = presetPalettes.grey;

const isLight = (color: string): boolean => tinycolor(color).isLight();
const isDark = (color: string): boolean => tinycolor(color).isDark();

export {
generate,
isLight,
isDark,
presetPalettes,
presetPrimaryColors,
red,
Expand Down
12 changes: 11 additions & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generate, presetPalettes } from '../src';
import { generate, isLight, isDark, yellow, purple, presetPalettes } from '../src';

export const blueColors = [
'#E6F7FF',
Expand All @@ -17,6 +17,16 @@ test('Generate palettes from a given color', () => {
expect(generate('#1890ff')).toEqual(blueColors);
});

test('Determine the lightness of a color', () => {
expect(isLight(yellow[5])).toEqual(true);
expect(isLight(purple[5])).toEqual(false);
});

test('Determine the darkness of a color', () => {
expect(isDark(yellow[5])).toEqual(false);
expect(isDark(purple[5])).toEqual(true);
});

test('should contain preseted palettes', () => {
expect(Object.keys(presetPalettes)).toEqual([
'red',
Expand Down