@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
package/dist/button/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/button/index.ts
|
|
@@ -35,100 +25,31 @@ __export(button_exports, {
|
|
|
35
25
|
module.exports = __toCommonJS(button_exports);
|
|
36
26
|
|
|
37
27
|
// src/button/Button.tsx
|
|
38
|
-
var import_MaterialCommunityIcons = __toESM(require("@expo/vector-icons/MaterialCommunityIcons"));
|
|
39
28
|
var import_react = require("react");
|
|
29
|
+
var import_react_native2 = require("react-native");
|
|
40
30
|
var import_react_native3 = require("react-native");
|
|
41
31
|
var import_react_native4 = require("react-native");
|
|
42
|
-
var import_react_native5 = require("react-native");
|
|
43
32
|
var import_core = require("@onlynative/core");
|
|
33
|
+
var import_utils2 = require("@onlynative/utils");
|
|
44
34
|
|
|
45
35
|
// src/button/styles.ts
|
|
46
|
-
var import_react_native2 = require("react-native");
|
|
47
|
-
|
|
48
|
-
// src/utils/color.ts
|
|
49
|
-
function parseHexColor(color) {
|
|
50
|
-
const normalized = color.replace("#", "");
|
|
51
|
-
if (normalized.length !== 6 && normalized.length !== 8) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
const r = Number.parseInt(normalized.slice(0, 2), 16);
|
|
55
|
-
const g = Number.parseInt(normalized.slice(2, 4), 16);
|
|
56
|
-
const b = Number.parseInt(normalized.slice(4, 6), 16);
|
|
57
|
-
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
return { r, g, b };
|
|
61
|
-
}
|
|
62
|
-
function clampAlpha(alpha) {
|
|
63
|
-
return Math.max(0, Math.min(1, alpha));
|
|
64
|
-
}
|
|
65
|
-
function alphaColor(color, alpha) {
|
|
66
|
-
const channels = parseHexColor(color);
|
|
67
|
-
const boundedAlpha = clampAlpha(alpha);
|
|
68
|
-
if (!channels) {
|
|
69
|
-
return color;
|
|
70
|
-
}
|
|
71
|
-
return `rgba(${channels.r}, ${channels.g}, ${channels.b}, ${boundedAlpha})`;
|
|
72
|
-
}
|
|
73
|
-
function blendColor(base, overlay, overlayAlpha) {
|
|
74
|
-
const baseChannels = parseHexColor(base);
|
|
75
|
-
const overlayChannels = parseHexColor(overlay);
|
|
76
|
-
const boundedAlpha = clampAlpha(overlayAlpha);
|
|
77
|
-
if (!baseChannels || !overlayChannels) {
|
|
78
|
-
return alphaColor(overlay, boundedAlpha);
|
|
79
|
-
}
|
|
80
|
-
const r = Math.round(
|
|
81
|
-
(1 - boundedAlpha) * baseChannels.r + boundedAlpha * overlayChannels.r
|
|
82
|
-
);
|
|
83
|
-
const g = Math.round(
|
|
84
|
-
(1 - boundedAlpha) * baseChannels.g + boundedAlpha * overlayChannels.g
|
|
85
|
-
);
|
|
86
|
-
const b = Math.round(
|
|
87
|
-
(1 - boundedAlpha) * baseChannels.b + boundedAlpha * overlayChannels.b
|
|
88
|
-
);
|
|
89
|
-
return `rgb(${r}, ${g}, ${b})`;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// src/utils/elevation.ts
|
|
93
36
|
var import_react_native = require("react-native");
|
|
94
|
-
|
|
95
|
-
if (import_react_native.Platform.OS === "web") {
|
|
96
|
-
const { shadowOffset, shadowOpacity, shadowRadius } = level;
|
|
97
|
-
if (shadowOpacity === 0) {
|
|
98
|
-
return { boxShadow: "none" };
|
|
99
|
-
}
|
|
100
|
-
return {
|
|
101
|
-
boxShadow: `${shadowOffset.width}px ${shadowOffset.height}px ${shadowRadius}px rgba(0, 0, 0, ${shadowOpacity})`
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
shadowColor: level.shadowColor,
|
|
106
|
-
shadowOffset: {
|
|
107
|
-
width: level.shadowOffset.width,
|
|
108
|
-
height: level.shadowOffset.height
|
|
109
|
-
},
|
|
110
|
-
shadowOpacity: level.shadowOpacity,
|
|
111
|
-
shadowRadius: level.shadowRadius,
|
|
112
|
-
elevation: level.elevation
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// src/button/styles.ts
|
|
37
|
+
var import_utils = require("@onlynative/utils");
|
|
117
38
|
function getVariantColors(theme, variant) {
|
|
118
|
-
const disabledContainerColor = alphaColor(theme.colors.onSurface, 0.12);
|
|
119
|
-
const disabledLabelColor = alphaColor(theme.colors.onSurface, 0.38);
|
|
120
|
-
const disabledOutlineColor = alphaColor(theme.colors.onSurface, 0.12);
|
|
39
|
+
const disabledContainerColor = (0, import_utils.alphaColor)(theme.colors.onSurface, 0.12);
|
|
40
|
+
const disabledLabelColor = (0, import_utils.alphaColor)(theme.colors.onSurface, 0.38);
|
|
41
|
+
const disabledOutlineColor = (0, import_utils.alphaColor)(theme.colors.onSurface, 0.12);
|
|
121
42
|
if (variant === "outlined") {
|
|
122
43
|
return {
|
|
123
44
|
backgroundColor: "transparent",
|
|
124
45
|
textColor: theme.colors.primary,
|
|
125
46
|
borderColor: theme.colors.outline,
|
|
126
47
|
borderWidth: 1,
|
|
127
|
-
hoveredBackgroundColor: alphaColor(
|
|
48
|
+
hoveredBackgroundColor: (0, import_utils.alphaColor)(
|
|
128
49
|
theme.colors.primary,
|
|
129
50
|
theme.stateLayer.hoveredOpacity
|
|
130
51
|
),
|
|
131
|
-
pressedBackgroundColor: alphaColor(
|
|
52
|
+
pressedBackgroundColor: (0, import_utils.alphaColor)(
|
|
132
53
|
theme.colors.primary,
|
|
133
54
|
theme.stateLayer.pressedOpacity
|
|
134
55
|
),
|
|
@@ -143,11 +64,11 @@ function getVariantColors(theme, variant) {
|
|
|
143
64
|
textColor: theme.colors.primary,
|
|
144
65
|
borderColor: "transparent",
|
|
145
66
|
borderWidth: 0,
|
|
146
|
-
hoveredBackgroundColor: alphaColor(
|
|
67
|
+
hoveredBackgroundColor: (0, import_utils.alphaColor)(
|
|
147
68
|
theme.colors.primary,
|
|
148
69
|
theme.stateLayer.hoveredOpacity
|
|
149
70
|
),
|
|
150
|
-
pressedBackgroundColor: alphaColor(
|
|
71
|
+
pressedBackgroundColor: (0, import_utils.alphaColor)(
|
|
151
72
|
theme.colors.primary,
|
|
152
73
|
theme.stateLayer.pressedOpacity
|
|
153
74
|
),
|
|
@@ -162,12 +83,12 @@ function getVariantColors(theme, variant) {
|
|
|
162
83
|
textColor: theme.colors.primary,
|
|
163
84
|
borderColor: theme.colors.surfaceContainerLow,
|
|
164
85
|
borderWidth: 0,
|
|
165
|
-
hoveredBackgroundColor: blendColor(
|
|
86
|
+
hoveredBackgroundColor: (0, import_utils.blendColor)(
|
|
166
87
|
theme.colors.surfaceContainerLow,
|
|
167
88
|
theme.colors.primary,
|
|
168
89
|
theme.stateLayer.hoveredOpacity
|
|
169
90
|
),
|
|
170
|
-
pressedBackgroundColor: blendColor(
|
|
91
|
+
pressedBackgroundColor: (0, import_utils.blendColor)(
|
|
171
92
|
theme.colors.surfaceContainerLow,
|
|
172
93
|
theme.colors.primary,
|
|
173
94
|
theme.stateLayer.pressedOpacity
|
|
@@ -183,12 +104,12 @@ function getVariantColors(theme, variant) {
|
|
|
183
104
|
textColor: theme.colors.onSecondaryContainer,
|
|
184
105
|
borderColor: theme.colors.secondaryContainer,
|
|
185
106
|
borderWidth: 0,
|
|
186
|
-
hoveredBackgroundColor: blendColor(
|
|
107
|
+
hoveredBackgroundColor: (0, import_utils.blendColor)(
|
|
187
108
|
theme.colors.secondaryContainer,
|
|
188
109
|
theme.colors.onSecondaryContainer,
|
|
189
110
|
theme.stateLayer.hoveredOpacity
|
|
190
111
|
),
|
|
191
|
-
pressedBackgroundColor: blendColor(
|
|
112
|
+
pressedBackgroundColor: (0, import_utils.blendColor)(
|
|
192
113
|
theme.colors.secondaryContainer,
|
|
193
114
|
theme.colors.onSecondaryContainer,
|
|
194
115
|
theme.stateLayer.pressedOpacity
|
|
@@ -203,12 +124,12 @@ function getVariantColors(theme, variant) {
|
|
|
203
124
|
textColor: theme.colors.onPrimary,
|
|
204
125
|
borderColor: theme.colors.primary,
|
|
205
126
|
borderWidth: 0,
|
|
206
|
-
hoveredBackgroundColor: blendColor(
|
|
127
|
+
hoveredBackgroundColor: (0, import_utils.blendColor)(
|
|
207
128
|
theme.colors.primary,
|
|
208
129
|
theme.colors.onPrimary,
|
|
209
130
|
theme.stateLayer.hoveredOpacity
|
|
210
131
|
),
|
|
211
|
-
pressedBackgroundColor: blendColor(
|
|
132
|
+
pressedBackgroundColor: (0, import_utils.blendColor)(
|
|
212
133
|
theme.colors.primary,
|
|
213
134
|
theme.colors.onPrimary,
|
|
214
135
|
theme.stateLayer.pressedOpacity
|
|
@@ -240,33 +161,33 @@ function applyColorOverrides(theme, colors, containerColor, contentColor) {
|
|
|
240
161
|
const overlay = contentColor != null ? contentColor : colors.textColor;
|
|
241
162
|
result.backgroundColor = containerColor;
|
|
242
163
|
result.borderColor = containerColor;
|
|
243
|
-
result.hoveredBackgroundColor = blendColor(
|
|
164
|
+
result.hoveredBackgroundColor = (0, import_utils.blendColor)(
|
|
244
165
|
containerColor,
|
|
245
166
|
overlay,
|
|
246
167
|
theme.stateLayer.hoveredOpacity
|
|
247
168
|
);
|
|
248
|
-
result.pressedBackgroundColor = blendColor(
|
|
169
|
+
result.pressedBackgroundColor = (0, import_utils.blendColor)(
|
|
249
170
|
containerColor,
|
|
250
171
|
overlay,
|
|
251
172
|
theme.stateLayer.pressedOpacity
|
|
252
173
|
);
|
|
253
174
|
} else if (contentColor) {
|
|
254
175
|
if (colors.backgroundColor === "transparent") {
|
|
255
|
-
result.hoveredBackgroundColor = alphaColor(
|
|
176
|
+
result.hoveredBackgroundColor = (0, import_utils.alphaColor)(
|
|
256
177
|
contentColor,
|
|
257
178
|
theme.stateLayer.hoveredOpacity
|
|
258
179
|
);
|
|
259
|
-
result.pressedBackgroundColor = alphaColor(
|
|
180
|
+
result.pressedBackgroundColor = (0, import_utils.alphaColor)(
|
|
260
181
|
contentColor,
|
|
261
182
|
theme.stateLayer.pressedOpacity
|
|
262
183
|
);
|
|
263
184
|
} else {
|
|
264
|
-
result.hoveredBackgroundColor = blendColor(
|
|
185
|
+
result.hoveredBackgroundColor = (0, import_utils.blendColor)(
|
|
265
186
|
colors.backgroundColor,
|
|
266
187
|
contentColor,
|
|
267
188
|
theme.stateLayer.hoveredOpacity
|
|
268
189
|
);
|
|
269
|
-
result.pressedBackgroundColor = blendColor(
|
|
190
|
+
result.pressedBackgroundColor = (0, import_utils.blendColor)(
|
|
270
191
|
colors.backgroundColor,
|
|
271
192
|
contentColor,
|
|
272
193
|
theme.stateLayer.pressedOpacity
|
|
@@ -290,11 +211,11 @@ function createStyles(theme, variant, hasLeadingIcon, hasTrailingIcon, container
|
|
|
290
211
|
hasLeadingIcon,
|
|
291
212
|
hasTrailingIcon
|
|
292
213
|
);
|
|
293
|
-
const elevationLevel0 = elevationStyle(theme.elevation.level0);
|
|
294
|
-
const elevationLevel1 = elevationStyle(theme.elevation.level1);
|
|
295
|
-
const elevationLevel2 = elevationStyle(theme.elevation.level2);
|
|
214
|
+
const elevationLevel0 = (0, import_utils.elevationStyle)(theme.elevation.level0);
|
|
215
|
+
const elevationLevel1 = (0, import_utils.elevationStyle)(theme.elevation.level1);
|
|
216
|
+
const elevationLevel2 = (0, import_utils.elevationStyle)(theme.elevation.level2);
|
|
296
217
|
const baseElevation = variant === "elevated" ? elevationLevel1 : elevationLevel0;
|
|
297
|
-
return
|
|
218
|
+
return import_react_native.StyleSheet.create({
|
|
298
219
|
container: {
|
|
299
220
|
alignSelf: "flex-start",
|
|
300
221
|
alignItems: "center",
|
|
@@ -393,8 +314,9 @@ function Button({
|
|
|
393
314
|
),
|
|
394
315
|
[theme, variant, hasLeading, hasTrailing, containerColor, contentColor]
|
|
395
316
|
);
|
|
317
|
+
const MaterialCommunityIcons = leadingIcon || trailingIcon ? (0, import_utils2.getMaterialCommunityIcons)() : null;
|
|
396
318
|
const resolvedIconColor = (0, import_react.useMemo)(() => {
|
|
397
|
-
const base =
|
|
319
|
+
const base = import_react_native3.StyleSheet.flatten([
|
|
398
320
|
styles.label,
|
|
399
321
|
isDisabled ? styles.disabledLabel : void 0
|
|
400
322
|
]);
|
|
@@ -409,12 +331,12 @@ function Button({
|
|
|
409
331
|
[isDisabled, styles.disabledLabel, styles.label, labelStyleOverride]
|
|
410
332
|
);
|
|
411
333
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
412
|
-
|
|
334
|
+
import_react_native2.Pressable,
|
|
413
335
|
{
|
|
414
336
|
...props,
|
|
415
337
|
accessibilityRole: "button",
|
|
416
338
|
accessibilityState: { disabled: isDisabled },
|
|
417
|
-
hitSlop:
|
|
339
|
+
hitSlop: import_react_native2.Platform.OS === "web" ? void 0 : 4,
|
|
418
340
|
disabled: isDisabled,
|
|
419
341
|
style: resolveStyle(
|
|
420
342
|
styles.container,
|
|
@@ -426,7 +348,7 @@ function Button({
|
|
|
426
348
|
),
|
|
427
349
|
children: [
|
|
428
350
|
leadingIcon ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
429
|
-
|
|
351
|
+
MaterialCommunityIcons,
|
|
430
352
|
{
|
|
431
353
|
name: leadingIcon,
|
|
432
354
|
size: iconSize,
|
|
@@ -434,9 +356,9 @@ function Button({
|
|
|
434
356
|
style: styles.leadingIcon
|
|
435
357
|
}
|
|
436
358
|
) : null,
|
|
437
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
359
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native4.Text, { style: computedLabelStyle, children }),
|
|
438
360
|
trailingIcon ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
439
|
-
|
|
361
|
+
MaterialCommunityIcons,
|
|
440
362
|
{
|
|
441
363
|
name: trailingIcon,
|
|
442
364
|
size: iconSize,
|
package/dist/card/index.js
CHANGED
|
@@ -26,94 +26,25 @@ module.exports = __toCommonJS(card_exports);
|
|
|
26
26
|
|
|
27
27
|
// src/card/Card.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
31
|
|
|
32
32
|
// src/card/styles.ts
|
|
33
|
-
var import_react_native2 = 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
|
-
function blendColor(base, overlay, overlayAlpha) {
|
|
61
|
-
const baseChannels = parseHexColor(base);
|
|
62
|
-
const overlayChannels = parseHexColor(overlay);
|
|
63
|
-
const boundedAlpha = clampAlpha(overlayAlpha);
|
|
64
|
-
if (!baseChannels || !overlayChannels) {
|
|
65
|
-
return alphaColor(overlay, boundedAlpha);
|
|
66
|
-
}
|
|
67
|
-
const r = Math.round(
|
|
68
|
-
(1 - boundedAlpha) * baseChannels.r + boundedAlpha * overlayChannels.r
|
|
69
|
-
);
|
|
70
|
-
const g = Math.round(
|
|
71
|
-
(1 - boundedAlpha) * baseChannels.g + boundedAlpha * overlayChannels.g
|
|
72
|
-
);
|
|
73
|
-
const b = Math.round(
|
|
74
|
-
(1 - boundedAlpha) * baseChannels.b + boundedAlpha * overlayChannels.b
|
|
75
|
-
);
|
|
76
|
-
return `rgb(${r}, ${g}, ${b})`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// src/utils/elevation.ts
|
|
80
33
|
var import_react_native = require("react-native");
|
|
81
|
-
|
|
82
|
-
if (import_react_native.Platform.OS === "web") {
|
|
83
|
-
const { shadowOffset, shadowOpacity, shadowRadius } = level;
|
|
84
|
-
if (shadowOpacity === 0) {
|
|
85
|
-
return { boxShadow: "none" };
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
boxShadow: `${shadowOffset.width}px ${shadowOffset.height}px ${shadowRadius}px rgba(0, 0, 0, ${shadowOpacity})`
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
shadowColor: level.shadowColor,
|
|
93
|
-
shadowOffset: {
|
|
94
|
-
width: level.shadowOffset.width,
|
|
95
|
-
height: level.shadowOffset.height
|
|
96
|
-
},
|
|
97
|
-
shadowOpacity: level.shadowOpacity,
|
|
98
|
-
shadowRadius: level.shadowRadius,
|
|
99
|
-
elevation: level.elevation
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// src/card/styles.ts
|
|
34
|
+
var import_utils = require("@onlynative/utils");
|
|
104
35
|
function getVariantColors(theme, variant) {
|
|
105
|
-
const disabledContainerColor = alphaColor(theme.colors.onSurface, 0.12);
|
|
106
|
-
const disabledOutlineColor = alphaColor(theme.colors.onSurface, 0.12);
|
|
36
|
+
const disabledContainerColor = (0, import_utils.alphaColor)(theme.colors.onSurface, 0.12);
|
|
37
|
+
const disabledOutlineColor = (0, import_utils.alphaColor)(theme.colors.onSurface, 0.12);
|
|
107
38
|
if (variant === "outlined") {
|
|
108
39
|
return {
|
|
109
40
|
backgroundColor: theme.colors.surface,
|
|
110
41
|
borderColor: theme.colors.outline,
|
|
111
42
|
borderWidth: 1,
|
|
112
|
-
hoveredBackgroundColor: alphaColor(
|
|
43
|
+
hoveredBackgroundColor: (0, import_utils.alphaColor)(
|
|
113
44
|
theme.colors.onSurface,
|
|
114
45
|
theme.stateLayer.hoveredOpacity
|
|
115
46
|
),
|
|
116
|
-
pressedBackgroundColor: alphaColor(
|
|
47
|
+
pressedBackgroundColor: (0, import_utils.alphaColor)(
|
|
117
48
|
theme.colors.onSurface,
|
|
118
49
|
theme.stateLayer.pressedOpacity
|
|
119
50
|
),
|
|
@@ -126,12 +57,12 @@ function getVariantColors(theme, variant) {
|
|
|
126
57
|
backgroundColor: theme.colors.surfaceContainerHighest,
|
|
127
58
|
borderColor: "transparent",
|
|
128
59
|
borderWidth: 0,
|
|
129
|
-
hoveredBackgroundColor: blendColor(
|
|
60
|
+
hoveredBackgroundColor: (0, import_utils.blendColor)(
|
|
130
61
|
theme.colors.surfaceContainerHighest,
|
|
131
62
|
theme.colors.onSurface,
|
|
132
63
|
theme.stateLayer.hoveredOpacity
|
|
133
64
|
),
|
|
134
|
-
pressedBackgroundColor: blendColor(
|
|
65
|
+
pressedBackgroundColor: (0, import_utils.blendColor)(
|
|
135
66
|
theme.colors.surfaceContainerHighest,
|
|
136
67
|
theme.colors.onSurface,
|
|
137
68
|
theme.stateLayer.pressedOpacity
|
|
@@ -144,12 +75,12 @@ function getVariantColors(theme, variant) {
|
|
|
144
75
|
backgroundColor: theme.colors.surface,
|
|
145
76
|
borderColor: "transparent",
|
|
146
77
|
borderWidth: 0,
|
|
147
|
-
hoveredBackgroundColor: blendColor(
|
|
78
|
+
hoveredBackgroundColor: (0, import_utils.blendColor)(
|
|
148
79
|
theme.colors.surface,
|
|
149
80
|
theme.colors.onSurface,
|
|
150
81
|
theme.stateLayer.hoveredOpacity
|
|
151
82
|
),
|
|
152
|
-
pressedBackgroundColor: blendColor(
|
|
83
|
+
pressedBackgroundColor: (0, import_utils.blendColor)(
|
|
153
84
|
theme.colors.surface,
|
|
154
85
|
theme.colors.onSurface,
|
|
155
86
|
theme.stateLayer.pressedOpacity
|
|
@@ -165,12 +96,12 @@ function applyColorOverrides(theme, colors, containerColor) {
|
|
|
165
96
|
backgroundColor: containerColor,
|
|
166
97
|
borderColor: containerColor,
|
|
167
98
|
borderWidth: 0,
|
|
168
|
-
hoveredBackgroundColor: blendColor(
|
|
99
|
+
hoveredBackgroundColor: (0, import_utils.blendColor)(
|
|
169
100
|
containerColor,
|
|
170
101
|
theme.colors.onSurface,
|
|
171
102
|
theme.stateLayer.hoveredOpacity
|
|
172
103
|
),
|
|
173
|
-
pressedBackgroundColor: blendColor(
|
|
104
|
+
pressedBackgroundColor: (0, import_utils.blendColor)(
|
|
174
105
|
containerColor,
|
|
175
106
|
theme.colors.onSurface,
|
|
176
107
|
theme.stateLayer.pressedOpacity
|
|
@@ -180,11 +111,11 @@ function applyColorOverrides(theme, colors, containerColor) {
|
|
|
180
111
|
function createStyles(theme, variant, containerColor) {
|
|
181
112
|
const baseColors = getVariantColors(theme, variant);
|
|
182
113
|
const colors = applyColorOverrides(theme, baseColors, containerColor);
|
|
183
|
-
const elevationLevel0 = elevationStyle(theme.elevation.level0);
|
|
184
|
-
const elevationLevel1 = elevationStyle(theme.elevation.level1);
|
|
185
|
-
const elevationLevel2 = elevationStyle(theme.elevation.level2);
|
|
114
|
+
const elevationLevel0 = (0, import_utils.elevationStyle)(theme.elevation.level0);
|
|
115
|
+
const elevationLevel1 = (0, import_utils.elevationStyle)(theme.elevation.level1);
|
|
116
|
+
const elevationLevel2 = (0, import_utils.elevationStyle)(theme.elevation.level2);
|
|
186
117
|
const baseElevation = variant === "elevated" ? elevationLevel1 : elevationLevel0;
|
|
187
|
-
return
|
|
118
|
+
return import_react_native.StyleSheet.create({
|
|
188
119
|
container: {
|
|
189
120
|
borderRadius: theme.shape.cornerMedium,
|
|
190
121
|
backgroundColor: colors.backgroundColor,
|
|
@@ -234,7 +165,7 @@ function Card({
|
|
|
234
165
|
[theme, variant, containerColor]
|
|
235
166
|
);
|
|
236
167
|
if (!isInteractive) {
|
|
237
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
168
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { ...props, style: [styles.container, style], children });
|
|
238
169
|
}
|
|
239
170
|
const resolvedStyle = (state) => [
|
|
240
171
|
styles.container,
|
|
@@ -245,16 +176,16 @@ function Card({
|
|
|
245
176
|
typeof style === "function" ? style(state) : style
|
|
246
177
|
];
|
|
247
178
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
248
|
-
|
|
179
|
+
import_react_native2.Pressable,
|
|
249
180
|
{
|
|
250
181
|
...props,
|
|
251
182
|
role: "button",
|
|
252
183
|
accessibilityState: { disabled: isDisabled },
|
|
253
|
-
hitSlop:
|
|
184
|
+
hitSlop: import_react_native2.Platform.OS === "web" ? void 0 : 4,
|
|
254
185
|
disabled: isDisabled,
|
|
255
186
|
onPress,
|
|
256
187
|
style: resolvedStyle,
|
|
257
|
-
children: isDisabled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
188
|
+
children: isDisabled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: styles.disabledContent, children }) : children
|
|
258
189
|
}
|
|
259
190
|
);
|
|
260
191
|
}
|
package/dist/checkbox/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/checkbox/index.ts
|
|
@@ -35,73 +25,28 @@ __export(checkbox_exports, {
|
|
|
35
25
|
module.exports = __toCommonJS(checkbox_exports);
|
|
36
26
|
|
|
37
27
|
// src/checkbox/Checkbox.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/checkbox/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/checkbox/styles.ts
|
|
35
|
+
var import_utils = require("@onlynative/utils");
|
|
91
36
|
function getColors(theme, checked) {
|
|
92
|
-
const disabledOnSurface38 = alphaColor(theme.colors.onSurface, 0.38);
|
|
37
|
+
const disabledOnSurface38 = (0, import_utils.alphaColor)(theme.colors.onSurface, 0.38);
|
|
93
38
|
if (checked) {
|
|
94
39
|
return {
|
|
95
40
|
backgroundColor: theme.colors.primary,
|
|
96
41
|
borderColor: "transparent",
|
|
97
42
|
borderWidth: 0,
|
|
98
43
|
iconColor: theme.colors.onPrimary,
|
|
99
|
-
hoveredBackgroundColor: blendColor(
|
|
44
|
+
hoveredBackgroundColor: (0, import_utils.blendColor)(
|
|
100
45
|
theme.colors.primary,
|
|
101
46
|
theme.colors.onPrimary,
|
|
102
47
|
theme.stateLayer.hoveredOpacity
|
|
103
48
|
),
|
|
104
|
-
pressedBackgroundColor: blendColor(
|
|
49
|
+
pressedBackgroundColor: (0, import_utils.blendColor)(
|
|
105
50
|
theme.colors.primary,
|
|
106
51
|
theme.colors.onPrimary,
|
|
107
52
|
theme.stateLayer.pressedOpacity
|
|
@@ -117,11 +62,11 @@ function getColors(theme, checked) {
|
|
|
117
62
|
borderColor: theme.colors.onSurfaceVariant,
|
|
118
63
|
borderWidth: 2,
|
|
119
64
|
iconColor: "transparent",
|
|
120
|
-
hoveredBackgroundColor: alphaColor(
|
|
65
|
+
hoveredBackgroundColor: (0, import_utils.alphaColor)(
|
|
121
66
|
theme.colors.onSurface,
|
|
122
67
|
theme.stateLayer.hoveredOpacity
|
|
123
68
|
),
|
|
124
|
-
pressedBackgroundColor: alphaColor(
|
|
69
|
+
pressedBackgroundColor: (0, import_utils.alphaColor)(
|
|
125
70
|
theme.colors.onSurface,
|
|
126
71
|
theme.stateLayer.pressedOpacity
|
|
127
72
|
),
|
|
@@ -141,12 +86,12 @@ function applyColorOverrides(theme, colors, containerColor, contentColor) {
|
|
|
141
86
|
const overlay = contentColor != null ? contentColor : colors.iconColor;
|
|
142
87
|
result.backgroundColor = containerColor;
|
|
143
88
|
result.borderColor = containerColor;
|
|
144
|
-
result.hoveredBackgroundColor = blendColor(
|
|
89
|
+
result.hoveredBackgroundColor = (0, import_utils.blendColor)(
|
|
145
90
|
containerColor,
|
|
146
91
|
overlay,
|
|
147
92
|
theme.stateLayer.hoveredOpacity
|
|
148
93
|
);
|
|
149
|
-
result.pressedBackgroundColor = blendColor(
|
|
94
|
+
result.pressedBackgroundColor = (0, import_utils.blendColor)(
|
|
150
95
|
containerColor,
|
|
151
96
|
overlay,
|
|
152
97
|
theme.stateLayer.pressedOpacity
|
|
@@ -237,6 +182,7 @@ function Checkbox({
|
|
|
237
182
|
}) {
|
|
238
183
|
const isDisabled = Boolean(disabled);
|
|
239
184
|
const isChecked = Boolean(value);
|
|
185
|
+
const MaterialCommunityIcons = isChecked ? (0, import_utils2.getMaterialCommunityIcons)() : null;
|
|
240
186
|
const theme = (0, import_core.useTheme)();
|
|
241
187
|
const styles = (0, import_react.useMemo)(
|
|
242
188
|
() => createStyles(theme, isChecked, containerColor, contentColor),
|
|
@@ -275,7 +221,7 @@ function Checkbox({
|
|
|
275
221
|
style
|
|
276
222
|
),
|
|
277
223
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [styles.box, isDisabled ? styles.disabledBox : void 0], children: isChecked ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
278
|
-
|
|
224
|
+
MaterialCommunityIcons,
|
|
279
225
|
{
|
|
280
226
|
name: "check",
|
|
281
227
|
size: 14,
|