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,230 @@
|
|
|
1
|
+
#import "ZKitWheelPicker.h"
|
|
2
|
+
|
|
3
|
+
#import <React/RCTConvert.h>
|
|
4
|
+
#import <React/RCTUtils.h>
|
|
5
|
+
|
|
6
|
+
#import "ZKitWheelPickerLabel.h"
|
|
7
|
+
|
|
8
|
+
@interface ZKitWheelPicker() <UIPickerViewDataSource, UIPickerViewDelegate, UIPickerViewAccessibilityDelegate>
|
|
9
|
+
@end
|
|
10
|
+
|
|
11
|
+
@implementation ZKitWheelPicker
|
|
12
|
+
|
|
13
|
+
static void ZKitStopDeceleratingScrollViews(UIView *view)
|
|
14
|
+
{
|
|
15
|
+
for (UIView *subview in view.subviews) {
|
|
16
|
+
if ([subview isKindOfClass:[UIScrollView class]]) {
|
|
17
|
+
UIScrollView *scrollView = (UIScrollView *)subview;
|
|
18
|
+
[scrollView setContentOffset:scrollView.contentOffset animated:NO];
|
|
19
|
+
[scrollView.layer removeAllAnimations];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
ZKitStopDeceleratingScrollViews(subview);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
- (instancetype)initWithFrame:(CGRect)frame
|
|
27
|
+
{
|
|
28
|
+
self = [super initWithFrame:frame];
|
|
29
|
+
if (!self) {
|
|
30
|
+
return nil;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
_items = @[];
|
|
34
|
+
_selectedIndex = NSNotFound;
|
|
35
|
+
_color = [UIColor blackColor];
|
|
36
|
+
_font = [UIFont systemFontOfSize:21 weight:UIFontWeightRegular];
|
|
37
|
+
_rowHeight = 0;
|
|
38
|
+
_numberOfLines = 1;
|
|
39
|
+
|
|
40
|
+
self.delegate = self;
|
|
41
|
+
self.dataSource = self;
|
|
42
|
+
|
|
43
|
+
// 保持系统中间选中指示线稳定显示。
|
|
44
|
+
[self selectRow:0 inComponent:0 animated:YES];
|
|
45
|
+
|
|
46
|
+
return self;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)coder)
|
|
50
|
+
|
|
51
|
+
- (void)setItems:(NSArray<NSDictionary *> *)items
|
|
52
|
+
{
|
|
53
|
+
_items = [items copy] ?: @[];
|
|
54
|
+
[self reloadAllComponents];
|
|
55
|
+
[self setNeedsLayout];
|
|
56
|
+
|
|
57
|
+
if (_items.count == 0) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
NSInteger targetIndex = _selectedIndex == NSNotFound ? 0 : _selectedIndex;
|
|
62
|
+
targetIndex = MAX(0, MIN(targetIndex, (NSInteger)_items.count - 1));
|
|
63
|
+
_selectedIndex = targetIndex;
|
|
64
|
+
|
|
65
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
66
|
+
[self selectRow:targetIndex inComponent:0 animated:NO];
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
- (void)setSelectedIndex:(NSInteger)selectedIndex
|
|
71
|
+
{
|
|
72
|
+
if (_selectedIndex == selectedIndex) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
NSInteger previousIndex = _selectedIndex;
|
|
77
|
+
_selectedIndex = selectedIndex;
|
|
78
|
+
|
|
79
|
+
if (_items.count == 0) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
NSInteger targetIndex = MAX(0, MIN(selectedIndex, (NSInteger)_items.count - 1));
|
|
84
|
+
BOOL animated = previousIndex != NSNotFound;
|
|
85
|
+
|
|
86
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
87
|
+
[self selectRow:targetIndex inComponent:0 animated:animated];
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
- (void)setColor:(UIColor *)color
|
|
92
|
+
{
|
|
93
|
+
_color = color ?: [UIColor blackColor];
|
|
94
|
+
[self reloadAllComponents];
|
|
95
|
+
[self setNeedsLayout];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
- (void)setFont:(UIFont *)font
|
|
99
|
+
{
|
|
100
|
+
_font = font ?: [UIFont systemFontOfSize:21 weight:UIFontWeightRegular];
|
|
101
|
+
[self reloadAllComponents];
|
|
102
|
+
[self setNeedsLayout];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
- (void)setRowHeight:(CGFloat)rowHeight
|
|
106
|
+
{
|
|
107
|
+
if (_rowHeight == rowHeight) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
_rowHeight = rowHeight;
|
|
112
|
+
[self reloadAllComponents];
|
|
113
|
+
[self setNeedsLayout];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
- (void)setNumberOfLines:(NSInteger)numberOfLines
|
|
117
|
+
{
|
|
118
|
+
_numberOfLines = MAX(1, numberOfLines);
|
|
119
|
+
[self reloadAllComponents];
|
|
120
|
+
[self setNeedsLayout];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
- (void)syncCurrentSelection
|
|
124
|
+
{
|
|
125
|
+
if (_items.count == 0) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
ZKitStopDeceleratingScrollViews(self);
|
|
130
|
+
[self layoutIfNeeded];
|
|
131
|
+
|
|
132
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
133
|
+
NSInteger row = [self selectedRowInComponent:0];
|
|
134
|
+
if (row < 0) {
|
|
135
|
+
row = self->_selectedIndex != NSNotFound ? self->_selectedIndex : 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
row = MAX(0, MIN(row, (NSInteger)self->_items.count - 1));
|
|
139
|
+
[self selectRow:row inComponent:0 animated:NO];
|
|
140
|
+
[self pickerView:self didSelectRow:row inComponent:0];
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
- (NSInteger)numberOfComponentsInPickerView:(__unused UIPickerView *)pickerView
|
|
145
|
+
{
|
|
146
|
+
return 1;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
- (NSInteger)pickerView:(__unused UIPickerView *)pickerView numberOfRowsInComponent:(__unused NSInteger)component
|
|
150
|
+
{
|
|
151
|
+
return _items.count;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
- (NSString *)pickerView:(__unused UIPickerView *)pickerView
|
|
155
|
+
titleForRow:(NSInteger)row
|
|
156
|
+
forComponent:(__unused NSInteger)component
|
|
157
|
+
{
|
|
158
|
+
if (row < 0 || row >= (NSInteger)_items.count) {
|
|
159
|
+
return @"";
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return [RCTConvert NSString:_items[row][@"label"]] ?: @"";
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
- (CGFloat)pickerView:(__unused UIPickerView *)pickerView rowHeightForComponent:(__unused NSInteger)component
|
|
166
|
+
{
|
|
167
|
+
if (_rowHeight > 0) {
|
|
168
|
+
return _rowHeight;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return (_font.lineHeight * MAX(1, _numberOfLines)) + 20.0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
- (UIView *)pickerView:(UIPickerView *)pickerView
|
|
175
|
+
viewForRow:(NSInteger)row
|
|
176
|
+
forComponent:(NSInteger)component
|
|
177
|
+
reusingView:(UIView *)view
|
|
178
|
+
{
|
|
179
|
+
CGFloat rowHeight = [pickerView rowSizeForComponent:component].height;
|
|
180
|
+
CGFloat rowWidth = [pickerView rowSizeForComponent:component].width;
|
|
181
|
+
|
|
182
|
+
if (!view) {
|
|
183
|
+
view = [[UIView alloc] initWithFrame:CGRectZero];
|
|
184
|
+
ZKitWheelPickerLabel *label = [[ZKitWheelPickerLabel alloc] initWithFrame:CGRectZero];
|
|
185
|
+
[view insertSubview:label atIndex:0];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
view.frame = CGRectMake(0, 0, rowWidth, rowHeight);
|
|
189
|
+
|
|
190
|
+
ZKitWheelPickerLabel *label = (ZKitWheelPickerLabel *)view.subviews.firstObject;
|
|
191
|
+
label.frame = CGRectMake(0, 0, rowWidth, rowHeight);
|
|
192
|
+
label.font = _font;
|
|
193
|
+
label.textColor = [RCTConvert UIColor:_items[row][@"textColor"]] ?: _color;
|
|
194
|
+
label.textAlignment = NSTextAlignmentCenter;
|
|
195
|
+
label.text = [self pickerView:pickerView titleForRow:row forComponent:component];
|
|
196
|
+
label.accessibilityIdentifier = _items[row][@"testID"];
|
|
197
|
+
label.numberOfLines = MAX(1, _numberOfLines);
|
|
198
|
+
label.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
199
|
+
label.adjustsFontSizeToFitWidth = NO;
|
|
200
|
+
label.leftInset = 20.0;
|
|
201
|
+
label.rightInset = 20.0;
|
|
202
|
+
|
|
203
|
+
return view;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
- (void)pickerView:(__unused UIPickerView *)pickerView
|
|
207
|
+
didSelectRow:(NSInteger)row
|
|
208
|
+
inComponent:(__unused NSInteger)component
|
|
209
|
+
{
|
|
210
|
+
_selectedIndex = row;
|
|
211
|
+
|
|
212
|
+
if (_onChange && row >= 0 && row < (NSInteger)_items.count) {
|
|
213
|
+
_onChange(@{
|
|
214
|
+
@"newIndex": @(row),
|
|
215
|
+
@"newValue": RCTNullIfNil(_items[row][@"value"]),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
- (NSString *)pickerView:(UIPickerView *)pickerView accessibilityLabelForComponent:(NSInteger)component
|
|
221
|
+
{
|
|
222
|
+
return self.accessibilityLabel;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
- (NSString *)pickerView:(UIPickerView *)pickerView accessibilityHintForComponent:(NSInteger)component
|
|
226
|
+
{
|
|
227
|
+
return self.accessibilityHint;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
@end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
@interface ZKitWheelPickerLabel : UILabel
|
|
4
|
+
|
|
5
|
+
@property (nonatomic, assign) CGFloat topInset;
|
|
6
|
+
@property (nonatomic, assign) CGFloat bottomInset;
|
|
7
|
+
@property (nonatomic, assign) CGFloat leftInset;
|
|
8
|
+
@property (nonatomic, assign) CGFloat rightInset;
|
|
9
|
+
|
|
10
|
+
@end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#import "ZKitWheelPickerLabel.h"
|
|
2
|
+
|
|
3
|
+
@implementation ZKitWheelPickerLabel
|
|
4
|
+
|
|
5
|
+
- (instancetype)initWithFrame:(CGRect)frame
|
|
6
|
+
{
|
|
7
|
+
self = [super initWithFrame:frame];
|
|
8
|
+
if (self) {
|
|
9
|
+
self.topInset = 0.0;
|
|
10
|
+
self.bottomInset = 0.0;
|
|
11
|
+
self.leftInset = 0.0;
|
|
12
|
+
self.rightInset = 0.0;
|
|
13
|
+
}
|
|
14
|
+
return self;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
- (void)drawTextInRect:(CGRect)rect
|
|
18
|
+
{
|
|
19
|
+
UIEdgeInsets insets = UIEdgeInsetsMake(self.topInset, self.leftInset, self.bottomInset, self.rightInset);
|
|
20
|
+
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
- (CGSize)intrinsicContentSize
|
|
24
|
+
{
|
|
25
|
+
CGSize intrinsicSize = [super intrinsicContentSize];
|
|
26
|
+
intrinsicSize.height += self.topInset + self.bottomInset;
|
|
27
|
+
intrinsicSize.width += self.leftInset + self.rightInset;
|
|
28
|
+
return intrinsicSize;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#import "ZKitWheelPickerManager.h"
|
|
2
|
+
|
|
3
|
+
#import <React/RCTBridge.h>
|
|
4
|
+
#import <React/RCTFont.h>
|
|
5
|
+
#import <React/RCTUIManager.h>
|
|
6
|
+
|
|
7
|
+
#import "ZKitWheelPicker.h"
|
|
8
|
+
|
|
9
|
+
@implementation ZKitWheelPickerManager
|
|
10
|
+
|
|
11
|
+
RCT_EXPORT_MODULE(ZKitWheelPicker)
|
|
12
|
+
|
|
13
|
+
- (UIView *)view
|
|
14
|
+
{
|
|
15
|
+
return [ZKitWheelPicker new];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
RCT_EXPORT_VIEW_PROPERTY(items, NSArray<NSDictionary *>)
|
|
19
|
+
RCT_EXPORT_VIEW_PROPERTY(selectedIndex, NSInteger)
|
|
20
|
+
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
|
|
21
|
+
RCT_EXPORT_VIEW_PROPERTY(color, UIColor)
|
|
22
|
+
RCT_EXPORT_VIEW_PROPERTY(numberOfLines, NSInteger)
|
|
23
|
+
RCT_EXPORT_VIEW_PROPERTY(rowHeight, CGFloat)
|
|
24
|
+
RCT_CUSTOM_VIEW_PROPERTY(fontSize, NSNumber, ZKitWheelPicker)
|
|
25
|
+
{
|
|
26
|
+
view.font = [RCTFont updateFont:view.font withSize:json ?: @(defaultView.font.pointSize)];
|
|
27
|
+
}
|
|
28
|
+
RCT_CUSTOM_VIEW_PROPERTY(fontWeight, NSString, ZKitWheelPicker)
|
|
29
|
+
{
|
|
30
|
+
view.font = [RCTFont updateFont:view.font withWeight:json];
|
|
31
|
+
}
|
|
32
|
+
RCT_CUSTOM_VIEW_PROPERTY(fontStyle, NSString, ZKitWheelPicker)
|
|
33
|
+
{
|
|
34
|
+
view.font = [RCTFont updateFont:view.font withStyle:json];
|
|
35
|
+
}
|
|
36
|
+
RCT_CUSTOM_VIEW_PROPERTY(fontFamily, NSString, ZKitWheelPicker)
|
|
37
|
+
{
|
|
38
|
+
view.font = [RCTFont updateFont:view.font withFamily:json ?: defaultView.font.familyName];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
RCT_EXPORT_METHOD(syncCurrentSelection:(nonnull NSNumber *)reactTag)
|
|
42
|
+
{
|
|
43
|
+
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
44
|
+
UIView *view = viewRegistry[reactTag];
|
|
45
|
+
if (![view isKindOfClass:[ZKitWheelPicker class]]) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
[(ZKitWheelPicker *)view syncCurrentSelection];
|
|
50
|
+
}];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@end
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "zkit-ui",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"source": "src/index.ts",
|
|
8
|
+
"react-native": "dist/index.js",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Concur-max/zkit.git",
|
|
12
|
+
"directory": "packages/ui"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/Concur-max/zkit/tree/main/packages/ui",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/Concur-max/zkit/issues"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"src",
|
|
21
|
+
"ios",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"zkit-ui.podspec",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"registry": "https://registry.npmjs.org/"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@vant/area-data": "^2.1.0",
|
|
31
|
+
"dayjs": "^1.11.13",
|
|
32
|
+
"react-native-toast-message": "^2.3.3",
|
|
33
|
+
"zkit-tools": "1.0.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@expo/vector-icons": "*",
|
|
37
|
+
"@lodev09/react-native-true-sheet": "*",
|
|
38
|
+
"@shopify/flash-list": "*",
|
|
39
|
+
"expo-image": "*",
|
|
40
|
+
"expo-linear-gradient": "*",
|
|
41
|
+
"lottie-react-native": "*",
|
|
42
|
+
"react": "*",
|
|
43
|
+
"react-native": "*",
|
|
44
|
+
"react-native-gesture-handler": "*",
|
|
45
|
+
"react-native-reanimated": "*",
|
|
46
|
+
"react-native-safe-area-context": "*",
|
|
47
|
+
"react-native-svg": "*",
|
|
48
|
+
"react-native-worklets": "*",
|
|
49
|
+
"sonner-native": "*"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@expo/vector-icons": "^15.1.1",
|
|
53
|
+
"@shopify/flash-list": "^2.3.1",
|
|
54
|
+
"@types/react": "~19.1.17",
|
|
55
|
+
"dayjs": "^1.11.13",
|
|
56
|
+
"expo-image": "~3.0.11",
|
|
57
|
+
"expo-linear-gradient": "~15.0.8",
|
|
58
|
+
"lottie-react-native": "7.3.2",
|
|
59
|
+
"react": "19.1.0",
|
|
60
|
+
"react-native": "0.81.5",
|
|
61
|
+
"react-native-gesture-handler": "~2.28.0",
|
|
62
|
+
"react-native-reanimated": "~4.1.6",
|
|
63
|
+
"react-native-safe-area-context": "5.6.2",
|
|
64
|
+
"react-native-screens": "~4.16.0",
|
|
65
|
+
"react-native-svg": "^15.12.1",
|
|
66
|
+
"react-native-worklets": "0.5.1",
|
|
67
|
+
"sonner-native": "^0.22.2",
|
|
68
|
+
"typescript": "~5.9.3",
|
|
69
|
+
"@lodev09/react-native-true-sheet": "3.10.0"
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "node scripts/build.cjs",
|
|
73
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { I18nProvider } from './i18n/I18nProvider';
|
|
3
|
+
import type { I18nMessages, I18nMissingKeyPolicy } from './i18n/types';
|
|
4
|
+
import { ActionDialogProvider } from './services/ActionDialogService/index';
|
|
5
|
+
import { ToastProvider } from './services/CardToastService/index';
|
|
6
|
+
import { ImagePreviewProvider } from './services/ImagePreviewService/index';
|
|
7
|
+
import { LoadingProvider, type LoadingDefaults } from './services/LoadingService/index';
|
|
8
|
+
import { PermissionPurposeDialogProvider } from './services/PermissionPurposeDialogService/index';
|
|
9
|
+
import { PickerServiceProvider } from './services/PickerService/index';
|
|
10
|
+
import { ThemeProvider } from './theme/ThemeProvider';
|
|
11
|
+
import type { Theme, ThemeOverride } from './theme/types';
|
|
12
|
+
|
|
13
|
+
export type ComponentLibProviderProps = {
|
|
14
|
+
// baseTheme 用于传入完整主题作为基线(例如品牌主题)
|
|
15
|
+
baseTheme?: Theme;
|
|
16
|
+
// theme 用于对 baseTheme 做局部覆盖(例如只改 primary)
|
|
17
|
+
theme?: ThemeOverride;
|
|
18
|
+
locale?: string;
|
|
19
|
+
messages?: I18nMessages;
|
|
20
|
+
missingKeyPolicy?: I18nMissingKeyPolicy;
|
|
21
|
+
loading?: LoadingDefaults;
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// ComponentLibProvider 是组件库推荐的顶层 Provider:
|
|
26
|
+
// - 同时提供 Theme 与 i18n
|
|
27
|
+
// - 避免业务方在 App 里层层包裹多个 Provider
|
|
28
|
+
export function ComponentLibProvider({
|
|
29
|
+
baseTheme,
|
|
30
|
+
theme,
|
|
31
|
+
locale,
|
|
32
|
+
messages,
|
|
33
|
+
missingKeyPolicy,
|
|
34
|
+
loading,
|
|
35
|
+
children,
|
|
36
|
+
}: ComponentLibProviderProps) {
|
|
37
|
+
return (
|
|
38
|
+
<ThemeProvider baseTheme={baseTheme} theme={theme}>
|
|
39
|
+
<I18nProvider locale={locale} messages={messages} missingKeyPolicy={missingKeyPolicy}>
|
|
40
|
+
<PickerServiceProvider>
|
|
41
|
+
<ToastProvider>
|
|
42
|
+
<ActionDialogProvider>
|
|
43
|
+
<LoadingProvider defaults={loading}>
|
|
44
|
+
<PermissionPurposeDialogProvider>
|
|
45
|
+
<ImagePreviewProvider>
|
|
46
|
+
{children}
|
|
47
|
+
</ImagePreviewProvider>
|
|
48
|
+
</PermissionPurposeDialogProvider>
|
|
49
|
+
</LoadingProvider>
|
|
50
|
+
</ActionDialogProvider>
|
|
51
|
+
</ToastProvider>
|
|
52
|
+
</PickerServiceProvider>
|
|
53
|
+
</I18nProvider>
|
|
54
|
+
</ThemeProvider>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"v":"5.7.5","fr":60,"ip":0,"op":61,"w":600,"h":600,"nm":"ios-spinner","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"1","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[100]},{"t":60,"s":[0]}],"ix":11},"r":{"a":0,"k":-180,"ix":10},"p":{"a":0,"k":[300,300,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[13,22],[13,124]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0,0,0,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":40,"ix":5},"lc":2,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[11,-82],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":61,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"2","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[8]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":4,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":5,"s":[100]},{"t":60,"s":[8]}],"ix":11},"r":{"a":0,"k":-150,"ix":10},"p":{"a":0,"k":[300,300,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[13,22],[13,124]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0,0,0,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":40,"ix":5},"lc":2,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[11,-82],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":61,"st":0,"bm":0},{"ddd":0,"ind":3,"ty":4,"nm":"3","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[16]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":9,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":10,"s":[100]},{"t":60,"s":[16]}],"ix":11},"r":{"a":0,"k":-120,"ix":10},"p":{"a":0,"k":[300,300,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[13,22],[13,124]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0,0,0,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":40,"ix":5},"lc":2,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[11,-82],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":61,"st":0,"bm":0},{"ddd":0,"ind":4,"ty":4,"nm":"4","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[24]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":14,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":15,"s":[100]},{"t":60,"s":[24]}],"ix":11},"r":{"a":0,"k":-90,"ix":10},"p":{"a":0,"k":[300,300,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[13,22],[13,124]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0,0,0,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":40,"ix":5},"lc":2,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[11,-82],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":61,"st":0,"bm":0},{"ddd":0,"ind":5,"ty":4,"nm":"5","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[32]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":19,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":20,"s":[100]},{"t":60,"s":[32]}],"ix":11},"r":{"a":0,"k":-60,"ix":10},"p":{"a":0,"k":[300,300,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[13,22],[13,124]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0,0,0,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":40,"ix":5},"lc":2,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[11,-82],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":61,"st":0,"bm":0},{"ddd":0,"ind":6,"ty":4,"nm":"6","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[40]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":24,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":25,"s":[100]},{"t":60,"s":[40]}],"ix":11},"r":{"a":0,"k":-30,"ix":10},"p":{"a":0,"k":[300,300,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[13,22],[13,124]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0,0,0,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":40,"ix":5},"lc":2,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[11,-82],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":61,"st":0,"bm":0},{"ddd":0,"ind":7,"ty":4,"nm":"7","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[48]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":29,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":30,"s":[100]},{"t":60,"s":[48]}],"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[300,300,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[13,22],[13,124]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0,0,0,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":40,"ix":5},"lc":2,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[11,-82],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":61,"st":0,"bm":0},{"ddd":0,"ind":8,"ty":4,"nm":"8","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[56]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":34,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":35,"s":[100]},{"t":60,"s":[56]}],"ix":11},"r":{"a":0,"k":-330,"ix":10},"p":{"a":0,"k":[300,300,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[13,22],[13,124]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0,0,0,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":40,"ix":5},"lc":2,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[11,-82],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":61,"st":0,"bm":0},{"ddd":0,"ind":9,"ty":4,"nm":"9","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[64]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":39,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":40,"s":[100]},{"t":60,"s":[64]}],"ix":11},"r":{"a":0,"k":-300,"ix":10},"p":{"a":0,"k":[300,300,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[13,22],[13,124]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0,0,0,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":40,"ix":5},"lc":2,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[11,-82],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":61,"st":0,"bm":0},{"ddd":0,"ind":10,"ty":4,"nm":"10","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[72]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":44,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":45,"s":[100]},{"t":60,"s":[72]}],"ix":11},"r":{"a":0,"k":-270,"ix":10},"p":{"a":0,"k":[300,300,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[13,22],[13,124]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0,0,0,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":40,"ix":5},"lc":2,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[11,-82],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":61,"st":0,"bm":0},{"ddd":0,"ind":11,"ty":4,"nm":"11","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[80]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":49,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":50,"s":[100]},{"t":60,"s":[80]}],"ix":11},"r":{"a":0,"k":-240,"ix":10},"p":{"a":0,"k":[300,300,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[13,22],[13,124]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0,0,0,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":40,"ix":5},"lc":2,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[11,-82],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":61,"st":0,"bm":0},{"ddd":0,"ind":12,"ty":4,"nm":"12","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[88]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":54,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":55,"s":[100]},{"t":60,"s":[88]}],"ix":11},"r":{"a":0,"k":-210,"ix":10},"p":{"a":0,"k":[300,300,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[13,22],[13,124]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0,0,0,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":40,"ix":5},"lc":2,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[11,-82],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":61,"st":0,"bm":0}],"markers":[]}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { defaultTheme } from './theme/defaultTheme';
|
|
2
|
+
import { mergeTheme } from './theme/mergeTheme';
|
|
3
|
+
import type { Theme, ThemeOverride } from './theme/types';
|
|
4
|
+
import { resolveSystemBuiltinLocale } from './i18n/locale';
|
|
5
|
+
import type { I18nMessages, I18nMissingKeyPolicy } from './i18n/types';
|
|
6
|
+
|
|
7
|
+
// zkit-ui 提供两类“全局默认配置”入口:
|
|
8
|
+
// 1) Theme:用于给所有组件提供默认 tokens(颜色等)
|
|
9
|
+
// 2) i18n:用于给所有组件提供默认文案字典/缺失策略
|
|
10
|
+
//
|
|
11
|
+
// 推荐在应用启动时调用一次 configureComponentLib()(例如在 app entry),
|
|
12
|
+
// 这样即便业务侧没有包 Provider,组件库也能拿到一致的默认值。
|
|
13
|
+
export type ComponentLibI18nConfig = {
|
|
14
|
+
// locale 目前仅用于透传;组件内部可据此选择 key 前缀或做格式化扩展
|
|
15
|
+
locale?: string;
|
|
16
|
+
// messages 是 key -> 文案 的扁平字典,组件内部用 t(key) 获取
|
|
17
|
+
messages?: I18nMessages;
|
|
18
|
+
// missingKeyPolicy:
|
|
19
|
+
// - key:找不到 key 就直接回显 key(对线上更友好)
|
|
20
|
+
// - throw:找不到 key 直接抛错(对开发/测试更“fail-fast”)
|
|
21
|
+
missingKeyPolicy?: I18nMissingKeyPolicy;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type ComponentLibConfig = {
|
|
25
|
+
// theme 是“覆盖对象”,只需要传你要改的字段即可(未传字段回落到 defaultTheme)
|
|
26
|
+
theme?: ThemeOverride;
|
|
27
|
+
i18n?: ComponentLibI18nConfig;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
let componentLibConfig: ComponentLibConfig = {};
|
|
31
|
+
|
|
32
|
+
// 合并式更新:多次调用会按层级合并(不会把之前的 i18n 整块覆盖掉)
|
|
33
|
+
export function configureComponentLib(next: ComponentLibConfig) {
|
|
34
|
+
componentLibConfig = {
|
|
35
|
+
...componentLibConfig,
|
|
36
|
+
...next,
|
|
37
|
+
i18n: {
|
|
38
|
+
...componentLibConfig.i18n,
|
|
39
|
+
...next.i18n,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getComponentLibConfig(): ComponentLibConfig {
|
|
45
|
+
return componentLibConfig;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// getDefaultTheme 用于生成“当前有效的默认主题”:
|
|
49
|
+
// - defaultTheme 作为组件库内置基线
|
|
50
|
+
// - configureComponentLib({ theme }) 提供全局覆盖
|
|
51
|
+
// - ThemeProvider({ theme }) 再做实例级覆盖(优先级更高)
|
|
52
|
+
export function getDefaultTheme(): Theme {
|
|
53
|
+
return mergeTheme(defaultTheme, componentLibConfig.theme);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// getDefaultI18nConfig 用于生成“当前有效的默认 i18n 配置”:
|
|
57
|
+
// - configureComponentLib({ i18n }) 可在应用启动时设定默认 locale/messages
|
|
58
|
+
// - I18nProvider({ ... }) 可在局部覆盖(例如某个子树临时切换语言)
|
|
59
|
+
export function getDefaultI18nConfig(): Required<ComponentLibI18nConfig> {
|
|
60
|
+
return {
|
|
61
|
+
locale: componentLibConfig.i18n?.locale ?? resolveSystemBuiltinLocale(),
|
|
62
|
+
messages: componentLibConfig.i18n?.messages ?? {},
|
|
63
|
+
missingKeyPolicy: componentLibConfig.i18n?.missingKeyPolicy ?? 'key',
|
|
64
|
+
};
|
|
65
|
+
}
|