ferns-ui 0.37.0 → 0.37.2
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/Avatar.js +5 -6
- package/dist/Avatar.js.map +1 -1
- package/dist/Badge.js +4 -3
- package/dist/Badge.js.map +1 -1
- package/dist/Body.d.ts +10 -5
- package/dist/Body.js +14 -15
- package/dist/Body.js.map +1 -1
- package/dist/Box.js +9 -7
- package/dist/Box.js.map +1 -1
- package/dist/Button.js +5 -3
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +7 -19
- package/dist/Common.js.map +1 -1
- package/dist/DateTimeActionSheet.js +9 -7
- package/dist/DateTimeActionSheet.js.map +1 -1
- package/dist/DateTimeField.android.js +5 -4
- package/dist/DateTimeField.android.js.map +1 -1
- package/dist/DateTimeField.ios.js +6 -5
- package/dist/DateTimeField.ios.js.map +1 -1
- package/dist/FernsProvider.js +4 -2
- package/dist/FernsProvider.js.map +1 -1
- package/dist/Heading.d.ts +1 -9
- package/dist/Heading.js +22 -43
- package/dist/Heading.js.map +1 -1
- package/dist/Icon.js +4 -3
- package/dist/Icon.js.map +1 -1
- package/dist/IconButton.d.ts +1 -1
- package/dist/IconButton.js +4 -2
- package/dist/IconButton.js.map +1 -1
- package/dist/Modal.js +2 -1
- package/dist/Modal.js.map +1 -1
- package/dist/Page.js +1 -3
- package/dist/Page.js.map +1 -1
- package/dist/ProgressBar.d.ts +5 -7
- package/dist/ProgressBar.js +30 -36
- package/dist/ProgressBar.js.map +1 -1
- package/dist/SelectList.js +6 -5
- package/dist/SelectList.js.map +1 -1
- package/dist/Spinner.d.ts +5 -1
- package/dist/Spinner.js +1 -1
- package/dist/Spinner.js.map +1 -1
- package/dist/SplitPage.js +4 -3
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.js +4 -2
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/Text.js +6 -5
- package/dist/Text.js.map +1 -1
- package/dist/TextField.js +11 -10
- package/dist/TextField.js.map +1 -1
- package/dist/Theme.d.ts +12 -0
- package/dist/Theme.js +108 -0
- package/dist/Theme.js.map +1 -0
- package/dist/Tooltip.js +4 -2
- package/dist/Tooltip.js.map +1 -1
- package/dist/Unifier.d.ts +1 -6
- package/dist/Unifier.js +0 -134
- package/dist/Unifier.js.map +1 -1
- package/dist/Utilities.d.ts +1 -0
- package/dist/Utilities.js +4 -0
- package/dist/Utilities.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Avatar.tsx +6 -6
- package/src/Badge.tsx +5 -3
- package/src/Body.tsx +32 -21
- package/src/Box.tsx +10 -8
- package/src/Button.tsx +5 -3
- package/src/Common.ts +11 -22
- package/src/DateTimeActionSheet.tsx +11 -7
- package/src/DateTimeField.android.tsx +5 -4
- package/src/DateTimeField.ios.tsx +6 -5
- package/src/FernsProvider.tsx +14 -11
- package/src/Heading.tsx +27 -44
- package/src/Icon.tsx +4 -3
- package/src/IconButton.tsx +12 -3
- package/src/Modal.tsx +2 -1
- package/src/Page.tsx +1 -5
- package/src/ProgressBar.tsx +41 -44
- package/src/SelectList.tsx +7 -5
- package/src/Spinner.tsx +7 -2
- package/src/SplitPage.native.tsx +4 -2
- package/src/SplitPage.tsx +4 -3
- package/src/Text.tsx +7 -5
- package/src/TextField.tsx +13 -11
- package/src/Theme.tsx +189 -0
- package/src/Tooltip.tsx +4 -2
- package/src/Unifier.ts +0 -196
- package/src/Utilities.tsx +5 -0
- package/src/index.tsx +1 -0
package/src/Unifier.ts
CHANGED
|
@@ -3,116 +3,15 @@
|
|
|
3
3
|
|
|
4
4
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
5
5
|
import * as Clipboard from "expo-clipboard";
|
|
6
|
-
import * as Font from "expo-font";
|
|
7
|
-
import {FontSource} from "expo-font";
|
|
8
6
|
import * as Haptics from "expo-haptics";
|
|
9
7
|
import {Dimensions, Keyboard, Linking, Platform, Vibration} from "react-native";
|
|
10
8
|
|
|
11
9
|
import {PermissionKind, UnifiedTheme} from "./Common";
|
|
12
10
|
import {requestPermissions} from "./Permissions";
|
|
13
11
|
|
|
14
|
-
function capitalize(string: string) {
|
|
15
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const DEFAULT_FONT = "Cochin";
|
|
19
|
-
const DEFAULT_BOLD_FONT = "Cochin";
|
|
20
|
-
|
|
21
|
-
const DefaultTheme: UnifiedTheme = {
|
|
22
|
-
// Primary colors
|
|
23
|
-
red: "#bd081c",
|
|
24
|
-
white: "#fdfdfd",
|
|
25
|
-
lightGray: "#efefef",
|
|
26
|
-
gray: "#8e8e8e",
|
|
27
|
-
darkGray: "#111",
|
|
28
|
-
// secondary colors
|
|
29
|
-
green: "#0fa573",
|
|
30
|
-
springGreen: "#008753",
|
|
31
|
-
pine: "#0a6955",
|
|
32
|
-
olive: "#364a4c",
|
|
33
|
-
blue: "#4a90e2",
|
|
34
|
-
navy: "#004b91",
|
|
35
|
-
midnight: "#133a5e",
|
|
36
|
-
purple: "#b469eb",
|
|
37
|
-
orchid: "#8046a5",
|
|
38
|
-
eggplant: "#5b2677",
|
|
39
|
-
maroon: "#6e0f3c",
|
|
40
|
-
watermelon: "#f13535",
|
|
41
|
-
orange: "#e3780c",
|
|
42
|
-
black: "#000000",
|
|
43
|
-
|
|
44
|
-
primaryLighter: "#4ED456",
|
|
45
|
-
primaryLight: "#28CA32",
|
|
46
|
-
primary: "#00BD0C",
|
|
47
|
-
primaryDark: "#00960A",
|
|
48
|
-
primaryDarker: "#007508",
|
|
49
|
-
|
|
50
|
-
secondaryLighter: "#41AAAE",
|
|
51
|
-
secondaryLight: "#20989D",
|
|
52
|
-
secondary: "#018B91",
|
|
53
|
-
secondaryDark: "#016E73",
|
|
54
|
-
secondaryDarker: "#00565A",
|
|
55
|
-
|
|
56
|
-
accentLighter: "#FF625D",
|
|
57
|
-
accentLight: "#FF3732",
|
|
58
|
-
accent: "#F00600",
|
|
59
|
-
accentDark: "#BE0500",
|
|
60
|
-
accentDarker: "#950400",
|
|
61
|
-
|
|
62
|
-
tertiaryLighter: "#FFCF67",
|
|
63
|
-
tertiaryLight: "#FFC23E",
|
|
64
|
-
tertiary: "#FFB109",
|
|
65
|
-
tertiaryDark: "#CA8A00",
|
|
66
|
-
tertiaryDarker: "#9F6D00",
|
|
67
|
-
|
|
68
|
-
// From the Atlassian templates
|
|
69
|
-
neutral900: "#091E42",
|
|
70
|
-
neutral800: "#172B4D",
|
|
71
|
-
neutral700: "#253858",
|
|
72
|
-
neutral600: "#344563",
|
|
73
|
-
neutral500: "#42526E",
|
|
74
|
-
neutral400: "#505F79",
|
|
75
|
-
neutral300: "#5E6C84",
|
|
76
|
-
neutral200: "#6B778C",
|
|
77
|
-
neutral100: "#7A869A",
|
|
78
|
-
neutral90: "#8993A4",
|
|
79
|
-
neutral80: "#97A0AF",
|
|
80
|
-
neutral70: "#A5ADBA",
|
|
81
|
-
neutral60: "#B3BAC5",
|
|
82
|
-
neutral50: "#C1C7D0",
|
|
83
|
-
neutral40: "#DFE1E6",
|
|
84
|
-
neutral30: "#EBECF0",
|
|
85
|
-
neutral20: "#F4F5F7",
|
|
86
|
-
neutral10: "#FAFBFC",
|
|
87
|
-
|
|
88
|
-
primaryFont: DEFAULT_FONT,
|
|
89
|
-
primaryBoldFont: DEFAULT_BOLD_FONT,
|
|
90
|
-
|
|
91
|
-
secondaryFont: DEFAULT_FONT,
|
|
92
|
-
secondaryBoldFont: DEFAULT_BOLD_FONT,
|
|
93
|
-
|
|
94
|
-
accentFont: DEFAULT_FONT,
|
|
95
|
-
accentBoldFont: DEFAULT_BOLD_FONT,
|
|
96
|
-
|
|
97
|
-
buttonFont: DEFAULT_FONT,
|
|
98
|
-
titleFont: DEFAULT_FONT,
|
|
99
|
-
};
|
|
100
|
-
|
|
101
12
|
export type PlatformOS = "ios" | "android" | "web";
|
|
102
13
|
|
|
103
|
-
const fontKeys = [
|
|
104
|
-
"primaryFont",
|
|
105
|
-
"primaryBoldFont",
|
|
106
|
-
"secondaryFont",
|
|
107
|
-
"secondaryBoldFont",
|
|
108
|
-
"buttonFont",
|
|
109
|
-
"accentFont",
|
|
110
|
-
"accentBoldFont",
|
|
111
|
-
"titleFont",
|
|
112
|
-
];
|
|
113
|
-
|
|
114
14
|
type Luminance = "light" | "lighter" | "dark" | "darker";
|
|
115
|
-
const luminances: Luminance[] = ["lighter", "light", "dark", "darker"];
|
|
116
15
|
|
|
117
16
|
// Changes a color luminance
|
|
118
17
|
export function changeColorLuminance(hex: string, luminanceChange: Luminance) {
|
|
@@ -170,93 +69,6 @@ class UnifierClass {
|
|
|
170
69
|
return this._dev;
|
|
171
70
|
}
|
|
172
71
|
|
|
173
|
-
private get fontMap() {
|
|
174
|
-
const fontMap: {[id: string]: FontSource} = {};
|
|
175
|
-
for (const key of fontKeys) {
|
|
176
|
-
if (typeof this.theme[key as keyof typeof Unifier.theme] === "string") {
|
|
177
|
-
fontMap[key] = key;
|
|
178
|
-
} else {
|
|
179
|
-
fontMap[(this.theme as any)[key].name] = (this.theme as any)[key].source;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return fontMap;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// If the theme only has e.g. "primary" set, calculate the primaryLighter, primaryLight, etc based on that color.
|
|
186
|
-
private calculateLuminances(
|
|
187
|
-
theme: Partial<UnifiedTheme>,
|
|
188
|
-
color: "primary" | "secondary" | "accent" | "tertiary"
|
|
189
|
-
) {
|
|
190
|
-
if (!theme[color]) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
for (const luminance of luminances) {
|
|
194
|
-
const capitalized = capitalize(luminance);
|
|
195
|
-
if (!theme[`${color}${capitalized}` as keyof typeof Unifier.theme] && theme[color]) {
|
|
196
|
-
theme[`${color}${capitalized}` as keyof typeof Unifier.theme] = changeColorLuminance(
|
|
197
|
-
theme[color] as string,
|
|
198
|
-
luminance
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
setTheme(theme: Partial<UnifiedTheme>) {
|
|
205
|
-
Unifier.calculateLuminances(theme, "primary");
|
|
206
|
-
Unifier.calculateLuminances(theme, "secondary");
|
|
207
|
-
Unifier.calculateLuminances(theme, "accent");
|
|
208
|
-
Unifier.calculateLuminances(theme, "tertiary");
|
|
209
|
-
this._theme = theme;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
get theme(): UnifiedTheme {
|
|
213
|
-
return {
|
|
214
|
-
...DefaultTheme,
|
|
215
|
-
// Custom per project
|
|
216
|
-
primaryLighter: this._theme?.primaryLighter || this._theme?.primary || DefaultTheme.primary,
|
|
217
|
-
primaryLight: this._theme?.primaryLight || this._theme?.primary || DefaultTheme.primary,
|
|
218
|
-
primary: this._theme?.primary || this._theme?.primary || DefaultTheme.primary,
|
|
219
|
-
primaryDark: this._theme?.primaryDark || this._theme?.primary || DefaultTheme.primary,
|
|
220
|
-
primaryDarker: this._theme?.primaryDarker || this._theme?.primary || DefaultTheme.primary,
|
|
221
|
-
|
|
222
|
-
secondaryLighter:
|
|
223
|
-
this._theme?.secondaryLighter || this._theme?.secondary || DefaultTheme.secondary,
|
|
224
|
-
secondaryLight:
|
|
225
|
-
this._theme?.secondaryLight || this._theme?.secondary || DefaultTheme.secondary,
|
|
226
|
-
secondary: this._theme?.secondary || this._theme?.secondary || DefaultTheme.secondary,
|
|
227
|
-
secondaryDark: this._theme?.secondaryDark || this._theme?.secondary || DefaultTheme.secondary,
|
|
228
|
-
secondaryDarker:
|
|
229
|
-
this._theme?.secondaryDarker || this._theme?.secondary || DefaultTheme.secondary,
|
|
230
|
-
|
|
231
|
-
accentLighter: this._theme?.accentLighter || this._theme?.accent || DefaultTheme.accent,
|
|
232
|
-
accentLight: this._theme?.accentLight || this._theme?.accent || DefaultTheme.accent,
|
|
233
|
-
accent: this._theme?.accent || this._theme?.accent || DefaultTheme.accent,
|
|
234
|
-
accentDark: this._theme?.accentDark || this._theme?.accent || DefaultTheme.accent,
|
|
235
|
-
accentDarker: this._theme?.accentDarker || this._theme?.accent || DefaultTheme.accent,
|
|
236
|
-
|
|
237
|
-
tertiaryLighter: this._theme?.tertiaryLighter || this._theme?.accent || DefaultTheme.accent,
|
|
238
|
-
tertiaryLight: this._theme?.tertiaryLight || this._theme?.accent || DefaultTheme.accent,
|
|
239
|
-
tertiary: this._theme?.tertiary || this._theme?.accent || DefaultTheme.accent,
|
|
240
|
-
tertiaryDark: this._theme?.tertiaryDark || this._theme?.accent || DefaultTheme.accent,
|
|
241
|
-
tertiaryDarker: this._theme?.tertiaryDarker || this._theme?.accent || DefaultTheme.accent,
|
|
242
|
-
|
|
243
|
-
primaryFont: this._theme?.primaryFont || DefaultTheme.primaryFont,
|
|
244
|
-
primaryBoldFont:
|
|
245
|
-
this._theme?.primaryBoldFont || this._theme?.primaryFont || DefaultTheme.primaryBoldFont,
|
|
246
|
-
secondaryFont:
|
|
247
|
-
this._theme?.secondaryFont || this._theme?.primaryFont || DefaultTheme.secondaryFont,
|
|
248
|
-
secondaryBoldFont:
|
|
249
|
-
this._theme?.secondaryBoldFont ||
|
|
250
|
-
this._theme?.primaryFont ||
|
|
251
|
-
DefaultTheme.secondaryBoldFont,
|
|
252
|
-
buttonFont: this._theme?.buttonFont || this._theme?.primaryFont || DefaultTheme.buttonFont,
|
|
253
|
-
accentFont: this._theme?.accentFont || this._theme?.primaryFont || DefaultTheme.accentFont,
|
|
254
|
-
accentBoldFont:
|
|
255
|
-
this._theme?.accentBoldFont || this._theme?.primaryFont || DefaultTheme.accentBoldFont,
|
|
256
|
-
titleFont: this._theme?.titleFont || this._theme?.primaryFont || DefaultTheme.titleFont,
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
|
|
260
72
|
constructor() {
|
|
261
73
|
console.debug("[unifier] Setting up Unifier");
|
|
262
74
|
}
|
|
@@ -267,14 +79,6 @@ class UnifierClass {
|
|
|
267
79
|
},
|
|
268
80
|
};
|
|
269
81
|
|
|
270
|
-
loadFonts = async () => {
|
|
271
|
-
try {
|
|
272
|
-
await Font.loadAsync(this.fontMap);
|
|
273
|
-
} catch (err) {
|
|
274
|
-
console.error(`[unifier] Fonts failed to load: ${err}`);
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
|
|
278
82
|
// tracking: Tracking,
|
|
279
83
|
utils = {
|
|
280
84
|
dismissKeyboard: () => {
|
package/src/Utilities.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Originally based on https://github.com/pinterest/gestalt
|
|
2
2
|
// Forked, updated to Typescript, and added features.
|
|
3
3
|
import get from "lodash/get";
|
|
4
|
+
import {Platform} from "react-native";
|
|
4
5
|
|
|
5
6
|
export function mergeInlineStyles(inlineStyle?: any, newStyle?: any) {
|
|
6
7
|
const inline = get(inlineStyle, "__style");
|
|
@@ -157,3 +158,7 @@ export const union =
|
|
|
157
158
|
<T,>(...fns: Functor<T>[]) =>
|
|
158
159
|
(val: T) =>
|
|
159
160
|
concat(fns.map((fn) => fn(val)));
|
|
161
|
+
|
|
162
|
+
export const isNative = (): boolean => {
|
|
163
|
+
return ["android", "ios"].includes(Platform.OS);
|
|
164
|
+
};
|