@xaui/native 0.0.31 → 0.0.33
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 +4 -0
- package/dist/app-bar/index.cjs +4 -1
- package/dist/app-bar/index.js +4 -1
- package/dist/bottom-sheet/index.cjs +4 -3
- package/dist/bottom-sheet/index.js +2 -1
- package/dist/chunk-2ANGPYCP.cjs +308 -0
- package/dist/chunk-DECMUMCI.js +0 -0
- package/dist/chunk-E4DOPNVW.js +308 -0
- package/dist/chunk-EUQDGTST.cjs +1 -0
- package/dist/color-picker/index.cjs +460 -0
- package/dist/color-picker/index.d.cts +124 -0
- package/dist/color-picker/index.d.ts +124 -0
- package/dist/color-picker/index.js +460 -0
- package/dist/dialog/index.cjs +381 -0
- package/dist/dialog/index.d.cts +151 -0
- package/dist/dialog/index.d.ts +151 -0
- package/dist/dialog/index.js +381 -0
- package/dist/index-DyU3sW3_.d.cts +4 -0
- package/dist/index-DyU3sW3_.d.ts +4 -0
- package/dist/input-trigger/index.cjs +8 -0
- package/dist/input-trigger/index.d.cts +9 -0
- package/dist/input-trigger/index.d.ts +9 -0
- package/dist/input-trigger/index.js +8 -0
- package/dist/input-trigger.type-BL70fHE9.d.cts +97 -0
- package/dist/input-trigger.type-BODYStHk.d.ts +97 -0
- package/dist/picker/index.cjs +250 -0
- package/dist/picker/index.d.cts +121 -0
- package/dist/picker/index.d.ts +121 -0
- package/dist/picker/index.js +250 -0
- package/dist/snackbar/index.d.cts +1 -2
- package/dist/snackbar/index.d.ts +1 -2
- package/dist/snippet/index.cjs +282 -0
- package/dist/snippet/index.d.cts +90 -0
- package/dist/snippet/index.d.ts +90 -0
- package/dist/snippet/index.js +282 -0
- package/dist/timepicker/index.cjs +4 -3
- package/dist/timepicker/index.js +2 -1
- package/dist/toolbar/index.cjs +24 -17
- package/dist/toolbar/index.js +25 -18
- package/package.json +26 -1
- /package/dist/{chunk-HC2SSHNU.js → chunk-ED22WCCI.js} +0 -0
- /package/dist/{chunk-XFPPR2VB.cjs → chunk-RVR42THG.cjs} +0 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InputTrigger
|
|
3
|
+
} from "../chunk-E4DOPNVW.js";
|
|
4
|
+
import {
|
|
5
|
+
BottomSheet
|
|
6
|
+
} from "../chunk-ED22WCCI.js";
|
|
7
|
+
import "../chunk-DXXNBF5P.js";
|
|
8
|
+
import {
|
|
9
|
+
useXUITheme
|
|
10
|
+
} from "../chunk-LTKYHG5V.js";
|
|
11
|
+
|
|
12
|
+
// src/components/picker/picker.tsx
|
|
13
|
+
import React, { useState } from "react";
|
|
14
|
+
import { Pressable, ScrollView, Text, View } from "react-native";
|
|
15
|
+
import { getSafeThemeColor, withOpacity } from "@xaui/core";
|
|
16
|
+
|
|
17
|
+
// src/components/picker/picker.style.ts
|
|
18
|
+
import { StyleSheet } from "react-native";
|
|
19
|
+
var styles = StyleSheet.create({
|
|
20
|
+
sheetContent: {
|
|
21
|
+
flex: 1,
|
|
22
|
+
paddingBottom: 24
|
|
23
|
+
},
|
|
24
|
+
sheetTitle: {
|
|
25
|
+
paddingHorizontal: 20,
|
|
26
|
+
paddingTop: 4,
|
|
27
|
+
paddingBottom: 12,
|
|
28
|
+
fontSize: 16,
|
|
29
|
+
fontWeight: "600"
|
|
30
|
+
},
|
|
31
|
+
optionItem: {
|
|
32
|
+
flexDirection: "row",
|
|
33
|
+
alignItems: "center",
|
|
34
|
+
paddingHorizontal: 20,
|
|
35
|
+
paddingVertical: 14,
|
|
36
|
+
gap: 12
|
|
37
|
+
},
|
|
38
|
+
optionItemDisabled: {
|
|
39
|
+
opacity: 0.4
|
|
40
|
+
},
|
|
41
|
+
optionLabel: {
|
|
42
|
+
flex: 1,
|
|
43
|
+
fontSize: 16
|
|
44
|
+
},
|
|
45
|
+
checkmark: {
|
|
46
|
+
width: 20,
|
|
47
|
+
height: 20,
|
|
48
|
+
borderRadius: 10,
|
|
49
|
+
alignItems: "center",
|
|
50
|
+
justifyContent: "center"
|
|
51
|
+
},
|
|
52
|
+
divider: {
|
|
53
|
+
height: StyleSheet.hairlineWidth,
|
|
54
|
+
marginHorizontal: 20
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// src/components/picker/picker.tsx
|
|
59
|
+
var ChevronDownIcon = ({
|
|
60
|
+
color,
|
|
61
|
+
size
|
|
62
|
+
}) => /* @__PURE__ */ React.createElement(
|
|
63
|
+
View,
|
|
64
|
+
{
|
|
65
|
+
style: {
|
|
66
|
+
width: size,
|
|
67
|
+
height: size,
|
|
68
|
+
alignItems: "center",
|
|
69
|
+
justifyContent: "center"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
/* @__PURE__ */ React.createElement(
|
|
73
|
+
View,
|
|
74
|
+
{
|
|
75
|
+
style: {
|
|
76
|
+
width: size * 0.5,
|
|
77
|
+
height: size * 0.5,
|
|
78
|
+
borderRightWidth: 2,
|
|
79
|
+
borderBottomWidth: 2,
|
|
80
|
+
borderColor: color,
|
|
81
|
+
transform: [{ rotate: "45deg" }],
|
|
82
|
+
marginTop: -(size * 0.15)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
);
|
|
87
|
+
var CheckIcon = ({ color }) => /* @__PURE__ */ React.createElement(View, { style: { width: 20, height: 20, alignItems: "center", justifyContent: "center" } }, /* @__PURE__ */ React.createElement(
|
|
88
|
+
View,
|
|
89
|
+
{
|
|
90
|
+
style: {
|
|
91
|
+
width: 6,
|
|
92
|
+
height: 10,
|
|
93
|
+
borderRightWidth: 2,
|
|
94
|
+
borderBottomWidth: 2,
|
|
95
|
+
borderColor: color,
|
|
96
|
+
transform: [{ rotate: "45deg" }],
|
|
97
|
+
marginTop: -3
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
));
|
|
101
|
+
var OptionItem = ({
|
|
102
|
+
option,
|
|
103
|
+
isSelected,
|
|
104
|
+
themeColor,
|
|
105
|
+
foreground,
|
|
106
|
+
onSelect
|
|
107
|
+
}) => {
|
|
108
|
+
const handlePress = () => {
|
|
109
|
+
if (!option.disabled) {
|
|
110
|
+
onSelect(option.value);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return /* @__PURE__ */ React.createElement(
|
|
114
|
+
Pressable,
|
|
115
|
+
{
|
|
116
|
+
onPress: handlePress,
|
|
117
|
+
style: [styles.optionItem, option.disabled && styles.optionItemDisabled],
|
|
118
|
+
disabled: option.disabled
|
|
119
|
+
},
|
|
120
|
+
/* @__PURE__ */ React.createElement(
|
|
121
|
+
Text,
|
|
122
|
+
{
|
|
123
|
+
style: [
|
|
124
|
+
styles.optionLabel,
|
|
125
|
+
{ color: isSelected ? themeColor : foreground }
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
option.label
|
|
129
|
+
),
|
|
130
|
+
isSelected && /* @__PURE__ */ React.createElement(CheckIcon, { color: themeColor })
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
var Picker = ({
|
|
134
|
+
options,
|
|
135
|
+
value,
|
|
136
|
+
placeholder = "Select an option...",
|
|
137
|
+
label,
|
|
138
|
+
labelPlacement = "outside",
|
|
139
|
+
description,
|
|
140
|
+
errorMessage,
|
|
141
|
+
sheetTitle,
|
|
142
|
+
themeColor = "primary",
|
|
143
|
+
variant = "flat",
|
|
144
|
+
size = "md",
|
|
145
|
+
radius = "md",
|
|
146
|
+
isOpened,
|
|
147
|
+
isDisabled = false,
|
|
148
|
+
isInvalid = false,
|
|
149
|
+
fullWidth = true,
|
|
150
|
+
sheetStyle,
|
|
151
|
+
endContent,
|
|
152
|
+
onValueChange,
|
|
153
|
+
onOpenChange,
|
|
154
|
+
onClose
|
|
155
|
+
}) => {
|
|
156
|
+
const [internalIsOpen, setInternalIsOpen] = useState(false);
|
|
157
|
+
const isControlled = isOpened !== void 0;
|
|
158
|
+
const isOpen = isControlled ? Boolean(isOpened) : internalIsOpen;
|
|
159
|
+
const theme = useXUITheme();
|
|
160
|
+
const sheetBackground = theme.mode === "dark" ? theme.colors.background : "#ffffff";
|
|
161
|
+
const safeThemeColor = getSafeThemeColor(themeColor);
|
|
162
|
+
const colorScheme = theme.colors[safeThemeColor];
|
|
163
|
+
const selectedOption = options.find((opt) => opt.value === value);
|
|
164
|
+
const displayLabel = selectedOption?.label;
|
|
165
|
+
const setOpen = (nextOpen) => {
|
|
166
|
+
if (nextOpen && isDisabled) return;
|
|
167
|
+
if (!isControlled) {
|
|
168
|
+
setInternalIsOpen(nextOpen);
|
|
169
|
+
}
|
|
170
|
+
onOpenChange?.(nextOpen);
|
|
171
|
+
};
|
|
172
|
+
const handleOpen = () => {
|
|
173
|
+
setOpen(true);
|
|
174
|
+
};
|
|
175
|
+
const requestClose = () => {
|
|
176
|
+
setOpen(false);
|
|
177
|
+
};
|
|
178
|
+
const handleSheetClose = () => {
|
|
179
|
+
if (isOpen) {
|
|
180
|
+
setOpen(false);
|
|
181
|
+
}
|
|
182
|
+
onClose?.();
|
|
183
|
+
};
|
|
184
|
+
const handleSelect = (selectedValue) => {
|
|
185
|
+
onValueChange?.(selectedValue);
|
|
186
|
+
requestClose();
|
|
187
|
+
};
|
|
188
|
+
const chevronColor = withOpacity(theme.colors.foreground, 0.45);
|
|
189
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
|
|
190
|
+
InputTrigger,
|
|
191
|
+
{
|
|
192
|
+
value: displayLabel,
|
|
193
|
+
placeholder,
|
|
194
|
+
label,
|
|
195
|
+
labelPlacement,
|
|
196
|
+
description,
|
|
197
|
+
errorMessage,
|
|
198
|
+
themeColor,
|
|
199
|
+
variant,
|
|
200
|
+
size,
|
|
201
|
+
radius,
|
|
202
|
+
isDisabled,
|
|
203
|
+
isInvalid,
|
|
204
|
+
fullWidth,
|
|
205
|
+
endContent: endContent ?? /* @__PURE__ */ React.createElement(ChevronDownIcon, { color: chevronColor, size: 20 }),
|
|
206
|
+
onPress: handleOpen
|
|
207
|
+
}
|
|
208
|
+
), /* @__PURE__ */ React.createElement(
|
|
209
|
+
BottomSheet,
|
|
210
|
+
{
|
|
211
|
+
isOpen,
|
|
212
|
+
snapPoints: [Math.min(0.35 + options.length * 0.065, 0.85)],
|
|
213
|
+
themeColor,
|
|
214
|
+
onClose: handleSheetClose,
|
|
215
|
+
style: { backgroundColor: sheetBackground, ...sheetStyle }
|
|
216
|
+
},
|
|
217
|
+
/* @__PURE__ */ React.createElement(View, { style: styles.sheetContent }, sheetTitle ? /* @__PURE__ */ React.createElement(
|
|
218
|
+
Text,
|
|
219
|
+
{
|
|
220
|
+
style: [styles.sheetTitle, { color: theme.colors.foreground }]
|
|
221
|
+
},
|
|
222
|
+
sheetTitle
|
|
223
|
+
) : null, /* @__PURE__ */ React.createElement(ScrollView, null, options.map((option, index) => /* @__PURE__ */ React.createElement(View, { key: option.value }, /* @__PURE__ */ React.createElement(
|
|
224
|
+
OptionItem,
|
|
225
|
+
{
|
|
226
|
+
option,
|
|
227
|
+
isSelected: option.value === value,
|
|
228
|
+
themeColor: colorScheme.main,
|
|
229
|
+
foreground: theme.colors.foreground,
|
|
230
|
+
onSelect: handleSelect
|
|
231
|
+
}
|
|
232
|
+
), index < options.length - 1 && /* @__PURE__ */ React.createElement(
|
|
233
|
+
View,
|
|
234
|
+
{
|
|
235
|
+
style: [
|
|
236
|
+
styles.divider,
|
|
237
|
+
{
|
|
238
|
+
backgroundColor: withOpacity(
|
|
239
|
+
theme.colors.foreground,
|
|
240
|
+
0.06
|
|
241
|
+
)
|
|
242
|
+
}
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
)))))
|
|
246
|
+
));
|
|
247
|
+
};
|
|
248
|
+
export {
|
|
249
|
+
Picker
|
|
250
|
+
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
import { ViewStyle, TextStyle } from 'react-native';
|
|
3
|
-
|
|
4
|
-
type ThemeColor = 'primary' | 'secondary' | 'tertiary' | 'danger' | 'warning' | 'success' | 'default';
|
|
3
|
+
import { T as ThemeColor } from '../index-DyU3sW3_.cjs';
|
|
5
4
|
|
|
6
5
|
type SnackbarPosition = 'top' | 'bottom';
|
|
7
6
|
type SnackbarCustomAppearance = {
|
package/dist/snackbar/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
import { ViewStyle, TextStyle } from 'react-native';
|
|
3
|
-
|
|
4
|
-
type ThemeColor = 'primary' | 'secondary' | 'tertiary' | 'danger' | 'warning' | 'success' | 'default';
|
|
3
|
+
import { T as ThemeColor } from '../index-DyU3sW3_.js';
|
|
5
4
|
|
|
6
5
|
type SnackbarPosition = 'top' | 'bottom';
|
|
7
6
|
type SnackbarCustomAppearance = {
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('../chunk-HSPTLUFA.cjs');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkOQ2BLOOGcjs = require('../chunk-OQ2BLOOG.cjs');
|
|
6
|
+
|
|
7
|
+
// src/components/snippet/snippet.tsx
|
|
8
|
+
var _react = require('react'); var _react2 = _interopRequireDefault(_react);
|
|
9
|
+
var _reactnative = require('react-native');
|
|
10
|
+
var _icons = require('@xaui/icons');
|
|
11
|
+
|
|
12
|
+
// src/components/snippet/snippet.style.ts
|
|
13
|
+
|
|
14
|
+
var styles = _reactnative.StyleSheet.create({
|
|
15
|
+
container: {
|
|
16
|
+
flexShrink: 1,
|
|
17
|
+
flexBasis: "auto",
|
|
18
|
+
width: "100%"
|
|
19
|
+
},
|
|
20
|
+
noFullWidth: {
|
|
21
|
+
width: void 0,
|
|
22
|
+
alignSelf: "flex-start"
|
|
23
|
+
},
|
|
24
|
+
snippet: {
|
|
25
|
+
position: "relative",
|
|
26
|
+
borderWidth: 1,
|
|
27
|
+
overflow: "hidden"
|
|
28
|
+
},
|
|
29
|
+
content: {
|
|
30
|
+
minHeight: 64,
|
|
31
|
+
justifyContent: "center",
|
|
32
|
+
paddingHorizontal: 14,
|
|
33
|
+
paddingVertical: 12
|
|
34
|
+
},
|
|
35
|
+
text: {
|
|
36
|
+
fontSize: 14,
|
|
37
|
+
lineHeight: 20,
|
|
38
|
+
fontFamily: "monospace",
|
|
39
|
+
includeFontPadding: false
|
|
40
|
+
},
|
|
41
|
+
topInset: {
|
|
42
|
+
paddingTop: 44
|
|
43
|
+
},
|
|
44
|
+
bottomInset: {
|
|
45
|
+
paddingBottom: 44
|
|
46
|
+
},
|
|
47
|
+
copyButton: {
|
|
48
|
+
position: "absolute",
|
|
49
|
+
flexDirection: "row",
|
|
50
|
+
alignItems: "center",
|
|
51
|
+
gap: 6,
|
|
52
|
+
borderWidth: 1,
|
|
53
|
+
paddingHorizontal: 10,
|
|
54
|
+
paddingVertical: 6
|
|
55
|
+
},
|
|
56
|
+
top: {
|
|
57
|
+
top: 8
|
|
58
|
+
},
|
|
59
|
+
bottom: {
|
|
60
|
+
bottom: 8
|
|
61
|
+
},
|
|
62
|
+
left: {
|
|
63
|
+
left: 8
|
|
64
|
+
},
|
|
65
|
+
right: {
|
|
66
|
+
right: 8
|
|
67
|
+
},
|
|
68
|
+
copyButtonText: {
|
|
69
|
+
fontSize: 12,
|
|
70
|
+
fontWeight: "600",
|
|
71
|
+
includeFontPadding: false
|
|
72
|
+
},
|
|
73
|
+
disabled: {
|
|
74
|
+
opacity: 0.55
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// src/components/snippet/snippet.hook.ts
|
|
79
|
+
|
|
80
|
+
var _core = require('@xaui/core');
|
|
81
|
+
var useSnippetColors = (themeColor, variant, isDisabled) => {
|
|
82
|
+
const theme = _chunkOQ2BLOOGcjs.useXUITheme.call(void 0, );
|
|
83
|
+
return _react.useMemo.call(void 0, () => {
|
|
84
|
+
const safeThemeColor = _core.getSafeThemeColor.call(void 0, themeColor);
|
|
85
|
+
const colorScheme = theme.colors[safeThemeColor];
|
|
86
|
+
const isDark = theme.mode === "dark";
|
|
87
|
+
const textColor = isDisabled ? _core.withOpacity.call(void 0, theme.colors.foreground, 0.56) : theme.colors.foreground;
|
|
88
|
+
if (variant === "flat") {
|
|
89
|
+
return {
|
|
90
|
+
containerBackground: colorScheme.background,
|
|
91
|
+
containerBorder: "transparent",
|
|
92
|
+
text: textColor,
|
|
93
|
+
copyButtonBackground: _core.withOpacity.call(void 0, colorScheme.main, isDark ? 0.2 : 0.14),
|
|
94
|
+
copyButtonBorder: "transparent",
|
|
95
|
+
copyButtonText: colorScheme.main
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (variant === "light") {
|
|
99
|
+
return {
|
|
100
|
+
containerBackground: _core.withOpacity.call(void 0, colorScheme.main, isDark ? 0.12 : 0.08),
|
|
101
|
+
containerBorder: "transparent",
|
|
102
|
+
text: textColor,
|
|
103
|
+
copyButtonBackground: "transparent",
|
|
104
|
+
copyButtonBorder: "transparent",
|
|
105
|
+
copyButtonText: colorScheme.main
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
containerBackground: theme.colors.background,
|
|
110
|
+
containerBorder: _core.withOpacity.call(void 0, colorScheme.main, isDark ? 0.7 : 0.55),
|
|
111
|
+
text: textColor,
|
|
112
|
+
copyButtonBackground: _core.withOpacity.call(void 0, colorScheme.main, isDark ? 0.16 : 0.08),
|
|
113
|
+
copyButtonBorder: _core.withOpacity.call(void 0, colorScheme.main, isDark ? 0.48 : 0.32),
|
|
114
|
+
copyButtonText: colorScheme.main
|
|
115
|
+
};
|
|
116
|
+
}, [isDisabled, theme, themeColor, variant]);
|
|
117
|
+
};
|
|
118
|
+
var useCopyButtonPositionStyles = (position) => {
|
|
119
|
+
return _react.useMemo.call(void 0,
|
|
120
|
+
() => ({
|
|
121
|
+
isTop: position.startsWith("top"),
|
|
122
|
+
isLeft: position.endsWith("left")
|
|
123
|
+
}),
|
|
124
|
+
[position]
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// src/components/snippet/snippet.tsx
|
|
129
|
+
var copyText = async (text) => {
|
|
130
|
+
const runtime = globalThis;
|
|
131
|
+
const writeText = _optionalChain([runtime, 'access', _ => _.navigator, 'optionalAccess', _2 => _2.clipboard, 'optionalAccess', _3 => _3.writeText]);
|
|
132
|
+
if (typeof writeText === "function") {
|
|
133
|
+
await writeText(text);
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
const modules = _reactnative.NativeModules;
|
|
137
|
+
const setString = _nullishCoalesce(_optionalChain([modules, 'access', _4 => _4.RNCClipboard, 'optionalAccess', _5 => _5.setString]), () => ( _optionalChain([modules, 'access', _6 => _6.Clipboard, 'optionalAccess', _7 => _7.setString])));
|
|
138
|
+
if (typeof setString === "function") {
|
|
139
|
+
setString(text);
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
};
|
|
144
|
+
var Snippet = ({
|
|
145
|
+
value,
|
|
146
|
+
themeColor = "primary",
|
|
147
|
+
variant = "outlined",
|
|
148
|
+
radius = "md",
|
|
149
|
+
copyButtonPosition = "top-right",
|
|
150
|
+
copyLabel = "Copy",
|
|
151
|
+
copiedLabel = "Copied",
|
|
152
|
+
copyResetDelay = 1500,
|
|
153
|
+
fullWidth = true,
|
|
154
|
+
isDisabled = false,
|
|
155
|
+
numberOfLines,
|
|
156
|
+
fontSize = 14,
|
|
157
|
+
fontWeight = "400",
|
|
158
|
+
onCopy,
|
|
159
|
+
customAppearance
|
|
160
|
+
}) => {
|
|
161
|
+
const [isCopied, setIsCopied] = _react2.default.useState(false);
|
|
162
|
+
const resetTimerRef = _react2.default.useRef(null);
|
|
163
|
+
const radiusStyles = _chunkOQ2BLOOGcjs.useBorderRadiusStyles.call(void 0, radius);
|
|
164
|
+
const colors = useSnippetColors(themeColor, variant, isDisabled);
|
|
165
|
+
const { isTop, isLeft } = useCopyButtonPositionStyles(copyButtonPosition);
|
|
166
|
+
_react2.default.useEffect(() => {
|
|
167
|
+
return () => {
|
|
168
|
+
if (resetTimerRef.current) {
|
|
169
|
+
clearTimeout(resetTimerRef.current);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}, []);
|
|
173
|
+
const handleCopy = _react2.default.useCallback(async () => {
|
|
174
|
+
if (isDisabled) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
let isSuccess = false;
|
|
178
|
+
try {
|
|
179
|
+
isSuccess = await copyText(value);
|
|
180
|
+
setIsCopied(isSuccess);
|
|
181
|
+
} catch (e) {
|
|
182
|
+
setIsCopied(false);
|
|
183
|
+
}
|
|
184
|
+
_optionalChain([onCopy, 'optionalCall', _8 => _8(value, isSuccess)]);
|
|
185
|
+
if (!isSuccess) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (resetTimerRef.current) {
|
|
189
|
+
clearTimeout(resetTimerRef.current);
|
|
190
|
+
}
|
|
191
|
+
resetTimerRef.current = setTimeout(() => {
|
|
192
|
+
setIsCopied(false);
|
|
193
|
+
}, copyResetDelay);
|
|
194
|
+
}, [copyResetDelay, isDisabled, onCopy, value]);
|
|
195
|
+
return /* @__PURE__ */ _react2.default.createElement(
|
|
196
|
+
_reactnative.View,
|
|
197
|
+
{
|
|
198
|
+
style: [
|
|
199
|
+
styles.container,
|
|
200
|
+
!fullWidth && styles.noFullWidth,
|
|
201
|
+
isDisabled && styles.disabled,
|
|
202
|
+
_optionalChain([customAppearance, 'optionalAccess', _9 => _9.container])
|
|
203
|
+
]
|
|
204
|
+
},
|
|
205
|
+
/* @__PURE__ */ _react2.default.createElement(
|
|
206
|
+
_reactnative.View,
|
|
207
|
+
{
|
|
208
|
+
style: [
|
|
209
|
+
styles.snippet,
|
|
210
|
+
radiusStyles,
|
|
211
|
+
{
|
|
212
|
+
backgroundColor: colors.containerBackground,
|
|
213
|
+
borderColor: colors.containerBorder
|
|
214
|
+
}
|
|
215
|
+
]
|
|
216
|
+
},
|
|
217
|
+
/* @__PURE__ */ _react2.default.createElement(
|
|
218
|
+
_reactnative.Pressable,
|
|
219
|
+
{
|
|
220
|
+
onPress: handleCopy,
|
|
221
|
+
accessibilityRole: "button",
|
|
222
|
+
accessibilityLabel: isCopied ? copiedLabel : copyLabel,
|
|
223
|
+
disabled: isDisabled,
|
|
224
|
+
style: [
|
|
225
|
+
styles.copyButton,
|
|
226
|
+
radiusStyles,
|
|
227
|
+
isTop ? styles.top : styles.bottom,
|
|
228
|
+
isLeft ? styles.left : styles.right,
|
|
229
|
+
{
|
|
230
|
+
backgroundColor: colors.copyButtonBackground,
|
|
231
|
+
borderColor: colors.copyButtonBorder
|
|
232
|
+
},
|
|
233
|
+
_optionalChain([customAppearance, 'optionalAccess', _10 => _10.copyButton])
|
|
234
|
+
]
|
|
235
|
+
},
|
|
236
|
+
/* @__PURE__ */ _react2.default.createElement(_icons.CopyIcon, { size: 14, color: colors.copyButtonText }),
|
|
237
|
+
/* @__PURE__ */ _react2.default.createElement(
|
|
238
|
+
_reactnative.Text,
|
|
239
|
+
{
|
|
240
|
+
style: [
|
|
241
|
+
styles.copyButtonText,
|
|
242
|
+
{ color: colors.copyButtonText },
|
|
243
|
+
_optionalChain([customAppearance, 'optionalAccess', _11 => _11.copyButtonText])
|
|
244
|
+
]
|
|
245
|
+
},
|
|
246
|
+
isCopied ? copiedLabel : copyLabel
|
|
247
|
+
)
|
|
248
|
+
),
|
|
249
|
+
/* @__PURE__ */ _react2.default.createElement(
|
|
250
|
+
_reactnative.View,
|
|
251
|
+
{
|
|
252
|
+
style: [
|
|
253
|
+
styles.content,
|
|
254
|
+
isTop ? styles.topInset : styles.bottomInset,
|
|
255
|
+
_optionalChain([customAppearance, 'optionalAccess', _12 => _12.content])
|
|
256
|
+
]
|
|
257
|
+
},
|
|
258
|
+
/* @__PURE__ */ _react2.default.createElement(
|
|
259
|
+
_reactnative.Text,
|
|
260
|
+
{
|
|
261
|
+
selectable: true,
|
|
262
|
+
numberOfLines,
|
|
263
|
+
style: [
|
|
264
|
+
styles.text,
|
|
265
|
+
{
|
|
266
|
+
color: colors.text,
|
|
267
|
+
fontSize,
|
|
268
|
+
lineHeight: Math.round(fontSize * 1.45),
|
|
269
|
+
fontWeight
|
|
270
|
+
},
|
|
271
|
+
_optionalChain([customAppearance, 'optionalAccess', _13 => _13.text])
|
|
272
|
+
]
|
|
273
|
+
},
|
|
274
|
+
value
|
|
275
|
+
)
|
|
276
|
+
)
|
|
277
|
+
)
|
|
278
|
+
);
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
exports.Snippet = Snippet;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TextStyle, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import { T as ThemeColor, R as Radius } from '../index-DyU3sW3_.cjs';
|
|
4
|
+
|
|
5
|
+
type SnippetVariant = 'outlined' | 'flat' | 'light';
|
|
6
|
+
type CopyButtonPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
7
|
+
type SnippetCustomAppearance = {
|
|
8
|
+
container?: StyleProp<ViewStyle>;
|
|
9
|
+
content?: StyleProp<ViewStyle>;
|
|
10
|
+
text?: StyleProp<TextStyle>;
|
|
11
|
+
copyButton?: StyleProp<ViewStyle>;
|
|
12
|
+
copyButtonText?: StyleProp<TextStyle>;
|
|
13
|
+
};
|
|
14
|
+
type SnippetProps = {
|
|
15
|
+
/**
|
|
16
|
+
* Text content displayed in the snippet.
|
|
17
|
+
*/
|
|
18
|
+
value: string;
|
|
19
|
+
/**
|
|
20
|
+
* Theme color used for variant styling.
|
|
21
|
+
* @default 'primary'
|
|
22
|
+
*/
|
|
23
|
+
themeColor?: ThemeColor;
|
|
24
|
+
/**
|
|
25
|
+
* Visual style variant.
|
|
26
|
+
* @default 'outlined'
|
|
27
|
+
*/
|
|
28
|
+
variant?: SnippetVariant;
|
|
29
|
+
/**
|
|
30
|
+
* Snippet border radius.
|
|
31
|
+
* @default 'md'
|
|
32
|
+
*/
|
|
33
|
+
radius?: Radius;
|
|
34
|
+
/**
|
|
35
|
+
* Position of the copy button in the snippet container.
|
|
36
|
+
* @default 'top-right'
|
|
37
|
+
*/
|
|
38
|
+
copyButtonPosition?: CopyButtonPosition;
|
|
39
|
+
/**
|
|
40
|
+
* Copy button label.
|
|
41
|
+
* @default 'Copy'
|
|
42
|
+
*/
|
|
43
|
+
copyLabel?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Label shown after a successful copy action.
|
|
46
|
+
* @default 'Copied'
|
|
47
|
+
*/
|
|
48
|
+
copiedLabel?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Delay in milliseconds before reverting copied state.
|
|
51
|
+
* @default 1500
|
|
52
|
+
*/
|
|
53
|
+
copyResetDelay?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Whether the snippet should occupy all available width.
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
fullWidth?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Whether the snippet is disabled.
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
isDisabled?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Number of lines to clamp the snippet text.
|
|
66
|
+
*/
|
|
67
|
+
numberOfLines?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Font size for snippet text.
|
|
70
|
+
* @default 14
|
|
71
|
+
*/
|
|
72
|
+
fontSize?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Font weight for snippet text.
|
|
75
|
+
* @default '400'
|
|
76
|
+
*/
|
|
77
|
+
fontWeight?: TextStyle['fontWeight'];
|
|
78
|
+
/**
|
|
79
|
+
* Callback fired after copy action.
|
|
80
|
+
*/
|
|
81
|
+
onCopy?: (value: string, isSuccess: boolean) => void;
|
|
82
|
+
/**
|
|
83
|
+
* Optional custom styles for snippet parts.
|
|
84
|
+
*/
|
|
85
|
+
customAppearance?: SnippetCustomAppearance;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
declare const Snippet: React.FC<SnippetProps>;
|
|
89
|
+
|
|
90
|
+
export { type CopyButtonPosition, Snippet, type SnippetCustomAppearance, type SnippetProps, type SnippetVariant };
|