Skip to content

Commit

Permalink
[TypeScript] Fix color exporting (mui#7989)
Browse files Browse the repository at this point in the history
* [TypeScript] Fix colors exported as types instead of const
* [TypeScript] Add a test case for color exporting
  • Loading branch information
fathyb authored and sebald committed Aug 31, 2017
1 parent c102e16 commit 362116c
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 35 deletions.
4 changes: 3 additions & 1 deletion src/colors/amber.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/blue.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/blueGrey.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/brown.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
40 changes: 24 additions & 16 deletions src/colors/common.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { Color } from '..';
declare const black: string;
declare const white: string;
declare const transparent: string;
declare const fullBlack: string;
declare const darkBlack: string;
declare const lightBlack: string;
declare const minBlack: string;
declare const faintBlack: string;
declare const fullWhite: string;
declare const darkWhite: string;
declare const lightWhite: string;

interface CommonColors {
black: Color;
white: Color;
transparent: Color;
fullBlack: Color;
darkBlack: Color;
lightBlack: Color;
minBlack: Color;
faintBlack: Color;
fullWhite: Color;
darkWhite: Color;
lightWhite: Color;
}

export default CommonColors;
export default {
black,
white,
transparent,
fullBlack,
darkBlack,
lightBlack,
minBlack,
faintBlack,
fullWhite,
darkWhite,
lightWhite
};
4 changes: 3 additions & 1 deletion src/colors/cyan.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/deepOrange.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/deepPurple.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/green.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/grey.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/indigo.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/lightBlue.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/lightGreen.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/lime.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/orange.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/pink.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/purple.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/red.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/teal.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
4 changes: 3 additions & 1 deletion src/colors/yellow.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Color } from '..';

export default Color;
declare const color: Color;

export default color;
56 changes: 56 additions & 0 deletions test/typescript/colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
amber, blue, blueGrey,
brown, cyan, deepOrange,
deepPurple, green, grey,
indigo, lightBlue, lightGreen,
lime, orange, pink,
purple, red, teal,
yellow, common
} from '../../src/colors';

[
// Check if the color is usable as a variable
amber, blue, blueGrey,
brown, cyan, deepOrange,
deepPurple, green, grey,
indigo, lightBlue, lightGreen,
lime, orange, pink,
purple, red, teal,
yellow
].forEach(color => {
// Check if each color is a string
color[50] as string;
color[100] as string;
color[200] as string;
color[300] as string;
color[400] as string;
color[500] as string;
color[600] as string;
color[700] as string;
color[800] as string;
color[900] as string;
color.A100 as string;
color.A200 as string;
color.A400 as string;
color.A700 as string;

// Check if contrastDefaultColor is a string too
color.contrastDefaultColor as string;
});

const {
black, white, transparent,
fullBlack, darkBlack, lightBlack,
minBlack, faintBlack,
fullWhite, darkWhite, lightWhite
} = common;

[
black, white, transparent,
fullBlack, darkBlack, lightBlack,
minBlack, faintBlack,
fullWhite, darkWhite, lightWhite
].forEach(color => {
color as string;
});

0 comments on commit 362116c

Please sign in to comment.