@wq/material-native 2.0.0-alpha.2 → 3.0.0-alpha.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/README.md +6 -22
- package/package.json +8 -25
- package/src/Root.js +80 -0
- package/src/components/Accordion.js +4 -1
- package/src/components/Badge.js +3 -0
- package/src/components/Button.js +4 -10
- package/src/components/ButtonLink.js +14 -3
- package/src/components/CheckboxButton.js +7 -4
- package/src/components/Chip.js +4 -2
- package/src/components/Container.js +2 -1
- package/src/components/Divider.js +2 -1
- package/src/components/ExpandableListItem.js +4 -2
- package/src/components/Fab.js +12 -2
- package/src/components/Footer.js +2 -1
- package/src/components/FooterContent.js +2 -1
- package/src/components/FormatJson.js +4 -1
- package/src/components/Grid.js +3 -0
- package/src/components/Header.js +13 -2
- package/src/components/HorizontalView.js +4 -1
- package/src/components/IconButton.js +6 -4
- package/src/components/Img.js +5 -2
- package/src/components/Link.js +13 -2
- package/src/components/List.js +2 -1
- package/src/components/ListItem.js +4 -2
- package/src/components/ListItemLink.js +14 -3
- package/src/components/ListSubheader.js +2 -1
- package/src/components/Main.js +2 -1
- package/src/components/Menu.js +3 -0
- package/src/components/MenuItem.js +3 -0
- package/src/components/Popup.js +4 -1
- package/src/components/RadioButton.js +4 -1
- package/src/components/ScrollView.js +4 -1
- package/src/components/SidePanel.js +4 -2
- package/src/components/Switch.js +4 -1
- package/src/components/TabGroup.js +5 -3
- package/src/components/TabItem.js +5 -1
- package/src/components/Table.js +2 -1
- package/src/components/TableBody.js +2 -1
- package/src/components/TableCell.js +4 -1
- package/src/components/TableContainer.js +3 -1
- package/src/components/TableHead.js +2 -1
- package/src/components/TableRow.js +2 -1
- package/src/components/TableTitle.js +2 -1
- package/src/components/Text.js +2 -1
- package/src/components/Typography.js +4 -1
- package/src/components/View.js +2 -1
- package/src/components/index.js +7 -26
- package/src/icons.js +3 -2
- package/src/index.js +3 -43
- package/src/App.js +0 -48
- package/src/components/CancelButton.js +0 -3
- package/src/components/DeleteForm.js +0 -64
- package/src/components/Fieldset.js +0 -3
- package/src/components/FieldsetArray.js +0 -21
- package/src/components/FileArray.js +0 -12
- package/src/components/FlatFieldset.js +0 -3
- package/src/components/FormError.js +0 -15
- package/src/components/FormRoot.js +0 -3
- package/src/components/IconSubmitButton.js +0 -12
- package/src/components/Spinner.js +0 -16
- package/src/components/SubmitButton.js +0 -17
- package/src/inputs/Checkbox.js +0 -47
- package/src/inputs/DateTime.js +0 -64
- package/src/inputs/File.js +0 -176
- package/src/inputs/HelperText.js +0 -29
- package/src/inputs/Hidden.js +0 -23
- package/src/inputs/Image.js +0 -6
- package/src/inputs/Input.js +0 -78
- package/src/inputs/Radio.js +0 -32
- package/src/inputs/Select.js +0 -58
- package/src/inputs/Toggle.js +0 -38
- package/src/inputs/date-utils.js +0 -21
- package/src/inputs/index.js +0 -30
package/src/inputs/File.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import React, { useState } from "react";
|
|
2
|
-
import { useField } from "formik";
|
|
3
|
-
import { useComponents } from "@wq/react";
|
|
4
|
-
import { View, Text } from "react-native";
|
|
5
|
-
import { Button, List, Menu } from "react-native-paper";
|
|
6
|
-
import * as Application from "expo-application";
|
|
7
|
-
import * as DocumentPicker from "expo-document-picker";
|
|
8
|
-
import * as ImagePicker from "expo-image-picker";
|
|
9
|
-
import { format } from "./date-utils.js";
|
|
10
|
-
import HelperText from "./HelperText.js";
|
|
11
|
-
import PropTypes from "prop-types";
|
|
12
|
-
|
|
13
|
-
export default function File({ name, accept, capture, required, label, hint }) {
|
|
14
|
-
const [, { value }, { setValue }] = useField(name),
|
|
15
|
-
[imageOpen, setImageOpen] = useState(false),
|
|
16
|
-
[menuOpen, setMenuOpen] = useState(false),
|
|
17
|
-
{ Img, Popup } = useComponents(),
|
|
18
|
-
acceptImage = accept && accept.startsWith("image/"),
|
|
19
|
-
showImage = () => setImageOpen(true),
|
|
20
|
-
hideImage = () => setImageOpen(false),
|
|
21
|
-
showMenu = () => setMenuOpen(true),
|
|
22
|
-
hideMenu = () => setMenuOpen(false);
|
|
23
|
-
|
|
24
|
-
async function handleFile(mode) {
|
|
25
|
-
const value = await mode(accept, capture);
|
|
26
|
-
if (value || mode === clear) {
|
|
27
|
-
setValue(value);
|
|
28
|
-
}
|
|
29
|
-
hideMenu();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const modes = capture
|
|
33
|
-
? [takePhoto]
|
|
34
|
-
: acceptImage
|
|
35
|
-
? [takePhoto, pickFile]
|
|
36
|
-
: [pickFile];
|
|
37
|
-
|
|
38
|
-
if (value && !required) {
|
|
39
|
-
modes.push(clear);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<View>
|
|
44
|
-
{label && <List.Subheader>{label}</List.Subheader>}
|
|
45
|
-
<View
|
|
46
|
-
style={{
|
|
47
|
-
flexDirection: "row",
|
|
48
|
-
alignItems: "center",
|
|
49
|
-
padding: 8,
|
|
50
|
-
}}
|
|
51
|
-
>
|
|
52
|
-
{isImage(value) && (
|
|
53
|
-
<Img
|
|
54
|
-
onPress={showImage}
|
|
55
|
-
style={{ width: 64, height: 64 }}
|
|
56
|
-
src={typeof value === "string" ? value : value.uri}
|
|
57
|
-
/>
|
|
58
|
-
)}
|
|
59
|
-
{value && !isImage(value) && <List.Icon icon="attachment" />}
|
|
60
|
-
<Text style={{ flex: 1, padding: 8 }}>
|
|
61
|
-
{value ? value.name : "No file selected"}
|
|
62
|
-
</Text>
|
|
63
|
-
<Menu
|
|
64
|
-
visible={menuOpen}
|
|
65
|
-
onDismiss={hideMenu}
|
|
66
|
-
anchor={
|
|
67
|
-
<Button
|
|
68
|
-
onPress={
|
|
69
|
-
modes.length > 1
|
|
70
|
-
? showMenu
|
|
71
|
-
: () => handleFile(modes[0])
|
|
72
|
-
}
|
|
73
|
-
icon={value ? "pencil" : "plus"}
|
|
74
|
-
mode="contained-tonal"
|
|
75
|
-
>
|
|
76
|
-
{value
|
|
77
|
-
? "Change"
|
|
78
|
-
: capture
|
|
79
|
-
? "Add Photo"
|
|
80
|
-
: acceptImage
|
|
81
|
-
? "Add Image"
|
|
82
|
-
: "Add File"}
|
|
83
|
-
</Button>
|
|
84
|
-
}
|
|
85
|
-
>
|
|
86
|
-
{modes.map((mode) => (
|
|
87
|
-
<Menu.Item
|
|
88
|
-
key={mode.icon}
|
|
89
|
-
onPress={() => handleFile(mode)}
|
|
90
|
-
leadingIcon={mode.icon}
|
|
91
|
-
title={mode.label}
|
|
92
|
-
/>
|
|
93
|
-
))}
|
|
94
|
-
</Menu>
|
|
95
|
-
</View>
|
|
96
|
-
<HelperText name={name} hint={hint} />
|
|
97
|
-
<Popup open={value && imageOpen} onClose={hideImage}>
|
|
98
|
-
<Img
|
|
99
|
-
onPress={hideImage}
|
|
100
|
-
resizeMode="contain"
|
|
101
|
-
style={{
|
|
102
|
-
width: "90%",
|
|
103
|
-
height: "90%",
|
|
104
|
-
margin: "5%",
|
|
105
|
-
}}
|
|
106
|
-
src={typeof value === "string" ? value : value && value.uri}
|
|
107
|
-
/>
|
|
108
|
-
</Popup>
|
|
109
|
-
</View>
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
File.propTypes = {
|
|
113
|
-
name: PropTypes.string,
|
|
114
|
-
accept: PropTypes.string,
|
|
115
|
-
capture: PropTypes.string,
|
|
116
|
-
required: PropTypes.bool,
|
|
117
|
-
label: PropTypes.string,
|
|
118
|
-
hint: PropTypes.string,
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
function isImage(value) {
|
|
122
|
-
if (typeof value === "string") {
|
|
123
|
-
return IMAGE_EXTENSIONS.some((ext) =>
|
|
124
|
-
value.toLowerCase().endsWith(ext)
|
|
125
|
-
);
|
|
126
|
-
} else {
|
|
127
|
-
return (
|
|
128
|
-
value && value.type && value.type.startsWith("image/") && value.uri
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function generateName() {
|
|
134
|
-
const appName = Application.applicationName.replace(/ /, ""),
|
|
135
|
-
timestamp = new Date(),
|
|
136
|
-
date = format.date(timestamp).replace(/-/g, ""),
|
|
137
|
-
time = format.time(timestamp).replace(/:/g, "");
|
|
138
|
-
return `${appName}_${date}_${time}.jpg`;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async function pickFile(accept) {
|
|
142
|
-
const result = await DocumentPicker.getDocumentAsync({ type: accept });
|
|
143
|
-
if (result.assets && result.assets.length > 0) {
|
|
144
|
-
const { name, mimeType: type, uri } = result.assets[0];
|
|
145
|
-
return { name, type, uri };
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
pickFile.icon = "folder";
|
|
149
|
-
pickFile.label = "Pick File";
|
|
150
|
-
|
|
151
|
-
async function takePhoto(accept, capture) {
|
|
152
|
-
const options = {};
|
|
153
|
-
if (capture) {
|
|
154
|
-
options.cameraType =
|
|
155
|
-
capture === "user"
|
|
156
|
-
? ImagePicker.CameraType.front
|
|
157
|
-
: ImagePicker.CameraType.back;
|
|
158
|
-
}
|
|
159
|
-
const result = await ImagePicker.launchCameraAsync(options);
|
|
160
|
-
if (result.assets && result.assets.length > 0) {
|
|
161
|
-
const name = generateName(),
|
|
162
|
-
type = "image/jpeg",
|
|
163
|
-
{ uri } = result.assets[0];
|
|
164
|
-
return { name, type, uri };
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
takePhoto.icon = "camera";
|
|
168
|
-
takePhoto.label = "Take Photo";
|
|
169
|
-
|
|
170
|
-
function clear() {
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
clear.icon = "delete";
|
|
174
|
-
clear.label = "Remove";
|
|
175
|
-
|
|
176
|
-
const IMAGE_EXTENSIONS = ["jpg", "jpeg", "png", "gif"];
|
package/src/inputs/HelperText.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { useFormikContext, getIn } from "formik";
|
|
3
|
-
import { HelperText as FormHelperText } from "react-native-paper";
|
|
4
|
-
import PropTypes from "prop-types";
|
|
5
|
-
|
|
6
|
-
export default function HelperText({ name, hint }) {
|
|
7
|
-
const { errors, touched } = useFormikContext(),
|
|
8
|
-
error = getIn(errors, name),
|
|
9
|
-
showError = !!error && !!getIn(touched, name);
|
|
10
|
-
|
|
11
|
-
if (showError) {
|
|
12
|
-
hint = error;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (!hint) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<FormHelperText type={showError ? "error" : "info"}>
|
|
21
|
-
{hint}
|
|
22
|
-
</FormHelperText>
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
HelperText.propTypes = {
|
|
27
|
-
name: PropTypes.string,
|
|
28
|
-
hint: PropTypes.string,
|
|
29
|
-
};
|
package/src/inputs/Hidden.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Field } from "formik";
|
|
3
|
-
import HelperText from "./HelperText.js";
|
|
4
|
-
import PropTypes from "prop-types";
|
|
5
|
-
|
|
6
|
-
function Empty() {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default function Hidden(props) {
|
|
11
|
-
const { name, hint } = props;
|
|
12
|
-
return (
|
|
13
|
-
<>
|
|
14
|
-
<Field {...props} component={Empty} />
|
|
15
|
-
<HelperText name={name} hint={hint} />
|
|
16
|
-
</>
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
Hidden.propTypes = {
|
|
21
|
-
name: PropTypes.string,
|
|
22
|
-
hint: PropTypes.string,
|
|
23
|
-
};
|
package/src/inputs/Image.js
DELETED
package/src/inputs/Input.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { View } from "react-native";
|
|
3
|
-
import { TextInput } from "react-native-paper";
|
|
4
|
-
import { useField } from "formik";
|
|
5
|
-
import { useHtmlInput } from "@wq/react";
|
|
6
|
-
import HelperText from "./HelperText.js";
|
|
7
|
-
import PropTypes from "prop-types";
|
|
8
|
-
|
|
9
|
-
const keyboards = {
|
|
10
|
-
int: "number-pad",
|
|
11
|
-
decimal: "decimal-pad",
|
|
12
|
-
tel: "phone-pad",
|
|
13
|
-
email: "email-address",
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export default function Input(props) {
|
|
17
|
-
const { name, type, label, hint, style, min, max } = props,
|
|
18
|
-
{ maxLength } = useHtmlInput(props),
|
|
19
|
-
[, meta, helpers] = useField(name),
|
|
20
|
-
{ value } = meta,
|
|
21
|
-
{ setValue, setTouched } = helpers;
|
|
22
|
-
|
|
23
|
-
function handleChange(value) {
|
|
24
|
-
if (type === "int" || type === "decimal") {
|
|
25
|
-
if (type === "int") {
|
|
26
|
-
value = parseInt(value);
|
|
27
|
-
} else {
|
|
28
|
-
value = +value;
|
|
29
|
-
}
|
|
30
|
-
if (Number.isNaN(value)) {
|
|
31
|
-
setValue(null);
|
|
32
|
-
} else {
|
|
33
|
-
if (typeof min === "number" && value < min) {
|
|
34
|
-
value = min;
|
|
35
|
-
}
|
|
36
|
-
if (typeof max === "number" && value > max) {
|
|
37
|
-
value = max;
|
|
38
|
-
}
|
|
39
|
-
setValue(value);
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
setValue(value);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let formatValue;
|
|
47
|
-
if (type === "int" || type === "decimal") {
|
|
48
|
-
formatValue = typeof value === "number" ? "" + value : "";
|
|
49
|
-
} else {
|
|
50
|
-
formatValue = value;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<View style={{ flex: (style || {}).flex }}>
|
|
55
|
-
<TextInput
|
|
56
|
-
label={label}
|
|
57
|
-
multiline={type === "text"}
|
|
58
|
-
keyboardType={keyboards[type] || "default"}
|
|
59
|
-
maxLength={maxLength}
|
|
60
|
-
onChangeText={handleChange}
|
|
61
|
-
onBlur={() => setTouched(true)}
|
|
62
|
-
value={formatValue}
|
|
63
|
-
style={style}
|
|
64
|
-
/>
|
|
65
|
-
<HelperText name={name} hint={hint} />
|
|
66
|
-
</View>
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
Input.propTypes = {
|
|
71
|
-
name: PropTypes.string,
|
|
72
|
-
type: PropTypes.string,
|
|
73
|
-
label: PropTypes.string,
|
|
74
|
-
hint: PropTypes.string,
|
|
75
|
-
style: PropTypes.object,
|
|
76
|
-
min: PropTypes.number,
|
|
77
|
-
max: PropTypes.number,
|
|
78
|
-
};
|
package/src/inputs/Radio.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { View } from "react-native";
|
|
3
|
-
import { RadioButton, List } from "react-native-paper";
|
|
4
|
-
import HelperText from "./HelperText.js";
|
|
5
|
-
import { useField } from "formik";
|
|
6
|
-
import PropTypes from "prop-types";
|
|
7
|
-
|
|
8
|
-
export default function Radio({ name, choices, label, hint }) {
|
|
9
|
-
const [, { value }, { setValue }] = useField(name);
|
|
10
|
-
return (
|
|
11
|
-
<View>
|
|
12
|
-
<List.Subheader>{label}</List.Subheader>
|
|
13
|
-
<RadioButton.Group onValueChange={setValue} value={value}>
|
|
14
|
-
{choices.map((choice) => (
|
|
15
|
-
<RadioButton.Item
|
|
16
|
-
key={choice.name}
|
|
17
|
-
value={choice.name}
|
|
18
|
-
label={choice.label}
|
|
19
|
-
/>
|
|
20
|
-
))}
|
|
21
|
-
</RadioButton.Group>
|
|
22
|
-
<HelperText name={name} hint={hint} />
|
|
23
|
-
</View>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
Radio.propTypes = {
|
|
28
|
-
name: PropTypes.string,
|
|
29
|
-
label: PropTypes.string,
|
|
30
|
-
hint: PropTypes.string,
|
|
31
|
-
choices: PropTypes.arrayOf(PropTypes.object),
|
|
32
|
-
};
|
package/src/inputs/Select.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import RNPickerSelect from "react-native-picker-select";
|
|
3
|
-
import { View } from "react-native";
|
|
4
|
-
import { TextInput, useTheme } from "react-native-paper";
|
|
5
|
-
import { useField } from "formik";
|
|
6
|
-
import HelperText from "./HelperText.js";
|
|
7
|
-
import PropTypes from "prop-types";
|
|
8
|
-
|
|
9
|
-
export default function Select({ name, choices, label, hint }) {
|
|
10
|
-
const theme = useTheme(),
|
|
11
|
-
[, meta, helpers] = useField(name),
|
|
12
|
-
{ value } = meta,
|
|
13
|
-
{ setValue } = helpers;
|
|
14
|
-
|
|
15
|
-
const styles = {
|
|
16
|
-
inputIOS: {
|
|
17
|
-
color: theme.colors.text,
|
|
18
|
-
marginLeft: 12,
|
|
19
|
-
paddingTop: 32,
|
|
20
|
-
fontSize: 16,
|
|
21
|
-
},
|
|
22
|
-
inputAndroid: {
|
|
23
|
-
color: theme.colors.text,
|
|
24
|
-
marginLeft: 4,
|
|
25
|
-
paddingTop: 40,
|
|
26
|
-
paddingBottom: 40,
|
|
27
|
-
marginBottom: -40,
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<View>
|
|
33
|
-
<TextInput
|
|
34
|
-
label={label}
|
|
35
|
-
value={"-"}
|
|
36
|
-
render={() => (
|
|
37
|
-
<RNPickerSelect
|
|
38
|
-
value={value}
|
|
39
|
-
onValueChange={setValue}
|
|
40
|
-
items={choices.map(({ name, label }) => ({
|
|
41
|
-
value: name,
|
|
42
|
-
label,
|
|
43
|
-
}))}
|
|
44
|
-
style={styles}
|
|
45
|
-
/>
|
|
46
|
-
)}
|
|
47
|
-
/>
|
|
48
|
-
<HelperText name={name} hint={hint} />
|
|
49
|
-
</View>
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
Select.propTypes = {
|
|
54
|
-
name: PropTypes.string,
|
|
55
|
-
label: PropTypes.string,
|
|
56
|
-
hint: PropTypes.string,
|
|
57
|
-
choices: PropTypes.arrayOf(PropTypes.object),
|
|
58
|
-
};
|
package/src/inputs/Toggle.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { View, Text } from "react-native";
|
|
3
|
-
import { ToggleButton, List } from "react-native-paper";
|
|
4
|
-
import HelperText from "./HelperText.js";
|
|
5
|
-
import { useField } from "formik";
|
|
6
|
-
import PropTypes from "prop-types";
|
|
7
|
-
|
|
8
|
-
export default function Toggle({ name, choices, label, hint, style }) {
|
|
9
|
-
const [, { value }, { setValue }] = useField(name);
|
|
10
|
-
return (
|
|
11
|
-
<View>
|
|
12
|
-
<List.Subheader>{label}</List.Subheader>
|
|
13
|
-
<ToggleButton.Row
|
|
14
|
-
onValueChange={setValue}
|
|
15
|
-
value={value}
|
|
16
|
-
style={{ paddingLeft: 16, paddingBottom: 8, ...style }}
|
|
17
|
-
>
|
|
18
|
-
{choices.map((choice) => (
|
|
19
|
-
<ToggleButton
|
|
20
|
-
key={choice.name}
|
|
21
|
-
value={choice.name}
|
|
22
|
-
icon={() => <Text>{choice.label}</Text>}
|
|
23
|
-
style={{ width: undefined, padding: 8 }}
|
|
24
|
-
/>
|
|
25
|
-
))}
|
|
26
|
-
</ToggleButton.Row>
|
|
27
|
-
<HelperText name={name} hint={hint} />
|
|
28
|
-
</View>
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
Toggle.propTypes = {
|
|
33
|
-
name: PropTypes.string,
|
|
34
|
-
label: PropTypes.string,
|
|
35
|
-
hint: PropTypes.string,
|
|
36
|
-
choices: PropTypes.arrayOf(PropTypes.object),
|
|
37
|
-
style: PropTypes.object,
|
|
38
|
-
};
|
package/src/inputs/date-utils.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { parseISO, formatISO9075 } from "date-fns";
|
|
2
|
-
|
|
3
|
-
export const format = {
|
|
4
|
-
date: (value) => tryFormat(value, { representation: "date" }),
|
|
5
|
-
time: (value) => tryFormat(value, { representation: "time" }),
|
|
6
|
-
datetime: (value) => tryFormat(value),
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
function tryFormat(value, options) {
|
|
10
|
-
try {
|
|
11
|
-
return formatISO9075(value, options);
|
|
12
|
-
} catch (e) {
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const parse = {
|
|
18
|
-
date: (value) => (value ? parseISO(value) : null),
|
|
19
|
-
time: (value) => (value ? parseISO("9999-01-01 " + value) : null),
|
|
20
|
-
datetime: (value) => (value ? parseISO(value) : null),
|
|
21
|
-
};
|
package/src/inputs/index.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import Input from "./Input.js";
|
|
2
|
-
import Checkbox from "./Checkbox.js";
|
|
3
|
-
import DateTime from "./DateTime.js";
|
|
4
|
-
import File from "./File.js";
|
|
5
|
-
import Image from "./Image.js";
|
|
6
|
-
import Select from "./Select.js";
|
|
7
|
-
import Radio from "./Radio.js";
|
|
8
|
-
import Toggle from "./Toggle.js";
|
|
9
|
-
import Hidden from "./Hidden.js";
|
|
10
|
-
import HelperText from "./HelperText.js";
|
|
11
|
-
|
|
12
|
-
const Date = DateTime;
|
|
13
|
-
const Time = DateTime;
|
|
14
|
-
const dateTime = DateTime;
|
|
15
|
-
|
|
16
|
-
export {
|
|
17
|
-
Input,
|
|
18
|
-
Checkbox,
|
|
19
|
-
DateTime,
|
|
20
|
-
Date,
|
|
21
|
-
Time,
|
|
22
|
-
dateTime,
|
|
23
|
-
File,
|
|
24
|
-
Image,
|
|
25
|
-
Select,
|
|
26
|
-
Radio,
|
|
27
|
-
Toggle,
|
|
28
|
-
Hidden,
|
|
29
|
-
HelperText,
|
|
30
|
-
};
|