@open-tender/utils 0.0.4 → 0.0.6
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/utils/cart.d.ts +1 -1
- package/dist/cjs/utils/datetimes.d.ts +10 -0
- package/dist/cjs/utils/errors.d.ts +1 -1
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/platform.d.ts +2 -0
- package/dist/cjs/utils/platform.js +19 -0
- package/dist/cjs/utils/theme.d.ts +415 -0
- package/dist/cjs/utils/theme.js +190 -0
- package/dist/esm/utils/cart.d.ts +1 -1
- package/dist/esm/utils/datetimes.d.ts +10 -0
- package/dist/esm/utils/errors.d.ts +1 -1
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/platform.d.ts +2 -0
- package/dist/esm/utils/platform.js +14 -0
- package/dist/esm/utils/theme.d.ts +415 -0
- package/dist/esm/utils/theme.js +179 -0
- package/package.json +3 -2
package/dist/esm/utils/cart.d.ts
CHANGED
|
@@ -418,5 +418,5 @@ export declare const validateCart: (cart: OrderCart, categories: MenuCategories,
|
|
|
418
418
|
} | null;
|
|
419
419
|
};
|
|
420
420
|
export declare const getDefaultTip: (config: CheckoutConfig) => string | null;
|
|
421
|
-
export declare const prepareOrder: (data:
|
|
421
|
+
export declare const prepareOrder: (data: UnpreparedOrderData) => Partial<Order>;
|
|
422
422
|
export declare const checkAmountRemaining: (total: Money, tenders: Array<Tender>) => number;
|
|
@@ -118,12 +118,22 @@ export declare const makeTimes: (date: DateString, firstTime: FirstTime, validTi
|
|
|
118
118
|
FRIDAY?: ValidTimes | undefined;
|
|
119
119
|
SATURDAY?: ValidTimes | undefined;
|
|
120
120
|
} | undefined;
|
|
121
|
+
OUTPOST?: {
|
|
122
|
+
SUNDAY?: ValidTimes | undefined;
|
|
123
|
+
MONDAY?: ValidTimes | undefined;
|
|
124
|
+
TUESDAY?: ValidTimes | undefined;
|
|
125
|
+
WEDNESDAY?: ValidTimes | undefined;
|
|
126
|
+
THURSDAY?: ValidTimes | undefined;
|
|
127
|
+
FRIDAY?: ValidTimes | undefined;
|
|
128
|
+
SATURDAY?: ValidTimes | undefined;
|
|
129
|
+
} | undefined;
|
|
121
130
|
}, holidays: {
|
|
122
131
|
[key: `${number}${number}${number}${number}-${number}${number}-${number}${number}`]: {
|
|
123
132
|
WALKIN?: HolidayItem | null | undefined;
|
|
124
133
|
PICKUP?: HolidayItem | null | undefined;
|
|
125
134
|
DELIVERY?: HolidayItem | null | undefined;
|
|
126
135
|
PORTAL?: HolidayItem | null | undefined;
|
|
136
|
+
OUTPOST?: HolidayItem | null | undefined;
|
|
127
137
|
};
|
|
128
138
|
}, serviceType: ServiceType) => Array<TimeObject> | null;
|
|
129
139
|
export interface DatePickerArgs {
|
|
@@ -11,7 +11,7 @@ export declare const handleRespError: (err: RequestError) => {
|
|
|
11
11
|
export declare const processError: (msg: string | null) => string;
|
|
12
12
|
export declare const handleFormErrors: (params: Record<string, string | null>) => Record<string, string>;
|
|
13
13
|
export declare const makeFormErrors: (error: RequestError) => Record<string, string>;
|
|
14
|
-
export declare const handleCheckoutErrors: (errors:
|
|
14
|
+
export declare const handleCheckoutErrors: (errors: any, asMessages?: boolean) => any;
|
|
15
15
|
export declare const errMessages: {
|
|
16
16
|
unknown: string;
|
|
17
17
|
forbidden: string;
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { widthPercentageToDP, heightPercentageToDP, } from 'react-native-responsive-screen';
|
|
2
|
+
// The dimensions of the default designs screen
|
|
3
|
+
const DESIGN_SCREEN_WIDTH = 390;
|
|
4
|
+
const DESIGN_SCREEN_HEIGHT = 844;
|
|
5
|
+
// Calculate the adaptive width given the design screen width dimension.
|
|
6
|
+
// To be used for style props like: width, marginHorizontal, fontSize, ...
|
|
7
|
+
export const wp = (designWidth) => {
|
|
8
|
+
return widthPercentageToDP((designWidth * 100) / DESIGN_SCREEN_WIDTH);
|
|
9
|
+
};
|
|
10
|
+
// Calculate the adaptive height given the design screen height dimension.
|
|
11
|
+
// To be used for style props like: height, marginVertical, ...
|
|
12
|
+
export const hp = (designHeight) => {
|
|
13
|
+
return heightPercentageToDP((designHeight * 100) / DESIGN_SCREEN_HEIGHT);
|
|
14
|
+
};
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import { ConfigTheme, ConfigThemeLayout } from '@open-tender/types';
|
|
2
|
+
export declare const makeLineHeight: (lineHeight?: string, fontSize?: string) => string;
|
|
3
|
+
export declare const remsToPixels: (rems?: string, responsive?: boolean) => string;
|
|
4
|
+
export declare const remsToNumber: (rems: string) => number;
|
|
5
|
+
export declare const objRemsToPixels: <T extends Partial<ConfigThemeLayout & {
|
|
6
|
+
big: string;
|
|
7
|
+
giga: string;
|
|
8
|
+
h1: string;
|
|
9
|
+
h2: string;
|
|
10
|
+
h3: string;
|
|
11
|
+
h4: string;
|
|
12
|
+
h5: string;
|
|
13
|
+
h6: string;
|
|
14
|
+
main: string;
|
|
15
|
+
mega: string;
|
|
16
|
+
small: string;
|
|
17
|
+
tera: string;
|
|
18
|
+
xBig: string;
|
|
19
|
+
xSmall: string;
|
|
20
|
+
xxBig: string;
|
|
21
|
+
xxSmall: string;
|
|
22
|
+
}>>(object: T, responsive?: boolean) => Record<string, string>;
|
|
23
|
+
export declare const pixelsToInt: (pixels: string) => string | number;
|
|
24
|
+
export declare const pixelsToFloat: (pixels: string) => string | number;
|
|
25
|
+
export declare const decorateTheme: (theme: ConfigTheme) => {
|
|
26
|
+
fonts: {
|
|
27
|
+
headline: {
|
|
28
|
+
letterSpacing: string;
|
|
29
|
+
lineHeights: {};
|
|
30
|
+
color: string;
|
|
31
|
+
family: string;
|
|
32
|
+
fontMobile: string;
|
|
33
|
+
fontSmoothing: string;
|
|
34
|
+
lineHeight: number;
|
|
35
|
+
textTransform: string;
|
|
36
|
+
url: string;
|
|
37
|
+
weight: string;
|
|
38
|
+
fontSize?: string | undefined;
|
|
39
|
+
} | {
|
|
40
|
+
fontSize: string;
|
|
41
|
+
lineHeight: string;
|
|
42
|
+
letterSpacing: string;
|
|
43
|
+
lineHeights: {};
|
|
44
|
+
color: string;
|
|
45
|
+
family: string;
|
|
46
|
+
fontMobile: string;
|
|
47
|
+
fontSmoothing: string;
|
|
48
|
+
textTransform: string;
|
|
49
|
+
url: string;
|
|
50
|
+
weight: string;
|
|
51
|
+
};
|
|
52
|
+
headings: {
|
|
53
|
+
letterSpacing: string;
|
|
54
|
+
lineHeights: {};
|
|
55
|
+
color: string;
|
|
56
|
+
family: string;
|
|
57
|
+
fontMobile: string;
|
|
58
|
+
fontSmoothing: string;
|
|
59
|
+
lineHeight: number;
|
|
60
|
+
textTransform: string;
|
|
61
|
+
url: string;
|
|
62
|
+
weight: string;
|
|
63
|
+
fontSize?: string | undefined;
|
|
64
|
+
} | {
|
|
65
|
+
fontSize: string;
|
|
66
|
+
lineHeight: string;
|
|
67
|
+
letterSpacing: string;
|
|
68
|
+
lineHeights: {};
|
|
69
|
+
color: string;
|
|
70
|
+
family: string;
|
|
71
|
+
fontMobile: string;
|
|
72
|
+
fontSmoothing: string;
|
|
73
|
+
textTransform: string;
|
|
74
|
+
url: string;
|
|
75
|
+
weight: string;
|
|
76
|
+
};
|
|
77
|
+
body: {
|
|
78
|
+
letterSpacing: string;
|
|
79
|
+
lineHeights: {};
|
|
80
|
+
color: string;
|
|
81
|
+
family: string;
|
|
82
|
+
fontMobile: string;
|
|
83
|
+
fontSmoothing: string;
|
|
84
|
+
lineHeight: number;
|
|
85
|
+
textTransform: string;
|
|
86
|
+
url: string;
|
|
87
|
+
weight: string;
|
|
88
|
+
fontSize?: string | undefined;
|
|
89
|
+
} | {
|
|
90
|
+
fontSize: string;
|
|
91
|
+
lineHeight: string;
|
|
92
|
+
letterSpacing: string;
|
|
93
|
+
lineHeights: {};
|
|
94
|
+
color: string;
|
|
95
|
+
family: string;
|
|
96
|
+
fontMobile: string;
|
|
97
|
+
fontSmoothing: string;
|
|
98
|
+
textTransform: string;
|
|
99
|
+
url: string;
|
|
100
|
+
weight: string;
|
|
101
|
+
};
|
|
102
|
+
preface: {
|
|
103
|
+
letterSpacing: string;
|
|
104
|
+
lineHeights: {};
|
|
105
|
+
color: string;
|
|
106
|
+
family: string;
|
|
107
|
+
fontMobile: string;
|
|
108
|
+
fontSmoothing: string;
|
|
109
|
+
lineHeight: number;
|
|
110
|
+
textTransform: string;
|
|
111
|
+
url: string;
|
|
112
|
+
weight: string;
|
|
113
|
+
fontSize?: string | undefined;
|
|
114
|
+
} | {
|
|
115
|
+
fontSize: string;
|
|
116
|
+
lineHeight: string;
|
|
117
|
+
letterSpacing: string;
|
|
118
|
+
lineHeights: {};
|
|
119
|
+
color: string;
|
|
120
|
+
family: string;
|
|
121
|
+
fontMobile: string;
|
|
122
|
+
fontSmoothing: string;
|
|
123
|
+
textTransform: string;
|
|
124
|
+
url: string;
|
|
125
|
+
weight: string;
|
|
126
|
+
};
|
|
127
|
+
sizes: Record<string, string>;
|
|
128
|
+
lineHeights: {};
|
|
129
|
+
};
|
|
130
|
+
lineHeight: string;
|
|
131
|
+
layout: Record<string, string>;
|
|
132
|
+
buttons: {
|
|
133
|
+
sizes: {};
|
|
134
|
+
colors: {
|
|
135
|
+
cart: import("@open-tender/types").ButtonColor;
|
|
136
|
+
cartHover: import("@open-tender/types").ButtonColor;
|
|
137
|
+
header: import("@open-tender/types").ButtonColor;
|
|
138
|
+
headerHover: import("@open-tender/types").ButtonColor;
|
|
139
|
+
large: import("@open-tender/types").ButtonColor & {
|
|
140
|
+
iconColor: string;
|
|
141
|
+
subtitleColor: string;
|
|
142
|
+
};
|
|
143
|
+
largeHover: import("@open-tender/types").ButtonColor & {
|
|
144
|
+
iconColor: string;
|
|
145
|
+
subtitleColor: string;
|
|
146
|
+
};
|
|
147
|
+
light: import("@open-tender/types").ButtonColor;
|
|
148
|
+
lightHover: import("@open-tender/types").ButtonColor;
|
|
149
|
+
primary: import("@open-tender/types").ButtonColor;
|
|
150
|
+
primaryHover: import("@open-tender/types").ButtonColor;
|
|
151
|
+
secondary: import("@open-tender/types").ButtonColor;
|
|
152
|
+
secondaryHover: import("@open-tender/types").ButtonColor;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
border: {
|
|
156
|
+
radius: string;
|
|
157
|
+
radiusSmall: string;
|
|
158
|
+
width: string;
|
|
159
|
+
widthApp: string;
|
|
160
|
+
color: string;
|
|
161
|
+
};
|
|
162
|
+
inputs: {
|
|
163
|
+
lineHeight: string;
|
|
164
|
+
letterSpacing: string;
|
|
165
|
+
fontSize: string;
|
|
166
|
+
radius: string;
|
|
167
|
+
borderWidth: string;
|
|
168
|
+
borderWidthApp: string;
|
|
169
|
+
padding: string;
|
|
170
|
+
paddingHorizontal: string;
|
|
171
|
+
paddingVertical: string;
|
|
172
|
+
paddingTop: string;
|
|
173
|
+
paddingTopActive: string;
|
|
174
|
+
paddingBottom: string;
|
|
175
|
+
paddingBottomActive: string;
|
|
176
|
+
label: {
|
|
177
|
+
fontSize: string;
|
|
178
|
+
lineHeight: string;
|
|
179
|
+
offset: string;
|
|
180
|
+
padding: string;
|
|
181
|
+
top: string;
|
|
182
|
+
left: string;
|
|
183
|
+
};
|
|
184
|
+
bgColor: string;
|
|
185
|
+
bgColorFocus: string;
|
|
186
|
+
borderColor: string;
|
|
187
|
+
borderColorFocus: string;
|
|
188
|
+
borderStyle: string;
|
|
189
|
+
bottomBorderOnly: boolean;
|
|
190
|
+
boxShadow: string;
|
|
191
|
+
color: string;
|
|
192
|
+
colorFocus: string;
|
|
193
|
+
family: string;
|
|
194
|
+
fontMobile: string;
|
|
195
|
+
fontSizeMobile: string;
|
|
196
|
+
fontSmoothing: string;
|
|
197
|
+
iconLeft: string;
|
|
198
|
+
iconPadding: string;
|
|
199
|
+
placeholderColor: string;
|
|
200
|
+
selectPaddingBottom: string;
|
|
201
|
+
selectSize: string;
|
|
202
|
+
selectSizeMobile: string;
|
|
203
|
+
showIcon: boolean;
|
|
204
|
+
showLabel: boolean;
|
|
205
|
+
showOutline: boolean;
|
|
206
|
+
textTransform: string;
|
|
207
|
+
weight: string;
|
|
208
|
+
};
|
|
209
|
+
counts: {
|
|
210
|
+
alerts: {
|
|
211
|
+
borderWidth: string;
|
|
212
|
+
borderWidthApp: string;
|
|
213
|
+
fontSize: string;
|
|
214
|
+
fontSizeMobile: string;
|
|
215
|
+
paddingBottom: string;
|
|
216
|
+
paddingTop: string;
|
|
217
|
+
bgColor?: string | undefined;
|
|
218
|
+
borderColor?: string | undefined;
|
|
219
|
+
color?: string | undefined;
|
|
220
|
+
family?: string | undefined;
|
|
221
|
+
fontMobile?: string | undefined;
|
|
222
|
+
fontSmoothing?: string | undefined;
|
|
223
|
+
weight?: string | undefined;
|
|
224
|
+
};
|
|
225
|
+
quantity: {
|
|
226
|
+
fontSize: string;
|
|
227
|
+
fontSizeMobile: string;
|
|
228
|
+
paddingBottom: string;
|
|
229
|
+
paddingTop: string;
|
|
230
|
+
bgColor?: string | undefined;
|
|
231
|
+
borderColor?: string | undefined;
|
|
232
|
+
borderWidth?: string | undefined;
|
|
233
|
+
borderWidthApp?: string | undefined;
|
|
234
|
+
color?: string | undefined;
|
|
235
|
+
family?: string | undefined;
|
|
236
|
+
fontMobile?: string | undefined;
|
|
237
|
+
fontSmoothing?: string | undefined;
|
|
238
|
+
weight?: string | undefined;
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
cards: {
|
|
242
|
+
default: {
|
|
243
|
+
borderWidth: string;
|
|
244
|
+
borderWidthApp: string;
|
|
245
|
+
borderRadius: string;
|
|
246
|
+
bgColor?: string | undefined;
|
|
247
|
+
borderColor?: string | undefined;
|
|
248
|
+
boxShadow?: string | undefined;
|
|
249
|
+
caloriesColor?: string | undefined;
|
|
250
|
+
overrideFontColors?: boolean | undefined;
|
|
251
|
+
priceColor?: string | undefined;
|
|
252
|
+
priceSize?: string | undefined;
|
|
253
|
+
priceSizeMobile?: string | undefined;
|
|
254
|
+
textColor?: string | undefined;
|
|
255
|
+
titleColor?: string | undefined;
|
|
256
|
+
titleSize?: string | undefined;
|
|
257
|
+
titleSizeMobile?: string | undefined;
|
|
258
|
+
};
|
|
259
|
+
form: {
|
|
260
|
+
borderWidth: string;
|
|
261
|
+
borderWidthApp: string;
|
|
262
|
+
borderRadius: string;
|
|
263
|
+
bgColor?: string | undefined;
|
|
264
|
+
borderColor?: string | undefined;
|
|
265
|
+
boxShadow?: string | undefined;
|
|
266
|
+
caloriesColor?: string | undefined;
|
|
267
|
+
overrideFontColors?: boolean | undefined;
|
|
268
|
+
priceColor?: string | undefined;
|
|
269
|
+
priceSize?: string | undefined;
|
|
270
|
+
priceSizeMobile?: string | undefined;
|
|
271
|
+
textColor?: string | undefined;
|
|
272
|
+
titleColor?: string | undefined;
|
|
273
|
+
titleSize?: string | undefined;
|
|
274
|
+
titleSizeMobile?: string | undefined;
|
|
275
|
+
};
|
|
276
|
+
menuItem: {
|
|
277
|
+
borderWidth: string;
|
|
278
|
+
borderWidthApp: string;
|
|
279
|
+
borderRadius: string;
|
|
280
|
+
bgColor?: string | undefined;
|
|
281
|
+
borderColor?: string | undefined;
|
|
282
|
+
boxShadow?: string | undefined;
|
|
283
|
+
caloriesColor?: string | undefined;
|
|
284
|
+
overrideFontColors?: boolean | undefined;
|
|
285
|
+
priceColor?: string | undefined;
|
|
286
|
+
priceSize?: string | undefined;
|
|
287
|
+
priceSizeMobile?: string | undefined;
|
|
288
|
+
textColor?: string | undefined;
|
|
289
|
+
titleColor?: string | undefined;
|
|
290
|
+
titleSize?: string | undefined;
|
|
291
|
+
titleSizeMobile?: string | undefined;
|
|
292
|
+
};
|
|
293
|
+
modifier: {
|
|
294
|
+
borderWidth: string;
|
|
295
|
+
borderWidthApp: string;
|
|
296
|
+
borderRadius: string;
|
|
297
|
+
bgColor?: string | undefined;
|
|
298
|
+
borderColor?: string | undefined;
|
|
299
|
+
boxShadow?: string | undefined;
|
|
300
|
+
caloriesColor?: string | undefined;
|
|
301
|
+
overrideFontColors?: boolean | undefined;
|
|
302
|
+
priceColor?: string | undefined;
|
|
303
|
+
priceSize?: string | undefined;
|
|
304
|
+
priceSizeMobile?: string | undefined;
|
|
305
|
+
textColor?: string | undefined;
|
|
306
|
+
titleColor?: string | undefined;
|
|
307
|
+
titleSize?: string | undefined;
|
|
308
|
+
titleSizeMobile?: string | undefined;
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
welcome: {
|
|
312
|
+
textAlign: string | undefined;
|
|
313
|
+
marginTop: string;
|
|
314
|
+
marginBottom: string;
|
|
315
|
+
titleMarginLeft: string;
|
|
316
|
+
titleSize: string;
|
|
317
|
+
titleLineHeight: string;
|
|
318
|
+
subtitleSize: string;
|
|
319
|
+
subtitleLineHeight: string;
|
|
320
|
+
subtitleMarginTop: string;
|
|
321
|
+
};
|
|
322
|
+
item: {
|
|
323
|
+
padding: string;
|
|
324
|
+
imagePadding: string;
|
|
325
|
+
maxWidth: string;
|
|
326
|
+
imageMinHeight: string;
|
|
327
|
+
imageMaxHeight: string;
|
|
328
|
+
desktop: import("@open-tender/types").ConfigItem;
|
|
329
|
+
mobile: import("@open-tender/types").ConfigItem;
|
|
330
|
+
};
|
|
331
|
+
alert: {
|
|
332
|
+
bgColor: string;
|
|
333
|
+
color: string;
|
|
334
|
+
};
|
|
335
|
+
bgColors: {
|
|
336
|
+
alert: string;
|
|
337
|
+
allergens: string;
|
|
338
|
+
dark: string;
|
|
339
|
+
error: string;
|
|
340
|
+
highlight: string;
|
|
341
|
+
light: string;
|
|
342
|
+
primary: string;
|
|
343
|
+
secondary: string;
|
|
344
|
+
success: string;
|
|
345
|
+
tertiary: string;
|
|
346
|
+
toast: string;
|
|
347
|
+
};
|
|
348
|
+
boldWeight: string;
|
|
349
|
+
boxShadow: {
|
|
350
|
+
appBig: string;
|
|
351
|
+
appSmall: string;
|
|
352
|
+
inset: string;
|
|
353
|
+
outer: string;
|
|
354
|
+
};
|
|
355
|
+
breakpoints: {
|
|
356
|
+
laptop: string;
|
|
357
|
+
mobile: string;
|
|
358
|
+
narrow: string;
|
|
359
|
+
tablet: string;
|
|
360
|
+
};
|
|
361
|
+
colors: {
|
|
362
|
+
alert: string;
|
|
363
|
+
allergens: string;
|
|
364
|
+
dark: string;
|
|
365
|
+
error: string;
|
|
366
|
+
light: string;
|
|
367
|
+
primary: string;
|
|
368
|
+
secondary: string;
|
|
369
|
+
success: string;
|
|
370
|
+
tags: string;
|
|
371
|
+
tertiary: string;
|
|
372
|
+
title: string;
|
|
373
|
+
toast: string;
|
|
374
|
+
};
|
|
375
|
+
error: {
|
|
376
|
+
bgColor: string;
|
|
377
|
+
color: string;
|
|
378
|
+
};
|
|
379
|
+
favorite: {
|
|
380
|
+
iconSize: string;
|
|
381
|
+
size: string;
|
|
382
|
+
};
|
|
383
|
+
header: {
|
|
384
|
+
primary: string;
|
|
385
|
+
stuck: string;
|
|
386
|
+
};
|
|
387
|
+
icons: {
|
|
388
|
+
strokeWidth: number;
|
|
389
|
+
};
|
|
390
|
+
links: {
|
|
391
|
+
customize: import("@open-tender/types").ConfigLink;
|
|
392
|
+
dark: import("@open-tender/types").ConfigLink;
|
|
393
|
+
light: import("@open-tender/types").ConfigLink;
|
|
394
|
+
primary: import("@open-tender/types").ConfigLink;
|
|
395
|
+
textDecoration: string;
|
|
396
|
+
transition: string;
|
|
397
|
+
};
|
|
398
|
+
overlay: {
|
|
399
|
+
alert: string;
|
|
400
|
+
dark: string;
|
|
401
|
+
light: string;
|
|
402
|
+
primary: string;
|
|
403
|
+
secondary: string;
|
|
404
|
+
tertiary: string;
|
|
405
|
+
};
|
|
406
|
+
success: {
|
|
407
|
+
bgColor: string;
|
|
408
|
+
color: string;
|
|
409
|
+
};
|
|
410
|
+
toast: {
|
|
411
|
+
bgColor: string;
|
|
412
|
+
color: string;
|
|
413
|
+
};
|
|
414
|
+
};
|
|
415
|
+
export declare const hexToRgbA: (hex: string, opacity: number) => string | null;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { wp } from './platform';
|
|
2
|
+
export const makeLineHeight = (lineHeight, fontSize) => {
|
|
3
|
+
var _a;
|
|
4
|
+
const size = parseInt((_a = fontSize === null || fontSize === void 0 ? void 0 : fontSize.replace('px', '')) !== null && _a !== void 0 ? _a : '0');
|
|
5
|
+
return `${wp(parseFloat(lineHeight !== null && lineHeight !== void 0 ? lineHeight : '0') * size).toFixed(3)}px`;
|
|
6
|
+
};
|
|
7
|
+
export const remsToPixels = (rems, responsive = false) => {
|
|
8
|
+
if (!rems)
|
|
9
|
+
return '0';
|
|
10
|
+
const pixels = parseFloat(rems.replace('rem', '')) * 10;
|
|
11
|
+
const adjustedPixels = responsive ? wp(pixels) : pixels;
|
|
12
|
+
const noZeroes = parseFloat(adjustedPixels.toFixed(2)).toString();
|
|
13
|
+
return noZeroes === '0' ? '0' : `${noZeroes}px`;
|
|
14
|
+
};
|
|
15
|
+
export const remsToNumber = (rems) => {
|
|
16
|
+
return parseFloat(rems.replace('rem', '')) * 10;
|
|
17
|
+
};
|
|
18
|
+
export const objRemsToPixels = (object, responsive = false) => {
|
|
19
|
+
return Object.entries(object).reduce((obj, [key, value]) => {
|
|
20
|
+
return Object.assign(Object.assign({}, obj), { [key]: remsToPixels(value, responsive) });
|
|
21
|
+
}, {});
|
|
22
|
+
};
|
|
23
|
+
export const pixelsToInt = (pixels) => {
|
|
24
|
+
try {
|
|
25
|
+
return parseInt(pixels.replace('px', ''));
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
return pixels;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export const pixelsToFloat = (pixels) => {
|
|
32
|
+
try {
|
|
33
|
+
return parseFloat(pixels.replace('px', ''));
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
return pixels;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const paddingToPixels = (padding) => {
|
|
40
|
+
const [top, horizontal, bottom] = padding.split(' ');
|
|
41
|
+
return `${remsToPixels(top)} ${remsToPixels(horizontal)} ${remsToPixels(bottom)}`;
|
|
42
|
+
};
|
|
43
|
+
const buttonToPixels = (button) => {
|
|
44
|
+
return Object.assign(Object.assign({}, button), { borderRadius: remsToPixels(button.borderRadius), borderWidth: remsToPixels(button.borderWidth), borderWidthApp: button.borderWidthApp
|
|
45
|
+
? remsToPixels(button.borderWidthApp)
|
|
46
|
+
: remsToPixels(button.borderWidth), fontSize: button.fontSize ? remsToPixels(button.fontSize, true) : null, letterSpacing: button.letterSpacing
|
|
47
|
+
? remsToPixels(button.letterSpacing)
|
|
48
|
+
: null, padding: button.padding ? paddingToPixels(button.padding) : null, subtitleFontSizeMobile: button.subtitleFontSizeMobile
|
|
49
|
+
? remsToPixels(button.subtitleFontSizeMobile)
|
|
50
|
+
: null, subtitleMarginTopMobile: button.subtitleMarginTopMobile
|
|
51
|
+
? remsToPixels(button.subtitleMarginTopMobile)
|
|
52
|
+
: null, titleFontSizeMobile: button.titleFontSizeMobile
|
|
53
|
+
? remsToPixels(button.titleFontSizeMobile)
|
|
54
|
+
: null, titleMarginLeftMobile: button.titleMarginLeftMobile
|
|
55
|
+
? remsToPixels(button.titleMarginLeftMobile)
|
|
56
|
+
: null });
|
|
57
|
+
};
|
|
58
|
+
const makeButtons = (buttons) => {
|
|
59
|
+
const sizes = Object.entries(buttons.sizes).reduce((obj, [key, value]) => {
|
|
60
|
+
return Object.assign(Object.assign({}, obj), { [key]: buttonToPixels(value) });
|
|
61
|
+
}, {});
|
|
62
|
+
return Object.assign(Object.assign({}, buttons), { sizes });
|
|
63
|
+
};
|
|
64
|
+
const makeLineHeights = (sizes, lineHeight) => {
|
|
65
|
+
return Object.entries(sizes).reduce((obj, [size, fontSize]) => {
|
|
66
|
+
return Object.assign(Object.assign({}, obj), { [size]: makeLineHeight(lineHeight, fontSize) });
|
|
67
|
+
}, {});
|
|
68
|
+
};
|
|
69
|
+
const makeFont = (font, sizes) => {
|
|
70
|
+
const fontStyle = Object.assign(Object.assign({}, font), { letterSpacing: remsToPixels(font.letterSpacing), lineHeights: makeLineHeights(sizes, `${font.lineHeight}`) });
|
|
71
|
+
if (!font.fontSize)
|
|
72
|
+
return fontStyle;
|
|
73
|
+
const fontSize = remsToPixels(font.fontSize, true);
|
|
74
|
+
const lineHeight = makeLineHeight(`${font.lineHeight}`, fontSize);
|
|
75
|
+
return Object.assign(Object.assign({}, fontStyle), { fontSize, lineHeight });
|
|
76
|
+
};
|
|
77
|
+
const makeFonts = (fonts, lineHeight) => {
|
|
78
|
+
const sizes = objRemsToPixels(fonts.sizes, true);
|
|
79
|
+
const lineHeights = makeLineHeights(sizes, lineHeight);
|
|
80
|
+
const headline = makeFont(fonts.headline, sizes);
|
|
81
|
+
const headings = makeFont(fonts.headings, sizes);
|
|
82
|
+
const body = makeFont(fonts.body, sizes);
|
|
83
|
+
const preface = makeFont(fonts.preface, sizes);
|
|
84
|
+
return Object.assign(Object.assign({}, fonts), { headline, headings, body, preface, sizes, lineHeights });
|
|
85
|
+
};
|
|
86
|
+
const makeBorder = (border) => {
|
|
87
|
+
return Object.assign(Object.assign({}, border), { radius: remsToPixels(border.radius), radiusSmall: remsToPixels(border.radiusSmall), width: remsToPixels(border.width), widthApp: remsToPixels(border.widthApp) });
|
|
88
|
+
};
|
|
89
|
+
const makeLabel = (label, lineHeight) => {
|
|
90
|
+
const [vertical, horizontal] = label.padding.split(' ');
|
|
91
|
+
const fs = parseFloat(label.fontSizeMobile.replace('rem', '')) * 10.0;
|
|
92
|
+
const lh = parseFloat(lineHeight);
|
|
93
|
+
return {
|
|
94
|
+
fontSize: remsToPixels(label.fontSizeMobile, true),
|
|
95
|
+
lineHeight: `${wp(fs * lh)}px`,
|
|
96
|
+
offset: remsToPixels(label.offset),
|
|
97
|
+
padding: `${remsToPixels(vertical)} ${remsToPixels(horizontal)}`,
|
|
98
|
+
top: remsToPixels(label.top),
|
|
99
|
+
left: remsToPixels(label.left),
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
const makeInputs = (inputs) => {
|
|
103
|
+
const [vertical, horizontal] = inputs.padding.split(' ');
|
|
104
|
+
const fs = parseFloat(inputs.fontSizeMobile.replace('rem', '')) * 10.0;
|
|
105
|
+
const lh = parseFloat(inputs.lineHeight);
|
|
106
|
+
return Object.assign(Object.assign({}, inputs), { lineHeight: `${wp(fs * lh)}px`, letterSpacing: remsToPixels(inputs.letterSpacing), fontSize: remsToPixels(inputs.fontSizeMobile, true), radius: remsToPixels(inputs.radius), borderWidth: remsToPixels(inputs.borderWidth), borderWidthApp: remsToPixels(inputs.borderWidthApp), padding: `${remsToPixels(vertical)} ${remsToPixels(horizontal)}`, paddingHorizontal: remsToPixels(inputs.paddingHorizontal), paddingVertical: remsToPixels(inputs.paddingVertical), paddingTop: remsToPixels(inputs.paddingTop), paddingTopActive: remsToPixels(inputs.paddingTopActive), paddingBottom: remsToPixels(inputs.paddingBottom), paddingBottomActive: remsToPixels(inputs.paddingBottomActive), label: makeLabel(inputs.label, inputs.lineHeight) });
|
|
107
|
+
};
|
|
108
|
+
const makeCounts = (counts) => {
|
|
109
|
+
const { alerts, quantity } = counts;
|
|
110
|
+
return {
|
|
111
|
+
alerts: Object.assign(Object.assign({}, alerts), { borderWidth: remsToPixels(alerts.borderWidth), borderWidthApp: remsToPixels(alerts.borderWidthApp), fontSize: remsToPixels(alerts.fontSize, true), fontSizeMobile: remsToPixels(alerts.fontSizeMobile, true), paddingBottom: remsToPixels(alerts.paddingBottom), paddingTop: remsToPixels(alerts.paddingTop) }),
|
|
112
|
+
quantity: Object.assign(Object.assign({}, quantity), { fontSize: remsToPixels(quantity.fontSize, true), fontSizeMobile: remsToPixels(quantity.fontSizeMobile, true), paddingBottom: remsToPixels(quantity.paddingBottom), paddingTop: remsToPixels(quantity.paddingTop) }),
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
const makeCards = (cards) => {
|
|
116
|
+
const { default: box, form, menuItem, modifier } = cards;
|
|
117
|
+
return {
|
|
118
|
+
default: Object.assign(Object.assign({}, box), { borderWidth: remsToPixels(box.borderWidth), borderWidthApp: remsToPixels(box.borderWidthApp), borderRadius: remsToPixels(box.borderRadius) }),
|
|
119
|
+
form: Object.assign(Object.assign({}, form), { borderWidth: remsToPixels(form.borderWidth), borderWidthApp: remsToPixels(form.borderWidthApp), borderRadius: remsToPixels(form.borderRadius) }),
|
|
120
|
+
menuItem: Object.assign(Object.assign({}, menuItem), { borderWidth: remsToPixels(menuItem.borderWidth), borderWidthApp: remsToPixels(menuItem.borderWidthApp), borderRadius: remsToPixels(menuItem.borderRadius) }),
|
|
121
|
+
modifier: Object.assign(Object.assign({}, modifier), { borderWidth: remsToPixels(modifier.borderWidth), borderWidthApp: remsToPixels(modifier.borderWidthApp), borderRadius: remsToPixels(modifier.borderRadius) }),
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
const makeWelcome = (welcome) => {
|
|
125
|
+
const { mobile } = welcome;
|
|
126
|
+
const titleSize = remsToPixels(mobile === null || mobile === void 0 ? void 0 : mobile.titleSize);
|
|
127
|
+
const subtitleSize = remsToPixels(mobile === null || mobile === void 0 ? void 0 : mobile.subtitleSize);
|
|
128
|
+
return {
|
|
129
|
+
textAlign: mobile === null || mobile === void 0 ? void 0 : mobile.textAlign,
|
|
130
|
+
marginTop: remsToPixels(mobile === null || mobile === void 0 ? void 0 : mobile.marginTop),
|
|
131
|
+
marginBottom: remsToPixels(mobile === null || mobile === void 0 ? void 0 : mobile.marginBottom),
|
|
132
|
+
titleMarginLeft: remsToPixels(mobile === null || mobile === void 0 ? void 0 : mobile.titleMarginLeft),
|
|
133
|
+
titleSize,
|
|
134
|
+
titleLineHeight: makeLineHeight(mobile === null || mobile === void 0 ? void 0 : mobile.titleLineHeight, titleSize),
|
|
135
|
+
subtitleSize,
|
|
136
|
+
subtitleLineHeight: makeLineHeight(mobile === null || mobile === void 0 ? void 0 : mobile.subtitleLineHeight, subtitleSize),
|
|
137
|
+
subtitleMarginTop: remsToPixels(mobile === null || mobile === void 0 ? void 0 : mobile.subtitleMarginTop),
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
const makeItem = (item) => {
|
|
141
|
+
const { mobile } = item;
|
|
142
|
+
return Object.assign(Object.assign({}, item), { padding: remsToPixels(mobile.padding), imagePadding: remsToPixels(mobile.imagePadding), maxWidth: remsToPixels(mobile.maxWidth), imageMinHeight: remsToPixels(mobile.imageMinHeight), imageMaxHeight: remsToPixels(mobile.imageMaxHeight) });
|
|
143
|
+
};
|
|
144
|
+
export const decorateTheme = (theme) => {
|
|
145
|
+
const fonts = makeFonts(theme.fonts, theme.lineHeight);
|
|
146
|
+
const lineHeight = makeLineHeight(theme.lineHeight, fonts.sizes.main);
|
|
147
|
+
const layout = objRemsToPixels(theme.layout);
|
|
148
|
+
const buttons = makeButtons(theme.buttons);
|
|
149
|
+
const border = makeBorder(theme.border);
|
|
150
|
+
const inputs = makeInputs(theme.inputs);
|
|
151
|
+
const counts = makeCounts(theme.counts);
|
|
152
|
+
const cards = makeCards(theme.cards);
|
|
153
|
+
const welcome = makeWelcome(theme.welcome);
|
|
154
|
+
const item = makeItem(theme.item);
|
|
155
|
+
return Object.assign(Object.assign({}, theme), { fonts,
|
|
156
|
+
lineHeight,
|
|
157
|
+
layout,
|
|
158
|
+
buttons,
|
|
159
|
+
border,
|
|
160
|
+
inputs,
|
|
161
|
+
counts,
|
|
162
|
+
cards,
|
|
163
|
+
welcome,
|
|
164
|
+
item });
|
|
165
|
+
};
|
|
166
|
+
export const hexToRgbA = (hex, opacity) => {
|
|
167
|
+
let c;
|
|
168
|
+
if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
|
|
169
|
+
c = hex.substring(1).split('');
|
|
170
|
+
if (c.length === 3) {
|
|
171
|
+
c = [c[0], c[0], c[1], c[1], c[2], c[2]];
|
|
172
|
+
}
|
|
173
|
+
c = '0x' + c.join('');
|
|
174
|
+
return ('rgba(' +
|
|
175
|
+
[(c >> 16) & 255, (c >> 8) & 255, c & 255].join(',') +
|
|
176
|
+
`,${opacity})`);
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -57,9 +57,10 @@
|
|
|
57
57
|
"react": "^18.2.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@open-tender/types": "^0.0.
|
|
60
|
+
"@open-tender/types": "^0.0.46",
|
|
61
61
|
"date-fns": "^2.29.3",
|
|
62
62
|
"date-fns-tz": "^1.3.7",
|
|
63
|
+
"react-native-responsive-screen": "^1.4.2",
|
|
63
64
|
"ts-transformer-keys": "^0.4.3"
|
|
64
65
|
}
|
|
65
66
|
}
|