@onlynative/components 0.1.0-alpha.2 → 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 +75 -123
- package/dist/button/index.js +33 -111
- package/dist/card/index.js +20 -89
- package/dist/checkbox/index.js +11 -65
- package/dist/chip/index.js +33 -110
- package/dist/icon-button/index.js +33 -87
- package/dist/index.d.ts +1 -0
- package/dist/index.js +535 -517
- 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 +13 -67
- package/dist/text-field/index.js +27 -69
- package/dist/typography/index.js +9 -0
- package/package.json +13 -3
- package/src/appbar/AppBar.tsx +1 -1
- package/src/button/Button.tsx +4 -1
- package/src/button/styles.ts +1 -2
- package/src/card/styles.ts +1 -2
- package/src/checkbox/Checkbox.tsx +5 -1
- package/src/checkbox/styles.ts +1 -1
- package/src/chip/Chip.tsx +7 -1
- package/src/chip/styles.ts +1 -2
- package/src/icon-button/IconButton.tsx +6 -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 +4 -1
- package/src/switch/styles.ts +1 -1
- package/src/text-field/TextField.tsx +4 -1
- package/src/text-field/styles.ts +1 -2
- package/src/typography/Typography.tsx +15 -1
- 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/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
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/switch/index.ts
|
|
@@ -35,73 +25,28 @@ __export(switch_exports, {
|
|
|
35
25
|
module.exports = __toCommonJS(switch_exports);
|
|
36
26
|
|
|
37
27
|
// src/switch/Switch.tsx
|
|
38
|
-
var import_MaterialCommunityIcons = __toESM(require("@expo/vector-icons/MaterialCommunityIcons"));
|
|
39
28
|
var import_react = require("react");
|
|
40
29
|
var import_react_native2 = require("react-native");
|
|
41
30
|
var import_core = require("@onlynative/core");
|
|
31
|
+
var import_utils2 = require("@onlynative/utils");
|
|
42
32
|
|
|
43
33
|
// src/switch/styles.ts
|
|
44
34
|
var import_react_native = require("react-native");
|
|
45
|
-
|
|
46
|
-
// src/utils/color.ts
|
|
47
|
-
function parseHexColor(color) {
|
|
48
|
-
const normalized = color.replace("#", "");
|
|
49
|
-
if (normalized.length !== 6 && normalized.length !== 8) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
const r = Number.parseInt(normalized.slice(0, 2), 16);
|
|
53
|
-
const g = Number.parseInt(normalized.slice(2, 4), 16);
|
|
54
|
-
const b = Number.parseInt(normalized.slice(4, 6), 16);
|
|
55
|
-
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
return { r, g, b };
|
|
59
|
-
}
|
|
60
|
-
function clampAlpha(alpha) {
|
|
61
|
-
return Math.max(0, Math.min(1, alpha));
|
|
62
|
-
}
|
|
63
|
-
function alphaColor(color, alpha) {
|
|
64
|
-
const channels = parseHexColor(color);
|
|
65
|
-
const boundedAlpha = clampAlpha(alpha);
|
|
66
|
-
if (!channels) {
|
|
67
|
-
return color;
|
|
68
|
-
}
|
|
69
|
-
return `rgba(${channels.r}, ${channels.g}, ${channels.b}, ${boundedAlpha})`;
|
|
70
|
-
}
|
|
71
|
-
function blendColor(base, overlay, overlayAlpha) {
|
|
72
|
-
const baseChannels = parseHexColor(base);
|
|
73
|
-
const overlayChannels = parseHexColor(overlay);
|
|
74
|
-
const boundedAlpha = clampAlpha(overlayAlpha);
|
|
75
|
-
if (!baseChannels || !overlayChannels) {
|
|
76
|
-
return alphaColor(overlay, boundedAlpha);
|
|
77
|
-
}
|
|
78
|
-
const r = Math.round(
|
|
79
|
-
(1 - boundedAlpha) * baseChannels.r + boundedAlpha * overlayChannels.r
|
|
80
|
-
);
|
|
81
|
-
const g = Math.round(
|
|
82
|
-
(1 - boundedAlpha) * baseChannels.g + boundedAlpha * overlayChannels.g
|
|
83
|
-
);
|
|
84
|
-
const b = Math.round(
|
|
85
|
-
(1 - boundedAlpha) * baseChannels.b + boundedAlpha * overlayChannels.b
|
|
86
|
-
);
|
|
87
|
-
return `rgb(${r}, ${g}, ${b})`;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// src/switch/styles.ts
|
|
35
|
+
var import_utils = require("@onlynative/utils");
|
|
91
36
|
function getColors(theme, selected) {
|
|
92
|
-
const disabledOnSurface12 = alphaColor(theme.colors.onSurface, 0.12);
|
|
93
|
-
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);
|
|
94
39
|
if (selected) {
|
|
95
40
|
return {
|
|
96
41
|
trackColor: theme.colors.primary,
|
|
97
42
|
thumbColor: theme.colors.onPrimary,
|
|
98
43
|
iconColor: theme.colors.onPrimaryContainer,
|
|
99
|
-
hoveredTrackColor: blendColor(
|
|
44
|
+
hoveredTrackColor: (0, import_utils.blendColor)(
|
|
100
45
|
theme.colors.primary,
|
|
101
46
|
theme.colors.onPrimary,
|
|
102
47
|
theme.stateLayer.hoveredOpacity
|
|
103
48
|
),
|
|
104
|
-
pressedTrackColor: blendColor(
|
|
49
|
+
pressedTrackColor: (0, import_utils.blendColor)(
|
|
105
50
|
theme.colors.primary,
|
|
106
51
|
theme.colors.onPrimary,
|
|
107
52
|
theme.stateLayer.pressedOpacity
|
|
@@ -118,12 +63,12 @@ function getColors(theme, selected) {
|
|
|
118
63
|
trackColor: theme.colors.surfaceContainerHighest,
|
|
119
64
|
thumbColor: theme.colors.outline,
|
|
120
65
|
iconColor: theme.colors.surfaceContainerHighest,
|
|
121
|
-
hoveredTrackColor: blendColor(
|
|
66
|
+
hoveredTrackColor: (0, import_utils.blendColor)(
|
|
122
67
|
theme.colors.surfaceContainerHighest,
|
|
123
68
|
theme.colors.onSurface,
|
|
124
69
|
theme.stateLayer.hoveredOpacity
|
|
125
70
|
),
|
|
126
|
-
pressedTrackColor: blendColor(
|
|
71
|
+
pressedTrackColor: (0, import_utils.blendColor)(
|
|
127
72
|
theme.colors.surfaceContainerHighest,
|
|
128
73
|
theme.colors.onSurface,
|
|
129
74
|
theme.stateLayer.pressedOpacity
|
|
@@ -147,12 +92,12 @@ function applyColorOverrides(theme, colors, containerColor, contentColor) {
|
|
|
147
92
|
const overlay = contentColor != null ? contentColor : colors.thumbColor;
|
|
148
93
|
result.trackColor = containerColor;
|
|
149
94
|
result.borderColor = containerColor;
|
|
150
|
-
result.hoveredTrackColor = blendColor(
|
|
95
|
+
result.hoveredTrackColor = (0, import_utils.blendColor)(
|
|
151
96
|
containerColor,
|
|
152
97
|
overlay,
|
|
153
98
|
theme.stateLayer.hoveredOpacity
|
|
154
99
|
);
|
|
155
|
-
result.pressedTrackColor = blendColor(
|
|
100
|
+
result.pressedTrackColor = (0, import_utils.blendColor)(
|
|
156
101
|
containerColor,
|
|
157
102
|
overlay,
|
|
158
103
|
theme.stateLayer.pressedOpacity
|
|
@@ -214,7 +159,7 @@ function createStyles(theme, selected, hasIcon, containerColor, contentColor) {
|
|
|
214
159
|
color: colors.iconColor
|
|
215
160
|
},
|
|
216
161
|
disabledIconColor: {
|
|
217
|
-
color: alphaColor(theme.colors.onSurface, 0.38)
|
|
162
|
+
color: (0, import_utils.alphaColor)(theme.colors.onSurface, 0.38)
|
|
218
163
|
}
|
|
219
164
|
});
|
|
220
165
|
}
|
|
@@ -271,6 +216,7 @@ function Switch({
|
|
|
271
216
|
}
|
|
272
217
|
};
|
|
273
218
|
const iconName = isSelected ? selectedIcon : unselectedIcon;
|
|
219
|
+
const MaterialCommunityIcons = iconName ? (0, import_utils2.getMaterialCommunityIcons)() : null;
|
|
274
220
|
const iconSize = 16;
|
|
275
221
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
276
222
|
import_react_native2.Pressable,
|
|
@@ -297,7 +243,7 @@ function Switch({
|
|
|
297
243
|
{
|
|
298
244
|
style: [styles.thumb, isDisabled ? styles.disabledThumb : void 0],
|
|
299
245
|
children: iconName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
300
|
-
|
|
246
|
+
MaterialCommunityIcons,
|
|
301
247
|
{
|
|
302
248
|
name: iconName,
|
|
303
249
|
size: iconSize,
|
package/dist/text-field/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/text-field/index.ts
|
|
@@ -35,47 +25,14 @@ __export(text_field_exports, {
|
|
|
35
25
|
module.exports = __toCommonJS(text_field_exports);
|
|
36
26
|
|
|
37
27
|
// src/text-field/TextField.tsx
|
|
38
|
-
var import_MaterialCommunityIcons = __toESM(require("@expo/vector-icons/MaterialCommunityIcons"));
|
|
39
28
|
var import_react = require("react");
|
|
40
|
-
var
|
|
29
|
+
var import_react_native2 = require("react-native");
|
|
41
30
|
var import_core = require("@onlynative/core");
|
|
31
|
+
var import_utils2 = require("@onlynative/utils");
|
|
42
32
|
|
|
43
33
|
// src/text-field/styles.ts
|
|
44
|
-
var import_react_native2 = require("react-native");
|
|
45
|
-
|
|
46
|
-
// src/utils/color.ts
|
|
47
|
-
function parseHexColor(color) {
|
|
48
|
-
const normalized = color.replace("#", "");
|
|
49
|
-
if (normalized.length !== 6 && normalized.length !== 8) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
const r = Number.parseInt(normalized.slice(0, 2), 16);
|
|
53
|
-
const g = Number.parseInt(normalized.slice(2, 4), 16);
|
|
54
|
-
const b = Number.parseInt(normalized.slice(4, 6), 16);
|
|
55
|
-
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
return { r, g, b };
|
|
59
|
-
}
|
|
60
|
-
function clampAlpha(alpha) {
|
|
61
|
-
return Math.max(0, Math.min(1, alpha));
|
|
62
|
-
}
|
|
63
|
-
function alphaColor(color, alpha) {
|
|
64
|
-
const channels = parseHexColor(color);
|
|
65
|
-
const boundedAlpha = clampAlpha(alpha);
|
|
66
|
-
if (!channels) {
|
|
67
|
-
return color;
|
|
68
|
-
}
|
|
69
|
-
return `rgba(${channels.r}, ${channels.g}, ${channels.b}, ${boundedAlpha})`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// src/utils/rtl.ts
|
|
73
34
|
var import_react_native = require("react-native");
|
|
74
|
-
|
|
75
|
-
return import_react_native.I18nManager.isRTL ? `right ${vertical}` : `left ${vertical}`;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// src/text-field/styles.ts
|
|
35
|
+
var import_utils = require("@onlynative/utils");
|
|
79
36
|
var CONTAINER_HEIGHT = 56;
|
|
80
37
|
var ICON_SIZE = 24;
|
|
81
38
|
var LABEL_FLOATED_LINE_HEIGHT = 16;
|
|
@@ -100,15 +57,15 @@ function getVariantColors(theme, variant) {
|
|
|
100
57
|
focusedLabelColor: theme.colors.primary,
|
|
101
58
|
errorLabelColor: theme.colors.error,
|
|
102
59
|
textColor: theme.colors.onSurface,
|
|
103
|
-
disabledTextColor: alphaColor(theme.colors.onSurface, disabledOpacity),
|
|
104
|
-
disabledLabelColor: alphaColor(theme.colors.onSurface, disabledOpacity),
|
|
105
|
-
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),
|
|
106
63
|
placeholderColor: theme.colors.onSurfaceVariant,
|
|
107
64
|
supportingTextColor: theme.colors.onSurfaceVariant,
|
|
108
65
|
errorSupportingTextColor: theme.colors.error,
|
|
109
66
|
iconColor: theme.colors.onSurfaceVariant,
|
|
110
67
|
errorIconColor: theme.colors.error,
|
|
111
|
-
disabledIconColor: alphaColor(theme.colors.onSurface, disabledOpacity)
|
|
68
|
+
disabledIconColor: (0, import_utils.alphaColor)(theme.colors.onSurface, disabledOpacity)
|
|
112
69
|
};
|
|
113
70
|
if (variant === "outlined") {
|
|
114
71
|
return {
|
|
@@ -123,7 +80,7 @@ function getVariantColors(theme, variant) {
|
|
|
123
80
|
...common,
|
|
124
81
|
backgroundColor: theme.colors.surfaceContainerHighest,
|
|
125
82
|
borderColor: theme.colors.onSurfaceVariant,
|
|
126
|
-
disabledBackgroundColor: alphaColor(theme.colors.onSurface, 0.04),
|
|
83
|
+
disabledBackgroundColor: (0, import_utils.alphaColor)(theme.colors.onSurface, 0.04),
|
|
127
84
|
labelColor: theme.colors.onSurfaceVariant
|
|
128
85
|
};
|
|
129
86
|
}
|
|
@@ -134,7 +91,7 @@ function createStyles(theme, variant) {
|
|
|
134
91
|
const isFilled = variant === "filled";
|
|
135
92
|
return {
|
|
136
93
|
colors,
|
|
137
|
-
styles:
|
|
94
|
+
styles: import_react_native.StyleSheet.create({
|
|
138
95
|
root: {
|
|
139
96
|
alignSelf: "stretch"
|
|
140
97
|
},
|
|
@@ -205,7 +162,7 @@ function createStyles(theme, variant) {
|
|
|
205
162
|
fontWeight: bodySmall.fontWeight,
|
|
206
163
|
letterSpacing: bodySmall.letterSpacing,
|
|
207
164
|
color: colors.labelColor,
|
|
208
|
-
transformOrigin: transformOrigin("top")
|
|
165
|
+
transformOrigin: (0, import_utils.transformOrigin)("top")
|
|
209
166
|
},
|
|
210
167
|
labelNotch: {
|
|
211
168
|
paddingHorizontal: 4
|
|
@@ -298,6 +255,7 @@ function TextField({
|
|
|
298
255
|
const isError = Boolean(error) || Boolean(errorText);
|
|
299
256
|
const isFilled = variant === "filled";
|
|
300
257
|
const hasLeadingIcon = Boolean(leadingIcon);
|
|
258
|
+
const MaterialCommunityIcons = leadingIcon || trailingIcon ? (0, import_utils2.getMaterialCommunityIcons)() : null;
|
|
301
259
|
const { colors, styles } = (0, import_react.useMemo)(
|
|
302
260
|
() => createStyles(theme, variant),
|
|
303
261
|
[theme, variant]
|
|
@@ -310,13 +268,13 @@ function TextField({
|
|
|
310
268
|
const isControlled = value !== void 0;
|
|
311
269
|
const hasValue = isControlled ? value !== "" : internalHasText;
|
|
312
270
|
const isLabelFloated = isFocused || hasValue;
|
|
313
|
-
const labelAnimRef = (0, import_react.useRef)(new
|
|
271
|
+
const labelAnimRef = (0, import_react.useRef)(new import_react_native2.Animated.Value(isLabelFloated ? 1 : 0));
|
|
314
272
|
const labelAnim = labelAnimRef.current;
|
|
315
273
|
(0, import_react.useEffect)(() => {
|
|
316
|
-
|
|
274
|
+
import_react_native2.Animated.timing(labelAnim, {
|
|
317
275
|
toValue: isLabelFloated ? 1 : 0,
|
|
318
276
|
duration: 150,
|
|
319
|
-
useNativeDriver:
|
|
277
|
+
useNativeDriver: import_react_native2.Platform.OS !== "web"
|
|
320
278
|
}).start();
|
|
321
279
|
}, [isLabelFloated, labelAnim]);
|
|
322
280
|
const labelScale = (0, import_react.useMemo)(() => {
|
|
@@ -394,10 +352,10 @@ function TextField({
|
|
|
394
352
|
[styles, isFocused, isError, isDisabled]
|
|
395
353
|
);
|
|
396
354
|
const displaySupportingText = isError ? errorText : supportingText;
|
|
397
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
398
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
399
|
-
leadingIcon ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
400
|
-
|
|
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)(
|
|
358
|
+
MaterialCommunityIcons,
|
|
401
359
|
{
|
|
402
360
|
name: leadingIcon,
|
|
403
361
|
size: ICON_SIZE2,
|
|
@@ -405,14 +363,14 @@ function TextField({
|
|
|
405
363
|
}
|
|
406
364
|
) }) : null,
|
|
407
365
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
408
|
-
|
|
366
|
+
import_react_native2.View,
|
|
409
367
|
{
|
|
410
368
|
style: [
|
|
411
369
|
styles.inputWrapper,
|
|
412
370
|
label ? styles.inputWrapperWithLabel : void 0
|
|
413
371
|
],
|
|
414
372
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
415
|
-
|
|
373
|
+
import_react_native2.TextInput,
|
|
416
374
|
{
|
|
417
375
|
ref: inputRef,
|
|
418
376
|
...textInputProps,
|
|
@@ -438,15 +396,15 @@ function TextField({
|
|
|
438
396
|
}
|
|
439
397
|
),
|
|
440
398
|
trailingIcon ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
441
|
-
|
|
399
|
+
import_react_native2.Pressable,
|
|
442
400
|
{
|
|
443
401
|
onPress: onTrailingIconPress,
|
|
444
402
|
disabled: isDisabled || !onTrailingIconPress,
|
|
445
403
|
accessibilityRole: "button",
|
|
446
404
|
hitSlop: 12,
|
|
447
405
|
style: styles.trailingIconPressable,
|
|
448
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
449
|
-
|
|
406
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: styles.trailingIcon, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
407
|
+
MaterialCommunityIcons,
|
|
450
408
|
{
|
|
451
409
|
name: trailingIcon,
|
|
452
410
|
size: ICON_SIZE2,
|
|
@@ -456,7 +414,7 @@ function TextField({
|
|
|
456
414
|
}
|
|
457
415
|
) : null,
|
|
458
416
|
label ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
459
|
-
|
|
417
|
+
import_react_native2.Animated.Text,
|
|
460
418
|
{
|
|
461
419
|
numberOfLines: 1,
|
|
462
420
|
style: [
|
|
@@ -476,10 +434,10 @@ function TextField({
|
|
|
476
434
|
children: label
|
|
477
435
|
}
|
|
478
436
|
) : null,
|
|
479
|
-
isFilled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
437
|
+
isFilled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: indicatorStyle }) : null
|
|
480
438
|
] }) }),
|
|
481
|
-
displaySupportingText ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
482
|
-
|
|
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,
|
|
483
441
|
{
|
|
484
442
|
style: [
|
|
485
443
|
styles.supportingText,
|