@onlynative/components 0.1.0 → 0.1.1-alpha.1
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 +133 -62
- package/dist/button/index.js +125 -33
- package/dist/card/index.js +88 -20
- package/dist/checkbox/index.js +88 -17
- package/dist/chip/index.js +122 -30
- package/dist/icon-button/index.js +107 -36
- package/dist/index.js +335 -251
- package/dist/list/index.js +71 -24
- package/dist/radio/index.js +43 -14
- package/dist/switch/index.js +90 -19
- package/dist/text-field/index.js +82 -26
- package/package.json +4 -23
- package/src/appbar/AppBar.tsx +0 -302
- package/src/appbar/index.ts +0 -2
- package/src/appbar/styles.ts +0 -92
- package/src/appbar/types.ts +0 -67
- package/src/button/Button.tsx +0 -133
- package/src/button/index.ts +0 -2
- package/src/button/styles.ts +0 -287
- package/src/button/types.ts +0 -42
- package/src/card/Card.tsx +0 -69
- package/src/card/index.ts +0 -2
- package/src/card/styles.ts +0 -150
- package/src/card/types.ts +0 -27
- package/src/checkbox/Checkbox.tsx +0 -113
- package/src/checkbox/index.ts +0 -2
- package/src/checkbox/styles.ts +0 -155
- package/src/checkbox/types.ts +0 -20
- package/src/chip/Chip.tsx +0 -188
- package/src/chip/index.ts +0 -2
- package/src/chip/styles.ts +0 -239
- package/src/chip/types.ts +0 -58
- package/src/icon-button/IconButton.tsx +0 -362
- package/src/icon-button/index.ts +0 -6
- package/src/icon-button/styles.ts +0 -259
- package/src/icon-button/types.ts +0 -55
- package/src/index.ts +0 -54
- package/src/keyboard-avoiding-wrapper/KeyboardAvoidingWrapper.tsx +0 -69
- package/src/keyboard-avoiding-wrapper/index.ts +0 -2
- package/src/keyboard-avoiding-wrapper/styles.ts +0 -10
- package/src/keyboard-avoiding-wrapper/types.ts +0 -37
- package/src/layout/Box.tsx +0 -99
- package/src/layout/Column.tsx +0 -16
- package/src/layout/Grid.tsx +0 -49
- package/src/layout/Layout.tsx +0 -81
- package/src/layout/Row.tsx +0 -22
- package/src/layout/index.ts +0 -13
- package/src/layout/resolveSpacing.ts +0 -11
- package/src/layout/types.ts +0 -82
- package/src/list/List.tsx +0 -17
- package/src/list/ListDivider.tsx +0 -20
- package/src/list/ListItem.tsx +0 -128
- package/src/list/index.ts +0 -9
- package/src/list/styles.ts +0 -132
- package/src/list/types.ts +0 -54
- package/src/radio/Radio.tsx +0 -103
- package/src/radio/index.ts +0 -2
- package/src/radio/styles.ts +0 -139
- package/src/radio/types.ts +0 -20
- package/src/switch/Switch.tsx +0 -121
- package/src/switch/index.ts +0 -2
- package/src/switch/styles.ts +0 -172
- package/src/switch/types.ts +0 -32
- package/src/text-field/TextField.tsx +0 -301
- package/src/text-field/index.ts +0 -2
- package/src/text-field/styles.ts +0 -239
- package/src/text-field/types.ts +0 -49
- package/src/typography/Typography.tsx +0 -79
- package/src/typography/index.ts +0 -3
- package/src/typography/types.ts +0 -17
package/dist/list/index.js
CHANGED
|
@@ -28,12 +28,59 @@ module.exports = __toCommonJS(list_exports);
|
|
|
28
28
|
|
|
29
29
|
// src/list/List.tsx
|
|
30
30
|
var import_react = require("react");
|
|
31
|
-
var
|
|
31
|
+
var import_react_native4 = require("react-native");
|
|
32
32
|
var import_core = require("@onlynative/core");
|
|
33
33
|
|
|
34
34
|
// src/list/styles.ts
|
|
35
|
+
var import_react_native3 = require("react-native");
|
|
36
|
+
|
|
37
|
+
// ../utils/dist/index.mjs
|
|
35
38
|
var import_react_native = require("react-native");
|
|
36
|
-
var
|
|
39
|
+
var import_react_native2 = require("react-native");
|
|
40
|
+
function parseHexColor(color) {
|
|
41
|
+
const normalized = color.replace("#", "");
|
|
42
|
+
if (normalized.length !== 6 && normalized.length !== 8) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const r = Number.parseInt(normalized.slice(0, 2), 16);
|
|
46
|
+
const g = Number.parseInt(normalized.slice(2, 4), 16);
|
|
47
|
+
const b = Number.parseInt(normalized.slice(4, 6), 16);
|
|
48
|
+
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return { r, g, b };
|
|
52
|
+
}
|
|
53
|
+
function clampAlpha(alpha) {
|
|
54
|
+
return Math.max(0, Math.min(1, alpha));
|
|
55
|
+
}
|
|
56
|
+
function alphaColor(color, alpha) {
|
|
57
|
+
const channels = parseHexColor(color);
|
|
58
|
+
const boundedAlpha = clampAlpha(alpha);
|
|
59
|
+
if (!channels) {
|
|
60
|
+
return color;
|
|
61
|
+
}
|
|
62
|
+
return `rgba(${channels.r}, ${channels.g}, ${channels.b}, ${boundedAlpha})`;
|
|
63
|
+
}
|
|
64
|
+
function blendColor(base, overlay, overlayAlpha) {
|
|
65
|
+
const baseChannels = parseHexColor(base);
|
|
66
|
+
const overlayChannels = parseHexColor(overlay);
|
|
67
|
+
const boundedAlpha = clampAlpha(overlayAlpha);
|
|
68
|
+
if (!baseChannels || !overlayChannels) {
|
|
69
|
+
return alphaColor(overlay, boundedAlpha);
|
|
70
|
+
}
|
|
71
|
+
const r = Math.round(
|
|
72
|
+
(1 - boundedAlpha) * baseChannels.r + boundedAlpha * overlayChannels.r
|
|
73
|
+
);
|
|
74
|
+
const g = Math.round(
|
|
75
|
+
(1 - boundedAlpha) * baseChannels.g + boundedAlpha * overlayChannels.g
|
|
76
|
+
);
|
|
77
|
+
const b = Math.round(
|
|
78
|
+
(1 - boundedAlpha) * baseChannels.b + boundedAlpha * overlayChannels.b
|
|
79
|
+
);
|
|
80
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/list/styles.ts
|
|
37
84
|
var ITEM_PADDING_VERTICAL = 12;
|
|
38
85
|
var INSET_START = 56;
|
|
39
86
|
var MIN_HEIGHT = {
|
|
@@ -42,7 +89,7 @@ var MIN_HEIGHT = {
|
|
|
42
89
|
3: 88
|
|
43
90
|
};
|
|
44
91
|
function createListStyles(theme) {
|
|
45
|
-
return
|
|
92
|
+
return import_react_native3.StyleSheet.create({
|
|
46
93
|
container: {
|
|
47
94
|
paddingVertical: theme.spacing.sm
|
|
48
95
|
}
|
|
@@ -53,12 +100,12 @@ function getItemColors(theme, containerColor) {
|
|
|
53
100
|
if (containerColor) {
|
|
54
101
|
return {
|
|
55
102
|
backgroundColor: containerColor,
|
|
56
|
-
hoveredBackgroundColor:
|
|
103
|
+
hoveredBackgroundColor: blendColor(
|
|
57
104
|
containerColor,
|
|
58
105
|
theme.colors.onSurface,
|
|
59
106
|
theme.stateLayer.hoveredOpacity
|
|
60
107
|
),
|
|
61
|
-
pressedBackgroundColor:
|
|
108
|
+
pressedBackgroundColor: blendColor(
|
|
62
109
|
containerColor,
|
|
63
110
|
theme.colors.onSurface,
|
|
64
111
|
theme.stateLayer.pressedOpacity
|
|
@@ -67,11 +114,11 @@ function getItemColors(theme, containerColor) {
|
|
|
67
114
|
}
|
|
68
115
|
return {
|
|
69
116
|
backgroundColor: base,
|
|
70
|
-
hoveredBackgroundColor:
|
|
117
|
+
hoveredBackgroundColor: alphaColor(
|
|
71
118
|
theme.colors.onSurface,
|
|
72
119
|
theme.stateLayer.hoveredOpacity
|
|
73
120
|
),
|
|
74
|
-
pressedBackgroundColor:
|
|
121
|
+
pressedBackgroundColor: alphaColor(
|
|
75
122
|
theme.colors.onSurface,
|
|
76
123
|
theme.stateLayer.pressedOpacity
|
|
77
124
|
)
|
|
@@ -79,7 +126,7 @@ function getItemColors(theme, containerColor) {
|
|
|
79
126
|
}
|
|
80
127
|
function createListItemStyles(theme, lines, containerColor) {
|
|
81
128
|
const colors = getItemColors(theme, containerColor);
|
|
82
|
-
return
|
|
129
|
+
return import_react_native3.StyleSheet.create({
|
|
83
130
|
container: {
|
|
84
131
|
flexDirection: "row",
|
|
85
132
|
alignItems: lines === 3 ? "flex-start" : "center",
|
|
@@ -134,7 +181,7 @@ function createListItemStyles(theme, lines, containerColor) {
|
|
|
134
181
|
});
|
|
135
182
|
}
|
|
136
183
|
function createDividerStyles(theme, inset) {
|
|
137
|
-
return
|
|
184
|
+
return import_react_native3.StyleSheet.create({
|
|
138
185
|
divider: {
|
|
139
186
|
height: 1,
|
|
140
187
|
backgroundColor: theme.colors.outlineVariant,
|
|
@@ -148,12 +195,12 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
148
195
|
function List({ children, style, ...props }) {
|
|
149
196
|
const theme = (0, import_core.useTheme)();
|
|
150
197
|
const styles = (0, import_react.useMemo)(() => createListStyles(theme), [theme]);
|
|
151
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
198
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native4.View, { ...props, style: [styles.container, style], children });
|
|
152
199
|
}
|
|
153
200
|
|
|
154
201
|
// src/list/ListItem.tsx
|
|
155
202
|
var import_react2 = require("react");
|
|
156
|
-
var
|
|
203
|
+
var import_react_native5 = require("react-native");
|
|
157
204
|
var import_core2 = require("@onlynative/core");
|
|
158
205
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
159
206
|
function getLines(supportingText, overlineText, supportingTextNumberOfLines) {
|
|
@@ -186,12 +233,12 @@ function ListItem({
|
|
|
186
233
|
[theme, lines, containerColor]
|
|
187
234
|
);
|
|
188
235
|
const content = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
189
|
-
leadingContent != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
190
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
191
|
-
overlineText != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
192
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
236
|
+
leadingContent != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native5.View, { style: styles.leadingContent, children: leadingContent }),
|
|
237
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native5.View, { style: styles.textBlock, children: [
|
|
238
|
+
overlineText != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native5.Text, { style: styles.overlineText, numberOfLines: 1, children: overlineText }),
|
|
239
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native5.Text, { style: styles.headlineText, numberOfLines: 1, children: headlineText }),
|
|
193
240
|
supportingText != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
194
|
-
|
|
241
|
+
import_react_native5.Text,
|
|
195
242
|
{
|
|
196
243
|
style: styles.supportingText,
|
|
197
244
|
numberOfLines: supportingTextNumberOfLines,
|
|
@@ -199,13 +246,13 @@ function ListItem({
|
|
|
199
246
|
}
|
|
200
247
|
)
|
|
201
248
|
] }),
|
|
202
|
-
(trailingContent != null || trailingSupportingText != null) && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
203
|
-
trailingSupportingText != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
249
|
+
(trailingContent != null || trailingSupportingText != null) && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native5.View, { style: styles.trailingBlock, children: [
|
|
250
|
+
trailingSupportingText != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native5.Text, { style: styles.trailingSupportingText, numberOfLines: 1, children: trailingSupportingText }),
|
|
204
251
|
trailingContent
|
|
205
252
|
] })
|
|
206
253
|
] });
|
|
207
254
|
if (!isInteractive) {
|
|
208
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
255
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native5.View, { ...props, style: [styles.container, style], children: content });
|
|
209
256
|
}
|
|
210
257
|
const resolvedStyle = (state) => [
|
|
211
258
|
styles.container,
|
|
@@ -216,23 +263,23 @@ function ListItem({
|
|
|
216
263
|
typeof style === "function" ? style(state) : style
|
|
217
264
|
];
|
|
218
265
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
219
|
-
|
|
266
|
+
import_react_native5.Pressable,
|
|
220
267
|
{
|
|
221
268
|
...props,
|
|
222
269
|
role: "button",
|
|
223
270
|
accessibilityState: { disabled: isDisabled },
|
|
224
|
-
hitSlop:
|
|
271
|
+
hitSlop: import_react_native5.Platform.OS === "web" ? void 0 : 4,
|
|
225
272
|
disabled: isDisabled,
|
|
226
273
|
onPress,
|
|
227
274
|
style: resolvedStyle,
|
|
228
|
-
children: isDisabled ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
275
|
+
children: isDisabled ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native5.View, { style: styles.disabledContentWrapper, children: content }) : content
|
|
229
276
|
}
|
|
230
277
|
);
|
|
231
278
|
}
|
|
232
279
|
|
|
233
280
|
// src/list/ListDivider.tsx
|
|
234
281
|
var import_react3 = require("react");
|
|
235
|
-
var
|
|
282
|
+
var import_react_native6 = require("react-native");
|
|
236
283
|
var import_core3 = require("@onlynative/core");
|
|
237
284
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
238
285
|
function ListDivider({
|
|
@@ -245,7 +292,7 @@ function ListDivider({
|
|
|
245
292
|
() => createDividerStyles(theme, inset),
|
|
246
293
|
[theme, inset]
|
|
247
294
|
);
|
|
248
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
295
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native6.View, { ...props, style: [styles.divider, style] });
|
|
249
296
|
}
|
|
250
297
|
// Annotate the CommonJS export names for ESM import in node:
|
|
251
298
|
0 && (module.exports = {
|
package/dist/radio/index.js
CHANGED
|
@@ -26,23 +26,52 @@ module.exports = __toCommonJS(radio_exports);
|
|
|
26
26
|
|
|
27
27
|
// src/radio/Radio.tsx
|
|
28
28
|
var import_react = require("react");
|
|
29
|
-
var
|
|
29
|
+
var import_react_native4 = require("react-native");
|
|
30
30
|
var import_core = require("@onlynative/core");
|
|
31
31
|
|
|
32
32
|
// src/radio/styles.ts
|
|
33
|
+
var import_react_native3 = require("react-native");
|
|
34
|
+
|
|
35
|
+
// ../utils/dist/index.mjs
|
|
33
36
|
var import_react_native = require("react-native");
|
|
34
|
-
var
|
|
37
|
+
var import_react_native2 = require("react-native");
|
|
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
|
+
|
|
63
|
+
// src/radio/styles.ts
|
|
35
64
|
function getColors(theme, selected) {
|
|
36
|
-
const disabledOnSurface38 =
|
|
65
|
+
const disabledOnSurface38 = alphaColor(theme.colors.onSurface, 0.38);
|
|
37
66
|
if (selected) {
|
|
38
67
|
return {
|
|
39
68
|
borderColor: theme.colors.primary,
|
|
40
69
|
dotColor: theme.colors.primary,
|
|
41
|
-
hoveredBackgroundColor:
|
|
70
|
+
hoveredBackgroundColor: alphaColor(
|
|
42
71
|
theme.colors.primary,
|
|
43
72
|
theme.stateLayer.hoveredOpacity
|
|
44
73
|
),
|
|
45
|
-
pressedBackgroundColor:
|
|
74
|
+
pressedBackgroundColor: alphaColor(
|
|
46
75
|
theme.colors.primary,
|
|
47
76
|
theme.stateLayer.pressedOpacity
|
|
48
77
|
),
|
|
@@ -53,11 +82,11 @@ function getColors(theme, selected) {
|
|
|
53
82
|
return {
|
|
54
83
|
borderColor: theme.colors.onSurfaceVariant,
|
|
55
84
|
dotColor: "transparent",
|
|
56
|
-
hoveredBackgroundColor:
|
|
85
|
+
hoveredBackgroundColor: alphaColor(
|
|
57
86
|
theme.colors.onSurface,
|
|
58
87
|
theme.stateLayer.hoveredOpacity
|
|
59
88
|
),
|
|
60
|
-
pressedBackgroundColor:
|
|
89
|
+
pressedBackgroundColor: alphaColor(
|
|
61
90
|
theme.colors.onSurface,
|
|
62
91
|
theme.stateLayer.pressedOpacity
|
|
63
92
|
),
|
|
@@ -71,11 +100,11 @@ function applyColorOverrides(theme, colors, containerColor, contentColor) {
|
|
|
71
100
|
if (containerColor) {
|
|
72
101
|
result.borderColor = containerColor;
|
|
73
102
|
result.dotColor = containerColor;
|
|
74
|
-
result.hoveredBackgroundColor =
|
|
103
|
+
result.hoveredBackgroundColor = alphaColor(
|
|
75
104
|
containerColor,
|
|
76
105
|
theme.stateLayer.hoveredOpacity
|
|
77
106
|
);
|
|
78
|
-
result.pressedBackgroundColor =
|
|
107
|
+
result.pressedBackgroundColor = alphaColor(
|
|
79
108
|
containerColor,
|
|
80
109
|
theme.stateLayer.pressedOpacity
|
|
81
110
|
);
|
|
@@ -95,7 +124,7 @@ function createStyles(theme, selected, containerColor, contentColor) {
|
|
|
95
124
|
const outerSize = 20;
|
|
96
125
|
const innerSize = 10;
|
|
97
126
|
const touchTarget = 48;
|
|
98
|
-
return
|
|
127
|
+
return import_react_native3.StyleSheet.create({
|
|
99
128
|
container: {
|
|
100
129
|
width: touchTarget,
|
|
101
130
|
height: touchTarget,
|
|
@@ -180,7 +209,7 @@ function Radio({
|
|
|
180
209
|
}
|
|
181
210
|
};
|
|
182
211
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
183
|
-
|
|
212
|
+
import_react_native4.Pressable,
|
|
184
213
|
{
|
|
185
214
|
...props,
|
|
186
215
|
accessibilityRole: "radio",
|
|
@@ -188,7 +217,7 @@ function Radio({
|
|
|
188
217
|
disabled: isDisabled,
|
|
189
218
|
checked: isSelected
|
|
190
219
|
},
|
|
191
|
-
hitSlop:
|
|
220
|
+
hitSlop: import_react_native4.Platform.OS === "web" ? void 0 : 4,
|
|
192
221
|
disabled: isDisabled,
|
|
193
222
|
onPress: handlePress,
|
|
194
223
|
style: resolveStyle(
|
|
@@ -200,11 +229,11 @@ function Radio({
|
|
|
200
229
|
style
|
|
201
230
|
),
|
|
202
231
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
203
|
-
|
|
232
|
+
import_react_native4.View,
|
|
204
233
|
{
|
|
205
234
|
style: [styles.outer, isDisabled ? styles.disabledOuter : void 0],
|
|
206
235
|
children: isSelected ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
207
|
-
|
|
236
|
+
import_react_native4.View,
|
|
208
237
|
{
|
|
209
238
|
style: [
|
|
210
239
|
styles.inner,
|
package/dist/switch/index.js
CHANGED
|
@@ -26,27 +26,98 @@ module.exports = __toCommonJS(switch_exports);
|
|
|
26
26
|
|
|
27
27
|
// src/switch/Switch.tsx
|
|
28
28
|
var import_react = require("react");
|
|
29
|
-
var
|
|
29
|
+
var import_react_native4 = require("react-native");
|
|
30
30
|
var import_core = require("@onlynative/core");
|
|
31
|
-
var import_utils2 = require("@onlynative/utils");
|
|
32
31
|
|
|
33
|
-
//
|
|
32
|
+
// ../utils/dist/chunk-OQRDRRQA.mjs
|
|
33
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
34
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
35
|
+
}) : x)(function(x) {
|
|
36
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
37
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// ../utils/dist/index.mjs
|
|
34
41
|
var import_react_native = require("react-native");
|
|
35
|
-
var
|
|
42
|
+
var import_react_native2 = require("react-native");
|
|
43
|
+
function parseHexColor(color) {
|
|
44
|
+
const normalized = color.replace("#", "");
|
|
45
|
+
if (normalized.length !== 6 && normalized.length !== 8) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const r = Number.parseInt(normalized.slice(0, 2), 16);
|
|
49
|
+
const g = Number.parseInt(normalized.slice(2, 4), 16);
|
|
50
|
+
const b = Number.parseInt(normalized.slice(4, 6), 16);
|
|
51
|
+
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return { r, g, b };
|
|
55
|
+
}
|
|
56
|
+
function clampAlpha(alpha) {
|
|
57
|
+
return Math.max(0, Math.min(1, alpha));
|
|
58
|
+
}
|
|
59
|
+
function alphaColor(color, alpha) {
|
|
60
|
+
const channels = parseHexColor(color);
|
|
61
|
+
const boundedAlpha = clampAlpha(alpha);
|
|
62
|
+
if (!channels) {
|
|
63
|
+
return color;
|
|
64
|
+
}
|
|
65
|
+
return `rgba(${channels.r}, ${channels.g}, ${channels.b}, ${boundedAlpha})`;
|
|
66
|
+
}
|
|
67
|
+
function blendColor(base, overlay, overlayAlpha) {
|
|
68
|
+
const baseChannels = parseHexColor(base);
|
|
69
|
+
const overlayChannels = parseHexColor(overlay);
|
|
70
|
+
const boundedAlpha = clampAlpha(overlayAlpha);
|
|
71
|
+
if (!baseChannels || !overlayChannels) {
|
|
72
|
+
return alphaColor(overlay, boundedAlpha);
|
|
73
|
+
}
|
|
74
|
+
const r = Math.round(
|
|
75
|
+
(1 - boundedAlpha) * baseChannels.r + boundedAlpha * overlayChannels.r
|
|
76
|
+
);
|
|
77
|
+
const g = Math.round(
|
|
78
|
+
(1 - boundedAlpha) * baseChannels.g + boundedAlpha * overlayChannels.g
|
|
79
|
+
);
|
|
80
|
+
const b = Math.round(
|
|
81
|
+
(1 - boundedAlpha) * baseChannels.b + boundedAlpha * overlayChannels.b
|
|
82
|
+
);
|
|
83
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
84
|
+
}
|
|
85
|
+
var _MCIcons = null;
|
|
86
|
+
var _resolved = false;
|
|
87
|
+
function getMaterialCommunityIcons() {
|
|
88
|
+
if (!_resolved) {
|
|
89
|
+
_resolved = true;
|
|
90
|
+
try {
|
|
91
|
+
const mod = __require("@expo/vector-icons/MaterialCommunityIcons");
|
|
92
|
+
_MCIcons = mod.default || mod;
|
|
93
|
+
} catch {
|
|
94
|
+
_MCIcons = null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!_MCIcons) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
"@expo/vector-icons is required for icon support. Install it with: npx expo install @expo/vector-icons"
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
return _MCIcons;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/switch/styles.ts
|
|
106
|
+
var import_react_native3 = require("react-native");
|
|
36
107
|
function getColors(theme, selected) {
|
|
37
|
-
const disabledOnSurface12 =
|
|
38
|
-
const disabledOnSurface38 =
|
|
108
|
+
const disabledOnSurface12 = alphaColor(theme.colors.onSurface, 0.12);
|
|
109
|
+
const disabledOnSurface38 = alphaColor(theme.colors.onSurface, 0.38);
|
|
39
110
|
if (selected) {
|
|
40
111
|
return {
|
|
41
112
|
trackColor: theme.colors.primary,
|
|
42
113
|
thumbColor: theme.colors.onPrimary,
|
|
43
114
|
iconColor: theme.colors.onPrimaryContainer,
|
|
44
|
-
hoveredTrackColor:
|
|
115
|
+
hoveredTrackColor: blendColor(
|
|
45
116
|
theme.colors.primary,
|
|
46
117
|
theme.colors.onPrimary,
|
|
47
118
|
theme.stateLayer.hoveredOpacity
|
|
48
119
|
),
|
|
49
|
-
pressedTrackColor:
|
|
120
|
+
pressedTrackColor: blendColor(
|
|
50
121
|
theme.colors.primary,
|
|
51
122
|
theme.colors.onPrimary,
|
|
52
123
|
theme.stateLayer.pressedOpacity
|
|
@@ -63,12 +134,12 @@ function getColors(theme, selected) {
|
|
|
63
134
|
trackColor: theme.colors.surfaceContainerHighest,
|
|
64
135
|
thumbColor: theme.colors.outline,
|
|
65
136
|
iconColor: theme.colors.surfaceContainerHighest,
|
|
66
|
-
hoveredTrackColor:
|
|
137
|
+
hoveredTrackColor: blendColor(
|
|
67
138
|
theme.colors.surfaceContainerHighest,
|
|
68
139
|
theme.colors.onSurface,
|
|
69
140
|
theme.stateLayer.hoveredOpacity
|
|
70
141
|
),
|
|
71
|
-
pressedTrackColor:
|
|
142
|
+
pressedTrackColor: blendColor(
|
|
72
143
|
theme.colors.surfaceContainerHighest,
|
|
73
144
|
theme.colors.onSurface,
|
|
74
145
|
theme.stateLayer.pressedOpacity
|
|
@@ -92,12 +163,12 @@ function applyColorOverrides(theme, colors, containerColor, contentColor) {
|
|
|
92
163
|
const overlay = contentColor != null ? contentColor : colors.thumbColor;
|
|
93
164
|
result.trackColor = containerColor;
|
|
94
165
|
result.borderColor = containerColor;
|
|
95
|
-
result.hoveredTrackColor =
|
|
166
|
+
result.hoveredTrackColor = blendColor(
|
|
96
167
|
containerColor,
|
|
97
168
|
overlay,
|
|
98
169
|
theme.stateLayer.hoveredOpacity
|
|
99
170
|
);
|
|
100
|
-
result.pressedTrackColor =
|
|
171
|
+
result.pressedTrackColor = blendColor(
|
|
101
172
|
containerColor,
|
|
102
173
|
overlay,
|
|
103
174
|
theme.stateLayer.pressedOpacity
|
|
@@ -120,7 +191,7 @@ function createStyles(theme, selected, hasIcon, containerColor, contentColor) {
|
|
|
120
191
|
const trackHeight = 32;
|
|
121
192
|
const trackPadding = 4;
|
|
122
193
|
const thumbOffset = selected ? trackWidth - trackPadding - thumbSize : trackPadding;
|
|
123
|
-
return
|
|
194
|
+
return import_react_native3.StyleSheet.create({
|
|
124
195
|
track: {
|
|
125
196
|
width: trackWidth,
|
|
126
197
|
height: trackHeight,
|
|
@@ -159,7 +230,7 @@ function createStyles(theme, selected, hasIcon, containerColor, contentColor) {
|
|
|
159
230
|
color: colors.iconColor
|
|
160
231
|
},
|
|
161
232
|
disabledIconColor: {
|
|
162
|
-
color:
|
|
233
|
+
color: alphaColor(theme.colors.onSurface, 0.38)
|
|
163
234
|
}
|
|
164
235
|
});
|
|
165
236
|
}
|
|
@@ -204,7 +275,7 @@ function Switch({
|
|
|
204
275
|
[theme, isSelected, hasIcon, containerColor, contentColor]
|
|
205
276
|
);
|
|
206
277
|
const resolvedIconColor = (0, import_react.useMemo)(() => {
|
|
207
|
-
const base =
|
|
278
|
+
const base = import_react_native4.StyleSheet.flatten([
|
|
208
279
|
styles.iconColor,
|
|
209
280
|
isDisabled ? styles.disabledIconColor : void 0
|
|
210
281
|
]);
|
|
@@ -216,10 +287,10 @@ function Switch({
|
|
|
216
287
|
}
|
|
217
288
|
};
|
|
218
289
|
const iconName = isSelected ? selectedIcon : unselectedIcon;
|
|
219
|
-
const MaterialCommunityIcons = iconName ?
|
|
290
|
+
const MaterialCommunityIcons = iconName ? getMaterialCommunityIcons() : null;
|
|
220
291
|
const iconSize = 16;
|
|
221
292
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
222
|
-
|
|
293
|
+
import_react_native4.Pressable,
|
|
223
294
|
{
|
|
224
295
|
...props,
|
|
225
296
|
accessibilityRole: "switch",
|
|
@@ -227,7 +298,7 @@ function Switch({
|
|
|
227
298
|
disabled: isDisabled,
|
|
228
299
|
checked: isSelected
|
|
229
300
|
},
|
|
230
|
-
hitSlop:
|
|
301
|
+
hitSlop: import_react_native4.Platform.OS === "web" ? void 0 : 4,
|
|
231
302
|
disabled: isDisabled,
|
|
232
303
|
onPress: handlePress,
|
|
233
304
|
style: resolveStyle(
|
|
@@ -239,7 +310,7 @@ function Switch({
|
|
|
239
310
|
style
|
|
240
311
|
),
|
|
241
312
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
242
|
-
|
|
313
|
+
import_react_native4.View,
|
|
243
314
|
{
|
|
244
315
|
style: [styles.thumb, isDisabled ? styles.disabledThumb : void 0],
|
|
245
316
|
children: iconName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|