ferns-ui 0.17.0 → 0.18.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/Field.d.ts CHANGED
@@ -4,26 +4,18 @@ import { SelectListOptions } from "./SelectList";
4
4
  export interface FieldProps extends FieldWithLabelsProps {
5
5
  name: string;
6
6
  label?: string;
7
- subLabel?: string;
8
- initialValue?: any;
9
- handleChange: any;
10
7
  height?: number;
11
- validate?: (value: any) => boolean;
12
- validateErrorMessage?: string;
13
8
  type?: "boolean" | "email" | "text" | "textarea" | "number" | "currency" | "percent" | "select" | "password" | "url" | "date" | "multiselect" | "address" | "customSelect";
14
9
  rows?: number;
10
+ value?: any;
11
+ onChange?: any;
15
12
  options?: SelectListOptions;
16
13
  placeholder?: string;
17
14
  disabled?: boolean;
18
15
  }
19
16
  /**
20
- * Field is a fully uncontrolled component for creating various inputs. Fully uncontrolled means Field manages its own
21
- * state for the TextFields/Switches/etc, not the parent component. When values are updated, Field will pass the data to
22
- * the parent through the handleChange prop. You can set an initialValue, but you should not update initialValue
23
- * this prop with the result of handleChange.
24
- *
25
17
  * Note: You MUST set a key={} prop for this component, otherwise you may wind up with stale data. Just changing
26
18
  * initialValue will not work.
27
19
  *
28
20
  */
29
- export declare function Field(props: FieldProps): JSX.Element;
21
+ export declare const Field: ({ name, label, labelColor, height, type, rows, value, onChange, options, placeholder, disabled, errorMessage, errorMessageColor, helperText, helperTextColor, }: FieldProps) => JSX.Element;
package/dist/Field.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from "react";
1
+ import React, { useState } from "react";
2
2
  import { Box } from "./Box";
3
3
  import { USSTATESLIST } from "./Constants";
4
4
  import { FieldWithLabels } from "./FieldWithLabels";
@@ -8,48 +8,20 @@ import { Text } from "./Text";
8
8
  import { TextArea } from "./TextArea";
9
9
  import { TextField } from "./TextField";
10
10
  /**
11
- * Field is a fully uncontrolled component for creating various inputs. Fully uncontrolled means Field manages its own
12
- * state for the TextFields/Switches/etc, not the parent component. When values are updated, Field will pass the data to
13
- * the parent through the handleChange prop. You can set an initialValue, but you should not update initialValue
14
- * this prop with the result of handleChange.
15
- *
16
11
  * Note: You MUST set a key={} prop for this component, otherwise you may wind up with stale data. Just changing
17
12
  * initialValue will not work.
18
13
  *
19
14
  */
