@onlynative/components 0.1.0-alpha.3 → 0.1.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/appbar/index.js +54 -122
- package/dist/button/index.js +31 -120
- package/dist/card/index.js +20 -89
- package/dist/checkbox/index.js +10 -75
- package/dist/chip/index.js +29 -118
- package/dist/icon-button/index.js +32 -97
- package/dist/index.d.ts +1 -0
- package/dist/index.js +461 -474
- package/dist/keyboard-avoiding-wrapper/index.d.ts +36 -0
- package/dist/keyboard-avoiding-wrapper/index.js +98 -0
- package/dist/list/index.js +5 -50
- package/dist/radio/index.js +8 -35
- package/dist/switch/index.js +12 -77
- package/dist/text-field/index.js +25 -78
- package/package.json +13 -3
- package/src/appbar/AppBar.tsx +1 -1
- package/src/button/Button.tsx +1 -1
- package/src/button/styles.ts +1 -2
- package/src/card/styles.ts +1 -2
- package/src/checkbox/Checkbox.tsx +1 -1
- package/src/checkbox/styles.ts +1 -1
- package/src/chip/Chip.tsx +1 -1
- package/src/chip/styles.ts +1 -2
- package/src/icon-button/IconButton.tsx +5 -2
- package/src/icon-button/styles.ts +1 -1
- package/src/index.ts +3 -0
- package/src/keyboard-avoiding-wrapper/KeyboardAvoidingWrapper.tsx +69 -0
- package/src/keyboard-avoiding-wrapper/index.ts +2 -0
- package/src/keyboard-avoiding-wrapper/styles.ts +10 -0
- package/src/keyboard-avoiding-wrapper/types.ts +37 -0
- package/src/list/styles.ts +1 -1
- package/src/radio/styles.ts +1 -1
- package/src/switch/Switch.tsx +1 -1
- package/src/switch/styles.ts +1 -1
- package/src/text-field/TextField.tsx +1 -1
- package/src/text-field/styles.ts +1 -2
- package/src/typography/Typography.tsx +2 -0
- package/src/test-utils/render-with-theme.tsx +0 -13
- package/src/utils/color.ts +0 -64
- package/src/utils/elevation.ts +0 -33
- package/src/utils/icon.ts +0 -30
- package/src/utils/rtl.ts +0 -19
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { PropsWithChildren } from 'react';
|
|
3
|
+
import { KeyboardAvoidingViewProps, ScrollViewProps, KeyboardEvent, StyleProp, ViewStyle } from 'react-native';
|
|
4
|
+
|
|
5
|
+
interface KeyboardAvoidingWrapperProps extends PropsWithChildren {
|
|
6
|
+
/**
|
|
7
|
+
* Keyboard avoidance strategy.
|
|
8
|
+
* @default 'padding'
|
|
9
|
+
*/
|
|
10
|
+
behavior?: KeyboardAvoidingViewProps['behavior'];
|
|
11
|
+
/**
|
|
12
|
+
* Extra offset added to the keyboard height calculation.
|
|
13
|
+
* Useful for accounting for headers or tab bars.
|
|
14
|
+
* @default 0
|
|
15
|
+
*/
|
|
16
|
+
keyboardVerticalOffset?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Enable or disable the keyboard avoiding behavior.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
enabled?: boolean;
|
|
22
|
+
/** Props forwarded to the inner `ScrollView`. */
|
|
23
|
+
scrollViewProps?: ScrollViewProps;
|
|
24
|
+
/** Called when the keyboard is about to show (iOS) or has shown (Android). */
|
|
25
|
+
onKeyboardShow?: (event: KeyboardEvent) => void;
|
|
26
|
+
/** Called when the keyboard is about to hide (iOS) or has hidden (Android). */
|
|
27
|
+
onKeyboardHide?: (event: KeyboardEvent) => void;
|
|
28
|
+
/** Style applied to the outer `KeyboardAvoidingView`. */
|
|
29
|
+
style?: StyleProp<ViewStyle>;
|
|
30
|
+
/** Style applied to the inner `ScrollView` contentContainerStyle. */
|
|
31
|
+
contentContainerStyle?: StyleProp<ViewStyle>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare function KeyboardAvoidingWrapper({ children, behavior, keyboardVerticalOffset, enabled, scrollViewProps, onKeyboardShow, onKeyboardHide, style, contentContainerStyle, }: KeyboardAvoidingWrapperProps): react_jsx_runtime.JSX.Element;
|
|
35
|
+
|
|
36
|
+
export { KeyboardAvoidingWrapper, type KeyboardAvoidingWrapperProps };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/keyboard-avoiding-wrapper/index.ts
|
|
21
|
+
var keyboard_avoiding_wrapper_exports = {};
|
|
22
|
+
__export(keyboard_avoiding_wrapper_exports, {
|
|
23
|
+
KeyboardAvoidingWrapper: () => KeyboardAvoidingWrapper
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(keyboard_avoiding_wrapper_exports);
|
|
26
|
+
|
|
27
|
+
// src/keyboard-avoiding-wrapper/KeyboardAvoidingWrapper.tsx
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_react_native2 = require("react-native");
|
|
30
|
+
|
|
31
|
+
// src/keyboard-avoiding-wrapper/styles.ts
|
|
32
|
+
var import_react_native = require("react-native");
|
|
33
|
+
var styles = import_react_native.StyleSheet.create({
|
|
34
|
+
root: {
|
|
35
|
+
flex: 1
|
|
36
|
+
},
|
|
37
|
+
container: {
|
|
38
|
+
flexGrow: 1
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// src/keyboard-avoiding-wrapper/KeyboardAvoidingWrapper.tsx
|
|
43
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
44
|
+
var isIOS = import_react_native2.Platform.OS === "ios";
|
|
45
|
+
function KeyboardAvoidingWrapper({
|
|
46
|
+
children,
|
|
47
|
+
behavior = "padding",
|
|
48
|
+
keyboardVerticalOffset = 0,
|
|
49
|
+
enabled = true,
|
|
50
|
+
scrollViewProps,
|
|
51
|
+
onKeyboardShow,
|
|
52
|
+
onKeyboardHide,
|
|
53
|
+
style,
|
|
54
|
+
contentContainerStyle
|
|
55
|
+
}) {
|
|
56
|
+
(0, import_react.useEffect)(() => {
|
|
57
|
+
const subscriptions = [];
|
|
58
|
+
if (onKeyboardShow) {
|
|
59
|
+
const showEvent = isIOS ? "keyboardWillShow" : "keyboardDidShow";
|
|
60
|
+
subscriptions.push(
|
|
61
|
+
import_react_native2.Keyboard.addListener(showEvent, onKeyboardShow)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
if (onKeyboardHide) {
|
|
65
|
+
const hideEvent = isIOS ? "keyboardWillHide" : "keyboardDidHide";
|
|
66
|
+
subscriptions.push(
|
|
67
|
+
import_react_native2.Keyboard.addListener(hideEvent, onKeyboardHide)
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return () => {
|
|
71
|
+
subscriptions.forEach((sub) => sub.remove());
|
|
72
|
+
};
|
|
73
|
+
}, [onKeyboardShow, onKeyboardHide]);
|
|
74
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
75
|
+
import_react_native2.KeyboardAvoidingView,
|
|
76
|
+
{
|
|
77
|
+
style: [styles.root, style],
|
|
78
|
+
behavior,
|
|
79
|
+
keyboardVerticalOffset,
|
|
80
|
+
enabled: !isIOS && enabled,
|
|
81
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
82
|
+
import_react_native2.ScrollView,
|
|
83
|
+
{
|
|
84
|
+
automaticallyAdjustKeyboardInsets: isIOS && enabled,
|
|
85
|
+
keyboardShouldPersistTaps: "handled",
|
|
86
|
+
showsVerticalScrollIndicator: false,
|
|
87
|
+
...scrollViewProps,
|
|
88
|
+
contentContainerStyle: [styles.container, contentContainerStyle],
|
|
89
|
+
children
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
KeyboardAvoidingWrapper
|
|
98
|
+
});
|
package/dist/list/index.js
CHANGED
|
@@ -33,52 +33,7 @@ var import_core = require("@onlynative/core");
|
|
|
33
33
|
|
|
34
34
|
// src/list/styles.ts
|
|
35
35
|
var import_react_native = require("react-native");
|
|
36
|
-
|
|
37
|
-
// src/utils/color.ts
|
|
38
|
-
function parseHexColor(color) {
|
|
39
|
-
const normalized = color.replace("#", "");
|
|
40
|
-
if (normalized.length !== 6 && normalized.length !== 8) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
const r = Number.parseInt(normalized.slice(0, 2), 16);
|
|
44
|
-
const g = Number.parseInt(normalized.slice(2, 4), 16);
|
|
45
|
-
const b = Number.parseInt(normalized.slice(4, 6), 16);
|
|
46
|
-
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
return { r, g, b };
|
|
50
|
-
}
|
|
51
|
-
function clampAlpha(alpha) {
|
|
52
|
-
return Math.max(0, Math.min(1, alpha));
|
|
53
|
-
}
|
|
54
|
-
function alphaColor(color, alpha) {
|
|
55
|
-
const channels = parseHexColor(color);
|
|
56
|
-
const boundedAlpha = clampAlpha(alpha);
|
|
57
|
-
if (!channels) {
|
|
58
|
-
return color;
|
|
59
|
-
}
|
|
60
|
-
return `rgba(${channels.r}, ${channels.g}, ${channels.b}, ${boundedAlpha})`;
|
|
61
|
-
}
|
|
62
|
-
function blendColor(base, overlay, overlayAlpha) {
|
|
63
|
-
const baseChannels = parseHexColor(base);
|
|
64
|
-
const overlayChannels = parseHexColor(overlay);
|
|
65
|
-
const boundedAlpha = clampAlpha(overlayAlpha);
|
|
66
|
-
if (!baseChannels || !overlayChannels) {
|
|
67
|
-
return alphaColor(overlay, boundedAlpha);
|
|
68
|
-
}
|
|
69
|
-
const r = Math.round(
|
|
70
|
-
(1 - boundedAlpha) * baseChannels.r + boundedAlpha * overlayChannels.r
|
|
71
|
-
);
|
|
72
|
-
const g = Math.round(
|
|
73
|
-
(1 - boundedAlpha) * baseChannels.g + boundedAlpha * overlayChannels.g
|
|
74
|
-
);
|
|
75
|
-
const b = Math.round(
|
|
76
|
-
(1 - boundedAlpha) * baseChannels.b + boundedAlpha * overlayChannels.b
|
|
77
|
-
);
|
|
78
|
-
return `rgb(${r}, ${g}, ${b})`;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// src/list/styles.ts
|
|
36
|
+
var import_utils = require("@onlynative/utils");
|
|
82
37
|
var ITEM_PADDING_VERTICAL = 12;
|
|
83
38
|
var INSET_START = 56;
|
|
84
39
|
var MIN_HEIGHT = {
|
|
@@ -98,12 +53,12 @@ function getItemColors(theme, containerColor) {
|
|
|
98
53
|
if (containerColor) {
|
|
99
54
|
return {
|
|
100
55
|
backgroundColor: containerColor,
|
|
101
|
-
hoveredBackgroundColor: blendColor(
|
|
56
|
+
hoveredBackgroundColor: (0, import_utils.blendColor)(
|
|
102
57
|
containerColor,
|
|
103
58
|
theme.colors.onSurface,
|
|
104
59
|
theme.stateLayer.hoveredOpacity
|
|
105
60
|
),
|
|
106
|
-
pressedBackgroundColor: blendColor(
|
|
61
|
+
pressedBackgroundColor: (0, import_utils.blendColor)(
|
|
107
62
|
containerColor,
|
|
108
63
|
theme.colors.onSurface,
|
|
109
64
|
theme.stateLayer.pressedOpacity
|
|
@@ -112,11 +67,11 @@ function getItemColors(theme, containerColor) {
|
|
|
112
67
|
}
|
|
113
68
|
return {
|
|
114
69
|
backgroundColor: base,
|
|
115
|
-
hoveredBackgroundColor: alphaColor(
|
|
70
|
+
hoveredBackgroundColor: (0, import_utils.alphaColor)(
|
|
116
71
|
theme.colors.onSurface,
|
|
117
72
|
theme.stateLayer.hoveredOpacity
|
|
118
73
|
),
|
|
119
|
-
pressedBackgroundColor: alphaColor(
|
|
74
|
+
pressedBackgroundColor: (0, import_utils.alphaColor)(
|
|
120
75
|
theme.colors.onSurface,
|
|
121
76
|
theme.stateLayer.pressedOpacity
|
|
122
77
|
)
|
package/dist/radio/index.js
CHANGED
|
@@ -31,45 +31,18 @@ var import_core = require("@onlynative/core");
|
|
|
31
31
|
|
|
32
32
|
// src/radio/styles.ts
|
|
33
33
|
var import_react_native = require("react-native");
|
|
34
|
-
|
|
35
|
-
// src/utils/color.ts
|
|
36
|
-
function parseHexColor(color) {
|
|
37
|
-
const normalized = color.replace("#", "");
|
|
38
|
-
if (normalized.length !== 6 && normalized.length !== 8) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
const r = Number.parseInt(normalized.slice(0, 2), 16);
|
|
42
|
-
const g = Number.parseInt(normalized.slice(2, 4), 16);
|
|
43
|
-
const b = Number.parseInt(normalized.slice(4, 6), 16);
|
|
44
|
-
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
return { r, g, b };
|
|
48
|
-
}
|
|
49
|
-
function clampAlpha(alpha) {
|
|
50
|
-
return Math.max(0, Math.min(1, alpha));
|
|
51
|
-
}
|
|
52
|
-
function alphaColor(color, alpha) {
|
|
53
|
-
const channels = parseHexColor(color);
|
|
54
|
-
const boundedAlpha = clampAlpha(alpha);
|
|
55
|
-
if (!channels) {
|
|
56
|
-
return color;
|
|
57
|
-
}
|
|
58
|
-
return `rgba(${channels.r}, ${channels.g}, ${channels.b}, ${boundedAlpha})`;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// src/radio/styles.ts
|
|
34
|
+
var import_utils = require("@onlynative/utils");
|
|
62
35
|
function getColors(theme, selected) {
|
|
63
|
-
const disabledOnSurface38 = alphaColor(theme.colors.onSurface, 0.38);
|
|
36
|
+
const disabledOnSurface38 = (0, import_utils.alphaColor)(theme.colors.onSurface, 0.38);
|
|
64
37
|
if (selected) {
|
|
65
38
|
return {
|
|
66
39
|
borderColor: theme.colors.primary,
|
|
67
40
|
dotColor: theme.colors.primary,
|
|
68
|
-
hoveredBackgroundColor: alphaColor(
|
|
41
|
+
hoveredBackgroundColor: (0, import_utils.alphaColor)(
|
|
69
42
|
theme.colors.primary,
|
|
70
43
|
theme.stateLayer.hoveredOpacity
|
|
71
44
|
),
|
|
72
|
-
pressedBackgroundColor: alphaColor(
|
|
45
|
+
pressedBackgroundColor: (0, import_utils.alphaColor)(
|
|
73
46
|
theme.colors.primary,
|
|
74
47
|
theme.stateLayer.pressedOpacity
|
|
75
48
|
),
|
|
@@ -80,11 +53,11 @@ function getColors(theme, selected) {
|
|
|
80
53
|
return {
|
|
81
54
|
borderColor: theme.colors.onSurfaceVariant,
|
|
82
55
|
dotColor: "transparent",
|
|
83
|
-
hoveredBackgroundColor: alphaColor(
|
|
56
|
+
hoveredBackgroundColor: (0, import_utils.alphaColor)(
|
|
84
57
|
theme.colors.onSurface,
|
|
85
58
|
theme.stateLayer.hoveredOpacity
|
|
86
59
|
),
|
|
87
|
-
pressedBackgroundColor: alphaColor(
|
|
60
|
+
pressedBackgroundColor: (0, import_utils.alphaColor)(
|
|
88
61
|
theme.colors.onSurface,
|
|
89
62
|
theme.stateLayer.pressedOpacity
|
|
90
63
|
),
|
|
@@ -98,11 +71,11 @@ function applyColorOverrides(theme, colors, containerColor, contentColor) {
|
|
|
98
71
|
if (containerColor) {
|
|
99
72
|
result.borderColor = containerColor;
|
|
100
73
|
result.dotColor = containerColor;
|
|
101
|
-
result.hoveredBackgroundColor = alphaColor(
|
|
74
|
+
result.hoveredBackgroundColor = (0, import_utils.alphaColor)(
|
|
102
75
|
containerColor,
|
|
103
76
|
theme.stateLayer.hoveredOpacity
|
|
104
77
|
);
|
|
105
|
-
result.pressedBackgroundColor = alphaColor(
|
|
78
|
+
result.pressedBackgroundColor = (0, import_utils.alphaColor)(
|
|
106
79
|
containerColor,
|
|
107
80
|
theme.stateLayer.pressedOpacity
|
|
108
81
|
);
|
package/dist/switch/index.js
CHANGED
|
@@ -28,90 +28,25 @@ module.exports = __toCommonJS(switch_exports);
|
|
|
28
28
|
var import_react = require("react");
|
|
29
29
|
var import_react_native2 = require("react-native");
|
|
30
30
|
var import_core = require("@onlynative/core");
|
|
31
|
-
|
|
32
|
-
// src/utils/icon.ts
|
|
33
|
-
var _MCIcons = null;
|
|
34
|
-
var _resolved = false;
|
|
35
|
-
function getMaterialCommunityIcons() {
|
|
36
|
-
if (!_resolved) {
|
|
37
|
-
_resolved = true;
|
|
38
|
-
try {
|
|
39
|
-
const mod = require("@expo/vector-icons/MaterialCommunityIcons");
|
|
40
|
-
_MCIcons = mod.default || mod;
|
|
41
|
-
} catch {
|
|
42
|
-
_MCIcons = null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (!_MCIcons) {
|
|
46
|
-
throw new Error(
|
|
47
|
-
"@expo/vector-icons is required for icon support. Install it with: npx expo install @expo/vector-icons"
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
return _MCIcons;
|
|
51
|
-
}
|
|
31
|
+
var import_utils2 = require("@onlynative/utils");
|
|
52
32
|
|
|
53
33
|
// src/switch/styles.ts
|
|
54
34
|
var import_react_native = require("react-native");
|
|
55
|
-
|
|
56
|
-
// src/utils/color.ts
|
|
57
|
-
function parseHexColor(color) {
|
|
58
|
-
const normalized = color.replace("#", "");
|
|
59
|
-
if (normalized.length !== 6 && normalized.length !== 8) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
const r = Number.parseInt(normalized.slice(0, 2), 16);
|
|
63
|
-
const g = Number.parseInt(normalized.slice(2, 4), 16);
|
|
64
|
-
const b = Number.parseInt(normalized.slice(4, 6), 16);
|
|
65
|
-
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
return { r, g, b };
|
|
69
|
-
}
|
|
70
|
-
function clampAlpha(alpha) {
|
|
71
|
-
return Math.max(0, Math.min(1, alpha));
|
|
72
|
-
}
|
|
73
|
-
function alphaColor(color, alpha) {
|
|
74
|
-
const channels = parseHexColor(color);
|
|
75
|
-
const boundedAlpha = clampAlpha(alpha);
|
|
76
|
-
if (!channels) {
|
|
77
|
-
return color;
|
|
78
|
-
}
|
|
79
|
-
return `rgba(${channels.r}, ${channels.g}, ${channels.b}, ${boundedAlpha})`;
|
|
80
|
-
}
|
|
81
|
-
function blendColor(base, overlay, overlayAlpha) {
|
|
82
|
-
const baseChannels = parseHexColor(base);
|
|
83
|
-
const overlayChannels = parseHexColor(overlay);
|
|
84
|
-
const boundedAlpha = clampAlpha(overlayAlpha);
|
|
85
|
-
if (!baseChannels || !overlayChannels) {
|
|
86
|
-
return alphaColor(overlay, boundedAlpha);
|
|
87
|
-
}
|
|
88
|
-
const r = Math.round(
|
|
89
|
-
(1 - boundedAlpha) * baseChannels.r + boundedAlpha * overlayChannels.r
|
|
90
|
-
);
|
|
91
|
-
const g = Math.round(
|
|
92
|
-
(1 - boundedAlpha) * baseChannels.g + boundedAlpha * overlayChannels.g
|
|
93
|
-
);
|
|
94
|
-
const b = Math.round(
|
|
95
|
-
(1 - boundedAlpha) * baseChannels.b + boundedAlpha * overlayChannels.b
|
|
96
|
-
);
|
|
97
|
-
return `rgb(${r}, ${g}, ${b})`;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// src/switch/styles.ts
|
|
35
|
+
var import_utils = require("@onlynative/utils");
|
|
101
36
|
function getColors(theme, selected) {
|
|
102
|
-
const disabledOnSurface12 = alphaColor(theme.colors.onSurface, 0.12);
|
|
103
|
-
const disabledOnSurface38 = alphaColor(theme.colors.onSurface, 0.38);
|
|
37
|
+
const disabledOnSurface12 = (0, import_utils.alphaColor)(theme.colors.onSurface, 0.12);
|
|
38
|
+
const disabledOnSurface38 = (0, import_utils.alphaColor)(theme.colors.onSurface, 0.38);
|
|
104
39
|
if (selected) {
|
|
105
40
|
return {
|
|
106
41
|
trackColor: theme.colors.primary,
|
|
107
42
|
thumbColor: theme.colors.onPrimary,
|
|
108
43
|
iconColor: theme.colors.onPrimaryContainer,
|
|
109
|
-
hoveredTrackColor: blendColor(
|
|
44
|
+
hoveredTrackColor: (0, import_utils.blendColor)(
|
|
110
45
|
theme.colors.primary,
|
|
111
46
|
theme.colors.onPrimary,
|
|
112
47
|
theme.stateLayer.hoveredOpacity
|
|
113
48
|
),
|
|
114
|
-
pressedTrackColor: blendColor(
|
|
49
|
+
pressedTrackColor: (0, import_utils.blendColor)(
|
|
115
50
|
theme.colors.primary,
|
|
116
51
|
theme.colors.onPrimary,
|
|
117
52
|
theme.stateLayer.pressedOpacity
|
|
@@ -128,12 +63,12 @@ function getColors(theme, selected) {
|
|
|
128
63
|
trackColor: theme.colors.surfaceContainerHighest,
|
|
129
64
|
thumbColor: theme.colors.outline,
|
|
130
65
|
iconColor: theme.colors.surfaceContainerHighest,
|
|
131
|
-
hoveredTrackColor: blendColor(
|
|
66
|
+
hoveredTrackColor: (0, import_utils.blendColor)(
|
|
132
67
|
theme.colors.surfaceContainerHighest,
|
|
133
68
|
theme.colors.onSurface,
|
|
134
69
|
theme.stateLayer.hoveredOpacity
|
|
135
70
|
),
|
|
136
|
-
pressedTrackColor: blendColor(
|
|
71
|
+
pressedTrackColor: (0, import_utils.blendColor)(
|
|
137
72
|
theme.colors.surfaceContainerHighest,
|
|
138
73
|
theme.colors.onSurface,
|
|
139
74
|
theme.stateLayer.pressedOpacity
|
|
@@ -157,12 +92,12 @@ function applyColorOverrides(theme, colors, containerColor, contentColor) {
|
|
|
157
92
|
const overlay = contentColor != null ? contentColor : colors.thumbColor;
|
|
158
93
|
result.trackColor = containerColor;
|
|
159
94
|
result.borderColor = containerColor;
|
|
160
|
-
result.hoveredTrackColor = blendColor(
|
|
95
|
+
result.hoveredTrackColor = (0, import_utils.blendColor)(
|
|
161
96
|
containerColor,
|
|
162
97
|
overlay,
|
|
163
98
|
theme.stateLayer.hoveredOpacity
|
|
164
99
|
);
|
|
165
|
-
result.pressedTrackColor = blendColor(
|
|
100
|
+
result.pressedTrackColor = (0, import_utils.blendColor)(
|
|
166
101
|
containerColor,
|
|
167
102
|
overlay,
|
|
168
103
|
theme.stateLayer.pressedOpacity
|
|
@@ -224,7 +159,7 @@ function createStyles(theme, selected, hasIcon, containerColor, contentColor) {
|
|
|
224
159
|
color: colors.iconColor
|
|
225
160
|
},
|
|
226
161
|
disabledIconColor: {
|
|
227
|
-
color: alphaColor(theme.colors.onSurface, 0.38)
|
|
162
|
+
color: (0, import_utils.alphaColor)(theme.colors.onSurface, 0.38)
|
|
228
163
|
}
|
|
229
164
|
});
|
|
230
165
|
}
|
|
@@ -281,7 +216,7 @@ function Switch({
|
|
|
281
216
|
}
|
|
282
217
|
};
|
|
283
218
|
const iconName = isSelected ? selectedIcon : unselectedIcon;
|
|
284
|
-
const MaterialCommunityIcons = iconName ? getMaterialCommunityIcons() : null;
|
|
219
|
+
const MaterialCommunityIcons = iconName ? (0, import_utils2.getMaterialCommunityIcons)() : null;
|
|
285
220
|
const iconSize = 16;
|
|
286
221
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
287
222
|
import_react_native2.Pressable,
|
package/dist/text-field/index.js
CHANGED
|
@@ -26,66 +26,13 @@ module.exports = __toCommonJS(text_field_exports);
|
|
|
26
26
|
|
|
27
27
|
// src/text-field/TextField.tsx
|
|
28
28
|
var import_react = require("react");
|
|
29
|
-
var
|
|
29
|
+
var import_react_native2 = require("react-native");
|
|
30
30
|
var import_core = require("@onlynative/core");
|
|
31
|
-
|
|
32
|
-
// src/utils/icon.ts
|
|
33
|
-
var _MCIcons = null;
|
|
34
|
-
var _resolved = false;
|
|
35
|
-
function getMaterialCommunityIcons() {
|
|
36
|
-
if (!_resolved) {
|
|
37
|
-
_resolved = true;
|
|
38
|
-
try {
|
|
39
|
-
const mod = require("@expo/vector-icons/MaterialCommunityIcons");
|
|
40
|
-
_MCIcons = mod.default || mod;
|
|
41
|
-
} catch {
|
|
42
|
-
_MCIcons = null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (!_MCIcons) {
|
|
46
|
-
throw new Error(
|
|
47
|
-
"@expo/vector-icons is required for icon support. Install it with: npx expo install @expo/vector-icons"
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
return _MCIcons;
|
|
51
|
-
}
|
|
31
|
+
var import_utils2 = require("@onlynative/utils");
|
|
52
32
|
|
|
53
33
|
// src/text-field/styles.ts
|
|
54
|
-
var import_react_native2 = require("react-native");
|
|
55
|
-
|
|
56
|
-
// src/utils/color.ts
|
|
57
|
-
function parseHexColor(color) {
|
|
58
|
-
const normalized = color.replace("#", "");
|
|
59
|
-
if (normalized.length !== 6 && normalized.length !== 8) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
const r = Number.parseInt(normalized.slice(0, 2), 16);
|
|
63
|
-
const g = Number.parseInt(normalized.slice(2, 4), 16);
|
|
64
|
-
const b = Number.parseInt(normalized.slice(4, 6), 16);
|
|
65
|
-
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
return { r, g, b };
|
|
69
|
-
}
|
|
70
|
-
function clampAlpha(alpha) {
|
|
71
|
-
return Math.max(0, Math.min(1, alpha));
|
|
72
|
-
}
|
|
73
|
-
function alphaColor(color, alpha) {
|
|
74
|
-
const channels = parseHexColor(color);
|
|
75
|
-
const boundedAlpha = clampAlpha(alpha);
|
|
76
|
-
if (!channels) {
|
|
77
|
-
return color;
|
|
78
|
-
}
|
|
79
|
-
return `rgba(${channels.r}, ${channels.g}, ${channels.b}, ${boundedAlpha})`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// src/utils/rtl.ts
|
|
83
34
|
var import_react_native = require("react-native");
|
|
84
|
-
|
|
85
|
-
return import_react_native.I18nManager.isRTL ? `right ${vertical}` : `left ${vertical}`;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// src/text-field/styles.ts
|
|
35
|
+
var import_utils = require("@onlynative/utils");
|
|
89
36
|
var CONTAINER_HEIGHT = 56;
|
|
90
37
|
var ICON_SIZE = 24;
|
|
91
38
|
var LABEL_FLOATED_LINE_HEIGHT = 16;
|
|
@@ -110,15 +57,15 @@ function getVariantColors(theme, variant) {
|
|
|
110
57
|
focusedLabelColor: theme.colors.primary,
|
|
111
58
|
errorLabelColor: theme.colors.error,
|
|
112
59
|
textColor: theme.colors.onSurface,
|
|
113
|
-
disabledTextColor: alphaColor(theme.colors.onSurface, disabledOpacity),
|
|
114
|
-
disabledLabelColor: alphaColor(theme.colors.onSurface, disabledOpacity),
|
|
115
|
-
disabledBorderColor: alphaColor(theme.colors.onSurface, 0.12),
|
|
60
|
+
disabledTextColor: (0, import_utils.alphaColor)(theme.colors.onSurface, disabledOpacity),
|
|
61
|
+
disabledLabelColor: (0, import_utils.alphaColor)(theme.colors.onSurface, disabledOpacity),
|
|
62
|
+
disabledBorderColor: (0, import_utils.alphaColor)(theme.colors.onSurface, 0.12),
|
|
116
63
|
placeholderColor: theme.colors.onSurfaceVariant,
|
|
117
64
|
supportingTextColor: theme.colors.onSurfaceVariant,
|
|
118
65
|
errorSupportingTextColor: theme.colors.error,
|
|
119
66
|
iconColor: theme.colors.onSurfaceVariant,
|
|
120
67
|
errorIconColor: theme.colors.error,
|
|
121
|
-
disabledIconColor: alphaColor(theme.colors.onSurface, disabledOpacity)
|
|
68
|
+
disabledIconColor: (0, import_utils.alphaColor)(theme.colors.onSurface, disabledOpacity)
|
|
122
69
|
};
|
|
123
70
|
if (variant === "outlined") {
|
|
124
71
|
return {
|
|
@@ -133,7 +80,7 @@ function getVariantColors(theme, variant) {
|
|
|
133
80
|
...common,
|
|
134
81
|
backgroundColor: theme.colors.surfaceContainerHighest,
|
|
135
82
|
borderColor: theme.colors.onSurfaceVariant,
|
|
136
|
-
disabledBackgroundColor: alphaColor(theme.colors.onSurface, 0.04),
|
|
83
|
+
disabledBackgroundColor: (0, import_utils.alphaColor)(theme.colors.onSurface, 0.04),
|
|
137
84
|
labelColor: theme.colors.onSurfaceVariant
|
|
138
85
|
};
|
|
139
86
|
}
|
|
@@ -144,7 +91,7 @@ function createStyles(theme, variant) {
|
|
|
144
91
|
const isFilled = variant === "filled";
|
|
145
92
|
return {
|
|
146
93
|
colors,
|
|
147
|
-
styles:
|
|
94
|
+
styles: import_react_native.StyleSheet.create({
|
|
148
95
|
root: {
|
|
149
96
|
alignSelf: "stretch"
|
|
150
97
|
},
|
|
@@ -215,7 +162,7 @@ function createStyles(theme, variant) {
|
|
|
215
162
|
fontWeight: bodySmall.fontWeight,
|
|
216
163
|
letterSpacing: bodySmall.letterSpacing,
|
|
217
164
|
color: colors.labelColor,
|
|
218
|
-
transformOrigin: transformOrigin("top")
|
|
165
|
+
transformOrigin: (0, import_utils.transformOrigin)("top")
|
|
219
166
|
},
|
|
220
167
|
labelNotch: {
|
|
221
168
|
paddingHorizontal: 4
|
|
@@ -308,7 +255,7 @@ function TextField({
|
|
|
308
255
|
const isError = Boolean(error) || Boolean(errorText);
|
|
309
256
|
const isFilled = variant === "filled";
|
|
310
257
|
const hasLeadingIcon = Boolean(leadingIcon);
|
|
311
|
-
const MaterialCommunityIcons = leadingIcon || trailingIcon ? getMaterialCommunityIcons() : null;
|
|
258
|
+
const MaterialCommunityIcons = leadingIcon || trailingIcon ? (0, import_utils2.getMaterialCommunityIcons)() : null;
|
|
312
259
|
const { colors, styles } = (0, import_react.useMemo)(
|
|
313
260
|
() => createStyles(theme, variant),
|
|
314
261
|
[theme, variant]
|
|
@@ -321,13 +268,13 @@ function TextField({
|
|
|
321
268
|
const isControlled = value !== void 0;
|
|
322
269
|
const hasValue = isControlled ? value !== "" : internalHasText;
|
|
323
270
|
const isLabelFloated = isFocused || hasValue;
|
|
324
|
-
const labelAnimRef = (0, import_react.useRef)(new
|
|
271
|
+
const labelAnimRef = (0, import_react.useRef)(new import_react_native2.Animated.Value(isLabelFloated ? 1 : 0));
|
|
325
272
|
const labelAnim = labelAnimRef.current;
|
|
326
273
|
(0, import_react.useEffect)(() => {
|
|
327
|
-
|
|
274
|
+
import_react_native2.Animated.timing(labelAnim, {
|
|
328
275
|
toValue: isLabelFloated ? 1 : 0,
|
|
329
276
|
duration: 150,
|
|
330
|
-
useNativeDriver:
|
|
277
|
+
useNativeDriver: import_react_native2.Platform.OS !== "web"
|
|
331
278
|
}).start();
|
|
332
279
|
}, [isLabelFloated, labelAnim]);
|
|
333
280
|
const labelScale = (0, import_react.useMemo)(() => {
|
|
@@ -405,9 +352,9 @@ function TextField({
|
|
|
405
352
|
[styles, isFocused, isError, isDisabled]
|
|
406
353
|
);
|
|
407
354
|
const displaySupportingText = isError ? errorText : supportingText;
|
|
408
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
409
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
410
|
-
leadingIcon ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
355
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: [styles.root, style], children: [
|
|
356
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Pressable, { onPress: handleContainerPress, disabled: isDisabled, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: containerStyle, children: [
|
|
357
|
+
leadingIcon ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: styles.leadingIcon, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
411
358
|
MaterialCommunityIcons,
|
|
412
359
|
{
|
|
413
360
|
name: leadingIcon,
|
|
@@ -416,14 +363,14 @@ function TextField({
|
|
|
416
363
|
}
|
|
417
364
|
) }) : null,
|
|
418
365
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
419
|
-
|
|
366
|
+
import_react_native2.View,
|
|
420
367
|
{
|
|
421
368
|
style: [
|
|
422
369
|
styles.inputWrapper,
|
|
423
370
|
label ? styles.inputWrapperWithLabel : void 0
|
|
424
371
|
],
|
|
425
372
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
426
|
-
|
|
373
|
+
import_react_native2.TextInput,
|
|
427
374
|
{
|
|
428
375
|
ref: inputRef,
|
|
429
376
|
...textInputProps,
|
|
@@ -449,14 +396,14 @@ function TextField({
|
|
|
449
396
|
}
|
|
450
397
|
),
|
|
451
398
|
trailingIcon ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
452
|
-
|
|
399
|
+
import_react_native2.Pressable,
|
|
453
400
|
{
|
|
454
401
|
onPress: onTrailingIconPress,
|
|
455
402
|
disabled: isDisabled || !onTrailingIconPress,
|
|
456
403
|
accessibilityRole: "button",
|
|
457
404
|
hitSlop: 12,
|
|
458
405
|
style: styles.trailingIconPressable,
|
|
459
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
406
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: styles.trailingIcon, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
460
407
|
MaterialCommunityIcons,
|
|
461
408
|
{
|
|
462
409
|
name: trailingIcon,
|
|
@@ -467,7 +414,7 @@ function TextField({
|
|
|
467
414
|
}
|
|
468
415
|
) : null,
|
|
469
416
|
label ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
470
|
-
|
|
417
|
+
import_react_native2.Animated.Text,
|
|
471
418
|
{
|
|
472
419
|
numberOfLines: 1,
|
|
473
420
|
style: [
|
|
@@ -487,10 +434,10 @@ function TextField({
|
|
|
487
434
|
children: label
|
|
488
435
|
}
|
|
489
436
|
) : null,
|
|
490
|
-
isFilled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
437
|
+
isFilled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: indicatorStyle }) : null
|
|
491
438
|
] }) }),
|
|
492
|
-
displaySupportingText ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
493
|
-
|
|
439
|
+
displaySupportingText ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: styles.supportingTextRow, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
440
|
+
import_react_native2.Text,
|
|
494
441
|
{
|
|
495
442
|
style: [
|
|
496
443
|
styles.supportingText,
|