zkit-ui 1.0.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/README.md +267 -0
- package/dist/ComponentLibProvider.d.ts +15 -0
- package/dist/ComponentLibProvider.d.ts.map +1 -0
- package/dist/ComponentLibProvider.js +18 -0
- package/dist/assets/animations/spinner.json +1 -0
- package/dist/assets/icons/check.svg +4 -0
- package/dist/assets/icons/toast/error.webp +0 -0
- package/dist/assets/icons/toast/success.webp +0 -0
- package/dist/assets/icons/toast/warning.webp +0 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +42 -0
- package/dist/i18n/I18nProvider.d.ts +11 -0
- package/dist/i18n/I18nProvider.d.ts.map +1 -0
- package/dist/i18n/I18nProvider.js +84 -0
- package/dist/i18n/locale.d.ts +7 -0
- package/dist/i18n/locale.d.ts.map +1 -0
- package/dist/i18n/locale.js +87 -0
- package/dist/i18n/locales/de.d.ts +51 -0
- package/dist/i18n/locales/de.d.ts.map +1 -0
- package/dist/i18n/locales/de.js +62 -0
- package/dist/i18n/locales/en-US.d.ts +51 -0
- package/dist/i18n/locales/en-US.d.ts.map +1 -0
- package/dist/i18n/locales/en-US.js +62 -0
- package/dist/i18n/locales/index.d.ts +9 -0
- package/dist/i18n/locales/index.d.ts.map +1 -0
- package/dist/i18n/locales/index.js +23 -0
- package/dist/i18n/locales/ja.d.ts +51 -0
- package/dist/i18n/locales/ja.d.ts.map +1 -0
- package/dist/i18n/locales/ja.js +62 -0
- package/dist/i18n/locales/zh-CN.d.ts +51 -0
- package/dist/i18n/locales/zh-CN.d.ts.map +1 -0
- package/dist/i18n/locales/zh-CN.js +62 -0
- package/dist/i18n/locales/zh-TW.d.ts +51 -0
- package/dist/i18n/locales/zh-TW.d.ts.map +1 -0
- package/dist/i18n/locales/zh-TW.js +62 -0
- package/dist/i18n/types.d.ts +11 -0
- package/dist/i18n/types.d.ts.map +1 -0
- package/dist/i18n/types.js +2 -0
- package/dist/i18n/useI18n.d.ts +2 -0
- package/dist/i18n/useI18n.d.ts.map +1 -0
- package/dist/i18n/useI18n.js +41 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +90 -0
- package/dist/services/ActionDialogService/ActionDialog.d.ts +4 -0
- package/dist/services/ActionDialogService/ActionDialog.d.ts.map +1 -0
- package/dist/services/ActionDialogService/ActionDialog.js +531 -0
- package/dist/services/ActionDialogService/index.d.ts +4 -0
- package/dist/services/ActionDialogService/index.d.ts.map +1 -0
- package/dist/services/ActionDialogService/index.js +8 -0
- package/dist/services/ActionDialogService/service.d.ts +7 -0
- package/dist/services/ActionDialogService/service.d.ts.map +1 -0
- package/dist/services/ActionDialogService/service.js +309 -0
- package/dist/services/ActionDialogService/shared.d.ts +17 -0
- package/dist/services/ActionDialogService/shared.d.ts.map +1 -0
- package/dist/services/ActionDialogService/shared.js +167 -0
- package/dist/services/ActionDialogService/types.d.ts +160 -0
- package/dist/services/ActionDialogService/types.d.ts.map +1 -0
- package/dist/services/ActionDialogService/types.js +2 -0
- package/dist/services/CardToastService/index.d.ts +115 -0
- package/dist/services/CardToastService/index.d.ts.map +1 -0
- package/dist/services/CardToastService/index.js +899 -0
- package/dist/services/ImagePreviewService/index.d.ts +179 -0
- package/dist/services/ImagePreviewService/index.d.ts.map +1 -0
- package/dist/services/ImagePreviewService/index.js +1383 -0
- package/dist/services/LoadingService/index.d.ts +146 -0
- package/dist/services/LoadingService/index.d.ts.map +1 -0
- package/dist/services/LoadingService/index.js +827 -0
- package/dist/services/PermissionPurposeDialogService/index.d.ts +99 -0
- package/dist/services/PermissionPurposeDialogService/index.d.ts.map +1 -0
- package/dist/services/PermissionPurposeDialogService/index.js +360 -0
- package/dist/services/PickerService/index.d.ts +128 -0
- package/dist/services/PickerService/index.d.ts.map +1 -0
- package/dist/services/PickerService/index.js +250 -0
- package/dist/theme/ThemeProvider.d.ts +15 -0
- package/dist/theme/ThemeProvider.d.ts.map +1 -0
- package/dist/theme/ThemeProvider.js +61 -0
- package/dist/theme/defaultTheme.d.ts +3 -0
- package/dist/theme/defaultTheme.d.ts.map +1 -0
- package/dist/theme/defaultTheme.js +28 -0
- package/dist/theme/mergeTheme.d.ts +3 -0
- package/dist/theme/mergeTheme.d.ts.map +1 -0
- package/dist/theme/mergeTheme.js +19 -0
- package/dist/theme/types.d.ts +17 -0
- package/dist/theme/types.d.ts.map +1 -0
- package/dist/theme/types.js +2 -0
- package/dist/theme/useTheme.d.ts +2 -0
- package/dist/theme/useTheme.d.ts.map +1 -0
- package/dist/theme/useTheme.js +46 -0
- package/dist/ui/Accordion/index.d.ts +99 -0
- package/dist/ui/Accordion/index.d.ts.map +1 -0
- package/dist/ui/Accordion/index.js +777 -0
- package/dist/ui/AddressCascader/index.d.ts +58 -0
- package/dist/ui/AddressCascader/index.d.ts.map +1 -0
- package/dist/ui/AddressCascader/index.js +710 -0
- package/dist/ui/BetweenTime/index.d.ts +82 -0
- package/dist/ui/BetweenTime/index.d.ts.map +1 -0
- package/dist/ui/BetweenTime/index.js +702 -0
- package/dist/ui/Button/index.d.ts +93 -0
- package/dist/ui/Button/index.d.ts.map +1 -0
- package/dist/ui/Button/index.js +832 -0
- package/dist/ui/Checkbox/index.d.ts +103 -0
- package/dist/ui/Checkbox/index.d.ts.map +1 -0
- package/dist/ui/Checkbox/index.js +694 -0
- package/dist/ui/DatePicker/index.d.ts +5 -0
- package/dist/ui/DatePicker/index.d.ts.map +1 -0
- package/dist/ui/DatePicker/index.js +157 -0
- package/dist/ui/DatePicker/types.d.ts +99 -0
- package/dist/ui/DatePicker/types.d.ts.map +1 -0
- package/dist/ui/DatePicker/types.js +2 -0
- package/dist/ui/DatePicker/utils.d.ts +32 -0
- package/dist/ui/DatePicker/utils.d.ts.map +1 -0
- package/dist/ui/DatePicker/utils.js +316 -0
- package/dist/ui/LinkedScroll/index.d.ts +78 -0
- package/dist/ui/LinkedScroll/index.d.ts.map +1 -0
- package/dist/ui/LinkedScroll/index.js +470 -0
- package/dist/ui/LoadingSpinner/index.d.ts +8 -0
- package/dist/ui/LoadingSpinner/index.d.ts.map +1 -0
- package/dist/ui/LoadingSpinner/index.js +122 -0
- package/dist/ui/Picker/actionBar.d.ts +14 -0
- package/dist/ui/Picker/actionBar.d.ts.map +1 -0
- package/dist/ui/Picker/actionBar.js +28 -0
- package/dist/ui/Picker/index.d.ts +5 -0
- package/dist/ui/Picker/index.d.ts.map +1 -0
- package/dist/ui/Picker/index.js +412 -0
- package/dist/ui/Picker/types.d.ts +80 -0
- package/dist/ui/Picker/types.d.ts.map +1 -0
- package/dist/ui/Picker/types.js +2 -0
- package/dist/ui/Picker/utils.d.ts +27 -0
- package/dist/ui/Picker/utils.d.ts.map +1 -0
- package/dist/ui/Picker/utils.js +182 -0
- package/dist/ui/Radio/index.d.ts +95 -0
- package/dist/ui/Radio/index.d.ts.map +1 -0
- package/dist/ui/Radio/index.js +633 -0
- package/dist/ui/Sheet/index.d.ts +12 -0
- package/dist/ui/Sheet/index.d.ts.map +1 -0
- package/dist/ui/Sheet/index.js +832 -0
- package/dist/ui/Sheet/nativeBottom.d.ts +52 -0
- package/dist/ui/Sheet/nativeBottom.d.ts.map +1 -0
- package/dist/ui/Sheet/nativeBottom.js +442 -0
- package/dist/ui/Sheet/nativeBottom.web.d.ts +18 -0
- package/dist/ui/Sheet/nativeBottom.web.d.ts.map +1 -0
- package/dist/ui/Sheet/nativeBottom.web.js +46 -0
- package/dist/ui/Sheet/slots.d.ts +5 -0
- package/dist/ui/Sheet/slots.d.ts.map +1 -0
- package/dist/ui/Sheet/slots.js +40 -0
- package/dist/ui/Sheet/types.d.ts +131 -0
- package/dist/ui/Sheet/types.d.ts.map +1 -0
- package/dist/ui/Sheet/types.js +2 -0
- package/dist/ui/SliderCaptcha/index.d.ts +57 -0
- package/dist/ui/SliderCaptcha/index.d.ts.map +1 -0
- package/dist/ui/SliderCaptcha/index.js +586 -0
- package/dist/ui/Switch/index.d.ts +72 -0
- package/dist/ui/Switch/index.d.ts.map +1 -0
- package/dist/ui/Switch/index.js +671 -0
- package/dist/ui/Text/index.d.ts +41 -0
- package/dist/ui/Text/index.d.ts.map +1 -0
- package/dist/ui/Text/index.js +325 -0
- package/dist/ui/TextInput/TextInputPrimitive.d.ts +8 -0
- package/dist/ui/TextInput/TextInputPrimitive.d.ts.map +1 -0
- package/dist/ui/TextInput/TextInputPrimitive.js +54 -0
- package/dist/ui/TextInput/index.d.ts +89 -0
- package/dist/ui/TextInput/index.d.ts.map +1 -0
- package/dist/ui/TextInput/index.js +545 -0
- package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.d.ts +39 -0
- package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.d.ts.map +1 -0
- package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.js +60 -0
- package/dist/ui/WheelColumn/constants.d.ts +2 -0
- package/dist/ui/WheelColumn/constants.d.ts.map +1 -0
- package/dist/ui/WheelColumn/constants.js +4 -0
- package/dist/ui/WheelColumn/index.d.ts +59 -0
- package/dist/ui/WheelColumn/index.d.ts.map +1 -0
- package/dist/ui/WheelColumn/index.js +547 -0
- package/ios/ZKitWheelPicker.h +18 -0
- package/ios/ZKitWheelPicker.mm +230 -0
- package/ios/ZKitWheelPickerLabel.h +10 -0
- package/ios/ZKitWheelPickerLabel.mm +31 -0
- package/ios/ZKitWheelPickerManager.h +5 -0
- package/ios/ZKitWheelPickerManager.mm +53 -0
- package/package.json +75 -0
- package/react-native.config.js +10 -0
- package/src/ComponentLibProvider.tsx +56 -0
- package/src/assets/animations/spinner.json +1 -0
- package/src/assets/icons/check.svg +4 -0
- package/src/assets/icons/toast/error.webp +0 -0
- package/src/assets/icons/toast/success.webp +0 -0
- package/src/assets/icons/toast/warning.webp +0 -0
- package/src/config.ts +65 -0
- package/src/i18n/I18nProvider.tsx +69 -0
- package/src/i18n/locale.ts +108 -0
- package/src/i18n/locales/de.ts +67 -0
- package/src/i18n/locales/en-US.ts +67 -0
- package/src/i18n/locales/index.ts +19 -0
- package/src/i18n/locales/ja.ts +67 -0
- package/src/i18n/locales/zh-CN.ts +67 -0
- package/src/i18n/locales/zh-TW.ts +67 -0
- package/src/i18n/types.ts +21 -0
- package/src/i18n/useI18n.ts +7 -0
- package/src/index.ts +395 -0
- package/src/services/ActionDialogService/ActionDialog.tsx +756 -0
- package/src/services/ActionDialogService/README.md +146 -0
- package/src/services/ActionDialogService/index.tsx +39 -0
- package/src/services/ActionDialogService/service.tsx +355 -0
- package/src/services/ActionDialogService/shared.ts +204 -0
- package/src/services/ActionDialogService/types.ts +197 -0
- package/src/services/CardToastService/README.md +128 -0
- package/src/services/CardToastService/index.tsx +1284 -0
- package/src/services/ImagePreviewService/README.md +67 -0
- package/src/services/ImagePreviewService/index.tsx +2148 -0
- package/src/services/LoadingService/README.md +128 -0
- package/src/services/LoadingService/index.tsx +1113 -0
- package/src/services/PermissionPurposeDialogService/README.md +80 -0
- package/src/services/PermissionPurposeDialogService/index.tsx +449 -0
- package/src/services/PickerService/README.md +154 -0
- package/src/services/PickerService/index.tsx +410 -0
- package/src/theme/ThemeProvider.tsx +40 -0
- package/src/theme/defaultTheme.ts +30 -0
- package/src/theme/mergeTheme.ts +16 -0
- package/src/theme/types.ts +36 -0
- package/src/theme/useTheme.ts +10 -0
- package/src/types/svg.d.ts +9 -0
- package/src/types/vant-area-data.d.ts +19 -0
- package/src/ui/Accordion/README.md +67 -0
- package/src/ui/Accordion/index.tsx +1221 -0
- package/src/ui/AddressCascader/README.md +144 -0
- package/src/ui/AddressCascader/index.tsx +1084 -0
- package/src/ui/BetweenTime/README.md +490 -0
- package/src/ui/BetweenTime/index.tsx +1001 -0
- package/src/ui/Button/README.md +186 -0
- package/src/ui/Button/index.tsx +1356 -0
- package/src/ui/Checkbox/README.md +211 -0
- package/src/ui/Checkbox/index.tsx +1231 -0
- package/src/ui/DatePicker/README.md +117 -0
- package/src/ui/DatePicker/index.tsx +295 -0
- package/src/ui/DatePicker/types.ts +115 -0
- package/src/ui/DatePicker/utils.ts +405 -0
- package/src/ui/LinkedScroll/README.md +55 -0
- package/src/ui/LinkedScroll/index.tsx +809 -0
- package/src/ui/LoadingSpinner/index.tsx +104 -0
- package/src/ui/Picker/README.md +190 -0
- package/src/ui/Picker/actionBar.tsx +70 -0
- package/src/ui/Picker/index.tsx +694 -0
- package/src/ui/Picker/types.ts +94 -0
- package/src/ui/Picker/utils.ts +239 -0
- package/src/ui/Radio/README.md +207 -0
- package/src/ui/Radio/index.tsx +1117 -0
- package/src/ui/Sheet/README.md +82 -0
- package/src/ui/Sheet/index.tsx +1163 -0
- package/src/ui/Sheet/nativeBottom.tsx +683 -0
- package/src/ui/Sheet/nativeBottom.web.tsx +40 -0
- package/src/ui/Sheet/slots.tsx +75 -0
- package/src/ui/Sheet/types.ts +195 -0
- package/src/ui/SliderCaptcha/README.md +61 -0
- package/src/ui/SliderCaptcha/index.tsx +816 -0
- package/src/ui/Switch/README.md +143 -0
- package/src/ui/Switch/index.tsx +1092 -0
- package/src/ui/Text/README.md +157 -0
- package/src/ui/Text/index.tsx +450 -0
- package/src/ui/TextInput/README.md +197 -0
- package/src/ui/TextInput/TextInputPrimitive.tsx +44 -0
- package/src/ui/TextInput/index.tsx +942 -0
- package/src/ui/WheelColumn/README.md +104 -0
- package/src/ui/WheelColumn/ZKitWheelPickerNativeComponent.tsx +68 -0
- package/src/ui/WheelColumn/constants.ts +1 -0
- package/src/ui/WheelColumn/index.tsx +826 -0
- package/zkit-ui.podspec +19 -0
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Switch = void 0;
|
|
37
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
|
+
const React = __importStar(require("react"));
|
|
39
|
+
const react_native_1 = require("react-native");
|
|
40
|
+
const react_native_reanimated_1 = __importStar(require("react-native-reanimated"));
|
|
41
|
+
const zkit_tools_1 = require("zkit-tools");
|
|
42
|
+
const useTheme_1 = require("../../theme/useTheme");
|
|
43
|
+
const LoadingSpinner_1 = require("../LoadingSpinner");
|
|
44
|
+
const Text_1 = require("../Text");
|
|
45
|
+
const SEMANTIC_COLORS = {
|
|
46
|
+
danger: '#DC2626',
|
|
47
|
+
error: '#DC2626',
|
|
48
|
+
info: '#2563EB',
|
|
49
|
+
success: '#16A34A',
|
|
50
|
+
warn: '#D97706',
|
|
51
|
+
warning: '#D97706',
|
|
52
|
+
};
|
|
53
|
+
const SIZE_TOKENS = {
|
|
54
|
+
sm: {
|
|
55
|
+
width: 44,
|
|
56
|
+
height: 26,
|
|
57
|
+
thumbInset: 2,
|
|
58
|
+
labelGap: 10,
|
|
59
|
+
textInset: 4,
|
|
60
|
+
textSize: 11,
|
|
61
|
+
textLineHeight: 13,
|
|
62
|
+
textSlotMinWidth: 24,
|
|
63
|
+
},
|
|
64
|
+
md: {
|
|
65
|
+
width: 52,
|
|
66
|
+
height: 32,
|
|
67
|
+
thumbInset: 3,
|
|
68
|
+
labelGap: 12,
|
|
69
|
+
textInset: 5,
|
|
70
|
+
textSize: 12,
|
|
71
|
+
textLineHeight: 14,
|
|
72
|
+
textSlotMinWidth: 30,
|
|
73
|
+
},
|
|
74
|
+
lg: {
|
|
75
|
+
width: 64,
|
|
76
|
+
height: 38,
|
|
77
|
+
thumbInset: 3,
|
|
78
|
+
labelGap: 14,
|
|
79
|
+
textInset: 6,
|
|
80
|
+
textSize: 13,
|
|
81
|
+
textLineHeight: 16,
|
|
82
|
+
textSlotMinWidth: 36,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
const PRESSED_OPACITY = 0.92;
|
|
86
|
+
const STATE_TEXT_WIDTH_FACTOR = 0.58;
|
|
87
|
+
const STATE_TEXT_WIDTH_GUARD_FACTOR = 0.25;
|
|
88
|
+
const VALUE_TIMING_DURATION = 180;
|
|
89
|
+
const PRESS_IN_DURATION = 90;
|
|
90
|
+
const PRESS_OUT_DURATION = 140;
|
|
91
|
+
const FOCUS_DURATION = 120;
|
|
92
|
+
function resolveSwitchMetrics(size) {
|
|
93
|
+
var _a;
|
|
94
|
+
const token = (_a = SIZE_TOKENS[size]) !== null && _a !== void 0 ? _a : SIZE_TOKENS.md;
|
|
95
|
+
return {
|
|
96
|
+
width: (0, zkit_tools_1.wp)(token.width),
|
|
97
|
+
height: (0, zkit_tools_1.wp)(token.height),
|
|
98
|
+
thumbInset: (0, zkit_tools_1.wp)(token.thumbInset),
|
|
99
|
+
labelGap: (0, zkit_tools_1.wp)(token.labelGap),
|
|
100
|
+
textInset: (0, zkit_tools_1.wp)(token.textInset),
|
|
101
|
+
textSize: (0, zkit_tools_1.wp)(token.textSize),
|
|
102
|
+
textLineHeight: (0, zkit_tools_1.wp)(token.textLineHeight),
|
|
103
|
+
textSlotMinWidth: (0, zkit_tools_1.wp)(token.textSlotMinWidth),
|
|
104
|
+
minTouchTarget: (0, zkit_tools_1.wp)(44),
|
|
105
|
+
focusRingWidth: (0, zkit_tools_1.wp)(2),
|
|
106
|
+
focusRingOffset: (0, zkit_tools_1.wp)(3),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function isProcessableColor(color) {
|
|
110
|
+
return (0, react_native_1.processColor)(color) != null;
|
|
111
|
+
}
|
|
112
|
+
function colorToRgba(color, alpha) {
|
|
113
|
+
const processed = (0, react_native_1.processColor)(color);
|
|
114
|
+
if (typeof processed !== 'number')
|
|
115
|
+
return undefined;
|
|
116
|
+
const normalized = processed >>> 0;
|
|
117
|
+
const r = (normalized >> 16) & 255;
|
|
118
|
+
const g = (normalized >> 8) & 255;
|
|
119
|
+
const b = normalized & 255;
|
|
120
|
+
const a = Math.max(0, Math.min(1, alpha));
|
|
121
|
+
return `rgba(${r},${g},${b},${a})`;
|
|
122
|
+
}
|
|
123
|
+
function colorToChannels(color) {
|
|
124
|
+
const processed = (0, react_native_1.processColor)(color);
|
|
125
|
+
if (typeof processed !== 'number')
|
|
126
|
+
return undefined;
|
|
127
|
+
const normalized = processed >>> 0;
|
|
128
|
+
return {
|
|
129
|
+
r: (normalized >> 16) & 255,
|
|
130
|
+
g: (normalized >> 8) & 255,
|
|
131
|
+
b: normalized & 255,
|
|
132
|
+
a: ((normalized >> 24) & 255) / 255,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function overlayColor(foreground, background, opacity) {
|
|
136
|
+
const fg = colorToChannels(foreground);
|
|
137
|
+
const bg = colorToChannels(background);
|
|
138
|
+
if (!fg || !bg)
|
|
139
|
+
return undefined;
|
|
140
|
+
const fgAlpha = Math.max(0, Math.min(1, opacity)) * fg.a;
|
|
141
|
+
const bgAlpha = bg.a;
|
|
142
|
+
const alpha = fgAlpha + bgAlpha * (1 - fgAlpha);
|
|
143
|
+
if (alpha <= 0)
|
|
144
|
+
return 'rgba(0,0,0,0)';
|
|
145
|
+
const r = Math.round((fg.r * fgAlpha + bg.r * bgAlpha * (1 - fgAlpha)) / alpha);
|
|
146
|
+
const g = Math.round((fg.g * fgAlpha + bg.g * bgAlpha * (1 - fgAlpha)) / alpha);
|
|
147
|
+
const b = Math.round((fg.b * fgAlpha + bg.b * bgAlpha * (1 - fgAlpha)) / alpha);
|
|
148
|
+
return `rgba(${r},${g},${b},${Math.round(alpha * 1000) / 1000})`;
|
|
149
|
+
}
|
|
150
|
+
function resolveColorToken(input, fallback, theme) {
|
|
151
|
+
var _a;
|
|
152
|
+
if (input == null)
|
|
153
|
+
return fallback;
|
|
154
|
+
const key = input.trim();
|
|
155
|
+
if (!key)
|
|
156
|
+
return fallback;
|
|
157
|
+
const resolved = key === 'primary'
|
|
158
|
+
? theme.colors.primary
|
|
159
|
+
: key === 'onPrimary'
|
|
160
|
+
? theme.colors.onPrimary
|
|
161
|
+
: key === 'secondary' || key === 'neutral'
|
|
162
|
+
? theme.colors.secondary
|
|
163
|
+
: key === 'onSecondary'
|
|
164
|
+
? theme.colors.onSecondary
|
|
165
|
+
: key === 'surface'
|
|
166
|
+
? theme.colors.surface
|
|
167
|
+
: key === 'onSurface'
|
|
168
|
+
? theme.colors.onSurface
|
|
169
|
+
: key === 'border'
|
|
170
|
+
? theme.colors.border
|
|
171
|
+
: key === 'muted'
|
|
172
|
+
? theme.colors.muted
|
|
173
|
+
: key === 'disabled'
|
|
174
|
+
? theme.colors.disabled
|
|
175
|
+
: (_a = SEMANTIC_COLORS[key]) !== null && _a !== void 0 ? _a : key;
|
|
176
|
+
return isProcessableColor(resolved) ? resolved : fallback;
|
|
177
|
+
}
|
|
178
|
+
function resolveTonePalette(tone, theme) {
|
|
179
|
+
if (tone === 'neutral') {
|
|
180
|
+
return {
|
|
181
|
+
checkedTrack: theme.colors.onSurface,
|
|
182
|
+
checkedText: theme.colors.surface,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
if (tone === 'success') {
|
|
186
|
+
return {
|
|
187
|
+
checkedTrack: SEMANTIC_COLORS.success,
|
|
188
|
+
checkedText: '#FFFFFF',
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
if (tone === 'warning') {
|
|
192
|
+
return {
|
|
193
|
+
checkedTrack: SEMANTIC_COLORS.warning,
|
|
194
|
+
checkedText: '#111827',
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
if (tone === 'danger') {
|
|
198
|
+
return {
|
|
199
|
+
checkedTrack: SEMANTIC_COLORS.danger,
|
|
200
|
+
checkedText: '#FFFFFF',
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
if (tone === 'info') {
|
|
204
|
+
return {
|
|
205
|
+
checkedTrack: SEMANTIC_COLORS.info,
|
|
206
|
+
checkedText: '#FFFFFF',
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
checkedTrack: theme.colors.primary,
|
|
211
|
+
checkedText: theme.colors.onPrimary,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function resolveUncheckedTrackFallback(scheme, theme) {
|
|
215
|
+
var _a;
|
|
216
|
+
if (scheme === 'dark')
|
|
217
|
+
return '#374151';
|
|
218
|
+
return (_a = colorToRgba(theme.colors.onSurface, 0.12)) !== null && _a !== void 0 ? _a : theme.colors.border;
|
|
219
|
+
}
|
|
220
|
+
function clampNumber(value, min, max) {
|
|
221
|
+
if (!Number.isFinite(value))
|
|
222
|
+
return min;
|
|
223
|
+
return Math.min(Math.max(value, min), max);
|
|
224
|
+
}
|
|
225
|
+
function resolvePositiveNumber(value, fallback) {
|
|
226
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : fallback;
|
|
227
|
+
}
|
|
228
|
+
function resolveNonNegativeNumber(value, fallback) {
|
|
229
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : fallback;
|
|
230
|
+
}
|
|
231
|
+
function resolveDuration(duration) {
|
|
232
|
+
if (duration == null || !Number.isFinite(duration))
|
|
233
|
+
return VALUE_TIMING_DURATION;
|
|
234
|
+
return Math.max(0, duration);
|
|
235
|
+
}
|
|
236
|
+
function toTimingConfig(duration) {
|
|
237
|
+
return {
|
|
238
|
+
duration,
|
|
239
|
+
easing: react_native_reanimated_1.Easing.out(react_native_reanimated_1.Easing.cubic),
|
|
240
|
+
reduceMotion: react_native_reanimated_1.ReduceMotion.System,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function resolveHitSlop(width, height, minTouchTarget) {
|
|
244
|
+
const vertical = Math.max(0, (minTouchTarget - height) / 2);
|
|
245
|
+
const horizontal = Math.max(0, (minTouchTarget - width) / 2);
|
|
246
|
+
if (vertical === 0 && horizontal === 0)
|
|
247
|
+
return undefined;
|
|
248
|
+
return {
|
|
249
|
+
top: vertical,
|
|
250
|
+
bottom: vertical,
|
|
251
|
+
left: horizontal,
|
|
252
|
+
right: horizontal,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function resolveWebCursorStyle(disabled) {
|
|
256
|
+
if (react_native_1.Platform.OS !== 'web')
|
|
257
|
+
return undefined;
|
|
258
|
+
return { cursor: disabled ? 'not-allowed' : 'pointer' };
|
|
259
|
+
}
|
|
260
|
+
function isPrimitiveText(node) {
|
|
261
|
+
return typeof node === 'string' || typeof node === 'number';
|
|
262
|
+
}
|
|
263
|
+
function isRenderProp(children) {
|
|
264
|
+
return typeof children === 'function';
|
|
265
|
+
}
|
|
266
|
+
function getTextLength(text) {
|
|
267
|
+
return text == null ? 0 : Array.from(text).length;
|
|
268
|
+
}
|
|
269
|
+
function isWideGlyph(codePoint) {
|
|
270
|
+
return ((codePoint >= 0x1100 && codePoint <= 0x115f) ||
|
|
271
|
+
(codePoint >= 0x2329 && codePoint <= 0x232a) ||
|
|
272
|
+
(codePoint >= 0x2e80 && codePoint <= 0xa4cf) ||
|
|
273
|
+
(codePoint >= 0xac00 && codePoint <= 0xd7a3) ||
|
|
274
|
+
(codePoint >= 0xf900 && codePoint <= 0xfaff) ||
|
|
275
|
+
(codePoint >= 0xfe10 && codePoint <= 0xfe6f) ||
|
|
276
|
+
(codePoint >= 0xff00 && codePoint <= 0xff60) ||
|
|
277
|
+
(codePoint >= 0xffe0 && codePoint <= 0xffe6) ||
|
|
278
|
+
(codePoint >= 0x1f000 && codePoint <= 0x1faff));
|
|
279
|
+
}
|
|
280
|
+
function estimateStateTextWidth(text, fontSize) {
|
|
281
|
+
var _a;
|
|
282
|
+
const glyphs = Array.from(text !== null && text !== void 0 ? text : '');
|
|
283
|
+
if (glyphs.length === 0)
|
|
284
|
+
return 0;
|
|
285
|
+
let widthUnits = 0;
|
|
286
|
+
for (const glyph of glyphs) {
|
|
287
|
+
const codePoint = (_a = glyph.codePointAt(0)) !== null && _a !== void 0 ? _a : 0;
|
|
288
|
+
if (isWideGlyph(codePoint)) {
|
|
289
|
+
widthUnits += 1;
|
|
290
|
+
}
|
|
291
|
+
else if (/\s/.test(glyph)) {
|
|
292
|
+
widthUnits += 0.32;
|
|
293
|
+
}
|
|
294
|
+
else if (/[ilI.,'`|!]/.test(glyph)) {
|
|
295
|
+
widthUnits += 0.34;
|
|
296
|
+
}
|
|
297
|
+
else if (/[mwMW@#%&]/.test(glyph)) {
|
|
298
|
+
widthUnits += 0.82;
|
|
299
|
+
}
|
|
300
|
+
else if (/[A-Z0-9]/.test(glyph)) {
|
|
301
|
+
widthUnits += 0.62;
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
widthUnits += 0.56;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return Math.max(getTextLength(text) * fontSize * STATE_TEXT_WIDTH_FACTOR, widthUnits * fontSize);
|
|
308
|
+
}
|
|
309
|
+
function SwitchImpl({ checked: checkedProp, defaultChecked = false, onCheckedChange, disabled = false, loading = false, loadingIndicator, size = 'md', tone = 'primary', duration, color, colors, layout, stateText, label, description, labelPlacement = 'start', children, style, contentStyle, trackStyle, thumbStyle, labelStyle, descriptionStyle, stateTextStyle, accessibilityLabel, accessibilityState, accessibilityValue, hitSlop, onPress, onPressIn, onPressOut, onFocus, onBlur, testID, ...pressableProps }, ref) {
|
|
310
|
+
var _a, _b, _c, _d, _e;
|
|
311
|
+
const theme = (0, useTheme_1.useTheme)();
|
|
312
|
+
const scheme = (0, react_native_1.useColorScheme)();
|
|
313
|
+
const { width: viewportWidth } = (0, react_native_1.useWindowDimensions)();
|
|
314
|
+
const isRTL = react_native_1.I18nManager.isRTL;
|
|
315
|
+
const isControlled = checkedProp !== undefined;
|
|
316
|
+
const [uncontrolledChecked, setUncontrolledChecked] = React.useState(() => defaultChecked);
|
|
317
|
+
const checked = isControlled ? checkedProp : uncontrolledChecked;
|
|
318
|
+
const checkedRef = React.useRef(checked);
|
|
319
|
+
checkedRef.current = checked;
|
|
320
|
+
const interactionDisabled = disabled || loading;
|
|
321
|
+
const interactive = !interactionDisabled;
|
|
322
|
+
const metrics = React.useMemo(() => resolveSwitchMetrics(size), [size, viewportWidth]);
|
|
323
|
+
const tonePalette = React.useMemo(() => resolveTonePalette(tone, theme), [theme, tone]);
|
|
324
|
+
const checkedTrackColor = React.useMemo(() => resolveColorToken(color !== null && color !== void 0 ? color : colors === null || colors === void 0 ? void 0 : colors.checkedTrack, tonePalette.checkedTrack, theme), [color, colors === null || colors === void 0 ? void 0 : colors.checkedTrack, theme, tonePalette.checkedTrack]);
|
|
325
|
+
const uncheckedTrackColor = React.useMemo(() => resolveColorToken(colors === null || colors === void 0 ? void 0 : colors.uncheckedTrack, resolveUncheckedTrackFallback(scheme, theme), theme), [colors === null || colors === void 0 ? void 0 : colors.uncheckedTrack, scheme, theme]);
|
|
326
|
+
const checkedThumbColor = React.useMemo(() => { var _a; return resolveColorToken((_a = colors === null || colors === void 0 ? void 0 : colors.checkedThumb) !== null && _a !== void 0 ? _a : colors === null || colors === void 0 ? void 0 : colors.thumb, theme.colors.surface, theme); }, [colors === null || colors === void 0 ? void 0 : colors.checkedThumb, colors === null || colors === void 0 ? void 0 : colors.thumb, theme]);
|
|
327
|
+
const uncheckedThumbColor = React.useMemo(() => { var _a; return resolveColorToken((_a = colors === null || colors === void 0 ? void 0 : colors.uncheckedThumb) !== null && _a !== void 0 ? _a : colors === null || colors === void 0 ? void 0 : colors.thumb, theme.colors.surface, theme); }, [colors === null || colors === void 0 ? void 0 : colors.thumb, colors === null || colors === void 0 ? void 0 : colors.uncheckedThumb, theme]);
|
|
328
|
+
const checkedTextColor = React.useMemo(() => resolveColorToken(colors === null || colors === void 0 ? void 0 : colors.checkedText, tonePalette.checkedText, theme), [colors === null || colors === void 0 ? void 0 : colors.checkedText, theme, tonePalette.checkedText]);
|
|
329
|
+
const uncheckedTextColor = React.useMemo(() => resolveColorToken(colors === null || colors === void 0 ? void 0 : colors.uncheckedText, scheme === 'dark' ? '#E5E7EB' : theme.colors.muted, theme), [colors === null || colors === void 0 ? void 0 : colors.uncheckedText, scheme, theme]);
|
|
330
|
+
const focusRingColor = React.useMemo(() => {
|
|
331
|
+
var _a;
|
|
332
|
+
return resolveColorToken(colors === null || colors === void 0 ? void 0 : colors.focusRing, (_a = colorToRgba(checkedTrackColor, scheme === 'dark' ? 0.36 : 0.28)) !== null && _a !== void 0 ? _a : checkedTrackColor, theme);
|
|
333
|
+
}, [checkedTrackColor, colors === null || colors === void 0 ? void 0 : colors.focusRing, scheme, theme]);
|
|
334
|
+
const disabledUncheckedTrackColor = React.useMemo(() => {
|
|
335
|
+
var _a;
|
|
336
|
+
return (_a = overlayColor(uncheckedTrackColor, theme.colors.surface, scheme === 'dark' ? 0.68 : 0.56)) !== null && _a !== void 0 ? _a : uncheckedTrackColor;
|
|
337
|
+
}, [scheme, theme.colors.surface, uncheckedTrackColor]);
|
|
338
|
+
const disabledCheckedTrackColor = React.useMemo(() => {
|
|
339
|
+
var _a;
|
|
340
|
+
return (_a = overlayColor(checkedTrackColor, theme.colors.surface, scheme === 'dark' ? 0.5 : 0.56)) !== null && _a !== void 0 ? _a : checkedTrackColor;
|
|
341
|
+
}, [checkedTrackColor, scheme, theme.colors.surface]);
|
|
342
|
+
const visualUncheckedTrackColor = disabled ? disabledUncheckedTrackColor : uncheckedTrackColor;
|
|
343
|
+
const visualCheckedTrackColor = disabled ? disabledCheckedTrackColor : checkedTrackColor;
|
|
344
|
+
const disabledUncheckedThumbColor = React.useMemo(() => {
|
|
345
|
+
var _a;
|
|
346
|
+
return (_a = overlayColor(uncheckedThumbColor, disabledUncheckedTrackColor, scheme === 'dark' ? 0.84 : 0.95)) !== null && _a !== void 0 ? _a : uncheckedThumbColor;
|
|
347
|
+
}, [disabledUncheckedTrackColor, scheme, uncheckedThumbColor]);
|
|
348
|
+
const disabledCheckedThumbColor = React.useMemo(() => {
|
|
349
|
+
var _a;
|
|
350
|
+
return (_a = overlayColor(checkedThumbColor, disabledCheckedTrackColor, scheme === 'dark' ? 0.84 : 0.92)) !== null && _a !== void 0 ? _a : checkedThumbColor;
|
|
351
|
+
}, [checkedThumbColor, disabledCheckedTrackColor, scheme]);
|
|
352
|
+
const visualUncheckedThumbColor = disabled ? disabledUncheckedThumbColor : uncheckedThumbColor;
|
|
353
|
+
const visualCheckedThumbColor = disabled ? disabledCheckedThumbColor : checkedThumbColor;
|
|
354
|
+
const visualCheckedTextColor = React.useMemo(() => {
|
|
355
|
+
var _a;
|
|
356
|
+
return disabled
|
|
357
|
+
? (_a = overlayColor(checkedTextColor, disabledCheckedTrackColor, scheme === 'dark' ? 0.78 : 0.72)) !== null && _a !== void 0 ? _a : checkedTextColor
|
|
358
|
+
: checkedTextColor;
|
|
359
|
+
}, [checkedTextColor, disabled, disabledCheckedTrackColor, scheme]);
|
|
360
|
+
const visualUncheckedTextColor = React.useMemo(() => {
|
|
361
|
+
var _a;
|
|
362
|
+
return disabled
|
|
363
|
+
? (_a = overlayColor(uncheckedTextColor, disabledUncheckedTrackColor, scheme === 'dark' ? 0.78 : 0.72)) !== null && _a !== void 0 ? _a : uncheckedTextColor
|
|
364
|
+
: uncheckedTextColor;
|
|
365
|
+
}, [disabled, disabledUncheckedTrackColor, scheme, uncheckedTextColor]);
|
|
366
|
+
const loadingColor = React.useMemo(() => resolveColorToken(colors === null || colors === void 0 ? void 0 : colors.loading, checked ? visualCheckedTrackColor : theme.colors.muted, theme), [checked, colors === null || colors === void 0 ? void 0 : colors.loading, theme, visualCheckedTrackColor]);
|
|
367
|
+
const thumbColorChanges = visualCheckedThumbColor !== visualUncheckedThumbColor;
|
|
368
|
+
const trackHeight = resolvePositiveNumber(layout === null || layout === void 0 ? void 0 : layout.height, metrics.height);
|
|
369
|
+
const baseTrackWidth = Math.max(trackHeight, resolvePositiveNumber(layout === null || layout === void 0 ? void 0 : layout.width, metrics.width));
|
|
370
|
+
const onePx = (0, zkit_tools_1.wp)(1);
|
|
371
|
+
const resolvedThumbInset = clampNumber(resolveNonNegativeNumber(layout === null || layout === void 0 ? void 0 : layout.thumbInset, metrics.thumbInset), 0, Math.max(0, (trackHeight - onePx) / 2));
|
|
372
|
+
const thumbSize = Math.max(onePx, trackHeight - resolvedThumbInset * 2);
|
|
373
|
+
const stateTextSize = resolvePositiveNumber(layout === null || layout === void 0 ? void 0 : layout.textSize, metrics.textSize);
|
|
374
|
+
const stateTextLineHeight = resolvePositiveNumber(layout === null || layout === void 0 ? void 0 : layout.textLineHeight, metrics.textLineHeight);
|
|
375
|
+
const stateTextInset = resolveNonNegativeNumber(layout === null || layout === void 0 ? void 0 : layout.textInset, metrics.textInset);
|
|
376
|
+
const labelGap = resolveNonNegativeNumber(layout === null || layout === void 0 ? void 0 : layout.labelGap, metrics.labelGap);
|
|
377
|
+
const hasStateText = (stateText === null || stateText === void 0 ? void 0 : stateText.checked) != null || (stateText === null || stateText === void 0 ? void 0 : stateText.unchecked) != null;
|
|
378
|
+
const maxStateTextWidth = Math.max(estimateStateTextWidth(stateText === null || stateText === void 0 ? void 0 : stateText.checked, stateTextSize), estimateStateTextWidth(stateText === null || stateText === void 0 ? void 0 : stateText.unchecked, stateTextSize));
|
|
379
|
+
const stateTextSlotWidth = hasStateText
|
|
380
|
+
? Math.max(metrics.textSlotMinWidth, maxStateTextWidth + stateTextSize * STATE_TEXT_WIDTH_GUARD_FACTOR + stateTextInset * 2)
|
|
381
|
+
: 0;
|
|
382
|
+
const trackWidth = hasStateText
|
|
383
|
+
? Math.max(baseTrackWidth, thumbSize + resolvedThumbInset + stateTextSlotWidth)
|
|
384
|
+
: baseTrackWidth;
|
|
385
|
+
const travel = Math.max(0, trackWidth - thumbSize - resolvedThumbInset * 2);
|
|
386
|
+
const thumbStart = isRTL ? trackWidth - thumbSize - resolvedThumbInset : resolvedThumbInset;
|
|
387
|
+
const travelDirection = isRTL ? -1 : 1;
|
|
388
|
+
const trackRadius = Math.max(0, (_a = layout === null || layout === void 0 ? void 0 : layout.radius) !== null && _a !== void 0 ? _a : trackHeight / 2);
|
|
389
|
+
const thumbRadius = thumbSize / 2;
|
|
390
|
+
const defaultHitSlop = React.useMemo(() => resolveHitSlop(trackWidth, trackHeight, metrics.minTouchTarget), [metrics.minTouchTarget, trackHeight, trackWidth]);
|
|
391
|
+
const thumbShadowStyle = React.useMemo(() => ({
|
|
392
|
+
shadowColor: '#000000',
|
|
393
|
+
shadowOffset: { width: 0, height: (0, zkit_tools_1.wp)(1) },
|
|
394
|
+
shadowOpacity: disabled ? 0 : scheme === 'dark' ? 0.28 : 0.14,
|
|
395
|
+
shadowRadius: disabled ? 0 : (0, zkit_tools_1.wp)(4),
|
|
396
|
+
elevation: disabled ? 0 : (0, zkit_tools_1.wp)(1),
|
|
397
|
+
}), [disabled, scheme]);
|
|
398
|
+
const webCursorStyle = React.useMemo(() => resolveWebCursorStyle(interactionDisabled), [interactionDisabled]);
|
|
399
|
+
const resolvedDuration = resolveDuration(duration);
|
|
400
|
+
const valueTiming = React.useMemo(() => toTimingConfig(resolvedDuration), [resolvedDuration]);
|
|
401
|
+
const pressInTiming = React.useMemo(() => toTimingConfig(PRESS_IN_DURATION), []);
|
|
402
|
+
const pressOutTiming = React.useMemo(() => toTimingConfig(PRESS_OUT_DURATION), []);
|
|
403
|
+
const focusTiming = React.useMemo(() => toTimingConfig(FOCUS_DURATION), []);
|
|
404
|
+
const progressSv = (0, react_native_reanimated_1.useSharedValue)(checked ? 1 : 0);
|
|
405
|
+
const pressSv = (0, react_native_reanimated_1.useSharedValue)(0);
|
|
406
|
+
const focusSv = (0, react_native_reanimated_1.useSharedValue)(0);
|
|
407
|
+
React.useEffect(() => {
|
|
408
|
+
if (!isControlled)
|
|
409
|
+
return;
|
|
410
|
+
progressSv.value = (0, react_native_reanimated_1.withTiming)(checked ? 1 : 0, valueTiming);
|
|
411
|
+
}, [checked, isControlled, progressSv, valueTiming]);
|
|
412
|
+
React.useEffect(() => {
|
|
413
|
+
if (interactive)
|
|
414
|
+
return;
|
|
415
|
+
pressSv.value = (0, react_native_reanimated_1.withTiming)(0, pressOutTiming);
|
|
416
|
+
focusSv.value = (0, react_native_reanimated_1.withTiming)(0, focusTiming);
|
|
417
|
+
}, [focusSv, focusTiming, interactive, pressOutTiming, pressSv]);
|
|
418
|
+
const commitChecked = React.useCallback((next) => {
|
|
419
|
+
if (!isControlled) {
|
|
420
|
+
checkedRef.current = next;
|
|
421
|
+
progressSv.value = (0, react_native_reanimated_1.withTiming)(next ? 1 : 0, valueTiming);
|
|
422
|
+
setUncontrolledChecked(next);
|
|
423
|
+
}
|
|
424
|
+
onCheckedChange === null || onCheckedChange === void 0 ? void 0 : onCheckedChange(next);
|
|
425
|
+
}, [isControlled, onCheckedChange, progressSv, valueTiming]);
|
|
426
|
+
const toggle = React.useCallback(() => {
|
|
427
|
+
if (interactionDisabled)
|
|
428
|
+
return;
|
|
429
|
+
commitChecked(!checkedRef.current);
|
|
430
|
+
}, [commitChecked, interactionDisabled]);
|
|
431
|
+
const handlePress = React.useCallback((event) => {
|
|
432
|
+
if (!interactionDisabled) {
|
|
433
|
+
commitChecked(!checkedRef.current);
|
|
434
|
+
}
|
|
435
|
+
onPress === null || onPress === void 0 ? void 0 : onPress(event);
|
|
436
|
+
}, [commitChecked, interactionDisabled, onPress]);
|
|
437
|
+
const handlePressIn = React.useCallback((event) => {
|
|
438
|
+
if (!interactionDisabled) {
|
|
439
|
+
pressSv.value = (0, react_native_reanimated_1.withTiming)(1, pressInTiming);
|
|
440
|
+
}
|
|
441
|
+
onPressIn === null || onPressIn === void 0 ? void 0 : onPressIn(event);
|
|
442
|
+
}, [interactionDisabled, onPressIn, pressInTiming, pressSv]);
|
|
443
|
+
const handlePressOut = React.useCallback((event) => {
|
|
444
|
+
pressSv.value = (0, react_native_reanimated_1.withTiming)(0, pressOutTiming);
|
|
445
|
+
onPressOut === null || onPressOut === void 0 ? void 0 : onPressOut(event);
|
|
446
|
+
}, [onPressOut, pressOutTiming, pressSv]);
|
|
447
|
+
const handleFocus = React.useCallback((event) => {
|
|
448
|
+
if (!interactionDisabled) {
|
|
449
|
+
focusSv.value = (0, react_native_reanimated_1.withTiming)(1, focusTiming);
|
|
450
|
+
}
|
|
451
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
452
|
+
}, [focusSv, focusTiming, interactionDisabled, onFocus]);
|
|
453
|
+
const handleBlur = React.useCallback((event) => {
|
|
454
|
+
focusSv.value = (0, react_native_reanimated_1.withTiming)(0, focusTiming);
|
|
455
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
|
456
|
+
}, [focusSv, focusTiming, onBlur]);
|
|
457
|
+
const visualAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => {
|
|
458
|
+
const pressedOpacity = (0, react_native_reanimated_1.interpolate)(pressSv.value, [0, 1], [1, PRESSED_OPACITY]);
|
|
459
|
+
return { opacity: pressedOpacity };
|
|
460
|
+
});
|
|
461
|
+
const focusRingAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => {
|
|
462
|
+
const opacity = (0, react_native_reanimated_1.interpolate)(focusSv.value, [0, 1], [0, 1]);
|
|
463
|
+
const scale = (0, react_native_reanimated_1.interpolate)(focusSv.value, [0, 1], [0.96, 1]);
|
|
464
|
+
return {
|
|
465
|
+
opacity,
|
|
466
|
+
transform: [{ scale }],
|
|
467
|
+
};
|
|
468
|
+
});
|
|
469
|
+
const checkedTrackAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => {
|
|
470
|
+
return { opacity: progressSv.value };
|
|
471
|
+
});
|
|
472
|
+
const thumbAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => {
|
|
473
|
+
if (!thumbColorChanges) {
|
|
474
|
+
return {
|
|
475
|
+
transform: [{ translateX: travel * travelDirection * progressSv.value }],
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
return {
|
|
479
|
+
backgroundColor: (0, react_native_reanimated_1.interpolateColor)(progressSv.value, [0, 1], [visualUncheckedThumbColor, visualCheckedThumbColor]),
|
|
480
|
+
transform: [{ translateX: travel * travelDirection * progressSv.value }],
|
|
481
|
+
};
|
|
482
|
+
}, [thumbColorChanges, travel, travelDirection, visualCheckedThumbColor, visualUncheckedThumbColor]);
|
|
483
|
+
const checkedTextAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => {
|
|
484
|
+
return { opacity: progressSv.value };
|
|
485
|
+
});
|
|
486
|
+
const uncheckedTextAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => {
|
|
487
|
+
return { opacity: 1 - progressSv.value };
|
|
488
|
+
});
|
|
489
|
+
const checkedTextSlotStyle = React.useMemo(() => isRTL
|
|
490
|
+
? {
|
|
491
|
+
left: thumbSize + resolvedThumbInset,
|
|
492
|
+
right: 0,
|
|
493
|
+
paddingLeft: stateTextInset,
|
|
494
|
+
paddingRight: stateTextInset,
|
|
495
|
+
}
|
|
496
|
+
: {
|
|
497
|
+
left: 0,
|
|
498
|
+
right: thumbSize + resolvedThumbInset,
|
|
499
|
+
paddingLeft: stateTextInset,
|
|
500
|
+
paddingRight: stateTextInset,
|
|
501
|
+
}, [isRTL, resolvedThumbInset, stateTextInset, thumbSize]);
|
|
502
|
+
const uncheckedTextSlotStyle = React.useMemo(() => isRTL
|
|
503
|
+
? {
|
|
504
|
+
left: 0,
|
|
505
|
+
right: thumbSize + resolvedThumbInset,
|
|
506
|
+
paddingLeft: stateTextInset,
|
|
507
|
+
paddingRight: stateTextInset,
|
|
508
|
+
}
|
|
509
|
+
: {
|
|
510
|
+
left: thumbSize + resolvedThumbInset,
|
|
511
|
+
right: 0,
|
|
512
|
+
paddingLeft: stateTextInset,
|
|
513
|
+
paddingRight: stateTextInset,
|
|
514
|
+
}, [isRTL, resolvedThumbInset, stateTextInset, thumbSize]);
|
|
515
|
+
const slot = React.useMemo(() => ({
|
|
516
|
+
checked,
|
|
517
|
+
disabled: interactionDisabled,
|
|
518
|
+
loading,
|
|
519
|
+
interactive,
|
|
520
|
+
size,
|
|
521
|
+
tone,
|
|
522
|
+
toggle,
|
|
523
|
+
}), [checked, interactionDisabled, interactive, loading, size, tone, toggle]);
|
|
524
|
+
const renderedContent = React.useMemo(() => {
|
|
525
|
+
if (isRenderProp(children))
|
|
526
|
+
return children(slot);
|
|
527
|
+
if (children != null)
|
|
528
|
+
return children;
|
|
529
|
+
if (label == null && description == null)
|
|
530
|
+
return null;
|
|
531
|
+
return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.copy, children: [label != null ? (isPrimitiveText(label) ? ((0, jsx_runtime_1.jsx)(Text_1.Text, { disabled: interactionDisabled, numberOfLines: 1, variant: "label", style: labelStyle, children: label })) : (label)) : null, description != null ? (isPrimitiveText(description) ? ((0, jsx_runtime_1.jsx)(Text_1.Text, { disabled: interactionDisabled, numberOfLines: 2, tone: interactionDisabled ? 'disabled' : 'muted', variant: "caption", style: descriptionStyle, children: description })) : (description)) : null] }));
|
|
532
|
+
}, [children, description, descriptionStyle, interactionDisabled, label, labelStyle, slot]);
|
|
533
|
+
const hasContent = renderedContent != null;
|
|
534
|
+
const inferredAccessibilityLabel = isPrimitiveText(label) ? String(label) : undefined;
|
|
535
|
+
const resolvedAccessibilityValue = accessibilityValue !== null && accessibilityValue !== void 0 ? accessibilityValue : (hasStateText
|
|
536
|
+
? {
|
|
537
|
+
text: checked ? ((_b = stateText === null || stateText === void 0 ? void 0 : stateText.checked) !== null && _b !== void 0 ? _b : '') : ((_c = stateText === null || stateText === void 0 ? void 0 : stateText.unchecked) !== null && _c !== void 0 ? _c : ''),
|
|
538
|
+
}
|
|
539
|
+
: undefined);
|
|
540
|
+
const resolvedStyle = React.useCallback((state) => {
|
|
541
|
+
const userStyle = typeof style === 'function' ? style(state) : style;
|
|
542
|
+
return [styles.root, webCursorStyle, userStyle];
|
|
543
|
+
}, [style, webCursorStyle]);
|
|
544
|
+
const switchNode = ((0, jsx_runtime_1.jsxs)(react_native_reanimated_1.default.View, { style: [
|
|
545
|
+
styles.visual,
|
|
546
|
+
{
|
|
547
|
+
width: trackWidth,
|
|
548
|
+
height: trackHeight,
|
|
549
|
+
borderRadius: trackRadius,
|
|
550
|
+
},
|
|
551
|
+
visualAnimatedStyle,
|
|
552
|
+
], children: [(0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { pointerEvents: "none", style: [
|
|
553
|
+
styles.focusRing,
|
|
554
|
+
{
|
|
555
|
+
top: -metrics.focusRingOffset,
|
|
556
|
+
bottom: -metrics.focusRingOffset,
|
|
557
|
+
left: -metrics.focusRingOffset,
|
|
558
|
+
right: -metrics.focusRingOffset,
|
|
559
|
+
borderWidth: metrics.focusRingWidth,
|
|
560
|
+
borderRadius: trackRadius + metrics.focusRingOffset,
|
|
561
|
+
borderColor: focusRingColor,
|
|
562
|
+
},
|
|
563
|
+
focusRingAnimatedStyle,
|
|
564
|
+
] }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: [
|
|
565
|
+
react_native_1.StyleSheet.absoluteFillObject,
|
|
566
|
+
{
|
|
567
|
+
borderRadius: trackRadius,
|
|
568
|
+
backgroundColor: visualUncheckedTrackColor,
|
|
569
|
+
},
|
|
570
|
+
trackStyle,
|
|
571
|
+
] }), (0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { pointerEvents: "none", style: [
|
|
572
|
+
react_native_1.StyleSheet.absoluteFillObject,
|
|
573
|
+
{
|
|
574
|
+
borderRadius: trackRadius,
|
|
575
|
+
backgroundColor: visualCheckedTrackColor,
|
|
576
|
+
},
|
|
577
|
+
checkedTrackAnimatedStyle,
|
|
578
|
+
] }), hasStateText ? ((0, jsx_runtime_1.jsxs)(react_native_1.View, { pointerEvents: "none", style: styles.stateTextLayer, children: [(0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { style: [styles.stateTextSlot, checkedTextSlotStyle, checkedTextAnimatedStyle], children: (0, jsx_runtime_1.jsx)(Text_1.Text, { allowFontScaling: false, ellipsizeMode: "clip", numberOfLines: 1, style: [
|
|
579
|
+
styles.stateText,
|
|
580
|
+
{
|
|
581
|
+
color: visualCheckedTextColor,
|
|
582
|
+
fontSize: stateTextSize,
|
|
583
|
+
lineHeight: stateTextLineHeight,
|
|
584
|
+
},
|
|
585
|
+
stateTextStyle,
|
|
586
|
+
], children: (_d = stateText === null || stateText === void 0 ? void 0 : stateText.checked) !== null && _d !== void 0 ? _d : '' }) }), (0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { style: [styles.stateTextSlot, uncheckedTextSlotStyle, uncheckedTextAnimatedStyle], children: (0, jsx_runtime_1.jsx)(Text_1.Text, { allowFontScaling: false, ellipsizeMode: "clip", numberOfLines: 1, style: [
|
|
587
|
+
styles.stateText,
|
|
588
|
+
{
|
|
589
|
+
color: visualUncheckedTextColor,
|
|
590
|
+
fontSize: stateTextSize,
|
|
591
|
+
lineHeight: stateTextLineHeight,
|
|
592
|
+
},
|
|
593
|
+
stateTextStyle,
|
|
594
|
+
], children: (_e = stateText === null || stateText === void 0 ? void 0 : stateText.unchecked) !== null && _e !== void 0 ? _e : '' }) })] })) : null, (0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { style: [
|
|
595
|
+
styles.thumb,
|
|
596
|
+
{
|
|
597
|
+
width: thumbSize,
|
|
598
|
+
height: thumbSize,
|
|
599
|
+
left: thumbStart,
|
|
600
|
+
top: resolvedThumbInset,
|
|
601
|
+
borderRadius: thumbRadius,
|
|
602
|
+
backgroundColor: visualUncheckedThumbColor,
|
|
603
|
+
},
|
|
604
|
+
thumbAnimatedStyle,
|
|
605
|
+
thumbShadowStyle,
|
|
606
|
+
thumbStyle,
|
|
607
|
+
], children: loading ? (loadingIndicator !== null && loadingIndicator !== void 0 ? loadingIndicator : ((0, jsx_runtime_1.jsx)(LoadingSpinner_1.LoadingSpinner, { size: Math.max((0, zkit_tools_1.wp)(12), thumbSize * 0.58), color: loadingColor }))) : null })] }));
|
|
608
|
+
const contentNode = hasContent ? ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [
|
|
609
|
+
styles.content,
|
|
610
|
+
contentStyle,
|
|
611
|
+
], children: labelPlacement === 'start' ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: [styles.contentSlot, { marginEnd: labelGap }], children: renderedContent }), switchNode] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [switchNode, (0, jsx_runtime_1.jsx)(react_native_1.View, { style: [styles.contentSlot, { marginStart: labelGap }], children: renderedContent })] })) })) : (switchNode);
|
|
612
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { ...pressableProps, ref: ref, accessibilityLabel: accessibilityLabel !== null && accessibilityLabel !== void 0 ? accessibilityLabel : inferredAccessibilityLabel, accessibilityRole: "switch", accessibilityState: {
|
|
613
|
+
...accessibilityState,
|
|
614
|
+
checked,
|
|
615
|
+
disabled: Boolean(interactionDisabled),
|
|
616
|
+
busy: Boolean(loading || (accessibilityState === null || accessibilityState === void 0 ? void 0 : accessibilityState.busy)),
|
|
617
|
+
}, accessibilityValue: resolvedAccessibilityValue, disabled: interactionDisabled, hitSlop: hitSlop !== null && hitSlop !== void 0 ? hitSlop : defaultHitSlop, onBlur: handleBlur, onFocus: handleFocus, onPress: handlePress, onPressIn: handlePressIn, onPressOut: handlePressOut, style: resolvedStyle, testID: testID, children: contentNode }));
|
|
618
|
+
}
|
|
619
|
+
const SwitchWithRef = React.forwardRef(SwitchImpl);
|
|
620
|
+
SwitchWithRef.displayName = 'Switch';
|
|
621
|
+
exports.Switch = React.memo(SwitchWithRef);
|
|
622
|
+
exports.Switch.displayName = 'Switch';
|
|
623
|
+
const styles = react_native_1.StyleSheet.create({
|
|
624
|
+
root: {
|
|
625
|
+
alignSelf: 'flex-start',
|
|
626
|
+
},
|
|
627
|
+
content: {
|
|
628
|
+
alignItems: 'center',
|
|
629
|
+
flexDirection: 'row',
|
|
630
|
+
minWidth: 0,
|
|
631
|
+
},
|
|
632
|
+
contentSlot: {
|
|
633
|
+
flexGrow: 1,
|
|
634
|
+
flexShrink: 1,
|
|
635
|
+
minWidth: 0,
|
|
636
|
+
},
|
|
637
|
+
copy: {
|
|
638
|
+
flexShrink: 1,
|
|
639
|
+
minWidth: 0,
|
|
640
|
+
},
|
|
641
|
+
visual: {
|
|
642
|
+
flexShrink: 0,
|
|
643
|
+
overflow: 'visible',
|
|
644
|
+
},
|
|
645
|
+
focusRing: {
|
|
646
|
+
position: 'absolute',
|
|
647
|
+
},
|
|
648
|
+
stateTextLayer: {
|
|
649
|
+
...react_native_1.StyleSheet.absoluteFillObject,
|
|
650
|
+
alignItems: 'center',
|
|
651
|
+
justifyContent: 'center',
|
|
652
|
+
},
|
|
653
|
+
stateTextSlot: {
|
|
654
|
+
...react_native_1.StyleSheet.absoluteFillObject,
|
|
655
|
+
alignItems: 'center',
|
|
656
|
+
justifyContent: 'center',
|
|
657
|
+
overflow: 'hidden',
|
|
658
|
+
},
|
|
659
|
+
stateText: {
|
|
660
|
+
includeFontPadding: false,
|
|
661
|
+
fontWeight: '600',
|
|
662
|
+
margin: 0,
|
|
663
|
+
padding: 0,
|
|
664
|
+
textAlign: 'center',
|
|
665
|
+
},
|
|
666
|
+
thumb: {
|
|
667
|
+
alignItems: 'center',
|
|
668
|
+
justifyContent: 'center',
|
|
669
|
+
position: 'absolute',
|
|
670
|
+
},
|
|
671
|
+
});
|