UNPKG

3.14 kBTypeScriptView Raw
1export type PaletteMode = 'light' | 'dark';
2export interface Color {
3 50: string;
4 100: string;
5 200: string;
6 300: string;
7 400: string;
8 500: string;
9 600: string;
10 700: string;
11 800: string;
12 900: string;
13 A100: string;
14 A200: string;
15 A400: string;
16 A700: string;
17}
18
19export {};
20// use standalone interface over typeof colors/commons
21// to enable module augmentation
22export interface CommonColors {
23 black: string;
24 white: string;
25}
26
27export type ColorPartial = Partial<Color>;
28
29export interface TypeText {
30 primary: string;
31 secondary: string;
32 disabled: string;
33}
34
35export interface TypeAction {
36 active: string;
37 hover: string;
38 hoverOpacity: number;
39 selected: string;
40 selectedOpacity: number;
41 disabled: string;
42 disabledOpacity: number;
43 disabledBackground: string;
44 focus: string;
45 focusOpacity: number;
46 activatedOpacity: number;
47}
48
49export interface TypeBackground {
50 default: string;
51 paper: string;
52}
53
54export type TypeDivider = string;
55
56export type PaletteColorOptions = SimplePaletteColorOptions | ColorPartial;
57
58export interface SimplePaletteColorOptions {
59 light?: string;
60 main: string;
61 dark?: string;
62 contrastText?: string;
63}
64
65export interface PaletteColor {
66 light: string;
67 main: string;
68 dark: string;
69 contrastText: string;
70}
71
72export interface TypeObject {
73 text: TypeText;
74 action: TypeAction;
75 divider: TypeDivider;
76 background: TypeBackground;
77}
78
79export type PaletteTonalOffset =
80 | number
81 | {
82 light: number;
83 dark: number;
84 };
85
86export const light: TypeObject;
87export const dark: TypeObject;
88
89export interface PaletteAugmentColorOptions {
90 color: PaletteColorOptions;
91 mainShade?: number | string;
92 lightShade?: number | string;
93 darkShade?: number | string;
94 name?: number | string;
95}
96
97export interface Palette {
98 common: CommonColors;
99 mode: PaletteMode;
100 contrastThreshold: number;
101 tonalOffset: PaletteTonalOffset;
102 primary: PaletteColor;
103 secondary: PaletteColor;
104 error: PaletteColor;
105 warning: PaletteColor;
106 info: PaletteColor;
107 success: PaletteColor;
108 grey: Color;
109 text: TypeText;
110 divider: TypeDivider;
111 action: TypeAction;
112 background: TypeBackground;
113 getContrastText: (background: string) => string;
114 augmentColor: (options: PaletteAugmentColorOptions) => PaletteColor;
115}
116
117export interface Channels {
118 mainChannel: string;
119 lightChannel: string;
120 darkChannel: string;
121 contrastTextChannel: string;
122}
123
124export type PartialTypeObject = { [P in keyof TypeObject]?: Partial<TypeObject[P]> };
125
126export interface PaletteOptions {
127 primary?: PaletteColorOptions;
128 secondary?: PaletteColorOptions;
129 error?: PaletteColorOptions;
130 warning?: PaletteColorOptions;
131 info?: PaletteColorOptions;
132 success?: PaletteColorOptions;
133 mode?: PaletteMode;
134 tonalOffset?: PaletteTonalOffset;
135 contrastThreshold?: number;
136 common?: Partial<CommonColors>;
137 grey?: ColorPartial;
138 text?: Partial<TypeText>;
139 divider?: string;
140 action?: Partial<TypeAction>;
141 background?: Partial<TypeBackground>;
142 getContrastText?: (background: string) => string;
143}
144
145export default function createPalette(palette: PaletteOptions): Palette;