Skip to content

Commit

Permalink
fix(typing): fix typing (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
mym0404 authored Mar 15, 2024
2 parents fda359a + 07f5387 commit 1bb8ac4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 155 deletions.
166 changes: 25 additions & 141 deletions bin/ret.d.ts
Original file line number Diff line number Diff line change
@@ -1,144 +1,28 @@
import type { DimensionValue } from 'react-native';


import type { RadiiValue, SizesValue, SpaceValue } from './Token';

export interface ThemedTypings {
colors:
| 'white'
| 'black'
| 'transparent'
| 'gray50'
| 'gray100'
| 'gray200'
| 'gray300'
| 'gray400'
| 'gray500'
| 'gray600'
| 'gray700'
| 'gray800'
| 'gray900'
| 'violet50'
| 'violet100'
| 'violet200'
| 'violet300'
| 'violet400'
| 'violet500'
| 'violet600'
| 'violet700'
| 'violet800'
| 'violet900'
| 'green50'
| 'green100'
| 'green200'
| 'green300'
| 'green400'
| 'green500'
| 'green600'
| 'yellow50'
| 'yellow100'
| 'yellow200'
| 'yellow300'
| 'yellow400'
| 'yellow500'
| 'yellow600'
| 'red50'
| 'red100'
| 'red200'
| 'red300'
| 'red400'
| 'red500'
| 'red600'
| 'blue50'
| 'blue100'
| 'blue200'
| 'blue300'
| 'blue400'
| 'blue500'
| 'blue600'
| 'blue700'
| 'blue800'
| 'blue900';

radii: number | `${number}` | `${number}px` | `${any}px` | '1' | '2' | 'sm' | 'md';

sizes:
| DimensionValue
| `${number}`
| `${number}px`
| `${any}px`
| '0'
| '1'
| '2'
| '3'
| '4'
| '5'
| '6'
| '7'
| '8'
| '9'
| '10'
| '12'
| '14'
| '16'
| '18'
| '20'
| '24'
| '28'
| '30'
| '32'
| '40'
| '48'
| 'px'
| '0.5';
space:
| DimensionValue
| `${number}`
| `${number}px`
| `${any}px`
| '0'
| '-0'
| '1'
| '-1'
| '2'
| '-2'
| '3'
| '-3'
| '4'
| '-4'
| '5'
| '-5'
| '6'
| '-6'
| '7'
| '-7'
| '8'
| '-8'
| '9'
| '-9'
| '10'
| '-10'
| '12'
| '-12'
| '14'
| '-14'
| '16'
| '-16'
| '18'
| '-18'
| '20'
| '-20'
| '24'
| '-24'
| '28'
| '-28'
| '30'
| '-30'
| '32'
| '-32'
| '40'
| '-40'
| '48'
| '-48'
| 'px'
| '-px'
| '0.5'
| '-0.5';





colors: "white" | "black" | "transparent" | "gray50" | "gray100" | "gray200" | "gray300" | "gray400" | "gray500" | "gray600" | "gray700" | "gray800" | "gray900" | "violet50" | "violet100" | "violet200" | "violet300" | "violet400" | "violet500" | "violet600" | "violet700" | "violet800" | "violet900" | "green50" | "green100" | "green200" | "green300" | "green400" | "green500" | "green600" | "yellow50" | "yellow100" | "yellow200" | "yellow300" | "yellow400" | "yellow500" | "yellow600" | "red50" | "red100" | "red200" | "red300" | "red400" | "red500" | "red600" | "blue50" | "blue100" | "blue200" | "blue300" | "blue400" | "blue500" | "blue600" | "blue700" | "blue800" | "blue900"







radii: RadiiValue | `${number}` | `${number}px` | `${any}px` | "1" | "2" | "sm" | "md"

sizes: SizesValue | `${number}` | `${number}px` | `${any}px` | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "12" | "14" | "16" | "18" | "20" | "24" | "28" | "30" | "32" | "40" | "48" | "px" | "0.5"
space: SpaceValue | `${number}` | `${number}px` | `${any}px` | "0" | "-0" | "1" | "-1" | "2" | "-2" | "3" | "-3" | "4" | "-4" | "5" | "-5" | "6" | "-6" | "7" | "-7" | "8" | "-8" | "9" | "-9" | "10" | "-10" | "12" | "-12" | "14" | "-14" | "16" | "-16" | "18" | "-18" | "20" | "-20" | "24" | "-24" | "28" | "-28" | "30" | "-30" | "32" | "-32" | "40" | "-40" | "48" | "-48" | "px" | "-px" | "0.5" | "-0.5"





}
15 changes: 11 additions & 4 deletions bin/theme-gen.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ try {
*/

let result = read(tmpFile);
result = result.replace(/import.*/, "import type { DimensionValue } from 'react-native';\n");
result = result.replace(
/import.*/,
"import type { RadiiValue, SizesValue, SpaceValue } from './Token';\n",
);
result = result.replace(/export.*/, 'export interface ThemedTypings {');
result = result.replace(/\/\/.*/g, '');
result = result.replace(/blur.*/, '');
Expand All @@ -170,14 +173,18 @@ try {

result = result.replace(
'space:',
'space: DimensionValue | `${number}` | `${number}px` | `${any}px` | ',
'space: SpaceValue | `${number}` | `${number}px` | `${any}px` | ',
);

result = result.replace(
'sizes:',
'sizes: DimensionValue | `${number}` | `${number}px` | `${any}px` | ',
'sizes: SizesValue | `${number}` | `${number}px` | `${any}px` | ',
);

result = result.replace(
'radii:',
'radii: RadiiValue | `${number}` | `${number}px` | `${any}px` | ',
);
result = result.replace('radii:', 'radii: number | `${number}` | `${number}px` | `${any}px` | ');

result = result.replace(/\|[\s ]*\n/g, ';');

Expand Down
10 changes: 5 additions & 5 deletions src/@types/ThemedDict.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { DimensionValue } from 'react-native';
import type { ColorsValue, RadiiValue, SizesValue, SpaceValue } from './Token';

export interface ThemedDict {
space: Record<string | number, DimensionValue>;
sizes: Record<string | number, DimensionValue>;
colors: Record<string, string>;
radii: Record<string | number, number>;
space: Record<string | number, SpaceValue>;
sizes: Record<string | number, SizesValue>;
colors: Record<string | number, ColorsValue>;
radii: Record<string | number, RadiiValue>;
}
export const emptyThemedDict = {
space: {},
Expand Down
10 changes: 5 additions & 5 deletions src/@types/ThemedTypings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { DimensionValue } from 'react-native';
import type { ColorsValue, RadiiValue, SizesValue, SpaceValue } from './Token';

export interface ThemedTypings {
space: DimensionValue | `${number}` | `${number}px` | `${any}px`;
sizes: DimensionValue | `${number}` | `${number}px` | `${any}px`;
colors: string;
radii: number | `${number}` | `${number}px` | `${any}px`;
space: SpaceValue | `${number}` | `${number}px` | `${any}px`;
sizes: SizesValue | `${number}` | `${number}px` | `${any}px`;
colors: ColorsValue;
radii: RadiiValue | `${number}` | `${number}px` | `${any}px`;
}
5 changes: 5 additions & 0 deletions src/@types/Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ import type { ThemedTypings } from './ThemedTypings';
export type Token<ThemeKey extends keyof ThemedTypings> = ThemeKey extends keyof ThemedTypings
? ThemedTypings[ThemeKey]
: never;

export type SpaceValue = number | 'auto' | `${number}%` | null;
export type SizesValue = number | 'auto' | `${number}%` | null;
export type ColorsValue = string;
export type RadiiValue = number;

0 comments on commit 1bb8ac4

Please sign in to comment.