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,40 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
SheetCloseOptions,
|
|
4
|
+
SheetOpenOptions,
|
|
5
|
+
SheetState,
|
|
6
|
+
} from './types';
|
|
7
|
+
|
|
8
|
+
export type NativeBottomSheetOpenChangeDetails = {
|
|
9
|
+
reason: 'api' | 'backdrop' | 'back' | 'gesture' | 'system';
|
|
10
|
+
detentIndex: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type NativeBottomSheetCloseCompleteDetails = {
|
|
14
|
+
reason: 'api' | 'backdrop' | 'back' | 'gesture' | 'system';
|
|
15
|
+
detentIndex: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type NativeBottomSheetRef = {
|
|
19
|
+
open: (options?: SheetOpenOptions) => Promise<void>;
|
|
20
|
+
close: (options?: SheetCloseOptions) => Promise<void>;
|
|
21
|
+
snapTo: (detentIndex: number) => Promise<void>;
|
|
22
|
+
getState: () => SheetState;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const NativeBottomSheet = React.forwardRef<NativeBottomSheetRef, Record<string, unknown>>(
|
|
26
|
+
function NativeBottomSheet(_, ref) {
|
|
27
|
+
React.useImperativeHandle(
|
|
28
|
+
ref,
|
|
29
|
+
() => ({
|
|
30
|
+
open: async () => {},
|
|
31
|
+
close: async () => {},
|
|
32
|
+
snapTo: async () => {},
|
|
33
|
+
getState: () => 'closed',
|
|
34
|
+
}),
|
|
35
|
+
[]
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
4
|
+
import { wp } from 'zkit-tools';
|
|
5
|
+
import { useTheme } from '../../theme/useTheme';
|
|
6
|
+
import { Text } from '../Text';
|
|
7
|
+
import type {
|
|
8
|
+
SheetContentProps,
|
|
9
|
+
SheetFooterProps,
|
|
10
|
+
SheetHeaderProps,
|
|
11
|
+
} from './types';
|
|
12
|
+
|
|
13
|
+
export function SheetHeader({
|
|
14
|
+
title,
|
|
15
|
+
description,
|
|
16
|
+
children,
|
|
17
|
+
style,
|
|
18
|
+
...props
|
|
19
|
+
}: SheetHeaderProps) {
|
|
20
|
+
const theme = useTheme();
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<View {...props} style={[styles.header, style]}>
|
|
24
|
+
{children ?? (
|
|
25
|
+
<>
|
|
26
|
+
{title != null ? (
|
|
27
|
+
<Text
|
|
28
|
+
accessibilityRole="header"
|
|
29
|
+
numberOfLines={2}
|
|
30
|
+
size="lg"
|
|
31
|
+
weight="semibold"
|
|
32
|
+
style={{ color: theme.colors.onSurface }}
|
|
33
|
+
>
|
|
34
|
+
{title}
|
|
35
|
+
</Text>
|
|
36
|
+
) : null}
|
|
37
|
+
{description != null ? (
|
|
38
|
+
<Text numberOfLines={3} size="sm" style={{ color: theme.colors.muted }}>
|
|
39
|
+
{description}
|
|
40
|
+
</Text>
|
|
41
|
+
) : null}
|
|
42
|
+
</>
|
|
43
|
+
)}
|
|
44
|
+
</View>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function SheetContent({ style, ...props }: SheetContentProps) {
|
|
49
|
+
return <View {...props} style={[styles.content, style]} />;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function SheetFooter({ safeArea = true, style, ...props }: SheetFooterProps) {
|
|
53
|
+
const insets = useSafeAreaInsets();
|
|
54
|
+
const paddingBottom = safeArea ? Math.max(insets.bottom, wp(12)) : undefined;
|
|
55
|
+
|
|
56
|
+
return <View {...props} style={[styles.footer, paddingBottom != null && { paddingBottom }, style]} />;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const styles = StyleSheet.create({
|
|
60
|
+
header: {
|
|
61
|
+
gap: wp(4),
|
|
62
|
+
paddingHorizontal: wp(20),
|
|
63
|
+
paddingTop: wp(20),
|
|
64
|
+
paddingBottom: wp(12),
|
|
65
|
+
},
|
|
66
|
+
content: {
|
|
67
|
+
paddingHorizontal: wp(20),
|
|
68
|
+
paddingVertical: wp(16),
|
|
69
|
+
},
|
|
70
|
+
footer: {
|
|
71
|
+
gap: wp(10),
|
|
72
|
+
paddingHorizontal: wp(20),
|
|
73
|
+
paddingTop: wp(12),
|
|
74
|
+
},
|
|
75
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
ColorValue,
|
|
4
|
+
StyleProp,
|
|
5
|
+
ViewProps,
|
|
6
|
+
ViewStyle,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import type { EasingFunction, ReduceMotion } from 'react-native-reanimated';
|
|
9
|
+
import type {
|
|
10
|
+
SheetDetent as NativeSheetDetent,
|
|
11
|
+
TrueSheetProps,
|
|
12
|
+
} from '@lodev09/react-native-true-sheet';
|
|
13
|
+
|
|
14
|
+
export type SheetPlacement = 'top' | 'right' | 'bottom' | 'left';
|
|
15
|
+
export type SheetSize = 'auto' | 'sm' | 'md' | 'lg' | 'full' | `${number}%` | number;
|
|
16
|
+
export type SheetState = 'closed' | 'opening' | 'open' | 'closing';
|
|
17
|
+
export type SheetDetent =
|
|
18
|
+
| 'content'
|
|
19
|
+
| 'auto'
|
|
20
|
+
| 'medium'
|
|
21
|
+
| 'large'
|
|
22
|
+
| 'full'
|
|
23
|
+
| `${number}%`
|
|
24
|
+
| number;
|
|
25
|
+
|
|
26
|
+
type ManagedNativeProps =
|
|
27
|
+
| 'name'
|
|
28
|
+
| 'children'
|
|
29
|
+
| 'detents'
|
|
30
|
+
| 'initialDetentIndex'
|
|
31
|
+
| 'initialDetentAnimated'
|
|
32
|
+
| 'dimmed'
|
|
33
|
+
| 'dimmedDetentIndex'
|
|
34
|
+
| 'dismissible'
|
|
35
|
+
| 'draggable'
|
|
36
|
+
| 'backgroundColor'
|
|
37
|
+
| 'cornerRadius'
|
|
38
|
+
| 'grabber'
|
|
39
|
+
| 'grabberOptions'
|
|
40
|
+
| 'maxContentHeight'
|
|
41
|
+
| 'maxContentWidth'
|
|
42
|
+
| 'header'
|
|
43
|
+
| 'headerStyle'
|
|
44
|
+
| 'footer'
|
|
45
|
+
| 'footerStyle'
|
|
46
|
+
| 'style'
|
|
47
|
+
| 'onDidPresent'
|
|
48
|
+
| 'onDidDismiss'
|
|
49
|
+
| 'onDetentChange';
|
|
50
|
+
|
|
51
|
+
export type SheetNativeProps = Omit<TrueSheetProps, ManagedNativeProps>;
|
|
52
|
+
|
|
53
|
+
export type SheetOpenReason = 'api';
|
|
54
|
+
export type SheetCloseReason = 'api' | 'backdrop' | 'back' | 'gesture' | 'system';
|
|
55
|
+
export type SheetOpenChangeReason = SheetOpenReason | SheetCloseReason;
|
|
56
|
+
|
|
57
|
+
export type SheetAnimationConfig = {
|
|
58
|
+
duration?: number;
|
|
59
|
+
openDuration?: number;
|
|
60
|
+
closeDuration?: number;
|
|
61
|
+
easing?: EasingFunction;
|
|
62
|
+
reduceMotion?: ReduceMotion;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type SheetSafeAreaEdges = {
|
|
66
|
+
top?: boolean;
|
|
67
|
+
right?: boolean;
|
|
68
|
+
bottom?: boolean;
|
|
69
|
+
left?: boolean;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type SheetBackdropConfig = {
|
|
73
|
+
visible?: boolean;
|
|
74
|
+
dismissOnPress?: boolean;
|
|
75
|
+
color?: string;
|
|
76
|
+
opacity?: number;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type SheetHandleConfig = {
|
|
80
|
+
width?: number;
|
|
81
|
+
height?: number;
|
|
82
|
+
topMargin?: number;
|
|
83
|
+
radius?: number;
|
|
84
|
+
color?: ColorValue;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export type SheetOpenOptions = {
|
|
88
|
+
detentIndex?: number;
|
|
89
|
+
animated?: boolean;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type SheetCloseOptions = {
|
|
93
|
+
animated?: boolean;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type SheetOpenChangeDetails = {
|
|
97
|
+
reason: SheetOpenChangeReason;
|
|
98
|
+
placement: SheetPlacement;
|
|
99
|
+
detentIndex: number | null;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export type SheetOpenCompleteDetails = {
|
|
103
|
+
placement: SheetPlacement;
|
|
104
|
+
detentIndex: number | null;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export type SheetCloseCompleteDetails = {
|
|
108
|
+
reason: SheetCloseReason;
|
|
109
|
+
placement: SheetPlacement;
|
|
110
|
+
detentIndex: number | null;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type SheetDetentChangePayload = {
|
|
114
|
+
index: number;
|
|
115
|
+
detent: SheetDetent;
|
|
116
|
+
nativeDetent: NativeSheetDetent;
|
|
117
|
+
position: number;
|
|
118
|
+
placement: 'bottom';
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export type SheetRenderContext = {
|
|
122
|
+
isOpen: boolean;
|
|
123
|
+
state: SheetState;
|
|
124
|
+
placement: SheetPlacement;
|
|
125
|
+
detentIndex: number | null;
|
|
126
|
+
open: (options?: SheetOpenOptions) => Promise<void>;
|
|
127
|
+
close: (options?: SheetCloseOptions) => Promise<void>;
|
|
128
|
+
snapTo: (detentIndex: number) => Promise<void>;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export type SheetRef = {
|
|
132
|
+
open: (options?: SheetOpenOptions) => Promise<void>;
|
|
133
|
+
close: (options?: SheetCloseOptions) => Promise<void>;
|
|
134
|
+
snapTo: (detentIndex: number) => Promise<void>;
|
|
135
|
+
getState: () => SheetState;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export type SheetSlot =
|
|
139
|
+
| React.ReactNode
|
|
140
|
+
| ((context: SheetRenderContext) => React.ReactNode);
|
|
141
|
+
|
|
142
|
+
export type SheetProps = {
|
|
143
|
+
placement?: SheetPlacement;
|
|
144
|
+
open?: boolean;
|
|
145
|
+
defaultOpen?: boolean;
|
|
146
|
+
onOpenChange?: (open: boolean, details: SheetOpenChangeDetails) => void;
|
|
147
|
+
onOpenComplete?: (details: SheetOpenCompleteDetails) => void;
|
|
148
|
+
onCloseComplete?: (details: SheetCloseCompleteDetails) => void;
|
|
149
|
+
|
|
150
|
+
disabled?: boolean;
|
|
151
|
+
dismissible?: boolean;
|
|
152
|
+
draggable?: boolean;
|
|
153
|
+
backdrop?: boolean | SheetBackdropConfig;
|
|
154
|
+
|
|
155
|
+
title?: React.ReactNode;
|
|
156
|
+
description?: React.ReactNode;
|
|
157
|
+
header?: SheetSlot;
|
|
158
|
+
footer?: SheetSlot;
|
|
159
|
+
children?: SheetSlot;
|
|
160
|
+
|
|
161
|
+
size?: SheetSize;
|
|
162
|
+
safeArea?: boolean | SheetSafeAreaEdges;
|
|
163
|
+
detents?: readonly SheetDetent[];
|
|
164
|
+
detentIndex?: number;
|
|
165
|
+
defaultDetentIndex?: number;
|
|
166
|
+
onDetentChange?: (index: number, payload: SheetDetentChangePayload) => void;
|
|
167
|
+
nativeProps?: SheetNativeProps;
|
|
168
|
+
|
|
169
|
+
backgroundColor?: ColorValue;
|
|
170
|
+
cornerRadius?: number;
|
|
171
|
+
maxHeight?: number;
|
|
172
|
+
maxWidth?: number;
|
|
173
|
+
handle?: boolean | SheetHandleConfig;
|
|
174
|
+
animation?: SheetAnimationConfig | false;
|
|
175
|
+
dragCloseThreshold?: number;
|
|
176
|
+
dragVelocityThreshold?: number;
|
|
177
|
+
style?: StyleProp<ViewStyle>;
|
|
178
|
+
headerStyle?: StyleProp<ViewStyle>;
|
|
179
|
+
footerStyle?: StyleProp<ViewStyle>;
|
|
180
|
+
|
|
181
|
+
testID?: ViewProps['testID'];
|
|
182
|
+
accessibilityLabel?: ViewProps['accessibilityLabel'];
|
|
183
|
+
backdropAccessibilityLabel?: string;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export type SheetHeaderProps = ViewProps & {
|
|
187
|
+
title?: React.ReactNode;
|
|
188
|
+
description?: React.ReactNode;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export type SheetContentProps = ViewProps;
|
|
192
|
+
|
|
193
|
+
export type SheetFooterProps = ViewProps & {
|
|
194
|
+
safeArea?: boolean;
|
|
195
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# SliderCaptcha
|
|
2
|
+
|
|
3
|
+
滑动拼图验证码弹层组件,负责通用的 UI、拖拽映射、校验反馈和失败后自动刷新。
|
|
4
|
+
|
|
5
|
+
## 设计边界
|
|
6
|
+
|
|
7
|
+
- `zkit-ui` 负责:
|
|
8
|
+
- 弹层展示
|
|
9
|
+
- 图片缩放与坐标换算
|
|
10
|
+
- 滑块拖拽与释放触发校验
|
|
11
|
+
- `loading / verifying / success / error` 状态反馈
|
|
12
|
+
- 校验失败后的自动重载
|
|
13
|
+
- 业务方负责:
|
|
14
|
+
- 拉取验证码题目
|
|
15
|
+
- 调用业务接口做验证
|
|
16
|
+
- 成功后的页面跳转、倒计时、埋点等副作用
|
|
17
|
+
|
|
18
|
+
## 最小示例
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import * as React from 'react';
|
|
22
|
+
import { SliderCaptcha, type SliderCaptchaChallenge } from 'zkit-ui';
|
|
23
|
+
|
|
24
|
+
type LoginCaptchaChallenge = SliderCaptchaChallenge & {
|
|
25
|
+
nonceStr: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function Example() {
|
|
29
|
+
const [visible, setVisible] = React.useState(false);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<SliderCaptcha<LoginCaptchaChallenge>
|
|
33
|
+
visible={visible}
|
|
34
|
+
onClose={() => setVisible(false)}
|
|
35
|
+
loadChallenge={async () => {
|
|
36
|
+
const res = await fetchCaptcha();
|
|
37
|
+
return {
|
|
38
|
+
nonceStr: res.nonceStr,
|
|
39
|
+
backgroundImage: res.canvasSrc,
|
|
40
|
+
blockImage: res.blockSrc,
|
|
41
|
+
blockY: res.blockY,
|
|
42
|
+
originalWidth: 320,
|
|
43
|
+
originalHeight: 220,
|
|
44
|
+
blockWidth: 50,
|
|
45
|
+
blockHeight: 50,
|
|
46
|
+
};
|
|
47
|
+
}}
|
|
48
|
+
verifyChallenge={async ({ challenge, offsetX }) => {
|
|
49
|
+
const res = await verifyCaptcha({
|
|
50
|
+
nonceStr: challenge.nonceStr,
|
|
51
|
+
blockX: offsetX,
|
|
52
|
+
});
|
|
53
|
+
return res.ok;
|
|
54
|
+
}}
|
|
55
|
+
onVerified={() => {
|
|
56
|
+
setVisible(false);
|
|
57
|
+
}}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|