@tamagui/theme-base 1.0.1-beta.21 → 1.0.1-beta.211

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/package.json CHANGED
@@ -1,26 +1,37 @@
1
1
  {
2
2
  "name": "@tamagui/theme-base",
3
- "version": "1.0.1-beta.21",
4
- "typings": "types",
3
+ "version": "1.0.1-beta.211",
4
+ "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
7
- "module:jsx": "dist/jsx",
7
+ "sideEffects": false,
8
8
  "files": [
9
+ "src",
9
10
  "types",
10
11
  "dist"
11
12
  ],
12
13
  "scripts": {
13
14
  "build": "tamagui-build",
14
15
  "watch": "tamagui-build --watch",
16
+ "lint": "eslint",
17
+ "lint:fix": "yarn lint --fix",
15
18
  "clean": "tamagui-build clean",
16
19
  "clean:build": "tamagui-build clean:build"
17
20
  },
21
+ "exports": {
22
+ "./package.json": "./package.json",
23
+ ".": {
24
+ "import": "./dist/esm/index.js",
25
+ "require": "./dist/cjs/index.js"
26
+ }
27
+ },
18
28
  "dependencies": {
19
- "@tamagui/colors": "^1.0.1-beta.21",
20
- "@tamagui/core": "^1.0.1-beta.21"
29
+ "@tamagui/colors": "^1.0.1-beta.211",
30
+ "@tamagui/core": "^1.0.1-beta.211",
31
+ "@tamagui/create-themes": "^1.0.1-beta.211"
21
32
  },
22
33
  "devDependencies": {
23
- "@tamagui/build": "^1.0.1-beta.21"
34
+ "@tamagui/build": "^1.0.1-beta.211"
24
35
  },
25
36
  "publishConfig": {
26
37
  "access": "public"
@@ -0,0 +1,42 @@
1
+ import { Variable, getVariableValue } from '@tamagui/core'
2
+
3
+ export const hexToRGBA = (hex: string, alpha = 1) => {
4
+ if (!isValidHex(hex)) {
5
+ throw new Error('Invalid HEX')
6
+ }
7
+ const chunkSize = Math.floor((hex.length - 1) / 3)
8
+ const hexArr = getChunksFromString(hex.slice(1), chunkSize)
9
+ const [r, g, b, a] = hexArr?.map(convertHexUnitTo256) ?? []
10
+ return `rgba(${r}, ${g}, ${b}, ${getAlphaFloat(a, alpha)})`
11
+ }
12
+
13
+ export const setColorAlpha = (colorIn: string | Variable, alpha = 1) => {
14
+ let color = `${getVariableValue(colorIn)}`
15
+ if (color.startsWith('hsl(')) {
16
+ return color.replace('hsl', 'hsla').replace(')', `, ${alpha})`)
17
+ }
18
+ if (color.startsWith('#')) {
19
+ return hexToRGBA(color, alpha)
20
+ }
21
+ if (color.startsWith('rgb(')) {
22
+ return color.replace('rgb', 'rgba').replace(')', `, ${alpha})`)
23
+ }
24
+ return color
25
+ }
26
+
27
+ const isValidHex = (hex: string) => /^#([A-Fa-f0-9]{3,4}){1,2}$/.test(hex)
28
+
29
+ const getChunksFromString = (st: string, chunkSize = 0) =>
30
+ st.match(new RegExp(`.{${chunkSize}}`, 'g'))
31
+
32
+ const convertHexUnitTo256 = (hexStr: string) => parseInt(hexStr.repeat(2 / hexStr.length), 16)
33
+
34
+ const getAlphaFloat = (a: any, alpha = 1) => {
35
+ if (a !== undefined) {
36
+ return a / 255
37
+ }
38
+ if (typeof alpha != 'number' || alpha < 0 || alpha > 1) {
39
+ return 1
40
+ }
41
+ return alpha
42
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,3 @@
1
+ export * from './themes'
2
+ export * from './tokens'
3
+ export * from '@tamagui/colors'
package/src/themes.tsx ADDED
@@ -0,0 +1,39 @@
1
+ import { createThemes } from '@tamagui/create-themes'
2
+
3
+ import { colorTokens } from './tokens'
4
+
5
+ export const themes = createThemes<keyof typeof colorTokens.light>({
6
+ activeColor: 'blue',
7
+ light: [
8
+ '#fff',
9
+ '#f4f4f4',
10
+ 'hsl(0, 0%, 99.0%)',
11
+ 'hsl(0, 0%, 97.3%)',
12
+ 'hsl(0, 0%, 95.1%)',
13
+ 'hsl(0, 0%, 93.0%)',
14
+ 'hsl(0, 0%, 90.9%)',
15
+ 'hsl(0, 0%, 88.7%)',
16
+ 'hsl(0, 0%, 85.8%)',
17
+ 'hsl(0, 0%, 78.0%)',
18
+ 'hsl(0, 0%, 56.1%)',
19
+ 'hsl(0, 0%, 52.3%)',
20
+ 'hsl(0, 0%, 43.5%)',
21
+ 'hsl(0, 0%, 9.0%)',
22
+ ],
23
+ dark: [
24
+ '#111111',
25
+ '#151515',
26
+ '#191919',
27
+ '#232323',
28
+ '#282828',
29
+ '#323232',
30
+ '#383838',
31
+ '#424242',
32
+ '#494949',
33
+ '#545454',
34
+ '#626262',
35
+ '#777777',
36
+ ],
37
+ colorsLight: colorTokens.light,
38
+ colorsDark: colorTokens.dark,
39
+ })
package/src/tokens.tsx ADDED
@@ -0,0 +1,172 @@
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/core'
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 Sizes = typeof size
66
+ type SizeKeys = `${keyof Sizes}`
67
+
68
+ const spaces = Object.entries(size).map(([k, v]) => [
69
+ k,
70
+ Math.max(0, v <= 16 ? Math.round(v * 0.333) : Math.floor(v * 0.7 - 12)),
71
+ ])
72
+
73
+ const spacesNegative = spaces.map(([k, v]) => [`-${k}`, -v])
74
+
75
+ export const space: {
76
+ [Key in `-${SizeKeys}` | SizeKeys]: Key extends keyof Sizes ? Sizes[Key] : number
77
+ } = {
78
+ ...Object.fromEntries(spaces),
79
+ ...Object.fromEntries(spacesNegative),
80
+ } as any
81
+
82
+ export const zIndex = {
83
+ 0: 0,
84
+ 1: 100,
85
+ 2: 200,
86
+ 3: 300,
87
+ 4: 400,
88
+ 5: 500,
89
+ }
90
+
91
+ export const colorTokens = {
92
+ light: {
93
+ blue: blue,
94
+ gray: gray,
95
+ green: green,
96
+ orange: orange,
97
+ pink: pink,
98
+ purple: purple,
99
+ red: red,
100
+ yellow: yellow,
101
+ },
102
+ dark: {
103
+ blue: blueDark,
104
+ gray: grayDark,
105
+ green: greenDark,
106
+ orange: orangeDark,
107
+ pink: pinkDark,
108
+ purple: purpleDark,
109
+ red: redDark,
110
+ yellow: yellowDark,
111
+ },
112
+ }
113
+
114
+ export const darkColors = {
115
+ ...colorTokens.dark.blue,
116
+ ...colorTokens.dark.gray,
117
+ ...colorTokens.dark.green,
118
+ ...colorTokens.dark.orange,
119
+ ...colorTokens.dark.pink,
120
+ ...colorTokens.dark.purple,
121
+ ...colorTokens.dark.red,
122
+ ...colorTokens.dark.yellow,
123
+ }
124
+
125
+ export const lightColors = {
126
+ ...colorTokens.light.blue,
127
+ ...colorTokens.light.gray,
128
+ ...colorTokens.light.green,
129
+ ...colorTokens.light.orange,
130
+ ...colorTokens.light.pink,
131
+ ...colorTokens.light.purple,
132
+ ...colorTokens.light.red,
133
+ ...colorTokens.light.yellow,
134
+ }
135
+
136
+ export const color = {
137
+ ...postfixObjKeys(lightColors, 'Light'),
138
+ ...postfixObjKeys(darkColors, 'Dark'),
139
+ }
140
+
141
+ function postfixObjKeys<A extends { [key: string]: Variable<string> | string }, B extends string>(
142
+ obj: A,
143
+ postfix: B
144
+ ): {
145
+ [Key in `${keyof A extends string ? keyof A : never}${B}`]: Variable<string> | string
146
+ } {
147
+ return Object.fromEntries(Object.entries(obj).map(([k, v]) => [`${k}${postfix}`, v])) as any
148
+ }
149
+
150
+ export const radius = {
151
+ 0: 0,
152
+ 1: 3,
153
+ 2: 5,
154
+ 3: 7,
155
+ 4: 9,
156
+ 5: 10,
157
+ 6: 16,
158
+ 7: 19,
159
+ 8: 22,
160
+ 9: 26,
161
+ 10: 34,
162
+ 11: 42,
163
+ 12: 50,
164
+ }
165
+
166
+ export const tokens = createTokens({
167
+ color,
168
+ radius,
169
+ zIndex,
170
+ space,
171
+ size,
172
+ })