ferns-ui 0.9.0 → 0.11.1
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/Common.d.ts +5 -0
- package/dist/Common.js.map +1 -1
- package/dist/DateTimeField.android.d.ts +3 -0
- package/dist/DateTimeField.android.js +26 -0
- package/dist/DateTimeField.android.js.map +1 -0
- package/dist/DateTimeField.d.ts +3 -0
- package/dist/DateTimeField.ios.d.ts +3 -0
- package/dist/DateTimeField.ios.js +19 -0
- package/dist/DateTimeField.ios.js.map +1 -0
- package/dist/DateTimeField.js +21 -0
- package/dist/DateTimeField.js.map +1 -0
- package/dist/Modal.d.ts +17 -0
- package/dist/Modal.js +62 -0
- package/dist/Modal.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -1
- package/src/Common.ts +6 -0
- package/src/DateTimeField.android.tsx +59 -0
- package/src/DateTimeField.ios.tsx +44 -0
- package/src/DateTimeField.tsx +48 -0
- package/src/Modal.tsx +143 -0
- package/src/index.tsx +3 -2
package/dist/Common.d.ts
CHANGED
|
@@ -354,6 +354,11 @@ export interface FieldWithLabelsProps {
|
|
|
354
354
|
helperTextColor?: AllColors;
|
|
355
355
|
children?: React.ReactNode;
|
|
356
356
|
}
|
|
357
|
+
export interface DateTimeFieldProps extends FieldWithLabelsProps {
|
|
358
|
+
mode: "date" | "time" | "datetime";
|
|
359
|
+
value: Date;
|
|
360
|
+
onChange: (date: Date) => void;
|
|
361
|
+
}
|
|
357
362
|
export interface TextFieldProps extends FieldWithLabelsProps {
|
|
358
363
|
innerRef?: any;
|
|
359
364
|
id?: string;
|
package/dist/Common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Common.js","sourceRoot":"","sources":["../src/Common.ts"],"names":[],"mappings":"AAgVA,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC;AAkBzB,MAAM,CAA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
|
|
2
|
+
import moment from "moment-timezone";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { View } from "react-native";
|
|
5
|
+
import { Box } from "./Box";
|
|
6
|
+
import { WithLabel } from "./WithLabel";
|
|
7
|
+
export const DateTimeField = ({ mode, value, onChange, errorMessage, errorMessageColor, }) => {
|
|
8
|
+
return (React.createElement(WithLabel, { label: errorMessage, labelColor: errorMessageColor || "red", labelPlacement: "after", labelSize: "sm" },
|
|
9
|
+
React.createElement(WithLabel, null,
|
|
10
|
+
React.createElement(View, null,
|
|
11
|
+
React.createElement(Box, { maxWidth: 300 },
|
|
12
|
+
React.createElement(DateTimePicker, { display: "spinner", mode: mode === "datetime" ? "date" : mode, testID: "dateTimePicker", value: moment(value).toDate(), onChange: (event, date) => {
|
|
13
|
+
if (!date) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
onChange(value);
|
|
17
|
+
} }),
|
|
18
|
+
mode === "datetime" && (React.createElement(DateTimePicker, { display: "spinner", mode: "time", testID: "dateTimePicker", value: moment(value).toDate(), onChange: (event, date) => {
|
|
19
|
+
// fix to append to date object
|
|
20
|
+
if (!date) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
onChange(value);
|
|
24
|
+
} })))))));
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=DateTimeField.android.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DateTimeField.android.js","sourceRoot":"","sources":["../src/DateTimeField.android.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,wCAAwC,CAAC;AACpE,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,KAAqB,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAC;AAElC,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAC5B,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,iBAAiB,GACE,EAAgB,EAAE;IACrC,OAAO,CACL,oBAAC,SAAS,IACR,KAAK,EAAE,YAAY,EACnB,UAAU,EAAE,iBAAiB,IAAI,KAAK,EACtC,cAAc,EAAC,OAAO,EACtB,SAAS,EAAC,IAAI;QAEd,oBAAC,SAAS;YACR,oBAAC,IAAI;gBACH,oBAAC,GAAG,IAAC,QAAQ,EAAE,GAAG;oBAChB,oBAAC,cAAc,IACb,OAAO,EAAC,SAAS,EACjB,IAAI,EAAE,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EACzC,MAAM,EAAC,gBAAgB,EACvB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAC7B,QAAQ,EAAE,CAAC,KAAU,EAAE,IAAS,EAAE,EAAE;4BAClC,IAAI,CAAC,IAAI,EAAE;gCACT,OAAO;6BACR;4BACD,QAAQ,CAAC,KAAK,CAAC,CAAC;wBAClB,CAAC,GACD;oBACD,IAAI,KAAK,UAAU,IAAI,CACtB,oBAAC,cAAc,IACb,OAAO,EAAC,SAAS,EACjB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,gBAAgB,EACvB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAC7B,QAAQ,EAAE,CAAC,KAAU,EAAE,IAAS,EAAE,EAAE;4BAClC,+BAA+B;4BAC/B,IAAI,CAAC,IAAI,EAAE;gCACT,OAAO;6BACR;4BACD,QAAQ,CAAC,KAAK,CAAC,CAAC;wBAClB,CAAC,GACD,CACH,CACG,CACD,CACG,CACF,CACb,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import DateTimePicker from "@react-native-community/datetimepicker";
|
|
2
|
+
import moment from "moment-timezone";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { View } from "react-native";
|
|
5
|
+
import { Box } from "./Box";
|
|
6
|
+
import { WithLabel } from "./WithLabel";
|
|
7
|
+
export const DateTimeField = ({ mode, value, onChange, errorMessage, errorMessageColor, }) => {
|
|
8
|
+
return (React.createElement(WithLabel, { label: errorMessage, labelColor: errorMessageColor || "red", labelPlacement: "after", labelSize: "sm" },
|
|
9
|
+
React.createElement(WithLabel, null,
|
|
10
|
+
React.createElement(View, null,
|
|
11
|
+
React.createElement(Box, { maxWidth: 300 },
|
|
12
|
+
React.createElement(DateTimePicker, { display: "spinner", mode: mode, testID: "dateTimePicker", value: moment(value).toDate(), onChange: (event, date) => {
|
|
13
|
+
if (!date) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
onChange(value);
|
|
17
|
+
} }))))));
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=DateTimeField.ios.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DateTimeField.ios.js","sourceRoot":"","sources":["../src/DateTimeField.ios.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,wCAAwC,CAAC;AACpE,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,KAAqB,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAC;AAElC,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAC5B,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,iBAAiB,GACE,EAAgB,EAAE;IACrC,OAAO,CACL,oBAAC,SAAS,IACR,KAAK,EAAE,YAAY,EACnB,UAAU,EAAE,iBAAiB,IAAI,KAAK,EACtC,cAAc,EAAC,OAAO,EACtB,SAAS,EAAC,IAAI;QAEd,oBAAC,SAAS;YACR,oBAAC,IAAI;gBACH,oBAAC,GAAG,IAAC,QAAQ,EAAE,GAAG;oBAChB,oBAAC,cAAc,IACb,OAAO,EAAC,SAAS,EACjB,IAAI,EAAE,IAAI,EACV,MAAM,EAAC,gBAAgB,EACvB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAC7B,QAAQ,EAAE,CAAC,KAAU,EAAE,IAAS,EAAE,EAAE;4BAClC,IAAI,CAAC,IAAI,EAAE;gCACT,OAAO;6BACR;4BACD,QAAQ,CAAC,KAAK,CAAC,CAAC;wBAClB,CAAC,GACD,CACE,CACD,CACG,CACF,CACb,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import DatePicker from "react-date-picker";
|
|
3
|
+
import DateTimePickerWeb from "react-datetime-picker";
|
|
4
|
+
import { View } from "react-native";
|
|
5
|
+
import TimePicker from "react-time-picker";
|
|
6
|
+
import { Box } from "./Box";
|
|
7
|
+
import { WithLabel } from "./WithLabel";
|
|
8
|
+
export const DateTimeField = ({ mode, value, onChange, errorMessage, errorMessageColor, }) => {
|
|
9
|
+
return (React.createElement(WithLabel, { label: errorMessage, labelColor: errorMessageColor || "red", labelPlacement: "after", labelSize: "sm" },
|
|
10
|
+
React.createElement(WithLabel, null,
|
|
11
|
+
React.createElement(View, null,
|
|
12
|
+
React.createElement(Box, { maxWidth: 300 },
|
|
13
|
+
mode === "datetime" && (React.createElement(DateTimePickerWeb, { disableClock: true, value: value, onChange: onChange })),
|
|
14
|
+
mode === "date" && React.createElement(DatePicker, { value: value, onChange: onChange }),
|
|
15
|
+
mode === "time" && (React.createElement(TimePicker, { disableClock: true, value: value, onChange: (newVal) => {
|
|
16
|
+
// TimePicker returns a string or Date, so we need to make sure it's a Date
|
|
17
|
+
const newDate = new Date(newVal);
|
|
18
|
+
onChange(newDate);
|
|
19
|
+
} })))))));
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=DateTimeField.js.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ACpB,CAAC,GACD,CACH,CACG,CACD,CACG,CACF,CACb,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/Modal.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface ModalProps {
|
|
3
|
+
onDismiss: () => void;
|
|
4
|
+
visible: boolean;
|
|
5
|
+
align?: "center" | "start";
|
|
6
|
+
children?: React.ReactElement;
|
|
7
|
+
footer?: React.ReactElement;
|
|
8
|
+
heading?: string;
|
|
9
|
+
size?: "sm" | "md" | "lg";
|
|
10
|
+
subHeading?: string;
|
|
11
|
+
primaryButtonText?: string;
|
|
12
|
+
primaryButtonOnClick?: (value?: any) => void;
|
|
13
|
+
secondaryButtonText?: string;
|
|
14
|
+
secondaryButtonOnClick?: (value?: any) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare const Modal: ({ onDismiss, visible, align, children, footer, heading, size, subHeading, primaryButtonText, primaryButtonOnClick, secondaryButtonText, secondaryButtonOnClick, }: ModalProps) => React.ReactElement;
|
|
17
|
+
export {};
|
package/dist/Modal.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Dimensions, Modal as RNModal } from "react-native";
|
|
3
|
+
import { Box } from "./Box";
|
|
4
|
+
import { Button } from "./Button";
|
|
5
|
+
import { Heading } from "./Heading";
|
|
6
|
+
import { Text } from "./Text";
|
|
7
|
+
export const Modal = ({ onDismiss, visible, align = "center", children, footer, heading, size, subHeading, primaryButtonText, primaryButtonOnClick, secondaryButtonText, secondaryButtonOnClick, }) => {
|
|
8
|
+
if (subHeading && !heading) {
|
|
9
|
+
throw new Error("Cannot render Modal with subHeading and no heading");
|
|
10
|
+
}
|
|
11
|
+
if (!footer && !primaryButtonText && !secondaryButtonText) {
|
|
12
|
+
throw new Error("Cannot render Modal without footer, primaryButtonText, or secondaryButtonText");
|
|
13
|
+
}
|
|
14
|
+
function renderHeader() {
|
|
15
|
+
return (React.createElement(Box, { paddingY: 3, width: "100%" },
|
|
16
|
+
React.createElement(Box, null,
|
|
17
|
+
React.createElement(Heading, { align: align === "center" ? "center" : undefined, size: "sm" }, heading)),
|
|
18
|
+
Boolean(subHeading) && (React.createElement(Box, { paddingY: 2 },
|
|
19
|
+
React.createElement(Text, { align: align === "center" ? "center" : undefined }, subHeading)))));
|
|
20
|
+
}
|
|
21
|
+
function renderFooter() {
|
|
22
|
+
if (footer) {
|
|
23
|
+
return footer;
|
|
24
|
+
}
|
|
25
|
+
return (React.createElement(Box, { direction: "row", justifyContent: "end", width: "100%" },
|
|
26
|
+
Boolean(secondaryButtonText) && (React.createElement(Box, { marginRight: 4, minWidth: 120 },
|
|
27
|
+
React.createElement(Button, { color: "gray", text: secondaryButtonText !== null && secondaryButtonText !== void 0 ? secondaryButtonText : "", onClick: secondaryButtonOnClick }))),
|
|
28
|
+
React.createElement(Box, { minWidth: 120 },
|
|
29
|
+
React.createElement(Button, { color: "primary", text: primaryButtonText !== null && primaryButtonText !== void 0 ? primaryButtonText : "", onClick: primaryButtonOnClick }))));
|
|
30
|
+
}
|
|
31
|
+
let sizePx = 540;
|
|
32
|
+
if (size === "md") {
|
|
33
|
+
sizePx = 720;
|
|
34
|
+
}
|
|
35
|
+
else if (size === "lg") {
|
|
36
|
+
sizePx = 900;
|
|
37
|
+
}
|
|
38
|
+
// Adjust size for small screens
|
|
39
|
+
if (sizePx > Dimensions.get("window").width) {
|
|
40
|
+
sizePx = "90%";
|
|
41
|
+
}
|
|
42
|
+
return (React.createElement(Box, { alignItems: "center", flex: "grow", height: "100%", justifyContent: "center", width: "100%" },
|
|
43
|
+
React.createElement(RNModal, { animationType: "slide", transparent: true, visible: visible, onRequestClose: onDismiss },
|
|
44
|
+
React.createElement(Box, { alignItems: "center", alignSelf: "center", color: "white", dangerouslySetInlineStyle: {
|
|
45
|
+
__style: {
|
|
46
|
+
zIndex: 1,
|
|
47
|
+
shadowColor: "#999",
|
|
48
|
+
shadowOffset: {
|
|
49
|
+
width: 4,
|
|
50
|
+
height: 6,
|
|
51
|
+
},
|
|
52
|
+
shadowRadius: 4,
|
|
53
|
+
shadowOpacity: 1.0,
|
|
54
|
+
elevation: 8,
|
|
55
|
+
},
|
|
56
|
+
}, direction: "column", justifyContent: "center", marginTop: 12, maxWidth: sizePx, minWidth: 300, paddingX: 8, paddingY: 2, rounding: 6, shadow: true, width: sizePx },
|
|
57
|
+
React.createElement(Box, { marginBottom: 6, width: "100%" },
|
|
58
|
+
renderHeader(),
|
|
59
|
+
React.createElement(Box, { paddingY: 4 }, children),
|
|
60
|
+
React.createElement(Box, { paddingY: 4 }, renderFooter()))))));
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=Modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Modal.js","sourceRoot":"","sources":["../src/Modal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,UAAU,EAAE,KAAK,IAAI,OAAO,EAAC,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAuB5B,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EACpB,SAAS,EACT,OAAO,EACP,KAAK,GAAG,QAAQ,EAChB,QAAQ,EACR,MAAM,EACN,OAAO,EACP,IAAI,EACJ,UAAU,EACV,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,GACX,EAAsB,EAAE;IACnC,IAAI,UAAU,IAAI,CAAC,OAAO,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;KACvE;IACD,IAAI,CAAC,MAAM,IAAI,CAAC,iBAAiB,IAAI,CAAC,mBA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AAC,GAAG,IAAC,QAAQ,EAAE,CAAC,IAAG,QAAQ,CAAO;oBAClC,oBAAC,GAAG,IAAC,QAAQ,EAAE,CAAC,IAAG,YAAY,EAAE,CAAO,CACpC,CACF,CACE,CACN,CACP,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./Constants";
|
|
2
2
|
export * from "./Common";
|
|
3
|
+
export * from "./ActionSheet";
|
|
3
4
|
export * from "./Avatar";
|
|
4
5
|
export * from "./Banner";
|
|
5
6
|
export * from "./BlurBox";
|
|
@@ -17,13 +18,13 @@ export * from "./Form";
|
|
|
17
18
|
export * from "./HeaderButtons";
|
|
18
19
|
export * from "./Heading";
|
|
19
20
|
export * from "./Icon";
|
|
20
|
-
export * from "./ActionSheet";
|
|
21
21
|
export * from "./IconButton";
|
|
22
22
|
export * from "./Image";
|
|
23
23
|
export * from "./ImageBackground";
|
|
24
24
|
export * from "./Link";
|
|
25
25
|
export * from "./Mask";
|
|
26
26
|
export * from "./Meta";
|
|
27
|
+
export * from "./Modal";
|
|
27
28
|
export * from "./Page";
|
|
28
29
|
export * from "./Pill";
|
|
29
30
|
export * from "./ScrollView";
|
|
@@ -44,6 +45,7 @@ export * from "./HeightActionSheet";
|
|
|
44
45
|
export * from "./NumberPickerActionSheet";
|
|
45
46
|
export * from "./ModalSheet";
|
|
46
47
|
export * from "./ProgressBar";
|
|
48
|
+
export * from "./DateTimeField";
|
|
47
49
|
declare type ImageRequireSource = number;
|
|
48
50
|
interface Insets {
|
|
49
51
|
top?: number;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./Constants";
|
|
2
2
|
export * from "./Common";
|
|
3
|
+
export * from "./ActionSheet";
|
|
3
4
|
export * from "./Avatar";
|
|
4
5
|
export * from "./Banner";
|
|
5
6
|
export * from "./BlurBox";
|
|
@@ -17,7 +18,6 @@ export * from "./Form";
|
|
|
17
18
|
export * from "./HeaderButtons";
|
|
18
19
|
export * from "./Heading";
|
|
19
20
|
export * from "./Icon";
|
|
20
|
-
export * from "./ActionSheet";
|
|
21
21
|
export * from "./IconButton";
|
|
22
22
|
export * from "./Image";
|
|
23
23
|
export * from "./ImageBackground";
|
|
@@ -26,7 +26,7 @@ export * from "./ImageBackground";
|
|
|
26
26
|
export * from "./Link";
|
|
27
27
|
export * from "./Mask";
|
|
28
28
|
export * from "./Meta";
|
|
29
|
-
|
|
29
|
+
export * from "./Modal";
|
|
30
30
|
export * from "./Page";
|
|
31
31
|
export * from "./Pill";
|
|
32
32
|
export * from "./ScrollView";
|
|
@@ -48,4 +48,5 @@ export * from "./NumberPickerActionSheet";
|
|
|
48
48
|
// export * from "./Chart";
|
|
49
49
|
export * from "./ModalSheet";
|
|
50
50
|
export * from "./ProgressBar";
|
|
51
|
+
export * from "./DateTimeField";
|
|
51
52
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../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C;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ferns-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"scripts": {
|
|
@@ -127,7 +127,9 @@
|
|
|
127
127
|
"@react-native-picker/picker": "2.4.4",
|
|
128
128
|
"@types/lodash": "^4.14.184",
|
|
129
129
|
"@types/mdurl": "^1.0.2",
|
|
130
|
+
"@types/react-datetime-picker": "^3.4.1",
|
|
130
131
|
"@types/react-native": "^0.69.1",
|
|
132
|
+
"@types/react-time-picker": "^4.0.2",
|
|
131
133
|
"@typescript-eslint/eslint-plugin": "^5.34.0",
|
|
132
134
|
"@typescript-eslint/parser": "^5.34.0",
|
|
133
135
|
"eslint": "^8.22.0",
|
|
@@ -149,6 +151,8 @@
|
|
|
149
151
|
"prettier": "^2.6.2",
|
|
150
152
|
"react": "^18.2.0",
|
|
151
153
|
"react-app-polyfill": "^3.0.0",
|
|
154
|
+
"react-date-picker": "^8.4.0",
|
|
155
|
+
"react-datetime-picker": "^3.5.0",
|
|
152
156
|
"react-dev-utils": "^12.0.1",
|
|
153
157
|
"react-dom": "18.2.0",
|
|
154
158
|
"react-native": "0.69.4",
|
|
@@ -161,6 +165,7 @@
|
|
|
161
165
|
"react-native-svg": "^13.0.0",
|
|
162
166
|
"react-router": "^6.3.0",
|
|
163
167
|
"react-router-dom": "^6.3.0",
|
|
168
|
+
"react-time-picker": "^4.5.0",
|
|
164
169
|
"typescript": "4.1.5"
|
|
165
170
|
},
|
|
166
171
|
"peerDependencies": {
|
package/src/Common.ts
CHANGED
|
@@ -659,6 +659,12 @@ export interface FieldWithLabelsProps {
|
|
|
659
659
|
children?: React.ReactNode;
|
|
660
660
|
}
|
|
661
661
|
|
|
662
|
+
export interface DateTimeFieldProps extends FieldWithLabelsProps {
|
|
663
|
+
mode: "date" | "time" | "datetime";
|
|
664
|
+
value: Date;
|
|
665
|
+
onChange: (date: Date) => void;
|
|
666
|
+
}
|
|
667
|
+
|
|
662
668
|
export interface TextFieldProps extends FieldWithLabelsProps {
|
|
663
669
|
innerRef?: any;
|
|
664
670
|
id?: string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import DateTimePicker from "@react-native-community/datetimepicker";
|
|
2
|
+
import moment from "moment-timezone";
|
|
3
|
+
import React, {ReactElement} from "react";
|
|
4
|
+
import {View} from "react-native";
|
|
5
|
+
|
|
6
|
+
import {Box} from "./Box";
|
|
7
|
+
import {DateTimeFieldProps} from "./Common";
|
|
8
|
+
import {WithLabel} from "./WithLabel";
|
|
9
|
+
|
|
10
|
+
export const DateTimeField = ({
|
|
11
|
+
mode,
|
|
12
|
+
value,
|
|
13
|
+
onChange,
|
|
14
|
+
errorMessage,
|
|
15
|
+
errorMessageColor,
|
|
16
|
+
}: DateTimeFieldProps): ReactElement => {
|
|
17
|
+
return (
|
|
18
|
+
<WithLabel
|
|
19
|
+
label={errorMessage}
|
|
20
|
+
labelColor={errorMessageColor || "red"}
|
|
21
|
+
labelPlacement="after"
|
|
22
|
+
labelSize="sm"
|
|
23
|
+
>
|
|
24
|
+
<WithLabel>
|
|
25
|
+
<View>
|
|
26
|
+
<Box maxWidth={300}>
|
|
27
|
+
<DateTimePicker
|
|
28
|
+
display="spinner"
|
|
29
|
+
mode={mode === "datetime" ? "date" : mode}
|
|
30
|
+
testID="dateTimePicker"
|
|
31
|
+
value={moment(value).toDate()}
|
|
32
|
+
onChange={(event: any, date: any) => {
|
|
33
|
+
if (!date) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
onChange(value);
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
{mode === "datetime" && (
|
|
40
|
+
<DateTimePicker
|
|
41
|
+
display="spinner"
|
|
42
|
+
mode="time"
|
|
43
|
+
testID="dateTimePicker"
|
|
44
|
+
value={moment(value).toDate()}
|
|
45
|
+
onChange={(event: any, date: any) => {
|
|
46
|
+
// fix to append to date object
|
|
47
|
+
if (!date) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
onChange(value);
|
|
51
|
+
}}
|
|
52
|
+
/>
|
|
53
|
+
)}
|
|
54
|
+
</Box>
|
|
55
|
+
</View>
|
|
56
|
+
</WithLabel>
|
|
57
|
+
</WithLabel>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import DateTimePicker from "@react-native-community/datetimepicker";
|
|
2
|
+
import moment from "moment-timezone";
|
|
3
|
+
import React, {ReactElement} from "react";
|
|
4
|
+
import {View} from "react-native";
|
|
5
|
+
|
|
6
|
+
import {Box} from "./Box";
|
|
7
|
+
import {DateTimeFieldProps} from "./Common";
|
|
8
|
+
import {WithLabel} from "./WithLabel";
|
|
9
|
+
|
|
10
|
+
export const DateTimeField = ({
|
|
11
|
+
mode,
|
|
12
|
+
value,
|
|
13
|
+
onChange,
|
|
14
|
+
errorMessage,
|
|
15
|
+
errorMessageColor,
|
|
16
|
+
}: DateTimeFieldProps): ReactElement => {
|
|
17
|
+
return (
|
|
18
|
+
<WithLabel
|
|
19
|
+
label={errorMessage}
|
|
20
|
+
labelColor={errorMessageColor || "red"}
|
|
21
|
+
labelPlacement="after"
|
|
22
|
+
labelSize="sm"
|
|
23
|
+
>
|
|
24
|
+
<WithLabel>
|
|
25
|
+
<View>
|
|
26
|
+
<Box maxWidth={300}>
|
|
27
|
+
<DateTimePicker
|
|
28
|
+
display="spinner"
|
|
29
|
+
mode={mode}
|
|
30
|
+
testID="dateTimePicker"
|
|
31
|
+
value={moment(value).toDate()}
|
|
32
|
+
onChange={(event: any, date: any) => {
|
|
33
|
+
if (!date) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
onChange(value);
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
</Box>
|
|
40
|
+
</View>
|
|
41
|
+
</WithLabel>
|
|
42
|
+
</WithLabel>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React, {ReactElement} from "react";
|
|
2
|
+
import DatePicker from "react-date-picker";
|
|
3
|
+
import DateTimePickerWeb from "react-datetime-picker";
|
|
4
|
+
import {View} from "react-native";
|
|
5
|
+
import TimePicker from "react-time-picker";
|
|
6
|
+
|
|
7
|
+
import {Box} from "./Box";
|
|
8
|
+
import {DateTimeFieldProps} from "./Common";
|
|
9
|
+
import {WithLabel} from "./WithLabel";
|
|
10
|
+
|
|
11
|
+
export const DateTimeField = ({
|
|
12
|
+
mode,
|
|
13
|
+
value,
|
|
14
|
+
onChange,
|
|
15
|
+
errorMessage,
|
|
16
|
+
errorMessageColor,
|
|
17
|
+
}: DateTimeFieldProps): ReactElement => {
|
|
18
|
+
return (
|
|
19
|
+
<WithLabel
|
|
20
|
+
label={errorMessage}
|
|
21
|
+
labelColor={errorMessageColor || "red"}
|
|
22
|
+
labelPlacement="after"
|
|
23
|
+
labelSize="sm"
|
|
24
|
+
>
|
|
25
|
+
<WithLabel>
|
|
26
|
+
<View>
|
|
27
|
+
<Box maxWidth={300}>
|
|
28
|
+
{mode === "datetime" && (
|
|
29
|
+
<DateTimePickerWeb disableClock value={value} onChange={onChange} />
|
|
30
|
+
)}
|
|
31
|
+
{mode === "date" && <DatePicker value={value} onChange={onChange} />}
|
|
32
|
+
{mode === "time" && (
|
|
33
|
+
<TimePicker
|
|
34
|
+
disableClock
|
|
35
|
+
value={value}
|
|
36
|
+
onChange={(newVal) => {
|
|
37
|
+
// TimePicker returns a string or Date, so we need to make sure it's a Date
|
|
38
|
+
const newDate = new Date(newVal);
|
|
39
|
+
onChange(newDate);
|
|
40
|
+
}}
|
|
41
|
+
/>
|
|
42
|
+
)}
|
|
43
|
+
</Box>
|
|
44
|
+
</View>
|
|
45
|
+
</WithLabel>
|
|
46
|
+
</WithLabel>
|
|
47
|
+
);
|
|
48
|
+
};
|
package/src/Modal.tsx
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {Dimensions, Modal as RNModal} from "react-native";
|
|
3
|
+
|
|
4
|
+
import {Box} from "./Box";
|
|
5
|
+
import {Button} from "./Button";
|
|
6
|
+
import {Heading} from "./Heading";
|
|
7
|
+
import {Text} from "./Text";
|
|
8
|
+
|
|
9
|
+
interface ModalProps {
|
|
10
|
+
onDismiss: () => void;
|
|
11
|
+
visible: boolean;
|
|
12
|
+
// Alignment of the header. Default is "center".
|
|
13
|
+
align?: "center" | "start";
|
|
14
|
+
// Element to render in the middle part of the modal.
|
|
15
|
+
children?: React.ReactElement;
|
|
16
|
+
// Element to render in the bottom of the modal. This takes precedence over primaryButton and secondaryButton.
|
|
17
|
+
footer?: React.ReactElement;
|
|
18
|
+
heading?: string;
|
|
19
|
+
size?: "sm" | "md" | "lg";
|
|
20
|
+
subHeading?: string;
|
|
21
|
+
// Renders a primary colored button all the way to the right in the footer, if no footer prop is provided.
|
|
22
|
+
primaryButtonText?: string;
|
|
23
|
+
primaryButtonOnClick?: (value?: any) => void;
|
|
24
|
+
// Renders a primary gray button to the left of the primary button in the footer, if no footer prop is provided.
|
|
25
|
+
// Requires primaryButtonText to be defined, but is not required itself.
|
|
26
|
+
secondaryButtonText?: string;
|
|
27
|
+
secondaryButtonOnClick?: (value?: any) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const Modal = ({
|
|
31
|
+
onDismiss,
|
|
32
|
+
visible,
|
|
33
|
+
align = "center",
|
|
34
|
+
children,
|
|
35
|
+
footer,
|
|
36
|
+
heading,
|
|
37
|
+
size,
|
|
38
|
+
subHeading,
|
|
39
|
+
primaryButtonText,
|
|
40
|
+
primaryButtonOnClick,
|
|
41
|
+
secondaryButtonText,
|
|
42
|
+
secondaryButtonOnClick,
|
|
43
|
+
}: ModalProps): React.ReactElement => {
|
|
44
|
+
if (subHeading && !heading) {
|
|
45
|
+
throw new Error("Cannot render Modal with subHeading and no heading");
|
|
46
|
+
}
|
|
47
|
+
if (!footer && !primaryButtonText && !secondaryButtonText) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
"Cannot render Modal without footer, primaryButtonText, or secondaryButtonText"
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function renderHeader(): React.ReactElement {
|
|
54
|
+
return (
|
|
55
|
+
<Box paddingY={3} width="100%">
|
|
56
|
+
<Box>
|
|
57
|
+
<Heading align={align === "center" ? "center" : undefined} size="sm">
|
|
58
|
+
{heading}
|
|
59
|
+
</Heading>
|
|
60
|
+
</Box>
|
|
61
|
+
{Boolean(subHeading) && (
|
|
62
|
+
<Box paddingY={2}>
|
|
63
|
+
<Text align={align === "center" ? "center" : undefined}>{subHeading}</Text>
|
|
64
|
+
</Box>
|
|
65
|
+
)}
|
|
66
|
+
</Box>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
function renderFooter(): React.ReactElement | null {
|
|
70
|
+
if (footer) {
|
|
71
|
+
return footer;
|
|
72
|
+
}
|
|
73
|
+
return (
|
|
74
|
+
<Box direction="row" justifyContent="end" width="100%">
|
|
75
|
+
{Boolean(secondaryButtonText) && (
|
|
76
|
+
<Box marginRight={4} minWidth={120}>
|
|
77
|
+
<Button
|
|
78
|
+
color="gray"
|
|
79
|
+
text={secondaryButtonText ?? ""}
|
|
80
|
+
onClick={secondaryButtonOnClick}
|
|
81
|
+
/>
|
|
82
|
+
</Box>
|
|
83
|
+
)}
|
|
84
|
+
<Box minWidth={120}>
|
|
85
|
+
<Button color="primary" text={primaryButtonText ?? ""} onClick={primaryButtonOnClick} />
|
|
86
|
+
</Box>
|
|
87
|
+
</Box>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let sizePx: string | number = 540;
|
|
92
|
+
if (size === "md") {
|
|
93
|
+
sizePx = 720;
|
|
94
|
+
} else if (size === "lg") {
|
|
95
|
+
sizePx = 900;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Adjust size for small screens
|
|
99
|
+
if (sizePx > Dimensions.get("window").width) {
|
|
100
|
+
sizePx = "90%";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<Box alignItems="center" flex="grow" height="100%" justifyContent="center" width="100%">
|
|
105
|
+
<RNModal animationType="slide" transparent visible={visible} onRequestClose={onDismiss}>
|
|
106
|
+
<Box
|
|
107
|
+
alignItems="center"
|
|
108
|
+
alignSelf="center"
|
|
109
|
+
color="white"
|
|
110
|
+
dangerouslySetInlineStyle={{
|
|
111
|
+
__style: {
|
|
112
|
+
zIndex: 1,
|
|
113
|
+
shadowColor: "#999",
|
|
114
|
+
shadowOffset: {
|
|
115
|
+
width: 4,
|
|
116
|
+
height: 6,
|
|
117
|
+
},
|
|
118
|
+
shadowRadius: 4,
|
|
119
|
+
shadowOpacity: 1.0,
|
|
120
|
+
elevation: 8,
|
|
121
|
+
},
|
|
122
|
+
}}
|
|
123
|
+
direction="column"
|
|
124
|
+
justifyContent="center"
|
|
125
|
+
marginTop={12}
|
|
126
|
+
maxWidth={sizePx}
|
|
127
|
+
minWidth={300}
|
|
128
|
+
paddingX={8}
|
|
129
|
+
paddingY={2}
|
|
130
|
+
rounding={6}
|
|
131
|
+
shadow
|
|
132
|
+
width={sizePx}
|
|
133
|
+
>
|
|
134
|
+
<Box marginBottom={6} width="100%">
|
|
135
|
+
{renderHeader()}
|
|
136
|
+
<Box paddingY={4}>{children}</Box>
|
|
137
|
+
<Box paddingY={4}>{renderFooter()}</Box>
|
|
138
|
+
</Box>
|
|
139
|
+
</Box>
|
|
140
|
+
</RNModal>
|
|
141
|
+
</Box>
|
|
142
|
+
);
|
|
143
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./Constants";
|
|
2
2
|
export * from "./Common";
|
|
3
|
+
export * from "./ActionSheet";
|
|
3
4
|
export * from "./Avatar";
|
|
4
5
|
export * from "./Banner";
|
|
5
6
|
export * from "./BlurBox";
|
|
@@ -17,7 +18,6 @@ export * from "./Form";
|
|
|
17
18
|
export * from "./HeaderButtons";
|
|
18
19
|
export * from "./Heading";
|
|
19
20
|
export * from "./Icon";
|
|
20
|
-
export * from "./ActionSheet";
|
|
21
21
|
export * from "./IconButton";
|
|
22
22
|
export * from "./Image";
|
|
23
23
|
export * from "./ImageBackground";
|
|
@@ -26,7 +26,7 @@ export * from "./ImageBackground";
|
|
|
26
26
|
export * from "./Link";
|
|
27
27
|
export * from "./Mask";
|
|
28
28
|
export * from "./Meta";
|
|
29
|
-
|
|
29
|
+
export * from "./Modal";
|
|
30
30
|
|
|
31
31
|
export * from "./Page";
|
|
32
32
|
export * from "./Pill";
|
|
@@ -49,6 +49,7 @@ export * from "./NumberPickerActionSheet";
|
|
|
49
49
|
// export * from "./Chart";
|
|
50
50
|
export * from "./ModalSheet";
|
|
51
51
|
export * from "./ProgressBar";
|
|
52
|
+
export * from "./DateTimeField";
|
|
52
53
|
|
|
53
54
|
// Lifted from react-native
|
|
54
55
|
type ImageRequireSource = number;
|