@open-tender/utils 0.0.5 → 0.0.7
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/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 +26 -0
- package/dist/cjs/utils/theme.js +182 -0
- package/dist/esm/utils/cart.d.ts +1 -1
- package/dist/esm/utils/datetimes.d.ts +10 -0
- 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 +26 -0
- package/dist/esm/utils/theme.js +171 -0
- package/package.json +3 -2
package/dist/cjs/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 {
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -15,3 +15,4 @@ tslib_1.__exportStar(require("./refunds"), exports);
|
|
|
15
15
|
tslib_1.__exportStar(require("./rewards"), exports);
|
|
16
16
|
tslib_1.__exportStar(require("./version"), exports);
|
|
17
17
|
tslib_1.__exportStar(require("./orders"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./theme"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hp = exports.wp = void 0;
|
|
4
|
+
const react_native_responsive_screen_1 = require("react-native-responsive-screen");
|
|
5
|
+
// The dimensions of the default designs screen
|
|
6
|
+
const DESIGN_SCREEN_WIDTH = 390;
|
|
7
|
+
const DESIGN_SCREEN_HEIGHT = 844;
|
|
8
|
+
// Calculate the adaptive width given the design screen width dimension.
|
|
9
|
+
// To be used for style props like: width, marginHorizontal, fontSize, ...
|
|
10
|
+
const wp = (designWidth) => {
|
|
11
|
+
return (0, react_native_responsive_screen_1.widthPercentageToDP)((designWidth * 100) / DESIGN_SCREEN_WIDTH);
|
|
12
|
+
};
|
|
13
|
+
exports.wp = wp;
|
|
14
|
+
// Calculate the adaptive height given the design screen height dimension.
|
|
15
|
+
// To be used for style props like: height, marginVertical, ...
|
|
16
|
+
const hp = (designHeight) => {
|
|
17
|
+
return (0, react_native_responsive_screen_1.heightPercentageToDP)((designHeight * 100) / DESIGN_SCREEN_HEIGHT);
|
|
18
|
+
};
|
|
19
|
+
exports.hp = hp;
|
|
@@ -0,0 +1,26 @@
|
|
|
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) => Partial<T>;
|
|
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) => ConfigTheme;
|
|
26
|
+
export declare const hexToRgbA: (hex: string, opacity: number) => string | null;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hexToRgbA = exports.decorateTheme = exports.pixelsToFloat = exports.pixelsToInt = exports.objRemsToPixels = exports.remsToNumber = exports.remsToPixels = exports.makeLineHeight = void 0;
|
|
4
|
+
const platform_1 = require("./platform");
|
|
5
|
+
const makeLineHeight = (lineHeight, fontSize) => {
|
|
6
|
+
var _a;
|
|
7
|
+
const size = parseInt((_a = fontSize === null || fontSize === void 0 ? void 0 : fontSize.replace('px', '')) !== null && _a !== void 0 ? _a : '0');
|
|
8
|
+
return `${(0, platform_1.wp)(parseFloat(lineHeight !== null && lineHeight !== void 0 ? lineHeight : '0') * size).toFixed(3)}px`;
|
|
9
|
+
};
|
|
10
|
+
exports.makeLineHeight = makeLineHeight;
|
|
11
|
+
const remsToPixels = (rems, responsive = false) => {
|
|
12
|
+
if (!rems)
|
|
13
|
+
return '0';
|
|
14
|
+
const pixels = parseFloat(rems.replace('rem', '')) * 10;
|
|
15
|
+
const adjustedPixels = responsive ? (0, platform_1.wp)(pixels) : pixels;
|
|
16
|
+
const noZeroes = parseFloat(adjustedPixels.toFixed(2)).toString();
|
|
17
|
+
return noZeroes === '0' ? '0' : `${noZeroes}px`;
|
|
18
|
+
};
|
|
19
|
+
exports.remsToPixels = remsToPixels;
|
|
20
|
+
const remsToNumber = (rems) => {
|
|
21
|
+
return parseFloat(rems.replace('rem', '')) * 10;
|
|
22
|
+
};
|
|
23
|
+
exports.remsToNumber = remsToNumber;
|
|
24
|
+
const objRemsToPixels = (object, responsive = false) => {
|
|
25
|
+
return Object.entries(object).reduce((obj, [key, value]) => {
|
|
26
|
+
return Object.assign(Object.assign({}, obj), { [key]: (0, exports.remsToPixels)(value, responsive) });
|
|
27
|
+
}, {});
|
|
28
|
+
};
|
|
29
|
+
exports.objRemsToPixels = objRemsToPixels;
|
|
30
|
+
const pixelsToInt = (pixels) => {
|
|
31
|
+
try {
|
|
32
|
+
return parseInt(pixels.replace('px', ''));
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
return pixels;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.pixelsToInt = pixelsToInt;
|
|
39
|
+
const pixelsToFloat = (pixels) => {
|
|
40
|
+
try {
|
|
41
|
+
return parseFloat(pixels.replace('px', ''));
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
return pixels;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.pixelsToFloat = pixelsToFloat;
|
|
48
|
+
const paddingToPixels = (padding) => {
|
|
49
|
+
const [top, horizontal, bottom] = padding.split(' ');
|
|
50
|
+
return `${(0, exports.remsToPixels)(top)} ${(0, exports.remsToPixels)(horizontal)} ${(0, exports.remsToPixels)(bottom)}`;
|
|
51
|
+
};
|
|
52
|
+
const buttonToPixels = (button) => {
|
|
53
|
+
return Object.assign(Object.assign({}, button), { borderRadius: (0, exports.remsToPixels)(button.borderRadius), borderWidth: (0, exports.remsToPixels)(button.borderWidth), borderWidthApp: button.borderWidthApp
|
|
54
|
+
? (0, exports.remsToPixels)(button.borderWidthApp)
|
|
55
|
+
: (0, exports.remsToPixels)(button.borderWidth), fontSize: button.fontSize ? (0, exports.remsToPixels)(button.fontSize, true) : null, letterSpacing: button.letterSpacing
|
|
56
|
+
? (0, exports.remsToPixels)(button.letterSpacing)
|
|
57
|
+
: null, padding: button.padding ? paddingToPixels(button.padding) : null, subtitleFontSizeMobile: button.subtitleFontSizeMobile
|
|
58
|
+
? (0, exports.remsToPixels)(button.subtitleFontSizeMobile)
|
|
59
|
+
: null, subtitleMarginTopMobile: button.subtitleMarginTopMobile
|
|
60
|
+
? (0, exports.remsToPixels)(button.subtitleMarginTopMobile)
|
|
61
|
+
: null, titleFontSizeMobile: button.titleFontSizeMobile
|
|
62
|
+
? (0, exports.remsToPixels)(button.titleFontSizeMobile)
|
|
63
|
+
: null, titleMarginLeftMobile: button.titleMarginLeftMobile
|
|
64
|
+
? (0, exports.remsToPixels)(button.titleMarginLeftMobile)
|
|
65
|
+
: null });
|
|
66
|
+
};
|
|
67
|
+
const makeButtons = (buttons) => {
|
|
68
|
+
const sizes = Object.entries(buttons.sizes).reduce((obj, [key, value]) => {
|
|
69
|
+
return Object.assign(Object.assign({}, obj), { [key]: buttonToPixels(value) });
|
|
70
|
+
}, {});
|
|
71
|
+
return Object.assign(Object.assign({}, buttons), { sizes });
|
|
72
|
+
};
|
|
73
|
+
const makeLineHeights = (sizes, lineHeight) => {
|
|
74
|
+
return Object.entries(sizes).reduce((obj, [size, fontSize]) => {
|
|
75
|
+
return Object.assign(Object.assign({}, obj), { [size]: (0, exports.makeLineHeight)(lineHeight, fontSize) });
|
|
76
|
+
}, {});
|
|
77
|
+
};
|
|
78
|
+
const makeFont = (font, sizes) => {
|
|
79
|
+
const fontStyle = Object.assign(Object.assign({}, font), { letterSpacing: (0, exports.remsToPixels)(font.letterSpacing), lineHeights: makeLineHeights(sizes, `${font.lineHeight}`) });
|
|
80
|
+
if (!font.fontSize)
|
|
81
|
+
return fontStyle;
|
|
82
|
+
const fontSize = (0, exports.remsToPixels)(font.fontSize, true);
|
|
83
|
+
const lineHeight = (0, exports.makeLineHeight)(`${font.lineHeight}`, fontSize);
|
|
84
|
+
return Object.assign(Object.assign({}, fontStyle), { fontSize, lineHeight });
|
|
85
|
+
};
|
|
86
|
+
const makeFonts = (fonts, lineHeight) => {
|
|
87
|
+
const sizes = (0, exports.objRemsToPixels)(fonts.sizes, true);
|
|
88
|
+
const lineHeights = makeLineHeights(sizes, lineHeight);
|
|
89
|
+
const headline = makeFont(fonts.headline, sizes);
|
|
90
|
+
const headings = makeFont(fonts.headings, sizes);
|
|
91
|
+
const body = makeFont(fonts.body, sizes);
|
|
92
|
+
const preface = makeFont(fonts.preface, sizes);
|
|
93
|
+
return Object.assign(Object.assign({}, fonts), { headline, headings, body, preface, sizes, lineHeights });
|
|
94
|
+
};
|
|
95
|
+
const makeBorder = (border) => {
|
|
96
|
+
return Object.assign(Object.assign({}, border), { radius: (0, exports.remsToPixels)(border.radius), radiusSmall: (0, exports.remsToPixels)(border.radiusSmall), width: (0, exports.remsToPixels)(border.width), widthApp: (0, exports.remsToPixels)(border.widthApp) });
|
|
97
|
+
};
|
|
98
|
+
const makeLabel = (label, lineHeight) => {
|
|
99
|
+
const [vertical, horizontal] = label.padding.split(' ');
|
|
100
|
+
const fs = parseFloat(label.fontSizeMobile.replace('rem', '')) * 10.0;
|
|
101
|
+
const lh = parseFloat(lineHeight);
|
|
102
|
+
return {
|
|
103
|
+
fontSize: (0, exports.remsToPixels)(label.fontSizeMobile, true),
|
|
104
|
+
lineHeight: `${(0, platform_1.wp)(fs * lh)}px`,
|
|
105
|
+
offset: (0, exports.remsToPixels)(label.offset),
|
|
106
|
+
padding: `${(0, exports.remsToPixels)(vertical)} ${(0, exports.remsToPixels)(horizontal)}`,
|
|
107
|
+
top: (0, exports.remsToPixels)(label.top),
|
|
108
|
+
left: (0, exports.remsToPixels)(label.left),
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
const makeInputs = (inputs) => {
|
|
112
|
+
const [vertical, horizontal] = inputs.padding.split(' ');
|
|
113
|
+
const fs = parseFloat(inputs.fontSizeMobile.replace('rem', '')) * 10.0;
|
|
114
|
+
const lh = parseFloat(inputs.lineHeight);
|
|
115
|
+
return Object.assign(Object.assign({}, inputs), { lineHeight: `${(0, platform_1.wp)(fs * lh)}px`, letterSpacing: (0, exports.remsToPixels)(inputs.letterSpacing), fontSize: (0, exports.remsToPixels)(inputs.fontSizeMobile, true), radius: (0, exports.remsToPixels)(inputs.radius), borderWidth: (0, exports.remsToPixels)(inputs.borderWidth), borderWidthApp: (0, exports.remsToPixels)(inputs.borderWidthApp), padding: `${(0, exports.remsToPixels)(vertical)} ${(0, exports.remsToPixels)(horizontal)}`, paddingHorizontal: (0, exports.remsToPixels)(inputs.paddingHorizontal), paddingVertical: (0, exports.remsToPixels)(inputs.paddingVertical), paddingTop: (0, exports.remsToPixels)(inputs.paddingTop), paddingTopActive: (0, exports.remsToPixels)(inputs.paddingTopActive), paddingBottom: (0, exports.remsToPixels)(inputs.paddingBottom), paddingBottomActive: (0, exports.remsToPixels)(inputs.paddingBottomActive), label: makeLabel(inputs.label, inputs.lineHeight) });
|
|
116
|
+
};
|
|
117
|
+
const makeCounts = (counts) => {
|
|
118
|
+
const { alerts, quantity } = counts;
|
|
119
|
+
return {
|
|
120
|
+
alerts: Object.assign(Object.assign({}, alerts), { borderWidth: (0, exports.remsToPixels)(alerts.borderWidth), borderWidthApp: (0, exports.remsToPixels)(alerts.borderWidthApp), fontSize: (0, exports.remsToPixels)(alerts.fontSize, true), fontSizeMobile: (0, exports.remsToPixels)(alerts.fontSizeMobile, true), paddingBottom: (0, exports.remsToPixels)(alerts.paddingBottom), paddingTop: (0, exports.remsToPixels)(alerts.paddingTop) }),
|
|
121
|
+
quantity: Object.assign(Object.assign({}, quantity), { fontSize: (0, exports.remsToPixels)(quantity.fontSize, true), fontSizeMobile: (0, exports.remsToPixels)(quantity.fontSizeMobile, true), paddingBottom: (0, exports.remsToPixels)(quantity.paddingBottom), paddingTop: (0, exports.remsToPixels)(quantity.paddingTop) }),
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
const makeCards = (cards) => {
|
|
125
|
+
const { default: box, form, menuItem, modifier } = cards;
|
|
126
|
+
return {
|
|
127
|
+
default: Object.assign(Object.assign({}, box), { borderWidth: (0, exports.remsToPixels)(box.borderWidth), borderWidthApp: (0, exports.remsToPixels)(box.borderWidthApp), borderRadius: (0, exports.remsToPixels)(box.borderRadius) }),
|
|
128
|
+
form: Object.assign(Object.assign({}, form), { borderWidth: (0, exports.remsToPixels)(form.borderWidth), borderWidthApp: (0, exports.remsToPixels)(form.borderWidthApp), borderRadius: (0, exports.remsToPixels)(form.borderRadius) }),
|
|
129
|
+
menuItem: Object.assign(Object.assign({}, menuItem), { borderWidth: (0, exports.remsToPixels)(menuItem.borderWidth), borderWidthApp: (0, exports.remsToPixels)(menuItem.borderWidthApp), borderRadius: (0, exports.remsToPixels)(menuItem.borderRadius) }),
|
|
130
|
+
modifier: Object.assign(Object.assign({}, modifier), { borderWidth: (0, exports.remsToPixels)(modifier.borderWidth), borderWidthApp: (0, exports.remsToPixels)(modifier.borderWidthApp), borderRadius: (0, exports.remsToPixels)(modifier.borderRadius) }),
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
const makeWelcome = (welcome) => {
|
|
134
|
+
const { mobile } = welcome;
|
|
135
|
+
const titleSize = (0, exports.remsToPixels)(mobile === null || mobile === void 0 ? void 0 : mobile.titleSize);
|
|
136
|
+
const subtitleSize = (0, exports.remsToPixels)(mobile === null || mobile === void 0 ? void 0 : mobile.subtitleSize);
|
|
137
|
+
return {
|
|
138
|
+
textAlign: mobile === null || mobile === void 0 ? void 0 : mobile.textAlign,
|
|
139
|
+
marginTop: (0, exports.remsToPixels)(mobile === null || mobile === void 0 ? void 0 : mobile.marginTop),
|
|
140
|
+
marginBottom: (0, exports.remsToPixels)(mobile === null || mobile === void 0 ? void 0 : mobile.marginBottom),
|
|
141
|
+
titleMarginLeft: (0, exports.remsToPixels)(mobile === null || mobile === void 0 ? void 0 : mobile.titleMarginLeft),
|
|
142
|
+
titleSize,
|
|
143
|
+
titleLineHeight: (0, exports.makeLineHeight)(mobile === null || mobile === void 0 ? void 0 : mobile.titleLineHeight, titleSize),
|
|
144
|
+
subtitleSize,
|
|
145
|
+
subtitleLineHeight: (0, exports.makeLineHeight)(mobile === null || mobile === void 0 ? void 0 : mobile.subtitleLineHeight, subtitleSize),
|
|
146
|
+
subtitleMarginTop: (0, exports.remsToPixels)(mobile === null || mobile === void 0 ? void 0 : mobile.subtitleMarginTop),
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
const makeItem = (item) => {
|
|
150
|
+
const { mobile } = item;
|
|
151
|
+
return Object.assign(Object.assign({}, item), { padding: (0, exports.remsToPixels)(mobile.padding), imagePadding: (0, exports.remsToPixels)(mobile.imagePadding), maxWidth: (0, exports.remsToPixels)(mobile.maxWidth), imageMinHeight: (0, exports.remsToPixels)(mobile.imageMinHeight), imageMaxHeight: (0, exports.remsToPixels)(mobile.imageMaxHeight) });
|
|
152
|
+
};
|
|
153
|
+
const decorateTheme = (theme) => {
|
|
154
|
+
const fonts = makeFonts(theme.fonts, theme.lineHeight);
|
|
155
|
+
const lineHeight = (0, exports.makeLineHeight)(theme.lineHeight, fonts.sizes.main);
|
|
156
|
+
const layout = (0, exports.objRemsToPixels)(theme.layout);
|
|
157
|
+
const buttons = makeButtons(theme.buttons);
|
|
158
|
+
const border = makeBorder(theme.border);
|
|
159
|
+
const inputs = makeInputs(theme.inputs);
|
|
160
|
+
const counts = makeCounts(theme.counts);
|
|
161
|
+
const cards = makeCards(theme.cards);
|
|
162
|
+
const welcome = makeWelcome(theme.welcome);
|
|
163
|
+
const item = makeItem(theme.item);
|
|
164
|
+
return Object.assign(Object.assign({}, theme), { fonts: fonts, lineHeight, layout: layout, buttons: buttons, border, inputs: inputs, counts,
|
|
165
|
+
cards, welcome: welcome, item });
|
|
166
|
+
};
|
|
167
|
+
exports.decorateTheme = decorateTheme;
|
|
168
|
+
const hexToRgbA = (hex, opacity) => {
|
|
169
|
+
let c;
|
|
170
|
+
if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
|
|
171
|
+
c = hex.substring(1).split('');
|
|
172
|
+
if (c.length === 3) {
|
|
173
|
+
c = [c[0], c[0], c[1], c[1], c[2], c[2]];
|
|
174
|
+
}
|
|
175
|
+
c = '0x' + c.join('');
|
|
176
|
+
return ('rgba(' +
|
|
177
|
+
[(c >> 16) & 255, (c >> 8) & 255, c & 255].join(',') +
|
|
178
|
+
`,${opacity})`);
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
};
|
|
182
|
+
exports.hexToRgbA = hexToRgbA;
|
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 {
|
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,26 @@
|
|
|
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) => Partial<T>;
|
|
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) => ConfigTheme;
|
|
26
|
+
export declare const hexToRgbA: (hex: string, opacity: number) => string | null;
|
|
@@ -0,0 +1,171 @@
|
|
|
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: fonts, lineHeight, layout: layout, buttons: buttons, border, inputs: inputs, counts,
|
|
156
|
+
cards, welcome: welcome, item });
|
|
157
|
+
};
|
|
158
|
+
export const hexToRgbA = (hex, opacity) => {
|
|
159
|
+
let c;
|
|
160
|
+
if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
|
|
161
|
+
c = hex.substring(1).split('');
|
|
162
|
+
if (c.length === 3) {
|
|
163
|
+
c = [c[0], c[0], c[1], c[1], c[2], c[2]];
|
|
164
|
+
}
|
|
165
|
+
c = '0x' + c.join('');
|
|
166
|
+
return ('rgba(' +
|
|
167
|
+
[(c >> 16) & 255, (c >> 8) & 255, c & 255].join(',') +
|
|
168
|
+
`,${opacity})`);
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
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
|
}
|