@draftbit/core 44.1.13-6f194c.0 → 44.1.13-9a8dff.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.
@@ -1,185 +0,0 @@
1
- import * as React from "react";
2
- import { View, /* StyleSheet, */ Text, Platform } from "react-native";
3
- import { SafeAreaView } from "react-native-safe-area-context";
4
- import { omit, pick, pickBy, identity } from "lodash";
5
- import { Picker as NativePicker } from "@react-native-picker/picker";
6
- import { withTheme } from "../../theming";
7
- import Portal from "../Portal/Portal";
8
- import Button from "../DeprecatedButton";
9
- import Touchable from "../Touchable";
10
- import { extractStyles } from "../../utilities";
11
- const Picker = ({ Icon, style, options = [], placeholder = "", value: selectedValue = "", disabled = false, onValueChange = () => { }, theme, assistiveText, label, leftIconMode = "inset", leftIconName, placeholderTextColor, rightIconName, type, }) => {
12
- const [pickerVisible, setIsPickerVisible] = React.useState(false);
13
- const { viewStyles, textStyles } = extractStyles(style);
14
- const { colors } = theme;
15
- console.log({
16
- // viewStyles,
17
- // textStyles,
18
- // options,
19
- // placeholder,
20
- // selectedValue,
21
- // theme,
22
- // disabled,
23
- // onValueChange,
24
- // colors,
25
- // assistiveText,
26
- // label,
27
- // leftIconMode,
28
- // leftIconName,
29
- // placeholderTextColor,
30
- // rightIconName,
31
- // type,
32
- });
33
- const borders = [
34
- "borderRadius",
35
- "borderTopLeftRadius",
36
- "borderTopRightRadius",
37
- "borderBottomRightRadius",
38
- "borderBottomLeftRadius",
39
- "borderTopWidth",
40
- "borderRightWidth",
41
- "borderBottomWidth",
42
- "borderLeftWidth",
43
- "borderColor",
44
- "borderStyle",
45
- ];
46
- const borderStyles = {
47
- ...{
48
- ...(type === "solid"
49
- ? {
50
- borderTopLeftRadius: 5,
51
- borderTopRightRadius: 5,
52
- borderBottomRightRadius: 5,
53
- borderBottomLeftRadius: 5,
54
- borderTopWidth: 1,
55
- borderRightWidth: 1,
56
- borderLeftWidth: 1,
57
- }
58
- : {}),
59
- borderBottomWidth: 1,
60
- borderColor: colors.light,
61
- borderStyle: "solid",
62
- },
63
- ...pick(viewStyles, borders),
64
- };
65
- const margins = ["marginLeft", "marginRight", "marginTop", "marginBottom"];
66
- const marginStyles = pick(viewStyles, margins);
67
- const stylesWithoutBordersAndMargins = {
68
- ...{
69
- height: 60,
70
- width: "100%",
71
- },
72
- ...omit(viewStyles, [...borders, ...margins]),
73
- };
74
- const selectedLabel = selectedValue &&
75
- (options.find((o) => o.value === selectedValue)?.label ??
76
- selectedValue);
77
- const labelText = label ? (React.createElement(Text, { style: {
78
- textAlign: textStyles.textAlign,
79
- color: colors.light,
80
- fontSize: 12,
81
- paddingBottom: 4,
82
- } }, label)) : null;
83
- const leftIconOutset = leftIconMode === "outset";
84
- const leftIcon = leftIconName ? (React.createElement(Icon, { name: leftIconName, size: 24, style: {
85
- marginRight: 8,
86
- marginLeft: -6,
87
- } })) : null;
88
- const rightIcon = rightIconName ? (React.createElement(Icon, { name: rightIconName, size: 24, style: {
89
- marginRight: -6,
90
- marginLeft: 8,
91
- } })) : null;
92
- // @ts-ignore
93
- const width = stylesWithoutBordersAndMargins?.width ?? undefined;
94
- const textAlign = textStyles?.textAlign;
95
- const paddingLeft = leftIconOutset &&
96
- (!textAlign || textAlign === "left" || textAlign === "justify")
97
- ? 28 // icon size + 4
98
- : 0;
99
- const assistiveTextLabel = assistiveText ? (React.createElement(Text, { style: {
100
- textAlign,
101
- width,
102
- paddingLeft,
103
- color: colors.light,
104
- fontSize: 12,
105
- paddingTop: 4,
106
- } }, assistiveText)) : null;
107
- const primaryTextStyle = {
108
- color: colors.light,
109
- fontSize: 14,
110
- ...pickBy(textStyles, identity),
111
- ...(placeholder === selectedValue
112
- ? { color: placeholderTextColor ?? colors.light }
113
- : {}),
114
- };
115
- const toggleVisibility = () => setIsPickerVisible(!pickerVisible);
116
- return (React.createElement(View, { style: [
117
- {
118
- alignSelf: "stretch",
119
- },
120
- marginStyles,
121
- ] },
122
- React.createElement(Touchable, { disabled: disabled, onPress: toggleVisibility, style: { alignSelf: "stretch", alignItems: "center" } },
123
- React.createElement(View, { pointerEvents: "none", style: [
124
- {
125
- //alignSelf: "stretch",
126
- flexDirection: "row",
127
- alignItems: "center",
128
- justifyContent: "space-between",
129
- },
130
- stylesWithoutBordersAndMargins,
131
- // @ts-ignore
132
- !leftIconOutset && borderStyles,
133
- ] },
134
- leftIcon,
135
- React.createElement(View, { style: [
136
- {
137
- flex: 1,
138
- height: "100%",
139
- flexDirection: "row",
140
- alignItems: "center",
141
- justifyContent: "space-between",
142
- paddingLeft: 12,
143
- paddingRight: 12,
144
- },
145
- // @ts-ignore
146
- leftIconOutset && borderStyles,
147
- ] },
148
- React.createElement(View, { style: {
149
- flex: 1,
150
- // paddingTop: 0,
151
- // paddingRight: 0, // add inner text paddding settings
152
- // paddingLeft: 0,
153
- // paddingBottom: 0,
154
- } },
155
- labelText,
156
- React.createElement(Text, { style: primaryTextStyle }, String(selectedLabel ?? placeholder))),
157
- rightIcon)),
158
- assistiveTextLabel),
159
- Platform.OS === "ios" && pickerVisible ? (React.createElement(Portal, null,
160
- React.createElement(View, { style: {
161
- position: "absolute",
162
- bottom: 0,
163
- left: 0,
164
- right: 0,
165
- flexDirection: "row",
166
- justifyContent: "center",
167
- backgroundColor: colors.divider,
168
- } },
169
- React.createElement(SafeAreaView, { style: {
170
- backgroundColor: "white",
171
- flexDirection: "column",
172
- width: "100%",
173
- } },
174
- React.createElement(Button, { Icon: Icon, type: "text", onPress: toggleVisibility, style: { alignSelf: "flex-end" } }, "Close"),
175
- React.createElement(NativePicker, { style: { backgroundColor: "white" }, selectedValue: selectedValue, onValueChange: onValueChange }, options.map((o) => (React.createElement(NativePicker.Item, { label: o.label, value: o.value, key: o.value })))))))) : (React.createElement(NativePicker, { enabled: pickerVisible, selectedValue: selectedValue, onValueChange: onValueChange, style: {
176
- opacity: 0,
177
- position: "absolute",
178
- top: 0,
179
- left: 0,
180
- right: 0,
181
- bottom: 0,
182
- width: "100%",
183
- } }, options.map((o) => (React.createElement(NativePicker.Item, { label: o.label, value: o.value, key: o.value })))))));
184
- };
185
- export default withTheme(Picker);
@@ -1,321 +0,0 @@
1
- import * as React from "react";
2
- import { View, /* StyleSheet, */ Text, Platform } from "react-native";
3
- import { SafeAreaView } from "react-native-safe-area-context";
4
- import { omit, pick, pickBy, identity } from "lodash";
5
- import { Picker as NativePicker } from "@react-native-picker/picker";
6
-
7
- import { withTheme } from "../../theming";
8
- import Portal from "../Portal/Portal";
9
- import Button from "../DeprecatedButton";
10
- import Touchable from "../Touchable";
11
- import { PickerProps, PickerOption } from "./Picker";
12
- import { extractStyles } from "../../utilities";
13
- import type { IconSlot } from "../../interfaces/Icon";
14
- import type { Theme } from "../../styles/DefaultTheme";
15
-
16
- const Picker: React.FC<PickerProps & IconSlot & Theme> = ({
17
- Icon,
18
- style,
19
- options = [],
20
- placeholder = "",
21
- value: selectedValue = "",
22
- disabled = false,
23
- onValueChange = () => {},
24
- theme,
25
- assistiveText,
26
- label,
27
- leftIconMode = "inset",
28
- leftIconName,
29
- placeholderTextColor,
30
- rightIconName,
31
- type,
32
- }) => {
33
- const [pickerVisible, setIsPickerVisible] = React.useState(false);
34
-
35
- const { viewStyles, textStyles } = extractStyles(style);
36
-
37
- const { colors } = theme;
38
-
39
- console.log({
40
- // viewStyles,
41
- // textStyles,
42
- // options,
43
- // placeholder,
44
- // selectedValue,
45
- // theme,
46
- // disabled,
47
- // onValueChange,
48
- // colors,
49
- // assistiveText,
50
- // label,
51
- // leftIconMode,
52
- // leftIconName,
53
- // placeholderTextColor,
54
- // rightIconName,
55
- // type,
56
- });
57
-
58
- const borders = [
59
- "borderRadius",
60
- "borderTopLeftRadius",
61
- "borderTopRightRadius",
62
- "borderBottomRightRadius",
63
- "borderBottomLeftRadius",
64
- "borderTopWidth",
65
- "borderRightWidth",
66
- "borderBottomWidth",
67
- "borderLeftWidth",
68
- "borderColor",
69
- "borderStyle",
70
- ];
71
-
72
- const borderStyles = {
73
- ...{
74
- ...(type === "solid"
75
- ? {
76
- borderTopLeftRadius: 5,
77
- borderTopRightRadius: 5,
78
- borderBottomRightRadius: 5,
79
- borderBottomLeftRadius: 5,
80
- borderTopWidth: 1,
81
- borderRightWidth: 1,
82
- borderLeftWidth: 1,
83
- }
84
- : {}),
85
- borderBottomWidth: 1,
86
- borderColor: colors.light,
87
- borderStyle: "solid",
88
- },
89
- ...pick(viewStyles, borders),
90
- };
91
-
92
- const margins = ["marginLeft", "marginRight", "marginTop", "marginBottom"];
93
-
94
- const marginStyles = pick(viewStyles, margins);
95
-
96
- const stylesWithoutBordersAndMargins = {
97
- ...{
98
- height: 60,
99
- width: "100%",
100
- },
101
- ...omit(viewStyles, [...borders, ...margins]),
102
- };
103
-
104
- const selectedLabel =
105
- selectedValue &&
106
- ((options as unknown as PickerOption[]).find(
107
- (o) => o.value === selectedValue
108
- )?.label ??
109
- selectedValue);
110
-
111
- const labelText = label ? (
112
- <Text
113
- style={{
114
- textAlign: textStyles.textAlign,
115
- color: colors.light,
116
- fontSize: 12,
117
- paddingBottom: 4,
118
- }}
119
- >
120
- {label}
121
- </Text>
122
- ) : null;
123
-
124
- const leftIconOutset = leftIconMode === "outset";
125
-
126
- const leftIcon = leftIconName ? (
127
- <Icon
128
- name={leftIconName}
129
- size={24}
130
- style={{
131
- marginRight: 8,
132
- marginLeft: -6,
133
- }}
134
- />
135
- ) : null;
136
-
137
- const rightIcon = rightIconName ? (
138
- <Icon
139
- name={rightIconName}
140
- size={24}
141
- style={{
142
- marginRight: -6,
143
- marginLeft: 8,
144
- }}
145
- />
146
- ) : null;
147
-
148
- // @ts-ignore
149
- const width = stylesWithoutBordersAndMargins?.width ?? undefined;
150
-
151
- const textAlign = textStyles?.textAlign;
152
-
153
- const paddingLeft =
154
- leftIconOutset &&
155
- (!textAlign || textAlign === "left" || textAlign === "justify")
156
- ? 28 // icon size + 4
157
- : 0;
158
-
159
- const assistiveTextLabel = assistiveText ? (
160
- <Text
161
- style={{
162
- textAlign,
163
- width,
164
- paddingLeft,
165
- color: colors.light,
166
- fontSize: 12,
167
- paddingTop: 4,
168
- }}
169
- >
170
- {assistiveText}
171
- </Text>
172
- ) : null;
173
-
174
- const primaryTextStyle = {
175
- color: colors.light,
176
- fontSize: 14,
177
- ...pickBy(textStyles, identity),
178
- ...(placeholder === selectedValue
179
- ? { color: placeholderTextColor ?? colors.light }
180
- : {}),
181
- };
182
-
183
- const toggleVisibility = () => setIsPickerVisible(!pickerVisible);
184
-
185
- return (
186
- <View
187
- style={[
188
- {
189
- alignSelf: "stretch",
190
- },
191
- marginStyles,
192
- ]}
193
- >
194
- <Touchable
195
- disabled={disabled}
196
- onPress={toggleVisibility}
197
- style={{ alignSelf: "stretch", alignItems: "center" }}
198
- >
199
- <View
200
- pointerEvents="none"
201
- style={[
202
- {
203
- //alignSelf: "stretch",
204
- flexDirection: "row",
205
- alignItems: "center",
206
- justifyContent: "space-between",
207
- },
208
- stylesWithoutBordersAndMargins,
209
- // @ts-ignore
210
- !leftIconOutset && borderStyles,
211
- ]}
212
- >
213
- {leftIcon}
214
-
215
- <View
216
- style={[
217
- {
218
- flex: 1,
219
- height: "100%",
220
- flexDirection: "row",
221
- alignItems: "center",
222
- justifyContent: "space-between",
223
- paddingLeft: 12,
224
- paddingRight: 12,
225
- },
226
- // @ts-ignore
227
- leftIconOutset && borderStyles,
228
- ]}
229
- >
230
- <View
231
- style={{
232
- flex: 1,
233
- // paddingTop: 0,
234
- // paddingRight: 0, // add inner text paddding settings
235
- // paddingLeft: 0,
236
- // paddingBottom: 0,
237
- }}
238
- >
239
- {labelText}
240
-
241
- <Text style={primaryTextStyle}>
242
- {String(selectedLabel ?? placeholder)}
243
- </Text>
244
- </View>
245
-
246
- {rightIcon}
247
- </View>
248
- </View>
249
- {assistiveTextLabel}
250
- </Touchable>
251
-
252
- {Platform.OS === "ios" && pickerVisible ? (
253
- <Portal>
254
- <View
255
- style={{
256
- position: "absolute",
257
- bottom: 0,
258
- left: 0,
259
- right: 0,
260
- flexDirection: "row",
261
- justifyContent: "center",
262
- backgroundColor: colors.divider,
263
- }}
264
- >
265
- <SafeAreaView
266
- style={{
267
- backgroundColor: "white",
268
- flexDirection: "column",
269
- width: "100%",
270
- }}
271
- >
272
- <Button
273
- Icon={Icon}
274
- type="text"
275
- onPress={toggleVisibility}
276
- style={{ alignSelf: "flex-end" }}
277
- >
278
- {"Close"}
279
- </Button>
280
-
281
- <NativePicker
282
- style={{ backgroundColor: "white" }}
283
- selectedValue={selectedValue}
284
- onValueChange={onValueChange}
285
- >
286
- {(options as unknown as PickerOption[]).map((o) => (
287
- <NativePicker.Item
288
- label={o.label}
289
- value={o.value}
290
- key={o.value}
291
- />
292
- ))}
293
- </NativePicker>
294
- </SafeAreaView>
295
- </View>
296
- </Portal>
297
- ) : (
298
- <NativePicker
299
- enabled={pickerVisible}
300
- selectedValue={selectedValue}
301
- onValueChange={onValueChange}
302
- style={{
303
- opacity: 0,
304
- position: "absolute",
305
- top: 0,
306
- left: 0,
307
- right: 0,
308
- bottom: 0,
309
- width: "100%",
310
- }}
311
- >
312
- {(options as unknown as PickerOption[]).map((o) => (
313
- <NativePicker.Item label={o.label} value={o.value} key={o.value} />
314
- ))}
315
- </NativePicker>
316
- )}
317
- </View>
318
- );
319
- };
320
-
321
- export default withTheme(Picker);