20
- export function Field(props) {
21
- var _a;
22
- const [value, setValue] = useState(props.initialValue || "");
23
- const [multiselectValue, setMultiselectValue] = useState((_a = props.initialValue) !== null && _a !== void 0 ? _a : []);
15
+ export const Field = ({ name, label, labelColor, height, type, rows, value, onChange, options, placeholder, disabled, errorMessage, errorMessageColor, helperText, helperTextColor, }) => {
24
16
  // showCustomInput, customValue, and selectValue are all for type="customSelect"
25
17
  const [showCustomInput, setShowCustomInput] = useState(false);
26
18
  const [customValue, setCustomValue] = useState("");
27
- const [selectValue, setSelectValue] = useState(props.initialValue || "");
28
- const handleChange = (newValue) => {
29
- if (props.type === "currency") {
30
- newValue = newValue.replace("$", "");
31
- }
32
- else if (props.type === "percent") {
33
- newValue = newValue.replace("%", "");
34
- }
35
- setValue(newValue);
36
- if (props.handleChange) {
37
- props.handleChange(props.name, newValue);
38
- }
39
- };
40
- useEffect(() => {
41
- // upon initialization, set the value within the parent to the initial value
42
- handleChange(props.initialValue || (props.options && props.options[0] ? props.options[0].value : ""));
43
- // only want to run this once so setting empty dependency array
44
- // eslint-disable-next-line react-hooks/exhaustive-deps
45
- }, []);
46
19
  // Custom select has 3 values - the overall field value, the value of the select menu, and the value of the custom input
47
20
  const handleCustomSelectListChange = (newValue) => {
48
21
  // If "custom" is selected from the dropdown, toggle the custom input open and clear the previous value
49
22
  if (newValue === "custom") {
50
23
  setShowCustomInput(true);
51
- setValue("");
52
- setSelectValue(newValue);
24
+ onChange("");
53
25
  }
54
26
  // If any non-custom value is selected
55
27
  else {
@@ -59,80 +31,63 @@ export function Field(props) {
59
31
  setCustomValue("");
60
32
  }
61
33
  // Update the field value and select value
62
- setValue(newValue);
63
- setSelectValue(newValue);
64
- if (props.handleChange) {
65
- props.handleChange(props.name, newValue);
66
- }
34
+ onChange(newValue);
67
35
  }
68
36
  };
69
37
  const handleCustomSelectTextInputChange = (newValue) => {
70
- setValue(newValue);
38
+ onChange(newValue);
71
39
  setCustomValue(newValue);
72
- if (props.handleChange) {
73
- props.handleChange(props.name, newValue);
74
- }
75
40
  };
76
41
  const handleAddressChange = (field, newValue) => {
77
- setValue(Object.assign(Object.assign({}, value), { [field]: newValue }));
78
- if (props.handleChange) {
79
- props.handleChange(props.name, Object.assign(Object.assign({}, value), { [field]: newValue }));
80
- }
42
+ onChange(Object.assign(Object.assign({}, value), { [field]: newValue }));
81
43
  };
82
44
  const handleSwitchChange = (switchValue) => {
83
- setValue(switchValue);
84
- if (props.handleChange) {
85
- props.handleChange(props.name, switchValue);
86
- }
45
+ onChange(switchValue);
87
46
  };
88
47
  const renderField = () => {
89
- var _a;
90
- if (props.type === "select") {
91
- if (!props.options) {
48
+ if (type === "select") {
49
+ if (!options) {
92
50
  console.error("Field with type=select require options");
93
51
  return null;
94
52
  }
95
- return (React.createElement(SelectList, { disabled: props.disabled, id: props.name, options: props.options, value: value, onChange: handleChange }));
53
+ return (React.createElement(SelectList, { disabled: disabled, id: name, options: options, value: value, onChange: onChange }));
96
54
  }
97
- else if (props.type === "multiselect") {
98
- if (!props.options) {
55
+ else if (type === "multiselect") {
56
+ if (!options) {
99
57
  console.error("Field with type=multiselect require options");
100
58
  return null;
101
59
  }
102
- return (React.createElement(Box, { width: "100%" }, props.options.map((o) => (React.createElement(Box, { key: o.label + o.value, direction: "row", justifyContent: "between", width: "100%" },
60
+ return (React.createElement(Box, { width: "100%" }, options.map((o) => (React.createElement(Box, { key: o.label + o.value, direction: "row", justifyContent: "between", width: "100%" },
103
61
  React.createElement(Box, { flex: "shrink", marginRight: 2 },
104
62
  React.createElement(Text, { weight: "bold" }, o.label)),
105
63
  React.createElement(Box, null,
106
- React.createElement(Switch, { key: o.label + o.value, disabled: props.disabled, id: props.name, name: props.name, switched: (multiselectValue !== null && multiselectValue !== void 0 ? multiselectValue : []).includes(o.value), onChange: (result) => {
64
+ React.createElement(Switch, { key: o.label + o.value, disabled: disabled, id: name, name: name, switched: (value !== null && value !== void 0 ? value : []).includes(o.value), onChange: (result) => {
107
65
  let newValue;
108
66
  if (result) {
109
- if (multiselectValue.includes(o.value)) {
67
+ if (value.includes(o.value)) {
110
68
  console.warn(`Tried to add value that already exists: ${o.value}`);
111
69
  return;
112
70
  }
113
- newValue = [...multiselectValue, o.value];
71
+ newValue = [...value, o.value];
114
72
  }
115
73
  else {
116
- newValue = multiselectValue.filter((v) => v !== o.value);
117
- }
118
- setMultiselectValue(newValue);
119
- if (props.handleChange) {
120
- props.handleChange(props.name, newValue);
74
+ newValue = value.filter((v) => v !== o.value);
121
75
  }
76
+ onChange(newValue);
122
77
  } })))))));
123
78
  }
124
- else if (props.type === "textarea") {
125
- return (React.createElement(TextArea, { disabled: props.disabled, height: (_a = props.height) !== null && _a !== void 0 ? _a : 100, id: props.name, placeholder: Boolean(value) ? "" : props.placeholder, rows: props.rows, value: String(value), onChange: (result) => handleChange(result.value) }));
79
+ else if (type === "textarea") {
80
+ return (React.createElement(TextArea, { disabled: disabled, height: height !== null && height !== void 0 ? height : 100, id: name, placeholder: Boolean(value) ? "" : placeholder, rows: rows, value: String(value), onChange: (result) => onChange(result.value) }));
126
81
  }
127
- else if (props.type === "boolean") {
128
- return (React.createElement(Switch, { disabled: props.disabled, id: props.name, name: props.name, switched: Boolean(value), onChange: (result) => handleSwitchChange(result) }));
82
+ else if (type === "boolean") {
83
+ return (React.createElement(Switch, { disabled: disabled, id: name, name: name, switched: Boolean(value), onChange: (result) => handleSwitchChange(result) }));
129
84
  }
130
- else if (props.type === "date") {
131
- return (React.createElement(TextField, { disabled: true, id: props.name, placeholder: props.placeholder, type: "date",
85
+ else if (type === "date") {
86
+ return (React.createElement(TextField, { disabled: true, id: name, placeholder: placeholder, type: "date",
132
87
  // TODO: allow editing with a date picker
133
- value: value, onChange: (result) => handleChange(result.value) }));
88
+ value: value, onChange: (result) => onChange(result.value) }));
134
89
  }
135
- else if (props.type === "address") {
90
+ else if (type === "address") {
136
91
  const { address1 = "", address2 = "", city = "", state = "", zipcode = "", } = value;
137
92
  return (React.createElement(React.Fragment, null,
138
93
  React.createElement(TextField, { id: "address1", label: "Street Address", type: "text", value: address1, onChange: (result) => handleAddressChange("address1", result.value) }),
@@ -141,45 +96,44 @@ export function Field(props) {
141
96
  React.createElement(SelectList, { id: "state", label: "State", options: USSTATESLIST, placeholder: "Select state", style: { borderRadius: 16 }, value: state, onChange: (result) => handleAddressChange("state", result) }),
142
97
  React.createElement(TextField, { id: "zipcode", label: "Zipcode", type: "text", value: zipcode, onChange: (result) => handleAddressChange("zipcode", result.value) })));
143
98
  }
144
- else if (props.type === "customSelect") {
145
- if (!props.options) {
99
+ else if (type === "customSelect") {
100
+ if (!options) {
146
101
  console.error("Field with type=customSelect require options");
147
102
  return null;
148
103
  }
149
104
  return (React.createElement(React.Fragment, null,
150
- React.createElement(SelectList, { id: "providedOptions", options: [...props.options, { label: "Custom", value: "custom" }], placeholder: "Select an option", value: selectValue, onChange: handleCustomSelectListChange }),
105
+ React.createElement(SelectList, { id: "providedOptions", options: [...options, { label: "Custom", value: "custom" }], placeholder: "Select an option", value: value, onChange: handleCustomSelectListChange }),
151
106
  Boolean(showCustomInput) && (React.createElement(Box, { paddingY: 2 },
152
- React.createElement(TextField, { disabled: props.disabled, id: "customOptions", placeholder: props.placeholder, type: "text", value: customValue, onChange: (result) => handleCustomSelectTextInputChange(result.value) })))));
107
+ React.createElement(TextField, { disabled: disabled, id: "customOptions", placeholder: placeholder, type: "text", value: customValue, onChange: (result) => handleCustomSelectTextInputChange(result.value) })))));
153
108
  }
154
109
  else {
155
- let type = "text";
110
+ let tfType = "text";
111
+ let tfValue = value;
156
112
  // Number is supported differently because we need fractional numbers and they don't work
157
113
  // well on iOS.
158
- if (props.type && ["date", "email", "password", "url"].indexOf(props.type) > -1) {
159
- type = props.type;
114
+ if (type && ["date", "email", "password", "url"].indexOf(type) > -1) {
115
+ tfType = type;
160
116
  }
161
- else if (props.type === "percent" || props.type === "currency") {
162
- type = "text";
117
+ else if (type === "percent" || type === "currency") {
118
+ tfType = "text";
163
119
  }
164
120
  let autoComplete = "on";
165
- if (type === "password") {
121
+ if (tfType === "password") {
166
122
  autoComplete = "current-password";
167
123
  }
168
- else if (type === "email") {
124
+ else if (tfType === "email") {
169
125
  autoComplete = "username";
170
126
  }
171
- const stringValue = String(value);
172
- // if (props.type === "percent") {
173
- // value = `${Number(value).toFixed(0)}%`;
174
- // } else if (props.type === "currency") {
175
- // value = `$${Number(value).toFixed(2)}`;
176
- // }
177
- // console.log("VAL", value);
178
- return (React.createElement(TextField, { autoComplete: autoComplete, disabled: props.disabled, id: props.name, placeholder: props.placeholder, type: type, value: stringValue, onChange: (result) => handleChange(result.value) }));
127
+ if (type === "percent") {
128
+ tfValue = `${Number(value).toFixed(0)}%`;
129
+ }
130
+ else if (type === "currency") {
131
+ tfValue = `$${Number(value).toFixed(2)}`;
132
+ }
133
+ return (React.createElement(TextField, { autoComplete: autoComplete, disabled: disabled, id: name, placeholder: placeholder, type: tfType, value: tfValue, onChange: (result) => onChange(result.value) }));
179
134
  }
180
135
  };
181
136
  const children = renderField();
182
- const { errorMessage, errorMessageColor, helperText, helperTextColor, label, labelColor } = props;
183
137
  return (React.createElement(Box, { marginBottom: 5 },
184
138
  React.createElement(FieldWithLabels, Object.assign({}, {
185
139
  errorMessage,
@@ -189,5 +143,5 @@ export function Field(props) {
189
143
  label,
190
144
  labelColor,
191
145
  }), children)));
192
- }
146
+ };
193
147
  //# sourceMappingURL=Field.js.map
package/dist/Field.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Field.js","sourceRoot":"","sources":["../src/Field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,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UAAU,CAAC;aAC3B;YACD,IAAI,IAAI,KAAK,SAAS,EAAE;gBACtB,OAAO,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;aAC1C;iBAAM,IAAI,IAAI,KAAK,UAAU,EAAE;gBAC9B,OAAO,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;aAC1C;YACD,OAAO,CACL,oBAAC,SAAS,IACR,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,IAAI,EACR,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,MAAmE,EACzE,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,GAC5C,CACH,CAAC;SACH;IACH,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,OAAO,CACL,oBAAC,GAAG,IAAC,YAAY,EAAE,CAAC;QAClB,oBAAC,eAAe,oBACV;YACF,YAAY;YACZ,iBAAiB;YACjB,UAAU;YACV,eAAe;YACf,KAAK;YACL,UAAU;SACX,GAEA,QAAQ,CACO,CACd,CACP,CAAC;AACJ,CAAC,CAAC"}
@@ -1,9 +1,14 @@
1
- import React from "react";
1
+ import React, { useEffect } from "react";
2
2
  import RNPickerSelect from "./PickerSelect";
3
3
  import { Unifier } from "./Unifier";
4
4
  import { WithLabel } from "./WithLabel";
5
5
  export function SelectList({ options, value, onChange, label, labelColor, style }) {
6
6
  const withLabelProps = { label, labelColor };
7
+ useEffect(() => {
8
+ if (!value && options && options.length > 0) {
9
+ onChange(options[0].value);
10
+ }
11
+ }, [onChange, options, value]);
7
12
  return (React.createElement(WithLabel, Object.assign({}, withLabelProps),
8
13
  React.createElement(RNPickerSelect, { items: options, placeholder: {}, style: {
9
14
  viewContainer: {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ACL,aAAa,EAAE;oBACb,aAAa,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,aAAa,KAAI,KAAK;oBAC5C,cAAc,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc,KAAI,QAAQ;oBACjD,UAAU,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,KAAI,QAAQ;oBACzC,SAAS,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,KAAI,EAAE;oBACjC,KAAK,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,KAAI,MAAM;oBAC7B,oDAAoD;oBACpD,iBAAiB,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,iBAAiB,KAAI,CAAC;oBAChD,eAAe,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,eAAe,KAAI,CAAC;oBAC5C,WAAW,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,KAAI,OAAO,CAAC,KAAK,CAAC,IAAI;oBACrD,WAAW,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,KAAI,CAAC;oBACpC,YAAY,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,YAAY,KAAI,CAAC;oBACtC,eAAe,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,eAAe,KAAI,OAAO,CAAC,KAAK,CAAC,KAAK;iBAC/D;aACF,EACD,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,QAAQ,GACvB,CACQ,CACb,CAAC;AACJ,CAAC"}
@@ -1,12 +1,13 @@
1
1
  import { ReactElement } from "react";
2
2
  import { BoxProps } from "./Common";
3
3
  import { FieldProps } from "./Field";
4
- export interface TapToEditProps extends Omit<FieldProps, "handleChange"> {
4
+ export interface TapToEditProps extends Omit<FieldProps, "handleChange" | "value"> {
5
5
  title: string;
6
+ initialValue: any;
6
7
  onSave?: (value: any) => void | Promise<void>;
7
8
  editable?: boolean;
8
9
  rowBoxProps?: Partial<BoxProps>;
9
10
  transform?: (value: any) => string;
10
11
  fieldComponent?: (setValue: () => void) => ReactElement;
11
12
  }
12
- export declare const TapToEdit: (props: TapToEditProps) => ReactElement;
13
+ export declare const TapToEdit: ({ initialValue, title, onSave, editable, rowBoxProps, transform, fieldComponent, ...fieldProps }: TapToEditProps) => ReactElement;
package/dist/TapToEdit.js CHANGED
@@ -15,20 +15,20 @@ import { Button } from "./Button";
15
15
  import { Field } from "./Field";
16
16
  import { Icon } from "./Icon";
17
17
  import { Text } from "./Text";
18
- export const TapToEdit = (props) => {
18
+ export const TapToEdit = (_a) => {
19
+ var { initialValue, title, onSave, editable, rowBoxProps, transform, fieldComponent } = _a, fieldProps = __rest(_a, ["initialValue", "title", "onSave", "editable", "rowBoxProps", "transform", "fieldComponent"]);
19
20
  const [editing, setEditing] = useState(false);
20
- const [value, setValue] = useState(props.initialValue);
21
- const { title, editable = true, rowBoxProps, transform, fieldComponent } = props, fieldProps = __rest(props, ["title", "editable", "rowBoxProps", "transform", "fieldComponent"]);
21
+ const [value, setValue] = useState(initialValue);
22
22
  if (editing) {
23
23
  return (React.createElement(Box, { direction: "column" },
24
- fieldComponent ? (fieldComponent(setValue)) : (React.createElement(Field, Object.assign({ handleChange: (_, val) => setValue(val), label: props.title }, fieldProps))),
24
+ fieldComponent ? (fieldComponent(setValue)) : (React.createElement(Field, Object.assign({ label: title, onChange: setValue }, fieldProps))),
25
25
  React.createElement(Box, { direction: "row" },
26
26
  React.createElement(Button, { color: "blue", inline: true, text: "Save", onClick: async () => {
27
- if (!props.onSave) {
27
+ if (!onSave) {
28
28
  console.error("No onSave provided for editable TapToEdit");
29
29
  }
30
30
  else {
31
- await props.onSave(value);
31
+ await onSave(value);
32
32
  }
33
33
  setEditing(false);
34
34
  } }),
@@ -38,10 +38,10 @@ export const TapToEdit = (props) => {
38
38
  } })))));
39
39
  }
40
40
  else {
41
- let displayValue = props.initialValue;
41
+ let displayValue = initialValue;
42
42
  // If a transform props is present, that takes priority
43
43
  if (transform) {
44
- displayValue = transform(props.initialValue);
44
+ displayValue = transform(initialValue);
45
45
  }
46
46
  else {
47
47
  // If no transform, try and display the value reasonably.
@@ -1 +1 @@
1
- {"version":3,"file":"TapToEdit.js","sourceRoot":"","sources":["../src/TapToEdit.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAe,QAAQ,EAAC,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAC,KAAK,EAAa,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAc5B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAqB,EAAgB,EAAE;IAC/D,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAEvD,MAAM,EAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,KAAmB,KAAK,EAAnB,UAAU,UAAI,KAAK,EAAvF,mEAA+E,CAAQ,CAAC;IAC9F,IAAI,OAAO,EAAE;QACX,OAAO,CACL,oBAAC,GAAG,IAAC,SAAS,EAAC,QAAQ;YACpB,cAAc,CAAC,CAAC,CAAC,CAChB,cAAc,CAAC,QAAe,CAAC,CAChC,CAAC,CAAC,CAAC,CACF,oBAAC,KAAK,kBACJ,YAAY,EAAE,CAAC,CAAS,E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Y,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aACxC;iBAAM,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,MAAK,aAAa,EAAE;gBAC7C,MAAM;gBACN,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACjC;SACF;QACD,OAAO,CACL,oBAAC,GAAG,kBACF,SAAS,EAAC,KAAK,EACf,cAAc,EAAC,SAAS,EACxB,QAAQ,EAAE,CAAC,EACX,QAAQ,EAAE,CAAC,EACX,KAAK,EAAC,MAAM,IACR,WAAW;YAEf,oBAAC,GAAG;gBACF,oBAAC,IAAI,IAAC,MAAM,EAAC,MAAM;oBAAE,KAAK;wBAAS,CAC/B;YACN,oBAAC,GAAG,IAAC,SAAS,EAAC,KAAK;gBAClB,oBAAC,GAAG;oBACF,oBAAC,IAAI,IAAC,QAAQ,EAAC,WAAW,IAAE,YAAY,CAAQ,CAC5C;gBACL,QAAQ,IAAI,CACX,oBAAC,GAAG,IAAC,UAAU,EAAE,CAAC,EAAE,OAAO,EAAE,GAAS,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;oBACvD,oBAAC,IAAI,IAAC,KAAK,EAAC,UAAU,EAAC,IAAI,EAAC,MAAM,EAAC,IAAI,EAAC,IAAI,GAAG,CAC3C,CACP,CACG,CACF,CACP,CAAC;KACH;AACH,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ferns-ui",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "scripts": {
package/src/Field.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import React, {useEffect, useState} from "react";
1
+ import React, {useState} from "react";
2
2
 
3
3
  import {Box} from "./Box";
4
4
  import {AddressInterface, FieldWithLabelsProps, TextFieldType} from "./Common";
@@ -13,13 +13,7 @@ import {TextField} from "./TextField";
13
13
  export interface FieldProps extends FieldWithLabelsProps {
14
14
  name: string;
15
15
  label?: string;
16
- subLabel?: string;
17
- initialValue?: any;
18
- handleChange: any;
19
16
  height?: number;
20
- // Additional validation
21
- validate?: (value: any) => boolean;
22
- validateErrorMessage?: string;
23
17
  type?:
24
18
  | "boolean"
25
19
  | "email"
@@ -36,58 +30,45 @@ export interface FieldProps extends FieldWithLabelsProps {
36
30
  | "address"
37
31
  | "customSelect";
38
32
  rows?: number;
33
+ value?: any;
34
+ onChange?: any;
39
35
  options?: SelectListOptions;
40
36
  placeholder?: string;
41
37
  disabled?: boolean;
42
38
  }
43
39
 
44
40
  /**
45
- * Field is a fully uncontrolled component for creating various inputs. Fully uncontrolled means Field manages its own
46
- * state for the TextFields/Switches/etc, not the parent component. When values are updated, Field will pass the data to
47
- * the parent through the handleChange prop. You can set an initialValue, but you should not update initialValue
48
- * this prop with the result of handleChange.
49
- *
50
41
  * Note: You MUST set a key={} prop for this component, otherwise you may wind up with stale data. Just changing
51
42
  * initialValue will not work.
52
43
  *
53
44
  */
54
- export function Field(props: FieldProps) {
55
- const [value, setValue] = useState(props.initialValue || "");
56
- const [multiselectValue, setMultiselectValue] = useState(props.initialValue ?? []);
57
-
45
+ export const Field = ({
46
+ name,
47
+ label,
48
+ labelColor,
49
+ height,
50
+ type,
51
+ rows,
52
+ value,
53
+ onChange,
54
+ options,
55
+ placeholder,
56
+ disabled,
57
+ errorMessage,
58
+ errorMessageColor,
59
+ helperText,
60
+ helperTextColor,
61
+ }: FieldProps) => {
58
62
  // showCustomInput, customValue, and selectValue are all for type="customSelect"
59
63
  const [showCustomInput, setShowCustomInput] = useState(false);
60
64
  const [customValue, setCustomValue] = useState("");
61
- const [selectValue, setSelectValue] = useState(props.initialValue || "");
62
-
63
- const handleChange = (newValue: string) => {
64
- if (props.type === "currency") {
65
- newValue = newValue.replace("$", "");
66
- } else if (props.type === "percent") {
67
- newValue = newValue.replace("%", "");
68
- }
69
- setValue(newValue);
70
- if (props.handleChange) {
71
- props.handleChange(props.name, newValue);
72
- }
73
- };
74
-
75
- useEffect(() => {
76
- // upon initialization, set the value within the parent to the initial value
77
- handleChange(
78
- props.initialValue || (props.options && props.options[0] ? props.options[0].value : "")
79
- );
80
- // only want to run this once so setting empty dependency array
81
- // eslint-disable-next-line react-hooks/exhaustive-deps
82
- }, []);
83
65
 
84
66
  // Custom select has 3 values - the overall field value, the value of the select menu, and the value of the custom input
85
67
  const handleCustomSelectListChange = (newValue: string) => {
86
68
  // If "custom" is selected from the dropdown, toggle the custom input open and clear the previous value
87
69
  if (newValue === "custom") {
88
70
  setShowCustomInput(true);
89
- setValue("");
90
- setSelectValue(newValue);
71
+ onChange("");
91
72
  }
92
73
 
93
74
  // If any non-custom value is selected
@@ -99,59 +80,46 @@ export function Field(props: FieldProps) {
99
80
  }
100
81
 
101
82
  // Update the field value and select value
102
- setValue(newValue);
103
- setSelectValue(newValue);
104
- if (props.handleChange) {
105
- props.handleChange(props.name, newValue);
106
- }
83
+ onChange(newValue);
107
84
  }
108
85
  };
109
86
 
110
87
  const handleCustomSelectTextInputChange = (newValue: string) => {
111
- setValue(newValue);
88
+ onChange(newValue);
112
89
  setCustomValue(newValue);
113
- if (props.handleChange) {
114
- props.handleChange(props.name, newValue);
115
- }
116
90
  };
117
91
 
118
92
  const handleAddressChange = (field: string, newValue: string) => {
119
- setValue({...value, [field]: newValue});
120
- if (props.handleChange) {
121
- props.handleChange(props.name, {...value, [field]: newValue});
122
- }
93
+ onChange({...value, [field]: newValue});
123
94
  };
124
95
 
125
96
  const handleSwitchChange = (switchValue: boolean) => {
126
- setValue(switchValue);
127
- if (props.handleChange) {
128
- props.handleChange(props.name, switchValue);
129
- }
97
+ onChange(switchValue);
130
98
  };
131
99
 
132
100
  const renderField = () => {
133
- if (props.type === "select") {
134
- if (!props.options) {
101
+ if (type === "select") {
102
+ if (!options) {
135
103
  console.error("Field with type=select require options");
136
104
  return null;
137
105
  }
138
106
  return (
139
107
  <SelectList
140
- disabled={props.disabled}
141
- id={props.name}
142
- options={props.options}
108
+ disabled={disabled}
109
+ id={name}
110
+ options={options}
143
111
  value={value}
144
- onChange={handleChange}
112
+ onChange={onChange}
145
113
  />
146
114
  );
147
- } else if (props.type === "multiselect") {
148
- if (!props.options) {
115
+ } else if (type === "multiselect") {
116
+ if (!options) {
149
117
  console.error("Field with type=multiselect require options");
150
118
  return null;
151
119
  }
152
120
  return (
153
121
  <Box width="100%">
154
- {props.options.map((o) => (
122
+ {options.map((o) => (
155
123
  <Box key={o.label + o.value} direction="row" justifyContent="between" width="100%">
156
124
  <Box flex="shrink" marginRight={2}>
157
125
  <Text weight="bold">{o.label}</Text>
@@ -159,25 +127,22 @@ export function Field(props: FieldProps) {
159
127
  <Box>
160
128
  <Switch
161
129
  key={o.label + o.value}
162
- disabled={props.disabled}
163
- id={props.name}
164
- name={props.name}
165
- switched={(multiselectValue ?? []).includes(o.value)}
130
+ disabled={disabled}
131
+ id={name}
132
+ name={name}
133
+ switched={(value ?? []).includes(o.value)}
166
134
  onChange={(result) => {
167
135
  let newValue;
168
136
  if (result) {
169
- if (multiselectValue.includes(o.value)) {
137
+ if (value.includes(o.value)) {
170
138
  console.warn(`Tried to add value that already exists: ${o.value}`);
171
139
  return;
172
140
  }
173
- newValue = [...multiselectValue, o.value];
141
+ newValue = [...value, o.value];
174
142
  } else {
175
- newValue = multiselectValue.filter((v: string) => v !== o.value);
176
- }
177
- setMultiselectValue(newValue);
178
- if (props.handleChange) {
179
- props.handleChange(props.name, newValue);
143
+ newValue = value.filter((v: string) => v !== o.value);
180
144
  }
145
+ onChange(newValue);
181
146
  }}
182
147
  />
183
148
  </Box>
@@ -185,41 +150,41 @@ export function Field(props: FieldProps) {
185
150
  ))}
186
151
  </Box>
187
152
  );
188
- } else if (props.type === "textarea") {
153
+ } else if (type === "textarea") {
189
154
  return (
190
155
  <TextArea
191
- disabled={props.disabled}
192
- height={props.height ?? 100}
193
- id={props.name}
194
- placeholder={Boolean(value) ? "" : props.placeholder}
195
- rows={props.rows}
156
+ disabled={disabled}
157
+ height={height ?? 100}
158
+ id={name}
159
+ placeholder={Boolean(value) ? "" : placeholder}
160
+ rows={rows}
196
161
  value={String(value)}
197
- onChange={(result) => handleChange(result.value)}
162
+ onChange={(result) => onChange(result.value)}
198
163
  />
199
164
  );
200
- } else if (props.type === "boolean") {
165
+ } else if (type === "boolean") {
201
166
  return (
202
167
  <Switch
203
- disabled={props.disabled}
204
- id={props.name}
205
- name={props.name}
168
+ disabled={disabled}
169
+ id={name}
170
+ name={name}
206
171
  switched={Boolean(value)}
207
172
  onChange={(result) => handleSwitchChange(result)}
208
173
  />
209
174
  );
210
- } else if (props.type === "date") {
175
+ } else if (type === "date") {
211
176
  return (
212
177
  <TextField
213
178
  disabled
214
- id={props.name}
215
- placeholder={props.placeholder}
179
+ id={name}
180
+ placeholder={placeholder}
216
181
  type="date"
217
182
  // TODO: allow editing with a date picker
218
183
  value={value}
219
- onChange={(result) => handleChange(result.value)}
184
+ onChange={(result) => onChange(result.value)}
220
185
  />
221
186
  );
222
- } else if (props.type === "address") {
187
+ } else if (type === "address") {
223
188
  const {
224
189
  address1 = "",
225
190
  address2 = "",
@@ -268,8 +233,8 @@ export function Field(props: FieldProps) {
268
233
  />
269
234
  </>
270
235
  );
271
- } else if (props.type === "customSelect") {
272
- if (!props.options) {
236
+ } else if (type === "customSelect") {
237
+ if (!options) {
273
238
  console.error("Field with type=customSelect require options");
274
239
  return null;
275
240
  }
@@ -277,17 +242,17 @@ export function Field(props: FieldProps) {
277
242
  <>
278
243
  <SelectList
279
244
  id="providedOptions"
280
- options={[...props.options, {label: "Custom", value: "custom"}]}
245
+ options={[...options, {label: "Custom", value: "custom"}]}
281
246
  placeholder="Select an option"
282
- value={selectValue}
247
+ value={value}
283
248
  onChange={handleCustomSelectListChange}
284
249
  />
285
250
  {Boolean(showCustomInput) && (
286
251
  <Box paddingY={2}>
287
252
  <TextField
288
- disabled={props.disabled}
253
+ disabled={disabled}
289
254
  id="customOptions"
290
- placeholder={props.placeholder}
255
+ placeholder={placeholder}
291
256
  type="text"
292
257
  value={customValue}
293
258
  onChange={(result) => handleCustomSelectTextInputChange(result.value)}
@@ -297,43 +262,41 @@ export function Field(props: FieldProps) {
297
262
  </>
298
263
  );
299
264
  } else {
300
- let type: TextFieldType = "text";
265
+ let tfType: TextFieldType = "text";
266
+ let tfValue: string = value;
301
267
  // Number is supported differently because we need fractional numbers and they don't work
302
268
  // well on iOS.
303
- if (props.type && ["date", "email", "password", "url"].indexOf(props.type) > -1) {
304
- type = props.type as TextFieldType;
305
- } else if (props.type === "percent" || props.type === "currency") {
306
- type = "text";
269
+ if (type && ["date", "email", "password", "url"].indexOf(type) > -1) {
270
+ tfType = type as TextFieldType;
271
+ } else if (type === "percent" || type === "currency") {
272
+ tfType = "text";
307
273
  }
308
274
  let autoComplete: "on" | "current-password" | "username" = "on";
309
- if (type === "password") {
275
+ if (tfType === "password") {
310
276
  autoComplete = "current-password";
311
- } else if (type === "email") {
277
+ } else if (tfType === "email") {
312
278
  autoComplete = "username";
313
279
  }
314
- const stringValue = String(value);
315
- // if (props.type === "percent") {
316
- // value = `${Number(value).toFixed(0)}%`;
317
- // } else if (props.type === "currency") {
318
- // value = `$${Number(value).toFixed(2)}`;
319
- // }
320
- // console.log("VAL", value);
280
+ if (type === "percent") {
281
+ tfValue = `${Number(value).toFixed(0)}%`;
282
+ } else if (type === "currency") {
283
+ tfValue = `$${Number(value).toFixed(2)}`;
284
+ }
321
285
  return (
322
286
  <TextField
323
287
  autoComplete={autoComplete}
324
- disabled={props.disabled}
325
- id={props.name}
326
- placeholder={props.placeholder}
327
- type={type as "date" | "email" | "number" | "password" | "text" | "url"}
328
- value={stringValue}
329
- onChange={(result) => handleChange(result.value)}
288
+ disabled={disabled}
289
+ id={name}
290
+ placeholder={placeholder}
291
+ type={tfType as "date" | "email" | "number" | "password" | "text" | "url"}
292
+ value={tfValue}
293
+ onChange={(result) => onChange(result.value)}
330
294
  />
331
295
  );
332
296
  }
333
297
  };
334
298
 
335
299
  const children = renderField();
336
- const {errorMessage, errorMessageColor, helperText, helperTextColor, label, labelColor} = props;
337
300
  return (
338
301
  <Box marginBottom={5}>
339
302
  <FieldWithLabels
@@ -350,4 +313,4 @@ export function Field(props: FieldProps) {
350
313
  </FieldWithLabels>
351
314
  </Box>
352
315
  );
353
- }
316
+ };
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, {useEffect} from "react";
2
2
 
3
3
  import {FieldWithLabelsProps, StyleProp} from "./Common";
4
4
  import RNPickerSelect from "./PickerSelect";
@@ -21,6 +21,12 @@ export interface SelectListProps extends FieldWithLabelsProps {
21
21
 
22
22
  export function SelectList({options, value, onChange, label, labelColor, style}: SelectListProps) {
23
23
  const withLabelProps = {label, labelColor};
24
+
25
+ useEffect(() => {
26
+ if (!value && options && options.length > 0) {
27
+ onChange(options[0].value);
28
+ }
29
+ }, [onChange, options, value]);
24
30
  return (
25
31
  <WithLabel {...withLabelProps}>
26
32
  <RNPickerSelect
package/src/TapToEdit.tsx CHANGED
@@ -7,8 +7,9 @@ import {Field, FieldProps} from "./Field";
7
7
  import {Icon} from "./Icon";
8
8
  import {Text} from "./Text";
9
9
 
10
- export interface TapToEditProps extends Omit<FieldProps, "handleChange"> {
10
+ export interface TapToEditProps extends Omit<FieldProps, "handleChange" | "value"> {
11
11
  title: string;
12
+ initialValue: any;
12
13
  // Not required if not editable.
13
14
  onSave?: (value: any) => void | Promise<void>;
14
15
  // Defaults to true
@@ -19,22 +20,26 @@ export interface TapToEditProps extends Omit<FieldProps, "handleChange"> {
19
20
  fieldComponent?: (setValue: () => void) => ReactElement;
20
21
  }
21
22
 
22
- export const TapToEdit = (props: TapToEditProps): ReactElement => {
23
+ export const TapToEdit = ({
24
+ initialValue,
25
+ title,
26
+ onSave,
27
+ editable,
28
+ rowBoxProps,
29
+ transform,
30
+ fieldComponent,
31
+ ...fieldProps
32
+ }: TapToEditProps): ReactElement => {
23
33
  const [editing, setEditing] = useState(false);
24
- const [value, setValue] = useState(props.initialValue);
34
+ const [value, setValue] = useState(initialValue);
25
35
 
26
- const {title, editable = true, rowBoxProps, transform, fieldComponent, ...fieldProps} = props;
27
36
  if (editing) {
28
37
  return (
29
38
  <Box direction="column">
30
39
  {fieldComponent ? (
31
40
  fieldComponent(setValue as any)
32
41
  ) : (
33
- <Field
34
- handleChange={(_: string, val: any): void => setValue(val)}
35
- label={props.title}
36
- {...fieldProps}
37
- />
42
+ <Field label={title} onChange={setValue} {...fieldProps} />
38
43
  )}
39
44
  <Box direction="row">
40
45
  <Button
@@ -42,10 +47,10 @@ export const TapToEdit = (props: TapToEditProps): ReactElement => {
42
47
  inline
43
48
  text="Save"
44
49
  onClick={async (): Promise<void> => {
45
- if (!props.onSave) {
50
+ if (!onSave) {
46
51
  console.error("No onSave provided for editable TapToEdit");
47
52
  } else {
48
- await props.onSave(value);
53
+ await onSave(value);
49
54
  }
50
55
  setEditing(false);
51
56
  }}
@@ -64,10 +69,10 @@ export const TapToEdit = (props: TapToEditProps): ReactElement => {
64
69
  </Box>
65
70
  );
66
71
  } else {
67
- let displayValue = props.initialValue;
72
+ let displayValue = initialValue;
68
73
  // If a transform props is present, that takes priority
69
74
  if (transform) {
70
- displayValue = transform(props.initialValue);
75
+ displayValue = transform(initialValue);
71
76
  } else {
72
77
  // If no transform, try and display the value reasonably.
73
78
  if (fieldProps?.type === "boolean") {