Skip to content

Instantly share code, notes, and snippets.

@pedroraft
Created January 29, 2020 16:24
Show Gist options
  • Save pedroraft/49229ffbf6e03682b453e487a4b017e7 to your computer and use it in GitHub Desktop.
Save pedroraft/49229ffbf6e03682b453e487a4b017e7 to your computer and use it in GitHub Desktop.
Typescript color palette utils
// TODO: typing of this could be better
export const getColor = <T>(colorPalette: T, defaultColor: keyof T) => (
level?: keyof T,
) => (colorPalette[level || defaultColor] as unknown) as string;
export interface IColorPaletteNumbered {
0: string;
1: string;
2: string;
3: string;
4: string;
5: string;
6: string;
7: string;
8: string;
9: string;
}
export interface IColorPaletteKeyed {
faded: string;
light: string;
default: string;
dark: string;
neutral: string;
}
// d88888b db db .d8b. .88b d88. d8888b. db d88888b
// 88' `8b d8' d8' `8b 88'YbdP`88 88 `8D 88 88'
// 88ooooo `8bd8' 88ooo88 88 88 88 88oodD' 88 88ooooo
// 88~~~~~ .dPYb. 88~~~88 88 88 88 88~~~ 88 88~~~~~
// 88. .8P Y8. 88 88 88 88 88 88 88booo. 88.
// Y88888P YP YP YP YP YP YP YP 88 Y88888P Y88888P
//==============================================================
// const Gray: IColorPaletteNumbered = {
// 0: '#edecec',
// 1: '#dad9d9',
// 2: '#c7c7c5',
// 3: '#b4b3b1',
// 4: '#a09f9d',
// 5: '#8c8a88',
// 6: '#787573',
// 7: '#625f5c',
// 8: '#4c4944',
// 9: '#2d2926',
// };
// const Tavel: IColorPaletteKeyed = {
// faded: '#fdebde',
// light: '#fcb84d',
// default: '#f79552',
// dark: '#6b4620',
// neutral: '#6d5e4e',
// };
// const Colors = {
// White: '#fff',
// Gray: getColor(Gray, 5),
// Tavel: getColor(Tavel, 'default'),
// };
// final use
// Colors.Gray(7)
// Colors.Gray()
// Colors.Tavel('dark')
// Colors.White
{
"name": "raft-color-utils",
"version": "0.1.0"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment