taro-uno-ui 0.9.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/js/{index-DffLRSro.js → index-CDFsvu80.js} +15369 -10741
- package/dist/js/index-CDFsvu80.js.map +1 -0
- package/dist/js/index-DFdcksbe.js.map +1 -1
- package/dist/js/index-DXRIkWX1.js.map +1 -1
- package/dist/js/{index-6NJ3A1Dn.js → index-JffnTUrv.js} +15430 -10801
- package/dist/js/index-JffnTUrv.js.map +1 -0
- package/dist/utils/http/request.d.ts +280 -0
- package/package.json +14 -10
- package/src/components/basic/Button/Button.tsx +53 -13
- package/src/components/basic/Button/Button.types.ts +45 -9
- package/src/components/basic/Divider/Divider.tsx +60 -29
- package/src/components/basic/Icon/Icon.data.ts +474 -0
- package/src/components/basic/Icon/Icon.test.tsx +2 -2
- package/src/components/basic/Icon/Icon.tsx +48 -35
- package/src/components/basic/Icon/IconManager.ts +229 -0
- package/src/components/basic/Text/Text.styles.ts +3 -3
- package/src/components/basic/Text/Text.types.ts +14 -4
- package/src/components/basic/Typography/Typography.styles.ts +10 -9
- package/src/components/basic/Typography/Typography.tsx +15 -13
- package/src/components/basic/Typography/Typography.types.ts +41 -41
- package/src/components/basic/Typography/index.tsx +1 -1
- package/src/components/basic/Video/Video.styles.ts +777 -0
- package/src/components/basic/Video/Video.test.tsx +490 -0
- package/src/components/basic/Video/Video.tsx +1468 -0
- package/src/components/basic/Video/Video.types.ts +500 -0
- package/src/components/basic/Video/index.tsx +26 -0
- package/src/components/basic/index.tsx +13 -15
- package/src/components/common/ErrorBoundary.tsx +1 -1
- package/src/components/common/LazyComponent.tsx +9 -8
- package/src/components/common/SecurityProvider.tsx +2 -14
- package/src/components/common/ThemeProvider.tsx +43 -56
- package/src/components/common/VirtualList.tsx +187 -205
- package/src/components/common/index.tsx +25 -0
- package/src/components/display/Avatar/Avatar.styles.ts +1 -1
- package/src/components/display/Avatar/Avatar.tsx +6 -19
- package/src/components/display/Avatar/Avatar.types.ts +1 -1
- package/src/components/display/Avatar/index.ts +1 -1
- package/src/components/display/Badge/Badge.tsx +3 -16
- package/src/components/display/Badge/Badge.types.ts +1 -1
- package/src/components/display/Badge/index.ts +1 -1
- package/src/components/display/Calendar/Calendar.styles.ts +36 -36
- package/src/components/display/Calendar/Calendar.test.tsx +27 -15
- package/src/components/display/Calendar/Calendar.tsx +56 -35
- package/src/components/display/Calendar/Calendar.types.ts +1 -1
- package/src/components/display/Calendar/index.ts +1 -1
- package/src/components/display/Card/Card.styles.ts +2 -2
- package/src/components/display/Card/Card.test.tsx +6 -4
- package/src/components/display/Card/Card.tsx +1 -1
- package/src/components/display/Card/Card.types.ts +4 -4
- package/src/components/display/Card/index.ts +1 -1
- package/src/components/display/Carousel/Carousel.styles.ts +31 -31
- package/src/components/display/Carousel/Carousel.tsx +34 -39
- package/src/components/display/Carousel/Carousel.types.ts +1 -1
- package/src/components/display/Carousel/index.ts +1 -1
- package/src/components/display/List/List.styles.ts +3 -3
- package/src/components/display/List/List.tsx +0 -1
- package/src/components/display/List/index.ts +1 -1
- package/src/components/display/Rate/Rate.styles.ts +5 -17
- package/src/components/display/Rate/Rate.tsx +6 -14
- package/src/components/display/Rate/Rate.types.ts +4 -3
- package/src/components/display/Rate/index.ts +3 -11
- package/src/components/display/Table/Table.test.tsx +2 -0
- package/src/components/display/Table/Table.tsx +3 -7
- package/src/components/display/Table/Table.types.ts +3 -2
- package/src/components/display/Tag/Tag.styles.ts +31 -31
- package/src/components/display/Tag/Tag.tsx +9 -26
- package/src/components/display/Tag/Tag.types.ts +1 -1
- package/src/components/display/Tag/index.ts +1 -1
- package/src/components/display/Timeline/Timeline.styles.ts +32 -32
- package/src/components/display/Timeline/Timeline.tsx +23 -42
- package/src/components/display/Timeline/Timeline.types.ts +1 -1
- package/src/components/display/Timeline/index.ts +1 -1
- package/src/components/display/index.tsx +33 -29
- package/src/components/feedback/Loading/Loading.tsx +6 -1
- package/src/components/feedback/Loading/index.ts +2 -5
- package/src/components/feedback/Message/Message.styles.ts +3 -3
- package/src/components/feedback/Message/index.ts +2 -5
- package/src/components/feedback/Modal/Modal.styles.ts +1 -1
- package/src/components/feedback/Modal/Modal.tsx +9 -31
- package/src/components/feedback/Modal/Modal.types.ts +12 -2
- package/src/components/feedback/Notification/Notification.styles.ts +49 -39
- package/src/components/feedback/Notification/Notification.test.tsx +1 -1
- package/src/components/feedback/Notification/Notification.tsx +97 -120
- package/src/components/feedback/Notification/Notification.types.ts +11 -8
- package/src/components/feedback/Notification/NotificationManager.tsx +135 -106
- package/src/components/feedback/Notification/index.ts +10 -3
- package/src/components/feedback/Notification/index.tsx +16 -26
- package/src/components/feedback/Progress/Progress.styles.ts +23 -14
- package/src/components/feedback/Progress/Progress.tsx +93 -113
- package/src/components/feedback/Progress/Progress.types.ts +1 -1
- package/src/components/feedback/Progress/index.ts +1 -1
- package/src/components/feedback/Progress/utils/animation.ts +12 -23
- package/src/components/feedback/Progress/utils/index.ts +2 -2
- package/src/components/feedback/Progress/utils/progress-calculator.ts +14 -32
- package/src/components/feedback/Result/Result.styles.ts +29 -29
- package/src/components/feedback/Result/Result.tsx +8 -20
- package/src/components/feedback/Result/Result.types.ts +7 -7
- package/src/components/feedback/Result/index.tsx +1 -1
- package/src/components/feedback/Toast/Toast.styles.ts +1 -1
- package/src/components/feedback/Toast/Toast.tsx +25 -13
- package/src/components/feedback/Tooltip/Tooltip.examples.tsx +21 -44
- package/src/components/feedback/Tooltip/Tooltip.styles.ts +16 -22
- package/src/components/feedback/Tooltip/Tooltip.test.tsx +1 -1
- package/src/components/feedback/Tooltip/Tooltip.tsx +65 -46
- package/src/components/feedback/Tooltip/Tooltip.types.ts +14 -20
- package/src/components/feedback/Tooltip/index.ts +1 -1
- package/src/components/feedback/Tooltip/index.tsx +12 -24
- package/src/components/feedback/index.tsx +54 -42
- package/src/components/form/Cascader/Cascader.styles.ts +2 -2
- package/src/components/form/Cascader/Cascader.tsx +84 -88
- package/src/components/form/Cascader/Cascader.types.ts +49 -50
- package/src/components/form/Cascader/hooks/useCascaderFieldNames.ts +11 -8
- package/src/components/form/Cascader/hooks/useCascaderOptions.ts +73 -55
- package/src/components/form/Cascader/hooks/useCascaderState.ts +31 -25
- package/src/components/form/Cascader/index.ts +1 -1
- package/src/components/form/Cascader/utils/formatDisplayValue.ts +4 -4
- package/src/components/form/Checkbox/Checkbox.styles.ts +83 -84
- package/src/components/form/Checkbox/Checkbox.tsx +2 -9
- package/src/components/form/Checkbox/CheckboxGroup.tsx +7 -7
- package/src/components/form/DatePicker/DatePicker.test.tsx +1 -1
- package/src/components/form/DatePicker/DatePicker.tsx +91 -75
- package/src/components/form/DatePicker/DatePicker.types.ts +4 -1
- package/src/components/form/Form/Form.tsx +66 -504
- package/src/components/form/Form/Form.types.ts +16 -1
- package/src/components/form/Form/useFormLogic.ts +497 -0
- package/src/components/form/Input/Input.styles.ts +8 -1
- package/src/components/form/Input/Input.tsx +55 -291
- package/src/components/form/Input/Input.types.ts +13 -1
- package/src/components/form/Input/useInputLogic.test.ts +82 -0
- package/src/components/form/Input/useInputLogic.ts +260 -0
- package/src/components/form/InputNumber/InputNumber.styles.ts +76 -25
- package/src/components/form/InputNumber/InputNumber.tsx +53 -21
- package/src/components/form/InputNumber/InputNumber.types.ts +21 -3
- package/src/components/form/InputNumber/components/InputNumberClearButton.tsx +3 -11
- package/src/components/form/InputNumber/components/InputNumberControls.tsx +3 -12
- package/src/components/form/InputNumber/hooks/index.ts +1 -1
- package/src/components/form/InputNumber/hooks/useInputNumberState.ts +7 -9
- package/src/components/form/InputNumber/hooks/useInputNumberValidation.ts +18 -17
- package/src/components/form/InputNumber/index.ts +7 -7
- package/src/components/form/Radio/Radio.styles.ts +1 -8
- package/src/components/form/Radio/Radio.tsx +3 -9
- package/src/components/form/Radio/Radio.types.ts +5 -1
- package/src/components/form/Select/Select.styles.ts +5 -1
- package/src/components/form/Select/Select.tsx +15 -15
- package/src/components/form/Select/Select.types.ts +2 -1
- package/src/components/form/Slider/Slider.styles.ts +13 -13
- package/src/components/form/Slider/Slider.tsx +19 -33
- package/src/components/form/Slider/Slider.types.ts +14 -12
- package/src/components/form/Slider/index.tsx +2 -9
- package/src/components/form/Switch/Switch.styles.ts +1 -7
- package/src/components/form/Switch/Switch.tsx +7 -13
- package/src/components/form/Textarea/Textarea.styles.ts +4 -4
- package/src/components/form/Textarea/Textarea.tsx +7 -1
- package/src/components/form/Textarea/Textarea.types.ts +4 -1
- package/src/components/form/TimePicker/TimePicker.styles.ts +8 -12
- package/src/components/form/TimePicker/TimePicker.tsx +122 -100
- package/src/components/form/TimePicker/TimePicker.types.ts +2 -2
- package/src/components/form/TimePicker/index.ts +1 -1
- package/src/components/form/Transfer/Transfer.styles.ts +3 -15
- package/src/components/form/Transfer/Transfer.tsx +146 -134
- package/src/components/form/Transfer/Transfer.types.ts +34 -26
- package/src/components/form/Transfer/components/TransferItem.tsx +55 -62
- package/src/components/form/Transfer/components/TransferList.tsx +212 -199
- package/src/components/form/Transfer/components/TransferOperations.tsx +52 -55
- package/src/components/form/Transfer/components/TransferPagination.tsx +115 -111
- package/src/components/form/Transfer/components/TransferSearch.tsx +52 -55
- package/src/components/form/Transfer/hooks/useTransferData.ts +91 -81
- package/src/components/form/Transfer/hooks/useTransferState.ts +22 -16
- package/src/components/form/Transfer/index.ts +2 -8
- package/src/components/form/Upload/Upload.styles.ts +21 -21
- package/src/components/form/Upload/Upload.tsx +189 -142
- package/src/components/form/Upload/Upload.types.ts +31 -31
- package/src/components/form/Upload/index.tsx +1 -1
- package/src/components/form/index.tsx +60 -29
- package/src/components/index.tsx +0 -1
- package/src/components/layout/Affix/Affix.styles.ts +16 -11
- package/src/components/layout/Affix/Affix.tsx +67 -75
- package/src/components/layout/Affix/Affix.types.ts +18 -18
- package/src/components/layout/Affix/index.tsx +1 -1
- package/src/components/layout/Col/Col.styles.ts +17 -17
- package/src/components/layout/Col/Col.test.tsx +7 -5
- package/src/components/layout/Col/Col.tsx +3 -21
- package/src/components/layout/Col/Col.types.ts +1 -1
- package/src/components/layout/Container/Container.styles.ts +3 -1
- package/src/components/layout/Container/Container.tsx +2 -11
- package/src/components/layout/Grid/Grid.tsx +3 -53
- package/src/components/layout/Layout/Content.tsx +24 -32
- package/src/components/layout/Layout/Footer.tsx +24 -32
- package/src/components/layout/Layout/Header.tsx +24 -32
- package/src/components/layout/Layout/Layout.styles.ts +17 -17
- package/src/components/layout/Layout/Layout.tsx +14 -25
- package/src/components/layout/Layout/Layout.types.ts +29 -29
- package/src/components/layout/Layout/Sider.tsx +44 -56
- package/src/components/layout/Layout/index.tsx +16 -2
- package/src/components/layout/Row/Row.tsx +15 -43
- package/src/components/layout/Space/Space.tsx +3 -11
- package/src/components/layout/Space/Space.types.ts +1 -1
- package/src/components/layout/index.tsx +29 -19
- package/src/components/navigation/Menu/Menu.constants.ts +69 -0
- package/src/components/navigation/Menu/Menu.stories.tsx +107 -0
- package/src/components/navigation/Menu/Menu.styles.ts +25 -37
- package/src/components/navigation/Menu/Menu.tsx +8 -11
- package/src/components/navigation/Menu/Menu.types.ts +2 -2
- package/src/components/navigation/Menu/Menu.utils.ts +17 -17
- package/src/components/navigation/Menu/MenuItem.tsx +9 -11
- package/src/components/navigation/Menu/SubMenu.tsx +8 -6
- package/src/components/navigation/Menu/index.tsx +4 -69
- package/src/components/navigation/NavBar/NavBar.styles.ts +1 -1
- package/src/components/navigation/NavBar/NavBar.tsx +7 -10
- package/src/components/navigation/NavBar/NavBar.types.ts +3 -3
- package/src/components/navigation/NavBar/index.tsx +1 -1
- package/src/components/navigation/Pagination/Pagination.test.tsx +2 -3
- package/src/components/navigation/Pagination/Pagination.tsx +3 -3
- package/src/components/navigation/Pagination/Pagination.types.ts +3 -2
- package/src/components/navigation/Pagination/index.ts +9 -3
- package/src/components/navigation/Steps/Step.tsx +24 -44
- package/src/components/navigation/Steps/Steps.styles.ts +28 -13
- package/src/components/navigation/Steps/Steps.test.tsx +2 -0
- package/src/components/navigation/Steps/Steps.tsx +88 -89
- package/src/components/navigation/Steps/Steps.types.ts +30 -30
- package/src/components/navigation/Steps/index.tsx +1 -1
- package/src/components/navigation/Tabs/Tabs.test.tsx +3 -2
- package/src/components/navigation/Tabs/Tabs.types.ts +4 -3
- package/src/components/navigation/index.tsx +21 -16
- package/src/constants/index.ts +1 -1
- package/src/hooks/index.ts +52 -102
- package/src/hooks/types.ts +4 -5
- package/src/hooks/useAsync.ts +46 -47
- package/src/hooks/useClickOutside.ts +52 -0
- package/src/hooks/useCounter.ts +87 -0
- package/src/hooks/useDebounce.ts +150 -0
- package/src/hooks/useDeepCompareEffect.ts +88 -0
- package/src/hooks/useEventListener.ts +77 -0
- package/src/hooks/useMediaQuery.ts +75 -0
- package/src/hooks/useMutation.ts +233 -0
- package/src/hooks/usePerformance.ts +1 -64
- package/src/hooks/usePlatform.ts +3 -1
- package/src/hooks/usePrevious.ts +25 -0
- package/src/hooks/useRequest.ts +12 -7
- package/src/hooks/useStateManagement.ts +1 -1
- package/src/hooks/useStorage.ts +169 -0
- package/src/hooks/useStyle.ts +8 -2
- package/src/hooks/useToggle.ts +54 -0
- package/src/index.ts +34 -9
- package/src/theme/ThemeProvider.tsx +3 -7
- package/src/theme/ThemeProvider.types.ts +1 -1
- package/src/theme/defaults.ts +1 -1
- package/src/theme/design-system.ts +2 -2
- package/src/theme/design-tokens.ts +85 -99
- package/src/theme/generated/dark-theme.scss +1 -1
- package/src/theme/generated/tokens.scss +82 -18
- package/src/theme/index.ts +8 -29
- package/src/theme/responsive.tsx +36 -34
- package/src/theme/styles.ts +1 -1
- package/src/theme/useThemeUtils.ts +43 -43
- package/src/theme/utils.ts +32 -32
- package/src/theme/variables.ts +70 -51
- package/src/types/accessibility.ts +36 -37
- package/src/types/button.ts +25 -27
- package/src/types/component-props.ts +6 -1
- package/src/types/glob.d.ts +4 -0
- package/src/types/index.ts +2 -2
- package/src/types/standardized-components.ts +9 -3
- package/src/types/utils.ts +13 -23
- package/src/utils/__tests__/responsiveUtils.test.ts +5 -4
- package/src/utils/abort-controller.ts +48 -0
- package/src/utils/cache.ts +2 -6
- package/src/utils/createNamespace.ts +4 -4
- package/src/utils/environment.ts +26 -6
- package/src/utils/error-handler.ts +2 -2
- package/src/utils/errorLogger.ts +16 -20
- package/src/utils/formatUtils.ts +38 -70
- package/src/utils/http/error-codes.ts +314 -0
- package/src/utils/http/http-client.test.ts +63 -0
- package/src/utils/{network → http}/http-client.ts +45 -35
- package/src/utils/http/request-cache.ts +127 -0
- package/src/utils/http/request.ts +954 -0
- package/src/utils/http/taro-adapter.test.ts +74 -0
- package/src/utils/http/taro-adapter.ts +24 -0
- package/src/utils/http/types.ts +414 -0
- package/src/utils/http/web-adapter.ts +33 -0
- package/src/utils/index.ts +5 -8
- package/src/utils/inputValidator.ts +17 -14
- package/src/utils/performance/performance.ts +60 -71
- package/src/utils/responsiveUtils.ts +7 -16
- package/src/utils/rtl-support.ts +29 -19
- package/src/utils/security/api-security.ts +47 -39
- package/src/utils/securityHeaders.ts +61 -67
- package/src/utils/typeHelpers.ts +10 -10
- package/src/utils/types/dataProcessing.ts +93 -92
- package/src/utils/types/typeHelpers.ts +31 -21
- package/src/utils/xssProtection.ts +96 -48
- package/dist/js/index-6NJ3A1Dn.js.map +0 -1
- package/dist/js/index-DffLRSro.js.map +0 -1
- package/src/components/form/Input/Input.enhanced.tsx +0 -732
- package/src/components/navigation/Menu/__tests__/Menu.test.tsx +0 -687
- package/src/components/navigation/Tree/Tree.styles.ts +0 -553
- package/src/components/navigation/Tree/Tree.test.basic.tsx +0 -7
- package/src/components/navigation/Tree/Tree.test.functional.tsx +0 -496
- package/src/components/navigation/Tree/Tree.test.import.check.tsx +0 -6
- package/src/components/navigation/Tree/Tree.test.import.tsx +0 -6
- package/src/components/navigation/Tree/Tree.test.minimal.tsx +0 -5
- package/src/components/navigation/Tree/Tree.test.simple.tsx +0 -30
- package/src/components/navigation/Tree/Tree.test.tsx +0 -908
- package/src/components/navigation/Tree/Tree.test.working.tsx +0 -673
- package/src/components/navigation/Tree/Tree.tsx +0 -600
- package/src/components/navigation/Tree/Tree.types.ts +0 -909
- package/src/components/navigation/Tree/Tree.utils.ts +0 -452
- package/src/components/navigation/Tree/index.ts +0 -33
- package/src/components/navigation/Tree/index.tsx +0 -23
- package/src/utils/network/http-client.test.ts +0 -18
|
@@ -6,16 +6,7 @@ import type { BadgeProps, BadgeRef } from './Badge.types';
|
|
|
6
6
|
const { bem } = createNamespace('badge');
|
|
7
7
|
|
|
8
8
|
export const Badge = forwardRef<BadgeRef, BadgeProps>((props, ref) => {
|
|
9
|
-
const {
|
|
10
|
-
count,
|
|
11
|
-
dot = false,
|
|
12
|
-
overflowCount = 99,
|
|
13
|
-
showZero = false,
|
|
14
|
-
children,
|
|
15
|
-
style,
|
|
16
|
-
className,
|
|
17
|
-
...rest
|
|
18
|
-
} = props;
|
|
9
|
+
const { count, dot = false, overflowCount = 99, showZero = false, children, style, className, ...rest } = props;
|
|
19
10
|
|
|
20
11
|
const displayCount = count !== undefined && count > overflowCount ? `${overflowCount}+` : count;
|
|
21
12
|
|
|
@@ -26,11 +17,7 @@ export const Badge = forwardRef<BadgeRef, BadgeProps>((props, ref) => {
|
|
|
26
17
|
{children}
|
|
27
18
|
{shouldShowBadge && (
|
|
28
19
|
<View className={`${bem('badge')} ${dot ? bem('dot') : ''}`.trim()}>
|
|
29
|
-
{dot ? null : (
|
|
30
|
-
<Text className={bem('count')}>
|
|
31
|
-
{displayCount}
|
|
32
|
-
</Text>
|
|
33
|
-
)}
|
|
20
|
+
{dot ? null : <Text className={bem('count')}>{displayCount}</Text>}
|
|
34
21
|
</View>
|
|
35
22
|
)}
|
|
36
23
|
</View>
|
|
@@ -39,4 +26,4 @@ export const Badge = forwardRef<BadgeRef, BadgeProps>((props, ref) => {
|
|
|
39
26
|
|
|
40
27
|
Badge.displayName = 'Badge';
|
|
41
28
|
|
|
42
|
-
export default Badge;
|
|
29
|
+
export default Badge;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Badge } from './Badge';
|
|
2
|
-
export type { BadgeProps, BadgeRef } from './Badge.types';
|
|
2
|
+
export type { BadgeProps, BadgeRef } from './Badge.types';
|
|
@@ -9,7 +9,7 @@ export const calendarStyles: Record<string, CSSProperties> = {
|
|
|
9
9
|
width: '100%',
|
|
10
10
|
maxWidth: '400px',
|
|
11
11
|
},
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
// 头部
|
|
14
14
|
header: {
|
|
15
15
|
display: 'flex',
|
|
@@ -18,7 +18,7 @@ export const calendarStyles: Record<string, CSSProperties> = {
|
|
|
18
18
|
marginBottom: '16px',
|
|
19
19
|
padding: '0 8px',
|
|
20
20
|
},
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
headerTitle: {
|
|
23
23
|
fontSize: '16px',
|
|
24
24
|
fontWeight: '500',
|
|
@@ -28,11 +28,11 @@ export const calendarStyles: Record<string, CSSProperties> = {
|
|
|
28
28
|
borderRadius: '4px',
|
|
29
29
|
transition: 'background-color 0.3s ease',
|
|
30
30
|
},
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
headerTitleHover: {
|
|
33
33
|
backgroundColor: '#f5f5f5',
|
|
34
34
|
},
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
headerButton: {
|
|
37
37
|
display: 'flex',
|
|
38
38
|
alignItems: 'center',
|
|
@@ -47,24 +47,24 @@ export const calendarStyles: Record<string, CSSProperties> = {
|
|
|
47
47
|
color: '#8c8c8c',
|
|
48
48
|
transition: 'all 0.3s ease',
|
|
49
49
|
},
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
headerButtonHover: {
|
|
52
52
|
backgroundColor: '#f5f5f5',
|
|
53
53
|
color: '#262626',
|
|
54
54
|
},
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
headerButtonDisabled: {
|
|
57
57
|
color: '#d9d9d9',
|
|
58
58
|
cursor: 'not-allowed',
|
|
59
59
|
},
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
// 操作按钮组
|
|
62
62
|
actions: {
|
|
63
63
|
display: 'flex',
|
|
64
64
|
alignItems: 'center',
|
|
65
65
|
gap: '8px',
|
|
66
66
|
},
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
todayButton: {
|
|
69
69
|
padding: '4px 8px',
|
|
70
70
|
fontSize: '12px',
|
|
@@ -75,19 +75,19 @@ export const calendarStyles: Record<string, CSSProperties> = {
|
|
|
75
75
|
color: '#1890ff',
|
|
76
76
|
transition: 'all 0.3s ease',
|
|
77
77
|
},
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
todayButtonHover: {
|
|
80
80
|
borderColor: '#1890ff',
|
|
81
81
|
backgroundColor: '#f0f8ff',
|
|
82
82
|
},
|
|
83
|
-
|
|
83
|
+
|
|
84
84
|
// 星期头部
|
|
85
85
|
weekHeader: {
|
|
86
86
|
display: 'grid',
|
|
87
87
|
gridTemplateColumns: 'repeat(7, 1fr)',
|
|
88
88
|
marginBottom: '8px',
|
|
89
89
|
},
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
weekHeaderCell: {
|
|
92
92
|
textAlign: 'center',
|
|
93
93
|
fontSize: '12px',
|
|
@@ -95,21 +95,21 @@ export const calendarStyles: Record<string, CSSProperties> = {
|
|
|
95
95
|
fontWeight: '500',
|
|
96
96
|
padding: '8px 4px',
|
|
97
97
|
},
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
// 日期网格
|
|
100
100
|
dateGrid: {
|
|
101
101
|
display: 'grid',
|
|
102
102
|
gridTemplateColumns: 'repeat(7, 1fr)',
|
|
103
103
|
gap: '2px',
|
|
104
104
|
},
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
// 月份网格
|
|
107
107
|
monthGrid: {
|
|
108
108
|
display: 'grid',
|
|
109
109
|
gridTemplateColumns: 'repeat(3, 1fr)',
|
|
110
110
|
gap: '8px',
|
|
111
111
|
},
|
|
112
|
-
|
|
112
|
+
|
|
113
113
|
// 日期单元格
|
|
114
114
|
dateCell: {
|
|
115
115
|
position: 'relative',
|
|
@@ -126,33 +126,33 @@ export const calendarStyles: Record<string, CSSProperties> = {
|
|
|
126
126
|
transition: 'all 0.3s ease',
|
|
127
127
|
border: '1px solid transparent',
|
|
128
128
|
},
|
|
129
|
-
|
|
129
|
+
|
|
130
130
|
dateCellHover: {
|
|
131
131
|
backgroundColor: '#f5f5f5',
|
|
132
132
|
},
|
|
133
|
-
|
|
133
|
+
|
|
134
134
|
dateCellToday: {
|
|
135
135
|
backgroundColor: '#e6f7ff',
|
|
136
136
|
borderColor: '#1890ff',
|
|
137
137
|
fontWeight: '500',
|
|
138
138
|
},
|
|
139
|
-
|
|
139
|
+
|
|
140
140
|
dateCellSelected: {
|
|
141
141
|
backgroundColor: '#1890ff',
|
|
142
142
|
color: '#ffffff',
|
|
143
143
|
fontWeight: '500',
|
|
144
144
|
},
|
|
145
|
-
|
|
145
|
+
|
|
146
146
|
dateCellDisabled: {
|
|
147
147
|
color: '#d9d9d9',
|
|
148
148
|
cursor: 'not-allowed',
|
|
149
149
|
backgroundColor: 'transparent',
|
|
150
150
|
},
|
|
151
|
-
|
|
151
|
+
|
|
152
152
|
dateCellOtherMonth: {
|
|
153
153
|
color: '#d9d9d9',
|
|
154
154
|
},
|
|
155
|
-
|
|
155
|
+
|
|
156
156
|
// 月份单元格
|
|
157
157
|
monthCell: {
|
|
158
158
|
display: 'flex',
|
|
@@ -166,23 +166,23 @@ export const calendarStyles: Record<string, CSSProperties> = {
|
|
|
166
166
|
transition: 'all 0.3s ease',
|
|
167
167
|
border: '1px solid transparent',
|
|
168
168
|
},
|
|
169
|
-
|
|
169
|
+
|
|
170
170
|
monthCellHover: {
|
|
171
171
|
backgroundColor: '#f5f5f5',
|
|
172
172
|
},
|
|
173
|
-
|
|
173
|
+
|
|
174
174
|
monthCellCurrent: {
|
|
175
175
|
backgroundColor: '#e6f7ff',
|
|
176
176
|
borderColor: '#1890ff',
|
|
177
177
|
fontWeight: '500',
|
|
178
178
|
},
|
|
179
|
-
|
|
179
|
+
|
|
180
180
|
monthCellSelected: {
|
|
181
181
|
backgroundColor: '#1890ff',
|
|
182
182
|
color: '#ffffff',
|
|
183
183
|
fontWeight: '500',
|
|
184
184
|
},
|
|
185
|
-
|
|
185
|
+
|
|
186
186
|
// 事件指示器
|
|
187
187
|
eventIndicator: {
|
|
188
188
|
position: 'absolute',
|
|
@@ -192,64 +192,64 @@ export const calendarStyles: Record<string, CSSProperties> = {
|
|
|
192
192
|
display: 'flex',
|
|
193
193
|
gap: '2px',
|
|
194
194
|
},
|
|
195
|
-
|
|
195
|
+
|
|
196
196
|
eventDot: {
|
|
197
197
|
width: '4px',
|
|
198
198
|
height: '4px',
|
|
199
199
|
borderRadius: '50%',
|
|
200
200
|
backgroundColor: '#1890ff',
|
|
201
201
|
},
|
|
202
|
-
|
|
202
|
+
|
|
203
203
|
eventDotDefault: {
|
|
204
204
|
backgroundColor: '#d9d9d9',
|
|
205
205
|
},
|
|
206
|
-
|
|
206
|
+
|
|
207
207
|
eventDotPrimary: {
|
|
208
208
|
backgroundColor: '#1890ff',
|
|
209
209
|
},
|
|
210
|
-
|
|
210
|
+
|
|
211
211
|
eventDotSuccess: {
|
|
212
212
|
backgroundColor: '#52c41a',
|
|
213
213
|
},
|
|
214
|
-
|
|
214
|
+
|
|
215
215
|
eventDotWarning: {
|
|
216
216
|
backgroundColor: '#faad14',
|
|
217
217
|
},
|
|
218
|
-
|
|
218
|
+
|
|
219
219
|
eventDotDanger: {
|
|
220
220
|
backgroundColor: '#ff4d4f',
|
|
221
221
|
},
|
|
222
|
-
|
|
222
|
+
|
|
223
223
|
// 事件列表
|
|
224
224
|
eventList: {
|
|
225
225
|
marginTop: '16px',
|
|
226
226
|
borderTop: '1px solid #f0f0f0',
|
|
227
227
|
paddingTop: '16px',
|
|
228
228
|
},
|
|
229
|
-
|
|
229
|
+
|
|
230
230
|
eventItem: {
|
|
231
231
|
padding: '8px 12px',
|
|
232
232
|
backgroundColor: '#f5f5f5',
|
|
233
233
|
borderRadius: '4px',
|
|
234
234
|
marginBottom: '8px',
|
|
235
235
|
},
|
|
236
|
-
|
|
236
|
+
|
|
237
237
|
eventTitle: {
|
|
238
238
|
fontSize: '14px',
|
|
239
239
|
fontWeight: '500',
|
|
240
240
|
color: '#262626',
|
|
241
241
|
marginBottom: '4px',
|
|
242
242
|
},
|
|
243
|
-
|
|
243
|
+
|
|
244
244
|
eventDescription: {
|
|
245
245
|
fontSize: '12px',
|
|
246
246
|
color: '#8c8c8c',
|
|
247
247
|
lineHeight: '1.4',
|
|
248
248
|
},
|
|
249
|
-
|
|
249
|
+
|
|
250
250
|
eventTime: {
|
|
251
251
|
fontSize: '12px',
|
|
252
252
|
color: '#8c8c8c',
|
|
253
253
|
marginTop: '4px',
|
|
254
254
|
},
|
|
255
|
-
};
|
|
255
|
+
};
|
|
@@ -2,29 +2,41 @@ import { render, screen } from '@testing-library/react'
|
|
|
2
2
|
import { describe, it, expect, vi } from 'vitest'
|
|
3
3
|
import '@testing-library/jest-dom'
|
|
4
4
|
import Calendar from './Calendar'
|
|
5
|
+
import { ThemeProvider } from '../../common/ThemeProvider'
|
|
5
6
|
|
|
6
7
|
describe('Calendar Component', () => {
|
|
7
8
|
it('renders calendar', () => {
|
|
8
|
-
render(
|
|
9
|
+
render(
|
|
10
|
+
<ThemeProvider defaultTheme="light">
|
|
11
|
+
<Calendar />
|
|
12
|
+
</ThemeProvider>
|
|
13
|
+
)
|
|
9
14
|
expect(screen.getByText(/年/)).toBeInTheDocument()
|
|
10
15
|
})
|
|
11
16
|
|
|
12
|
-
it('renders with ariaLabel', () => {
|
|
13
|
-
render(
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
it('renders with ariaLabel and role', () => {
|
|
18
|
+
render(
|
|
19
|
+
<ThemeProvider defaultTheme="light">
|
|
20
|
+
<Calendar ariaLabel="Test calendar" role="navigation" data-testid="calendar" />
|
|
21
|
+
</ThemeProvider>
|
|
22
|
+
)
|
|
23
|
+
const calendar = screen.getByTestId('calendar')
|
|
24
|
+
expect(calendar).toHaveAttribute('aria-label', 'Test calendar')
|
|
25
|
+
expect(calendar).toHaveAttribute('role', 'navigation')
|
|
16
26
|
})
|
|
17
27
|
|
|
18
|
-
it('
|
|
19
|
-
render(<Calendar role="navigation" />)
|
|
20
|
-
const calendar = screen.getByRole('navigation')
|
|
21
|
-
expect(calendar).toBeInTheDocument() // failing
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('handles date selection', () => {
|
|
28
|
+
it('handles date selection when date is clicked', () => {
|
|
25
29
|
const onSelect = vi.fn()
|
|
26
|
-
render(
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
render(
|
|
31
|
+
<ThemeProvider defaultTheme="light">
|
|
32
|
+
<Calendar onSelect={onSelect} />
|
|
33
|
+
</ThemeProvider>
|
|
34
|
+
)
|
|
35
|
+
// Click on the first date cell
|
|
36
|
+
const dateCells = screen.getAllByText(/^\d+$/)
|
|
37
|
+
if (dateCells.length > 0) {
|
|
38
|
+
dateCells[0].click()
|
|
39
|
+
expect(onSelect).toHaveBeenCalled()
|
|
40
|
+
}
|
|
29
41
|
})
|
|
30
42
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef, useImperativeHandle, useRef, useState, useEffect } from 'react';
|
|
1
|
+
import { forwardRef, useImperativeHandle, useRef, useState, useEffect, useMemo, useCallback } from 'react';
|
|
2
2
|
import { View, Text } from '@tarojs/components';
|
|
3
3
|
import { calendarStyles } from './Calendar.styles';
|
|
4
4
|
import type { CalendarProps, CalendarRef, CalendarDate } from './Calendar.types';
|
|
@@ -80,15 +80,28 @@ export const CalendarComponent = forwardRef<CalendarRef, CalendarProps>((props,
|
|
|
80
80
|
}
|
|
81
81
|
}, [value]);
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
83
|
+
// 固定的星期和月份名称,提取到组件外部避免重复创建
|
|
84
|
+
const WEEK_DAYS = ['日', '一', '二', '三', '四', '五', '六'];
|
|
85
|
+
const MONTH_NAMES = [
|
|
86
|
+
'一月',
|
|
87
|
+
'二月',
|
|
88
|
+
'三月',
|
|
89
|
+
'四月',
|
|
90
|
+
'五月',
|
|
91
|
+
'六月',
|
|
92
|
+
'七月',
|
|
93
|
+
'八月',
|
|
94
|
+
'九月',
|
|
95
|
+
'十月',
|
|
96
|
+
'十一月',
|
|
97
|
+
'十二月',
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
const getWeekDays = () => WEEK_DAYS;
|
|
101
|
+
const getMonthNames = () => MONTH_NAMES;
|
|
102
|
+
|
|
103
|
+
// 使用 useMemo 优化 getDatesInMonth 函数,只在依赖项变化时重新计算
|
|
104
|
+
const datesInMonth = useMemo(() => {
|
|
92
105
|
const year = currentDate.getFullYear();
|
|
93
106
|
const month = currentDate.getMonth();
|
|
94
107
|
const today = new Date();
|
|
@@ -144,31 +157,38 @@ export const CalendarComponent = forwardRef<CalendarRef, CalendarProps>((props,
|
|
|
144
157
|
}
|
|
145
158
|
|
|
146
159
|
return dates;
|
|
147
|
-
};
|
|
160
|
+
}, [currentDate, selectedDate, events, disabledDate]);
|
|
148
161
|
|
|
149
|
-
|
|
150
|
-
|
|
162
|
+
// 使用 useCallback 优化事件处理函数
|
|
163
|
+
const handleDateClick = useCallback(
|
|
164
|
+
(date: CalendarDate) => {
|
|
165
|
+
if (date.disabled) return;
|
|
151
166
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
167
|
+
const newDate = new Date(date.year, date.month - 1, date.day);
|
|
168
|
+
setSelectedDate(newDate);
|
|
169
|
+
onSelect?.(newDate);
|
|
170
|
+
onChange?.(newDate);
|
|
171
|
+
},
|
|
172
|
+
[onSelect, onChange],
|
|
173
|
+
);
|
|
157
174
|
|
|
158
|
-
const handleMonthClick = (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
175
|
+
const handleMonthClick = useCallback(
|
|
176
|
+
(monthIndex: number) => {
|
|
177
|
+
const newDate = new Date(currentDate.getFullYear(), monthIndex, 1);
|
|
178
|
+
setCurrentDate(newDate);
|
|
179
|
+
setCurrentMode('month');
|
|
180
|
+
onChange?.(newDate);
|
|
181
|
+
onModeChange?.('month');
|
|
182
|
+
},
|
|
183
|
+
[currentDate, onChange, onModeChange],
|
|
184
|
+
);
|
|
165
185
|
|
|
166
|
-
const handleHeaderTitleClick = () => {
|
|
186
|
+
const handleHeaderTitleClick = useCallback(() => {
|
|
167
187
|
setCurrentMode(currentMode === 'month' ? 'year' : 'month');
|
|
168
188
|
onModeChange?.(currentMode === 'month' ? 'year' : 'month');
|
|
169
|
-
};
|
|
189
|
+
}, [currentMode, onModeChange]);
|
|
170
190
|
|
|
171
|
-
const handlePrevClick = () => {
|
|
191
|
+
const handlePrevClick = useCallback(() => {
|
|
172
192
|
const newDate = new Date(currentDate);
|
|
173
193
|
if (currentMode === 'month') {
|
|
174
194
|
newDate.setMonth(newDate.getMonth() - 1);
|
|
@@ -177,9 +197,9 @@ export const CalendarComponent = forwardRef<CalendarRef, CalendarProps>((props,
|
|
|
177
197
|
}
|
|
178
198
|
setCurrentDate(newDate);
|
|
179
199
|
onChange?.(newDate);
|
|
180
|
-
};
|
|
200
|
+
}, [currentDate, currentMode, onChange]);
|
|
181
201
|
|
|
182
|
-
const handleNextClick = () => {
|
|
202
|
+
const handleNextClick = useCallback(() => {
|
|
183
203
|
const newDate = new Date(currentDate);
|
|
184
204
|
if (currentMode === 'month') {
|
|
185
205
|
newDate.setMonth(newDate.getMonth() + 1);
|
|
@@ -188,15 +208,15 @@ export const CalendarComponent = forwardRef<CalendarRef, CalendarProps>((props,
|
|
|
188
208
|
}
|
|
189
209
|
setCurrentDate(newDate);
|
|
190
210
|
onChange?.(newDate);
|
|
191
|
-
};
|
|
211
|
+
}, [currentDate, currentMode, onChange]);
|
|
192
212
|
|
|
193
|
-
const handleTodayClick = () => {
|
|
213
|
+
const handleTodayClick = useCallback(() => {
|
|
194
214
|
const today = new Date();
|
|
195
215
|
setCurrentDate(today);
|
|
196
216
|
setSelectedDate(today);
|
|
197
217
|
setCurrentMode('month');
|
|
198
218
|
onChange?.(today);
|
|
199
|
-
};
|
|
219
|
+
}, [onChange]);
|
|
200
220
|
|
|
201
221
|
const renderDateCell = (date: CalendarDate) => {
|
|
202
222
|
if (dateRender) {
|
|
@@ -242,7 +262,6 @@ export const CalendarComponent = forwardRef<CalendarRef, CalendarProps>((props,
|
|
|
242
262
|
};
|
|
243
263
|
|
|
244
264
|
const renderMonthView = () => {
|
|
245
|
-
const dates = getDatesInMonth();
|
|
246
265
|
const weekDays = getWeekDays();
|
|
247
266
|
|
|
248
267
|
return (
|
|
@@ -254,7 +273,9 @@ export const CalendarComponent = forwardRef<CalendarRef, CalendarProps>((props,
|
|
|
254
273
|
</View>
|
|
255
274
|
))}
|
|
256
275
|
</View>
|
|
257
|
-
<View style={calendarStyles['dateGrid'] ?? {}}>
|
|
276
|
+
<View style={calendarStyles['dateGrid'] ?? {}}>
|
|
277
|
+
{datesInMonth.map((date: CalendarDate) => renderDateCell(date))}
|
|
278
|
+
</View>
|
|
258
279
|
</>
|
|
259
280
|
);
|
|
260
281
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Calendar } from './Calendar';
|
|
2
2
|
export { calendarStyles } from './Calendar.styles';
|
|
3
|
-
export type { CalendarProps, CalendarRef, CalendarDate, CalendarEvent } from './Calendar.types';
|
|
3
|
+
export type { CalendarProps, CalendarRef, CalendarDate, CalendarEvent } from './Calendar.types';
|
|
@@ -7,7 +7,7 @@ export const CardStyles = createStyles({
|
|
|
7
7
|
none: '',
|
|
8
8
|
small: 'shadow-sm',
|
|
9
9
|
default: 'shadow-md',
|
|
10
|
-
large: 'shadow-lg'
|
|
10
|
+
large: 'shadow-lg',
|
|
11
11
|
},
|
|
12
12
|
|
|
13
13
|
bordered: `
|
|
@@ -85,5 +85,5 @@ export const CardStyles = createStyles({
|
|
|
85
85
|
|
|
86
86
|
action: `
|
|
87
87
|
flex-shrink-0
|
|
88
|
-
|
|
88
|
+
`,
|
|
89
89
|
});
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render, screen, fireEvent } from '@testing-library/react'
|
|
3
|
-
import { vi } from 'vitest'
|
|
3
|
+
import { vi, describe, test, expect, beforeEach } from 'vitest'
|
|
4
4
|
import { Card } from './Card'
|
|
5
5
|
|
|
6
6
|
// Mock Taro components
|
|
7
7
|
vi.mock('@tarojs/components', () => ({
|
|
8
|
-
View: ({ children, ...props }) => {
|
|
8
|
+
View: React.forwardRef<any, any>(({ children, ...props }, ref) => {
|
|
9
9
|
const { className, style, id, role, hidden, onClick, ...rest } = props as any
|
|
10
|
-
const allowed: Record<string, any> = {
|
|
10
|
+
const allowed: Record<string, any> = {
|
|
11
|
+
className, style, id, role, hidden, onClick, ref
|
|
12
|
+
}
|
|
11
13
|
Object.keys(rest).forEach((key) => {
|
|
12
14
|
if (key.startsWith('aria-') || key.startsWith('data-')) {
|
|
13
15
|
allowed[key] = rest[key]
|
|
14
16
|
}
|
|
15
17
|
})
|
|
16
18
|
return <div {...allowed}>{children}</div>
|
|
17
|
-
},
|
|
19
|
+
}),
|
|
18
20
|
}))
|
|
19
21
|
|
|
20
22
|
// Mock @/utils
|
|
@@ -107,7 +107,7 @@ export const Card = forwardRef<CardRef, CardProps>((props, ref) => {
|
|
|
107
107
|
style={style}
|
|
108
108
|
onClick={handlePress}
|
|
109
109
|
onLongPress={onLongPress}
|
|
110
|
-
|
|
110
|
+
data-testid="card"
|
|
111
111
|
data-shadow={shadow}
|
|
112
112
|
data-bordered={bordered}
|
|
113
113
|
data-hoverable={hoverable}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { BaseComponentProps } from '../../../types';
|
|
2
|
+
import { BaseComponentProps as StandardBaseComponentProps } from '../../../types/component-props';
|
|
3
3
|
|
|
4
|
-
export interface CardProps extends
|
|
4
|
+
export interface CardProps extends StandardBaseComponentProps {
|
|
5
5
|
/** 卡片内容 */
|
|
6
6
|
children: React.ReactNode;
|
|
7
7
|
/** 卡片标题 */
|
|
@@ -27,9 +27,9 @@ export interface CardProps extends BaseComponentProps {
|
|
|
27
27
|
/** 自定义样式 */
|
|
28
28
|
style?: React.CSSProperties;
|
|
29
29
|
/** 点击事件 */
|
|
30
|
-
onPress?: (_event: any) => void;
|
|
30
|
+
onPress?: (_event: React.MouseEvent | any) => void;
|
|
31
31
|
/** 长按事件 */
|
|
32
|
-
onLongPress?: (_event: any) => void;
|
|
32
|
+
onLongPress?: (_event: React.MouseEvent | any) => void;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export interface CardRef {
|