@jobber/components-native 0.38.0 → 0.39.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/src/AtlantisContext/AtlantisContext.js +2 -0
- package/dist/src/InputDate/InputDate.js +76 -0
- package/dist/src/InputDate/index.js +1 -0
- package/dist/src/InputDate/messages.js +8 -0
- package/dist/src/Menu/Menu.js +67 -0
- package/dist/src/Menu/Menu.style.js +6 -0
- package/dist/src/Menu/components/MenuOption/MenuOption.js +25 -0
- package/dist/src/Menu/components/MenuOption/MenuOption.style.js +10 -0
- package/dist/src/Menu/components/MenuOption/index.js +1 -0
- package/dist/src/Menu/components/Overlay/Overlay.js +9 -0
- package/dist/src/Menu/components/Overlay/Overlay.style.js +6 -0
- package/dist/src/Menu/components/Overlay/index.js +1 -0
- package/dist/src/Menu/index.js +1 -0
- package/dist/src/Menu/messages.js +8 -0
- package/dist/src/Menu/types.js +1 -0
- package/dist/src/Menu/utils.js +84 -0
- package/dist/src/index.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/AtlantisContext/AtlantisContext.d.ts +7 -1
- package/dist/types/src/InputDate/InputDate.d.ts +74 -0
- package/dist/types/src/InputDate/index.d.ts +1 -0
- package/dist/types/src/InputDate/messages.d.ts +7 -0
- package/dist/types/src/Menu/Menu.d.ts +3 -0
- package/dist/types/src/Menu/Menu.style.d.ts +18 -0
- package/dist/types/src/Menu/components/MenuOption/MenuOption.d.ts +3 -0
- package/dist/types/src/Menu/components/MenuOption/MenuOption.style.d.ts +8 -0
- package/dist/types/src/Menu/components/MenuOption/index.d.ts +1 -0
- package/dist/types/src/Menu/components/Overlay/Overlay.d.ts +3 -0
- package/dist/types/src/Menu/components/Overlay/Overlay.style.d.ts +12 -0
- package/dist/types/src/Menu/components/Overlay/index.d.ts +1 -0
- package/dist/types/src/Menu/index.d.ts +2 -0
- package/dist/types/src/Menu/messages.d.ts +7 -0
- package/dist/types/src/Menu/types.d.ts +22 -0
- package/dist/types/src/Menu/utils.d.ts +10 -0
- package/dist/types/src/index.d.ts +2 -0
- package/package.json +2 -2
- package/src/AtlantisContext/AtlantisContext.tsx +10 -1
- package/src/InputDate/InputDate.test.tsx +295 -0
- package/src/InputDate/InputDate.tsx +231 -0
- package/src/InputDate/index.ts +1 -0
- package/src/InputDate/messages.ts +9 -0
- package/src/Menu/Menu.style.ts +16 -0
- package/src/Menu/Menu.test.tsx +201 -0
- package/src/Menu/Menu.tsx +116 -0
- package/src/Menu/components/MenuOption/MenuOption.style.tsx +11 -0
- package/src/Menu/components/MenuOption/MenuOption.tsx +63 -0
- package/src/Menu/components/MenuOption/index.ts +1 -0
- package/src/Menu/components/Overlay/Overlay.style.ts +13 -0
- package/src/Menu/components/Overlay/Overlay.tsx +16 -0
- package/src/Menu/components/Overlay/index.ts +1 -0
- package/src/Menu/index.ts +6 -0
- package/src/Menu/messages.ts +9 -0
- package/src/Menu/types.ts +25 -0
- package/src/Menu/utils.ts +151 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IconColorNames, IconNames } from "@jobber/design";
|
|
2
|
+
import { TextAlign } from "../Typography";
|
|
3
|
+
|
|
4
|
+
export interface MenuOptionProps {
|
|
5
|
+
readonly label: string;
|
|
6
|
+
readonly icon?: IconNames;
|
|
7
|
+
readonly iconColor?: IconColorNames;
|
|
8
|
+
readonly textAlign?: TextAlign;
|
|
9
|
+
readonly destructive?: boolean;
|
|
10
|
+
readonly textTransform?: "none" | "capitalize";
|
|
11
|
+
onPress: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface MenuOptionInternalProps extends MenuOptionProps {
|
|
15
|
+
setOpen: (bool: boolean) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface MenuProps {
|
|
19
|
+
readonly menuOptions?: MenuOptionProps[];
|
|
20
|
+
readonly customActivator?: JSX.Element;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface OverlayProp {
|
|
24
|
+
setOpen: (bool: boolean) => void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { LayoutRectangle } from "react-native";
|
|
2
|
+
import { styles } from "./Menu.style";
|
|
3
|
+
|
|
4
|
+
interface ScreenInfo {
|
|
5
|
+
windowHeight: number;
|
|
6
|
+
headerHeight: number;
|
|
7
|
+
windowWidth: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function findViewpoint(
|
|
11
|
+
screenInfo: ScreenInfo,
|
|
12
|
+
activatorLayout: LayoutRectangle,
|
|
13
|
+
): { [key: string]: number | undefined } {
|
|
14
|
+
const { windowHeight, windowWidth, headerHeight } = screenInfo;
|
|
15
|
+
const pos: { [key: string]: number | undefined } = {};
|
|
16
|
+
const menuWidth = styles.menu.width;
|
|
17
|
+
const windowHalf = (windowHeight - headerHeight) / 2 + headerHeight;
|
|
18
|
+
const menuPositionVertical =
|
|
19
|
+
activatorLayout.y + activatorLayout.height > windowHalf
|
|
20
|
+
? "menuAbove"
|
|
21
|
+
: "menuBelow";
|
|
22
|
+
|
|
23
|
+
const menuPositionHorizontal =
|
|
24
|
+
windowWidth / 2 > activatorLayout.width / 2 + activatorLayout.x
|
|
25
|
+
? "menuRight"
|
|
26
|
+
: "menuLeft";
|
|
27
|
+
|
|
28
|
+
const menuPadding = 36;
|
|
29
|
+
|
|
30
|
+
getVerticalPosition(pos, windowHeight, activatorLayout, menuPositionVertical);
|
|
31
|
+
|
|
32
|
+
getHorizontalPosition(
|
|
33
|
+
pos,
|
|
34
|
+
activatorLayout,
|
|
35
|
+
windowWidth,
|
|
36
|
+
menuPadding,
|
|
37
|
+
menuWidth,
|
|
38
|
+
menuPositionHorizontal,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return pos;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getVerticalPosition(
|
|
45
|
+
pos: { [key: string]: number | undefined },
|
|
46
|
+
windowHeight: number,
|
|
47
|
+
activatorLayout: LayoutRectangle,
|
|
48
|
+
menuPositionVertical: string,
|
|
49
|
+
) {
|
|
50
|
+
if (menuPositionVertical === "menuAbove") {
|
|
51
|
+
getAbovePosition(pos, windowHeight, activatorLayout);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (menuPositionVertical === "menuBelow") {
|
|
55
|
+
getBelowPosition(pos, activatorLayout);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getBelowPosition(
|
|
60
|
+
pos: { [key: string]: number | undefined },
|
|
61
|
+
activatorLayout: LayoutRectangle,
|
|
62
|
+
) {
|
|
63
|
+
pos.top = activatorLayout.y + activatorLayout.height;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getAbovePosition(
|
|
67
|
+
pos: { [key: string]: number | undefined },
|
|
68
|
+
windowHeight: number,
|
|
69
|
+
activatorLayout: LayoutRectangle,
|
|
70
|
+
) {
|
|
71
|
+
pos.bottom = windowHeight - activatorLayout.y;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getHorizontalPosition(
|
|
75
|
+
pos: { [key: string]: number | undefined },
|
|
76
|
+
activatorLayout: LayoutRectangle,
|
|
77
|
+
windowWidth: number,
|
|
78
|
+
menuPadding: number,
|
|
79
|
+
menuWidth: number,
|
|
80
|
+
menuPositionHorizontal: string,
|
|
81
|
+
) {
|
|
82
|
+
if (menuPositionHorizontal === "menuRight") {
|
|
83
|
+
getRightPosition(pos, activatorLayout, windowWidth, menuPadding, menuWidth);
|
|
84
|
+
}
|
|
85
|
+
if (menuPositionHorizontal === "menuLeft") {
|
|
86
|
+
getLeftPosition(pos, activatorLayout, windowWidth, menuPadding, menuWidth);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function getLeftPosition(
|
|
91
|
+
pos: { [key: string]: number | undefined },
|
|
92
|
+
activatorLayout: LayoutRectangle,
|
|
93
|
+
windowWidth: number,
|
|
94
|
+
menuHorizontalPadding: number,
|
|
95
|
+
menuWidth: number,
|
|
96
|
+
) {
|
|
97
|
+
const overflowLeft =
|
|
98
|
+
windowWidth -
|
|
99
|
+
activatorLayout.x -
|
|
100
|
+
activatorLayout.width +
|
|
101
|
+
activatorLayout.width / 2 -
|
|
102
|
+
menuHorizontalPadding +
|
|
103
|
+
menuWidth >
|
|
104
|
+
windowWidth;
|
|
105
|
+
|
|
106
|
+
const overflowRight =
|
|
107
|
+
windowWidth -
|
|
108
|
+
activatorLayout.x -
|
|
109
|
+
activatorLayout.width +
|
|
110
|
+
activatorLayout.width / 2 -
|
|
111
|
+
menuHorizontalPadding <
|
|
112
|
+
0;
|
|
113
|
+
|
|
114
|
+
if (overflowLeft) {
|
|
115
|
+
pos.right = undefined;
|
|
116
|
+
pos.left = 0;
|
|
117
|
+
} else if (overflowRight) {
|
|
118
|
+
pos.right = 0;
|
|
119
|
+
} else {
|
|
120
|
+
pos.right =
|
|
121
|
+
windowWidth -
|
|
122
|
+
activatorLayout.x -
|
|
123
|
+
activatorLayout.width +
|
|
124
|
+
activatorLayout.width / 2 -
|
|
125
|
+
menuHorizontalPadding;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getRightPosition(
|
|
130
|
+
pos: { [key: string]: number | undefined },
|
|
131
|
+
activatorLayout: LayoutRectangle,
|
|
132
|
+
windowWidth: number,
|
|
133
|
+
menuPadding: number,
|
|
134
|
+
menuWidth: number,
|
|
135
|
+
) {
|
|
136
|
+
const overflowRight =
|
|
137
|
+
activatorLayout.x + activatorLayout.width / 2 - menuPadding + menuWidth >
|
|
138
|
+
windowWidth;
|
|
139
|
+
|
|
140
|
+
const overflowLeft =
|
|
141
|
+
activatorLayout.x + activatorLayout.width / 2 - menuPadding < 0;
|
|
142
|
+
|
|
143
|
+
if (overflowRight) {
|
|
144
|
+
pos.left = undefined;
|
|
145
|
+
pos.right = 0;
|
|
146
|
+
} else if (overflowLeft) {
|
|
147
|
+
pos.left = 0;
|
|
148
|
+
} else {
|
|
149
|
+
pos.left = activatorLayout.x + activatorLayout.width / 2 - menuPadding;
|
|
150
|
+
}
|
|
151
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -22,12 +22,14 @@ export * from "./Icon";
|
|
|
22
22
|
export * from "./IconButton";
|
|
23
23
|
export * from "./InputFieldWrapper";
|
|
24
24
|
export * from "./InputCurrency";
|
|
25
|
+
export * from "./InputDate";
|
|
25
26
|
export * from "./InputNumber";
|
|
26
27
|
export * from "./InputPassword";
|
|
27
28
|
export * from "./InputPressable";
|
|
28
29
|
export * from "./InputSearch";
|
|
29
30
|
export * from "./InputTime";
|
|
30
31
|
export * from "./InputText";
|
|
32
|
+
export * from "./Menu";
|
|
31
33
|
export * from "./TextList";
|
|
32
34
|
export * from "./ProgressBar";
|
|
33
35
|
export * from "./Select";
|