@tamagui/themes 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/themes.js +220 -0
- package/dist/cjs/themes.js.map +7 -0
- package/dist/cjs/tokens.js +180 -0
- package/dist/cjs/tokens.js.map +7 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/index.mjs.map +7 -0
- package/dist/esm/themes.js +202 -0
- package/dist/esm/themes.js.map +7 -0
- package/dist/esm/themes.mjs +202 -0
- package/dist/esm/themes.mjs.map +7 -0
- package/dist/esm/tokens.js +165 -0
- package/dist/esm/tokens.js.map +7 -0
- package/dist/esm/tokens.mjs +165 -0
- package/dist/esm/tokens.mjs.map +7 -0
- package/package.json +47 -0
- package/src/index.tsx +3 -0
- package/src/themes.tsx +230 -0
- package/src/tokens.tsx +194 -0
- package/types/index.d.ts +4 -0
- package/types/index.d.ts.map +1 -0
- package/types/themes.d.ts +2202 -0
- package/types/themes.d.ts.map +1 -0
- package/types/tokens.d.ts +998 -0
- package/types/tokens.d.ts.map +1 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
blue,
|
|
3
|
+
blueDark,
|
|
4
|
+
gray,
|
|
5
|
+
grayDark,
|
|
6
|
+
green,
|
|
7
|
+
greenDark,
|
|
8
|
+
orange,
|
|
9
|
+
orangeDark,
|
|
10
|
+
pink,
|
|
11
|
+
pinkDark,
|
|
12
|
+
purple,
|
|
13
|
+
purpleDark,
|
|
14
|
+
red,
|
|
15
|
+
redDark,
|
|
16
|
+
yellow,
|
|
17
|
+
yellowDark
|
|
18
|
+
} from "@tamagui/colors";
|
|
19
|
+
import { createTokens } from "@tamagui/web";
|
|
20
|
+
const size = {
|
|
21
|
+
$0: 0,
|
|
22
|
+
"$0.25": 2,
|
|
23
|
+
"$0.5": 4,
|
|
24
|
+
"$0.75": 8,
|
|
25
|
+
$1: 20,
|
|
26
|
+
"$1.5": 24,
|
|
27
|
+
$2: 28,
|
|
28
|
+
"$2.5": 32,
|
|
29
|
+
$3: 36,
|
|
30
|
+
"$3.5": 40,
|
|
31
|
+
$4: 44,
|
|
32
|
+
$true: 44,
|
|
33
|
+
"$4.5": 48,
|
|
34
|
+
$5: 52,
|
|
35
|
+
$6: 64,
|
|
36
|
+
$7: 74,
|
|
37
|
+
$8: 84,
|
|
38
|
+
$9: 94,
|
|
39
|
+
$10: 104,
|
|
40
|
+
$11: 124,
|
|
41
|
+
$12: 144,
|
|
42
|
+
$13: 164,
|
|
43
|
+
$14: 184,
|
|
44
|
+
$15: 204,
|
|
45
|
+
$16: 224,
|
|
46
|
+
$17: 224,
|
|
47
|
+
$18: 244,
|
|
48
|
+
$19: 264,
|
|
49
|
+
$20: 284
|
|
50
|
+
};
|
|
51
|
+
const spaces = Object.entries(size).map(([k, v]) => {
|
|
52
|
+
return [k, sizeToSpace(v)];
|
|
53
|
+
});
|
|
54
|
+
function sizeToSpace(v) {
|
|
55
|
+
if (v === 0)
|
|
56
|
+
return 0;
|
|
57
|
+
if (v === 2)
|
|
58
|
+
return 0.5;
|
|
59
|
+
if (v === 4)
|
|
60
|
+
return 1;
|
|
61
|
+
if (v === 8)
|
|
62
|
+
return 1.5;
|
|
63
|
+
if (v <= 16)
|
|
64
|
+
return Math.round(v * 0.333);
|
|
65
|
+
return Math.floor(v * 0.7 - 12);
|
|
66
|
+
}
|
|
67
|
+
const spacesNegative = spaces.map(([k, v]) => [`-${k.slice(1)}`, -v]);
|
|
68
|
+
const space = {
|
|
69
|
+
...Object.fromEntries(spaces),
|
|
70
|
+
...Object.fromEntries(spacesNegative)
|
|
71
|
+
};
|
|
72
|
+
const zIndex = {
|
|
73
|
+
0: 0,
|
|
74
|
+
1: 100,
|
|
75
|
+
2: 200,
|
|
76
|
+
3: 300,
|
|
77
|
+
4: 400,
|
|
78
|
+
5: 500
|
|
79
|
+
};
|
|
80
|
+
const colorTokens = {
|
|
81
|
+
light: {
|
|
82
|
+
blue,
|
|
83
|
+
gray,
|
|
84
|
+
green,
|
|
85
|
+
orange,
|
|
86
|
+
pink,
|
|
87
|
+
purple,
|
|
88
|
+
red,
|
|
89
|
+
yellow
|
|
90
|
+
},
|
|
91
|
+
dark: {
|
|
92
|
+
blue: blueDark,
|
|
93
|
+
gray: grayDark,
|
|
94
|
+
green: greenDark,
|
|
95
|
+
orange: orangeDark,
|
|
96
|
+
pink: pinkDark,
|
|
97
|
+
purple: purpleDark,
|
|
98
|
+
red: redDark,
|
|
99
|
+
yellow: yellowDark
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const darkColors = {
|
|
103
|
+
...colorTokens.dark.blue,
|
|
104
|
+
...colorTokens.dark.gray,
|
|
105
|
+
...colorTokens.dark.green,
|
|
106
|
+
...colorTokens.dark.orange,
|
|
107
|
+
...colorTokens.dark.pink,
|
|
108
|
+
...colorTokens.dark.purple,
|
|
109
|
+
...colorTokens.dark.red,
|
|
110
|
+
...colorTokens.dark.yellow
|
|
111
|
+
};
|
|
112
|
+
const lightColors = {
|
|
113
|
+
...colorTokens.light.blue,
|
|
114
|
+
...colorTokens.light.gray,
|
|
115
|
+
...colorTokens.light.green,
|
|
116
|
+
...colorTokens.light.orange,
|
|
117
|
+
...colorTokens.light.pink,
|
|
118
|
+
...colorTokens.light.purple,
|
|
119
|
+
...colorTokens.light.red,
|
|
120
|
+
...colorTokens.light.yellow
|
|
121
|
+
};
|
|
122
|
+
const color = {
|
|
123
|
+
...postfixObjKeys(lightColors, "Light"),
|
|
124
|
+
...postfixObjKeys(darkColors, "Dark")
|
|
125
|
+
};
|
|
126
|
+
function postfixObjKeys(obj, postfix) {
|
|
127
|
+
return Object.fromEntries(
|
|
128
|
+
Object.entries(obj).map(([k, v]) => [`${k}${postfix}`, v])
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
const radius = {
|
|
132
|
+
0: 0,
|
|
133
|
+
1: 3,
|
|
134
|
+
2: 5,
|
|
135
|
+
3: 7,
|
|
136
|
+
4: 9,
|
|
137
|
+
true: 9,
|
|
138
|
+
5: 10,
|
|
139
|
+
6: 16,
|
|
140
|
+
7: 19,
|
|
141
|
+
8: 22,
|
|
142
|
+
9: 26,
|
|
143
|
+
10: 34,
|
|
144
|
+
11: 42,
|
|
145
|
+
12: 50
|
|
146
|
+
};
|
|
147
|
+
const tokens = createTokens({
|
|
148
|
+
color,
|
|
149
|
+
radius,
|
|
150
|
+
zIndex,
|
|
151
|
+
space,
|
|
152
|
+
size
|
|
153
|
+
});
|
|
154
|
+
export {
|
|
155
|
+
color,
|
|
156
|
+
colorTokens,
|
|
157
|
+
darkColors,
|
|
158
|
+
lightColors,
|
|
159
|
+
radius,
|
|
160
|
+
size,
|
|
161
|
+
space,
|
|
162
|
+
tokens,
|
|
163
|
+
zIndex
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=tokens.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/tokens.tsx"],
|
|
4
|
+
"sourcesContent": ["import {\n blue,\n blueDark,\n gray,\n grayDark,\n green,\n greenDark,\n orange,\n orangeDark,\n pink,\n pinkDark,\n purple,\n purpleDark,\n red,\n redDark,\n yellow,\n yellowDark,\n} from '@tamagui/colors'\nimport { Variable, createTokens } from '@tamagui/web'\n\n// should roughly map to button/input etc height at each level\n// fonts should match that height/lineHeight at each stop\n// so these are really non-linear on purpose\n// why?\n// - at sizes <1, used for fine grained things (borders, smallest paddingY)\n// - so smallest padY should be roughly 1-4px so it can join with lineHeight\n// - at sizes >=1, have to consider \"pressability\" (jumps up)\n// - after that it should go upwards somewhat naturally\n// - H1 / headings top out at 10 naturally, so after 10 we can go upwards faster\n// but also one more wrinkle...\n// space is used in conjunction with size\n// i'm setting space to generally just a fixed fraction of size (~1/3-2/3 still fine tuning)\nexport const size = {\n $0: 0,\n '$0.25': 2,\n '$0.5': 4,\n '$0.75': 8,\n $1: 20,\n '$1.5': 24,\n $2: 28,\n '$2.5': 32,\n $3: 36,\n '$3.5': 40,\n $4: 44,\n $true: 44,\n '$4.5': 48,\n $5: 52,\n $6: 64,\n $7: 74,\n $8: 84,\n $9: 94,\n $10: 104,\n $11: 124,\n $12: 144,\n $13: 164,\n $14: 184,\n $15: 204,\n $16: 224,\n $17: 224,\n $18: 244,\n $19: 264,\n $20: 284,\n}\n\ntype SizeKeysIn = keyof typeof size\ntype Sizes = {\n [Key in SizeKeysIn extends `$${infer Key}` ? Key : SizeKeysIn]: number\n}\ntype SizeKeys = `${keyof Sizes extends `${infer K}` ? K : never}`\n\nconst spaces = Object.entries(size).map(([k, v]) => {\n return [k, sizeToSpace(v)]\n})\n\n// a bit odd but keeping backward compat for values >8 while fixing below\nfunction sizeToSpace(v: number) {\n if (v === 0) return 0\n if (v === 2) return 0.5\n if (v === 4) return 1\n if (v === 8) return 1.5\n if (v <= 16) return Math.round(v * 0.333)\n return Math.floor(v * 0.7 - 12)\n}\n\nconst spacesNegative = spaces.map(([k, v]) => [`-${(k as string).slice(1)}`, -v])\n\ntype SizeKeysWithNegatives =\n | `-${SizeKeys extends `$${infer Key}` ? Key : SizeKeys}`\n | SizeKeys\n\nexport const space: {\n [Key in SizeKeysWithNegatives]: Key extends keyof Sizes ? Sizes[Key] : number\n} = {\n ...Object.fromEntries(spaces),\n ...Object.fromEntries(spacesNegative),\n} as any\n\nexport const zIndex = {\n 0: 0,\n 1: 100,\n 2: 200,\n 3: 300,\n 4: 400,\n 5: 500,\n}\n\nexport const colorTokens = {\n light: {\n blue: blue,\n gray: gray,\n green: green,\n orange: orange,\n pink: pink,\n purple: purple,\n red: red,\n yellow: yellow,\n },\n dark: {\n blue: blueDark,\n gray: grayDark,\n green: greenDark,\n orange: orangeDark,\n pink: pinkDark,\n purple: purpleDark,\n red: redDark,\n yellow: yellowDark,\n },\n}\n\nexport const darkColors = {\n ...colorTokens.dark.blue,\n ...colorTokens.dark.gray,\n ...colorTokens.dark.green,\n ...colorTokens.dark.orange,\n ...colorTokens.dark.pink,\n ...colorTokens.dark.purple,\n ...colorTokens.dark.red,\n ...colorTokens.dark.yellow,\n}\n\nexport const lightColors = {\n ...colorTokens.light.blue,\n ...colorTokens.light.gray,\n ...colorTokens.light.green,\n ...colorTokens.light.orange,\n ...colorTokens.light.pink,\n ...colorTokens.light.purple,\n ...colorTokens.light.red,\n ...colorTokens.light.yellow,\n}\n\nexport const color = {\n ...postfixObjKeys(lightColors, 'Light'),\n ...postfixObjKeys(darkColors, 'Dark'),\n}\n\nfunction postfixObjKeys<\n A extends { [key: string]: Variable<string> | string },\n B extends string\n>(\n obj: A,\n postfix: B\n): {\n [Key in `${keyof A extends string ? keyof A : never}${B}`]: Variable<string> | string\n} {\n return Object.fromEntries(\n Object.entries(obj).map(([k, v]) => [`${k}${postfix}`, v])\n ) as any\n}\n\nexport const radius = {\n 0: 0,\n 1: 3,\n 2: 5,\n 3: 7,\n 4: 9,\n true: 9,\n 5: 10,\n 6: 16,\n 7: 19,\n 8: 22,\n 9: 26,\n 10: 34,\n 11: 42,\n 12: 50,\n}\n\nexport const tokens = createTokens({\n color,\n radius,\n zIndex,\n space,\n size,\n})\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAmB,oBAAoB;AAchC,MAAM,OAAO;AAAA,EAClB,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,IAAI;AAAA,EACJ,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,QAAQ;AAAA,EACR,IAAI;AAAA,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,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tamagui/themes",
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"types": "./types/index.d.ts",
|
|
5
|
+
"main": "dist/cjs",
|
|
6
|
+
"module": "dist/esm",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"files": [
|
|
9
|
+
"src",
|
|
10
|
+
"types",
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tamagui-build",
|
|
15
|
+
"watch": "tamagui-build --watch",
|
|
16
|
+
"lint": "../../node_modules/.bin/rome check src",
|
|
17
|
+
"lint:fix": "../../node_modules/.bin/rome check --apply-suggested src",
|
|
18
|
+
"clean": "tamagui-build clean",
|
|
19
|
+
"clean:build": "tamagui-build clean:build"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
"./package.json": "./package.json",
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./types/index.d.ts",
|
|
25
|
+
"import": "./dist/esm/index.mjs",
|
|
26
|
+
"require": "./dist/cjs/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./v2": {
|
|
29
|
+
"types": "./types/v2/index.d.ts",
|
|
30
|
+
"import": "./dist/esm/v2/index.mjs",
|
|
31
|
+
"require": "./dist/cjs/v2/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@tamagui/colors": "^1.4.0",
|
|
36
|
+
"@tamagui/core": "^1.4.0",
|
|
37
|
+
"@tamagui/create-theme": "^1.4.0",
|
|
38
|
+
"@tamagui/create-themes": "^1.4.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@tamagui/build": "^1.4.0"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14"
|
|
47
|
+
}
|
package/src/index.tsx
ADDED
package/src/themes.tsx
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addChildren,
|
|
3
|
+
applyMask,
|
|
4
|
+
createStrengthenMask,
|
|
5
|
+
createTheme,
|
|
6
|
+
createWeakenMask,
|
|
7
|
+
} from '@tamagui/create-theme'
|
|
8
|
+
|
|
9
|
+
import { colorTokens, darkColors, lightColors } from './tokens'
|
|
10
|
+
|
|
11
|
+
type ColorName = keyof typeof colorTokens.dark
|
|
12
|
+
|
|
13
|
+
const lightTransparent = 'rgba(255,255,255,0)'
|
|
14
|
+
const darkTransparent = 'rgba(10,10,10,0)'
|
|
15
|
+
|
|
16
|
+
// background => foreground
|
|
17
|
+
const palettes = {
|
|
18
|
+
dark: [
|
|
19
|
+
darkTransparent,
|
|
20
|
+
'#090909',
|
|
21
|
+
'#151515',
|
|
22
|
+
'#191919',
|
|
23
|
+
'#232323',
|
|
24
|
+
'#282828',
|
|
25
|
+
'#323232',
|
|
26
|
+
'#424242',
|
|
27
|
+
'#494949',
|
|
28
|
+
'#545454',
|
|
29
|
+
'#626262',
|
|
30
|
+
'#a5a5a5',
|
|
31
|
+
'#fff',
|
|
32
|
+
lightTransparent,
|
|
33
|
+
],
|
|
34
|
+
light: [
|
|
35
|
+
lightTransparent,
|
|
36
|
+
'#fff',
|
|
37
|
+
'#f4f4f4',
|
|
38
|
+
'hsl(0, 0%, 99.0%)',
|
|
39
|
+
'hsl(0, 0%, 97.3%)',
|
|
40
|
+
'hsl(0, 0%, 95.1%)',
|
|
41
|
+
'hsl(0, 0%, 93.0%)',
|
|
42
|
+
'hsl(0, 0%, 90.9%)',
|
|
43
|
+
'hsl(0, 0%, 80.0%)',
|
|
44
|
+
'hsl(0, 0%, 56.1%)',
|
|
45
|
+
'hsl(0, 0%, 52.3%)',
|
|
46
|
+
'hsl(0, 0%, 43.5%)',
|
|
47
|
+
'hsl(0, 0%, 9.0%)',
|
|
48
|
+
darkTransparent,
|
|
49
|
+
],
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const colorScale = {
|
|
53
|
+
color1: 1,
|
|
54
|
+
color2: 2,
|
|
55
|
+
color3: 3,
|
|
56
|
+
color4: 4,
|
|
57
|
+
color5: 5,
|
|
58
|
+
color6: 6,
|
|
59
|
+
color7: 7,
|
|
60
|
+
color8: 8,
|
|
61
|
+
color9: 9,
|
|
62
|
+
color10: 10,
|
|
63
|
+
color11: 11,
|
|
64
|
+
color12: 12,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// we can use subset of our template as a "skip" so it doesn't get adjusted with masks
|
|
68
|
+
const skip = {
|
|
69
|
+
...colorScale,
|
|
70
|
+
shadowColor: 1,
|
|
71
|
+
shadowColorHover: 1,
|
|
72
|
+
shadowColorPress: 2,
|
|
73
|
+
shadowColorFocus: 2,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// templates use the palette and specify index
|
|
77
|
+
// negative goes backwards from end so -1 is the last item
|
|
78
|
+
const template = {
|
|
79
|
+
...skip,
|
|
80
|
+
// the background, color, etc keys here work like generics - they make it so you
|
|
81
|
+
// can publish components for others to use without mandating a specific color scale
|
|
82
|
+
// the @tamagui/button Button component looks for `$background`, so you set the
|
|
83
|
+
// dark_red_Button theme to have a stronger background than the dark_red theme.
|
|
84
|
+
background: 2,
|
|
85
|
+
backgroundHover: 3,
|
|
86
|
+
backgroundPress: 1,
|
|
87
|
+
backgroundFocus: 2,
|
|
88
|
+
backgroundStrong: 1,
|
|
89
|
+
backgroundTransparent: 0,
|
|
90
|
+
color: -1,
|
|
91
|
+
colorHover: -2,
|
|
92
|
+
colorPress: -1,
|
|
93
|
+
colorFocus: -2,
|
|
94
|
+
colorTransparent: -0,
|
|
95
|
+
borderColor: 3,
|
|
96
|
+
borderColorHover: 4,
|
|
97
|
+
borderColorPress: 2,
|
|
98
|
+
borderColorFocus: 3,
|
|
99
|
+
placeholderColor: -4,
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const lightShadowColor = 'rgba(0,0,0,0.15)'
|
|
103
|
+
const lightShadowColorStrong = 'rgba(0,0,0,0.2)'
|
|
104
|
+
const darkShadowColor = 'rgba(0,0,0,0.5)'
|
|
105
|
+
const darkShadowColorStrong = 'rgba(0,0,0,0.7)'
|
|
106
|
+
|
|
107
|
+
const lightShadows = {
|
|
108
|
+
shadowColor: lightShadowColorStrong,
|
|
109
|
+
shadowColorHover: lightShadowColorStrong,
|
|
110
|
+
shadowColorPress: lightShadowColor,
|
|
111
|
+
shadowColorFocus: lightShadowColor,
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const darkShadows = {
|
|
115
|
+
shadowColor: darkShadowColorStrong,
|
|
116
|
+
shadowColorHover: darkShadowColorStrong,
|
|
117
|
+
shadowColorPress: darkShadowColor,
|
|
118
|
+
shadowColorFocus: darkShadowColor,
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const lightTemplate = {
|
|
122
|
+
...template,
|
|
123
|
+
...lightShadows,
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const darkTemplate = { ...template, ...darkShadows }
|
|
127
|
+
|
|
128
|
+
const light = createTheme(palettes.light, lightTemplate, {
|
|
129
|
+
nonInheritedValues: lightColors,
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
const dark = createTheme(palettes.dark, darkTemplate, { nonInheritedValues: darkColors })
|
|
133
|
+
|
|
134
|
+
const baseThemes = {
|
|
135
|
+
light,
|
|
136
|
+
dark,
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
type Theme = typeof light
|
|
140
|
+
|
|
141
|
+
// avoid transparent ends
|
|
142
|
+
const max = palettes.dark.length - 1
|
|
143
|
+
const masks = {
|
|
144
|
+
weaker: createWeakenMask({
|
|
145
|
+
by: 1,
|
|
146
|
+
min: 1,
|
|
147
|
+
max,
|
|
148
|
+
}),
|
|
149
|
+
stronger: createStrengthenMask({
|
|
150
|
+
by: 1,
|
|
151
|
+
min: 1,
|
|
152
|
+
max,
|
|
153
|
+
}),
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export const themes = addChildren(baseThemes, (name, themeIn) => {
|
|
157
|
+
const theme = themeIn as Theme
|
|
158
|
+
const inverseName = name === 'light' ? 'dark' : 'light'
|
|
159
|
+
const inverseTheme = baseThemes[inverseName]
|
|
160
|
+
const transparent = (hsl: string, opacity = 0) =>
|
|
161
|
+
hsl.replace(`%)`, `%, ${opacity})`).replace(`hsl(`, `hsla(`)
|
|
162
|
+
|
|
163
|
+
// setup colorThemes and their inverses
|
|
164
|
+
const [colorThemes, inverseColorThemes] = [
|
|
165
|
+
colorTokens[name],
|
|
166
|
+
colorTokens[inverseName],
|
|
167
|
+
].map((colorSet) => {
|
|
168
|
+
return Object.fromEntries(
|
|
169
|
+
Object.keys(colorSet).map((color) => {
|
|
170
|
+
const colorPalette = Object.values(colorSet[color as ColorName])
|
|
171
|
+
// we want a much lighter text color by default so swap them around a bit
|
|
172
|
+
const first6 = colorPalette.slice(0, 6)
|
|
173
|
+
const last5 = colorPalette.slice(colorPalette.length - 5)
|
|
174
|
+
return [
|
|
175
|
+
color,
|
|
176
|
+
createTheme(
|
|
177
|
+
[
|
|
178
|
+
transparent(colorPalette[0]),
|
|
179
|
+
...first6,
|
|
180
|
+
...last5,
|
|
181
|
+
theme.color,
|
|
182
|
+
transparent(colorPalette[colorPalette.length - 1]),
|
|
183
|
+
],
|
|
184
|
+
template
|
|
185
|
+
),
|
|
186
|
+
]
|
|
187
|
+
})
|
|
188
|
+
) as Record<ColorName, Theme>
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
...getAltThemes(theme, inverseTheme),
|
|
193
|
+
...getComponentThemes(theme, inverseTheme),
|
|
194
|
+
...addChildren(colorThemes, (colorName, colorTheme) => {
|
|
195
|
+
const inverse = inverseColorThemes[colorName]
|
|
196
|
+
return {
|
|
197
|
+
...getAltThemes(colorTheme as any, inverse as any),
|
|
198
|
+
...getComponentThemes(colorTheme as any, inverse as any),
|
|
199
|
+
}
|
|
200
|
+
}),
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function getComponentThemes(theme: Theme, inverse: Theme) {
|
|
204
|
+
const stronger1 = applyMask(theme, masks.stronger, { skip })
|
|
205
|
+
const stronger2 = applyMask(stronger1, masks.stronger, { skip })
|
|
206
|
+
const inverse1 = applyMask(inverse, masks.weaker, { skip })
|
|
207
|
+
const inverse2 = applyMask(inverse1, masks.weaker, { skip })
|
|
208
|
+
return {
|
|
209
|
+
Button: stronger2,
|
|
210
|
+
DrawerFrame: stronger1,
|
|
211
|
+
SliderTrack: theme,
|
|
212
|
+
SliderTrackActive: stronger2,
|
|
213
|
+
SliderThumb: inverse1,
|
|
214
|
+
Progress: stronger1,
|
|
215
|
+
ProgressIndicator: inverse,
|
|
216
|
+
Switch: stronger2,
|
|
217
|
+
SwitchThumb: inverse2,
|
|
218
|
+
TooltipArrow: stronger1,
|
|
219
|
+
TooltipContent: stronger2,
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function getAltThemes(theme: Theme, inverse: Theme) {
|
|
224
|
+
const alt1 = applyMask(theme, masks.weaker, { skip })
|
|
225
|
+
const alt2 = applyMask(alt1, masks.weaker, { skip })
|
|
226
|
+
return addChildren({ alt1, alt2 }, (name, theme) => {
|
|
227
|
+
return getComponentThemes(theme as any, inverse)
|
|
228
|
+
})
|
|
229
|
+
}
|
|
230
|
+
})
|
package/src/tokens.tsx
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import {
|
|
2
|
+
blue,
|
|
3
|
+
blueDark,
|
|
4
|
+
gray,
|
|
5
|
+
grayDark,
|
|
6
|
+
green,
|
|
7
|
+
greenDark,
|
|
8
|
+
orange,
|
|
9
|
+
orangeDark,
|
|
10
|
+
pink,
|
|
11
|
+
pinkDark,
|
|
12
|
+
purple,
|
|
13
|
+
purpleDark,
|
|
14
|
+
red,
|
|
15
|
+
redDark,
|
|
16
|
+
yellow,
|
|
17
|
+
yellowDark,
|
|
18
|
+
} from '@tamagui/colors'
|
|
19
|
+
import { Variable, createTokens } from '@tamagui/web'
|
|
20
|
+
|
|
21
|
+
// should roughly map to button/input etc height at each level
|
|
22
|
+
// fonts should match that height/lineHeight at each stop
|
|
23
|
+
// so these are really non-linear on purpose
|
|
24
|
+
// why?
|
|
25
|
+
// - at sizes <1, used for fine grained things (borders, smallest paddingY)
|
|
26
|
+
// - so smallest padY should be roughly 1-4px so it can join with lineHeight
|
|
27
|
+
// - at sizes >=1, have to consider "pressability" (jumps up)
|
|
28
|
+
// - after that it should go upwards somewhat naturally
|
|
29
|
+
// - H1 / headings top out at 10 naturally, so after 10 we can go upwards faster
|
|
30
|
+
// but also one more wrinkle...
|
|
31
|
+
// space is used in conjunction with size
|
|
32
|
+
// i'm setting space to generally just a fixed fraction of size (~1/3-2/3 still fine tuning)
|
|
33
|
+
export const size = {
|
|
34
|
+
$0: 0,
|
|
35
|
+
'$0.25': 2,
|
|
36
|
+
'$0.5': 4,
|
|
37
|
+
'$0.75': 8,
|
|
38
|
+
$1: 20,
|
|
39
|
+
'$1.5': 24,
|
|
40
|
+
$2: 28,
|
|
41
|
+
'$2.5': 32,
|
|
42
|
+
$3: 36,
|
|
43
|
+
'$3.5': 40,
|
|
44
|
+
$4: 44,
|
|
45
|
+
$true: 44,
|
|
46
|
+
'$4.5': 48,
|
|
47
|
+
$5: 52,
|
|
48
|
+
$6: 64,
|
|
49
|
+
$7: 74,
|
|
50
|
+
$8: 84,
|
|
51
|
+
$9: 94,
|
|
52
|
+
$10: 104,
|
|
53
|
+
$11: 124,
|
|
54
|
+
$12: 144,
|
|
55
|
+
$13: 164,
|
|
56
|
+
$14: 184,
|
|
57
|
+
$15: 204,
|
|
58
|
+
$16: 224,
|
|
59
|
+
$17: 224,
|
|
60
|
+
$18: 244,
|
|
61
|
+
$19: 264,
|
|
62
|
+
$20: 284,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type SizeKeysIn = keyof typeof size
|
|
66
|
+
type Sizes = {
|
|
67
|
+
[Key in SizeKeysIn extends `$${infer Key}` ? Key : SizeKeysIn]: number
|
|
68
|
+
}
|
|
69
|
+
type SizeKeys = `${keyof Sizes extends `${infer K}` ? K : never}`
|
|
70
|
+
|
|
71
|
+
const spaces = Object.entries(size).map(([k, v]) => {
|
|
72
|
+
return [k, sizeToSpace(v)]
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
// a bit odd but keeping backward compat for values >8 while fixing below
|
|
76
|
+
function sizeToSpace(v: number) {
|
|
77
|
+
if (v === 0) return 0
|
|
78
|
+
if (v === 2) return 0.5
|
|
79
|
+
if (v === 4) return 1
|
|
80
|
+
if (v === 8) return 1.5
|
|
81
|
+
if (v <= 16) return Math.round(v * 0.333)
|
|
82
|
+
return Math.floor(v * 0.7 - 12)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const spacesNegative = spaces.map(([k, v]) => [`-${(k as string).slice(1)}`, -v])
|
|
86
|
+
|
|
87
|
+
type SizeKeysWithNegatives =
|
|
88
|
+
| `-${SizeKeys extends `$${infer Key}` ? Key : SizeKeys}`
|
|
89
|
+
| SizeKeys
|
|
90
|
+
|
|
91
|
+
export const space: {
|
|
92
|
+
[Key in SizeKeysWithNegatives]: Key extends keyof Sizes ? Sizes[Key] : number
|
|
93
|
+
} = {
|
|
94
|
+
...Object.fromEntries(spaces),
|
|
95
|
+
...Object.fromEntries(spacesNegative),
|
|
96
|
+
} as any
|
|
97
|
+
|
|
98
|
+
export const zIndex = {
|
|
99
|
+
0: 0,
|
|
100
|
+
1: 100,
|
|
101
|
+
2: 200,
|
|
102
|
+
3: 300,
|
|
103
|
+
4: 400,
|
|
104
|
+
5: 500,
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const colorTokens = {
|
|
108
|
+
light: {
|
|
109
|
+
blue: blue,
|
|
110
|
+
gray: gray,
|
|
111
|
+
green: green,
|
|
112
|
+
orange: orange,
|
|
113
|
+
pink: pink,
|
|
114
|
+
purple: purple,
|
|
115
|
+
red: red,
|
|
116
|
+
yellow: yellow,
|
|
117
|
+
},
|
|
118
|
+
dark: {
|
|
119
|
+
blue: blueDark,
|
|
120
|
+
gray: grayDark,
|
|
121
|
+
green: greenDark,
|
|
122
|
+
orange: orangeDark,
|
|
123
|
+
pink: pinkDark,
|
|
124
|
+
purple: purpleDark,
|
|
125
|
+
red: redDark,
|
|
126
|
+
yellow: yellowDark,
|
|
127
|
+
},
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const darkColors = {
|
|
131
|
+
...colorTokens.dark.blue,
|
|
132
|
+
...colorTokens.dark.gray,
|
|
133
|
+
...colorTokens.dark.green,
|
|
134
|
+
...colorTokens.dark.orange,
|
|
135
|
+
...colorTokens.dark.pink,
|
|
136
|
+
...colorTokens.dark.purple,
|
|
137
|
+
...colorTokens.dark.red,
|
|
138
|
+
...colorTokens.dark.yellow,
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export const lightColors = {
|
|
142
|
+
...colorTokens.light.blue,
|
|
143
|
+
...colorTokens.light.gray,
|
|
144
|
+
...colorTokens.light.green,
|
|
145
|
+
...colorTokens.light.orange,
|
|
146
|
+
...colorTokens.light.pink,
|
|
147
|
+
...colorTokens.light.purple,
|
|
148
|
+
...colorTokens.light.red,
|
|
149
|
+
...colorTokens.light.yellow,
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export const color = {
|
|
153
|
+
...postfixObjKeys(lightColors, 'Light'),
|
|
154
|
+
...postfixObjKeys(darkColors, 'Dark'),
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function postfixObjKeys<
|
|
158
|
+
A extends { [key: string]: Variable<string> | string },
|
|
159
|
+
B extends string
|
|
160
|
+
>(
|
|
161
|
+
obj: A,
|
|
162
|
+
postfix: B
|
|
163
|
+
): {
|
|
164
|
+
[Key in `${keyof A extends string ? keyof A : never}${B}`]: Variable<string> | string
|
|
165
|
+
} {
|
|
166
|
+
return Object.fromEntries(
|
|
167
|
+
Object.entries(obj).map(([k, v]) => [`${k}${postfix}`, v])
|
|
168
|
+
) as any
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export const radius = {
|
|
172
|
+
0: 0,
|
|
173
|
+
1: 3,
|
|
174
|
+
2: 5,
|
|
175
|
+
3: 7,
|
|
176
|
+
4: 9,
|
|
177
|
+
true: 9,
|
|
178
|
+
5: 10,
|
|
179
|
+
6: 16,
|
|
180
|
+
7: 19,
|
|
181
|
+
8: 22,
|
|
182
|
+
9: 26,
|
|
183
|
+
10: 34,
|
|
184
|
+
11: 42,
|
|
185
|
+
12: 50,
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export const tokens = createTokens({
|
|
189
|
+
color,
|
|
190
|
+
radius,
|
|
191
|
+
zIndex,
|
|
192
|
+
space,
|
|
193
|
+
size,
|
|
194
|
+
})
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA"}
|