@tendaui/components 1.3.0 → 1.3.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/LICENSE +21 -21
- package/README.md +176 -176
- package/button/_example/ghost.tsx +2 -5
- package/color-picker/utils/color-picker/cmyk.ts +89 -89
- package/color-picker/utils/color-picker/color.ts +467 -467
- package/color-picker/utils/color-picker/constants.ts +187 -187
- package/color-picker/utils/color-picker/draggable.ts +99 -99
- package/color-picker/utils/color-picker/format.ts +90 -90
- package/color-picker/utils/color-picker/gradient.ts +237 -237
- package/color-picker/utils/color-picker/index.ts +7 -7
- package/color-picker/utils/color-picker/types.ts +33 -33
- package/dialog/hooks/useDialogPosition.ts +35 -35
- package/form/type.ts +519 -519
- package/global-config/default-config.ts +95 -95
- package/global-config/locale/ar_KW.ts +259 -259
- package/global-config/locale/en_US.ts +265 -265
- package/global-config/locale/it_IT.ts +264 -264
- package/global-config/locale/ja_JP.ts +264 -264
- package/global-config/locale/ko_KR.ts +264 -264
- package/global-config/locale/ru_RU.ts +277 -277
- package/global-config/locale/zh_CN.ts +265 -265
- package/global-config/locale/zh_TW.ts +265 -265
- package/global-config/mobile/default-config.ts +6 -6
- package/global-config/mobile/locale/ar_KW.ts +112 -112
- package/global-config/mobile/locale/en_US.ts +113 -113
- package/global-config/mobile/locale/it_IT.ts +113 -113
- package/global-config/mobile/locale/ja_JP.ts +100 -100
- package/global-config/mobile/locale/ko_KR.ts +100 -100
- package/global-config/mobile/locale/ru_RU.ts +112 -112
- package/global-config/mobile/locale/zh_CN.ts +100 -100
- package/global-config/mobile/locale/zh_TW.ts +100 -100
- package/global-config/t.ts +111 -111
- package/input-number/InputNumber.tsx +124 -124
- package/input-number/defaultProps.ts +17 -17
- package/input-number/index.ts +9 -9
- package/input-number/style/css.js +1 -1
- package/input-number/style/index.js +1 -1
- package/input-number/useInputNumber.tsx +270 -270
- package/list/ListItem.tsx +36 -36
- package/list/ListItemMeta.tsx +40 -40
- package/list/defaultProps.ts +11 -11
- package/list/hooks/useListVirtualScroll.ts +82 -82
- package/list/style/css.js +1 -1
- package/list/style/index.js +1 -1
- package/locale/LocalReceiver.ts +55 -55
- package/locale/ar_KW.ts +7 -7
- package/locale/en_US.ts +7 -7
- package/locale/it_IT.ts +6 -6
- package/locale/ja_JP.ts +6 -6
- package/locale/ko_KR.ts +6 -6
- package/locale/ru_RU.ts +6 -6
- package/locale/zh_CN.ts +5 -5
- package/locale/zh_TW.ts +7 -7
- package/package.json +2 -2
- package/radio/_example/default.tsx +2 -2
- package/select/type.ts +382 -382
- package/select-input/type.ts +280 -280
- package/slider/SliderHandleButton.tsx +50 -50
- package/slider/defaultProps.ts +15 -15
- package/slider/style/css.js +1 -1
- package/slider/style/index.js +1 -1
- package/styles/_global.scss +40 -40
- package/styles/_vars.scss +374 -374
- package/styles/components/alert/_index.scss +175 -175
- package/styles/components/alert/_vars.scss +41 -41
- package/styles/components/badge/_index.scss +71 -71
- package/styles/components/badge/_vars.scss +26 -26
- package/styles/components/button/_index.scss +499 -499
- package/styles/components/button/_mixins.scss +40 -40
- package/styles/components/button/_vars.scss +121 -121
- package/styles/components/checkbox/_index.scss +158 -158
- package/styles/components/checkbox/_var.scss +59 -59
- package/styles/components/color-picker/_index.scss +586 -586
- package/styles/components/color-picker/_vars.scss +79 -79
- package/styles/components/dialog/_animate.scss +133 -133
- package/styles/components/dialog/_index.scss +310 -310
- package/styles/components/dialog/_vars.scss +60 -60
- package/styles/components/drawer/_index.scss +206 -206
- package/styles/components/drawer/_var.scss +55 -55
- package/styles/components/fireworks/_index.scss +86 -86
- package/styles/components/fireworks/_vars.scss +5 -5
- package/styles/components/form/_index.scss +175 -175
- package/styles/components/form/_mixins.scss +74 -74
- package/styles/components/form/_vars.scss +101 -101
- package/styles/components/input/_index.scss +350 -350
- package/styles/components/input/_mixins.scss +120 -120
- package/styles/components/input/_vars.scss +130 -130
- package/styles/components/input-number/_index.scss +327 -327
- package/styles/components/input-number/_vars.scss +56 -56
- package/styles/components/ip-input/_index.scss +277 -277
- package/styles/components/layout/_index.scss +47 -47
- package/styles/components/layout/_vars.scss +19 -19
- package/styles/components/layout/doc.scss +74 -74
- package/styles/components/list/_index.scss +172 -172
- package/styles/components/list/_vars.scss +42 -42
- package/styles/components/loading/_index.scss +113 -113
- package/styles/components/loading/_vars.scss +40 -40
- package/styles/components/notification/_index.scss +140 -140
- package/styles/components/notification/_mixins.scss +13 -13
- package/styles/components/notification/_vars.scss +60 -60
- package/styles/components/popup/_index.scss +78 -78
- package/styles/components/popup/_mixin.scss +149 -149
- package/styles/components/popup/_vars.scss +33 -33
- package/styles/components/radio/_index.scss +376 -376
- package/styles/components/radio/_vars.scss +89 -89
- package/styles/components/select/_index.scss +291 -291
- package/styles/components/select/_var.scss +64 -64
- package/styles/components/select-input/_index.scss +5 -5
- package/styles/components/select-input/_var.scss +4 -4
- package/styles/components/slider/_index.scss +241 -241
- package/styles/components/slider/_vars.scss +51 -51
- package/styles/components/switch/_index.scss +175 -175
- package/styles/components/switch/_vars.scss +63 -63
- package/styles/components/table/_index.scss +194 -194
- package/styles/components/table/_var.scss +52 -52
- package/styles/components/tabs/_index.scss +165 -165
- package/styles/components/tabs/_mixins.scss +11 -11
- package/styles/components/tabs/_vars.scss +72 -72
- package/styles/components/tag/_index.scss +317 -317
- package/styles/components/tag/_var.scss +86 -86
- package/styles/components/tag-input/_index.scss +164 -164
- package/styles/components/tag-input/_vars.scss +17 -17
- package/styles/mixins/_focus.scss +8 -8
- package/styles/mixins/_layout.scss +32 -32
- package/styles/mixins/_reset.scss +11 -11
- package/styles/mixins/_scrollbar.scss +32 -32
- package/styles/mixins/_text.scss +50 -50
- package/styles/themes/_dark.scss +169 -169
- package/styles/themes/_font.scss +69 -69
- package/styles/themes/_index.scss +5 -5
- package/styles/themes/_light.scss +170 -170
- package/styles/themes/_radius.scss +9 -9
- package/styles/themes/_size.scss +68 -68
- package/styles/utilities/_animation.scss +58 -58
- package/styles/utilities/_tips.scss +10 -10
- package/switch/_example/with-label.tsx +1 -1
- package/utils/input-number/large-number.ts +423 -423
- package/utils/input-number/number.ts +257 -257
- package/utils/log/index.ts +3 -3
- package/utils/log/log.ts +29 -29
- package/utils/log/types.ts +9 -9
- package/utils/style.ts +58 -58
package/list/ListItemMeta.tsx
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import React, { forwardRef } from "react";
|
|
2
|
-
import classNames from "classnames";
|
|
3
|
-
import useConfig from "../hooks/useConfig";
|
|
4
|
-
import { TdListItemMetaProps } from "./type";
|
|
5
|
-
import { StyledProps } from "../common";
|
|
6
|
-
|
|
7
|
-
export interface ListItemMetaProps extends TdListItemMetaProps, StyledProps {}
|
|
8
|
-
/**
|
|
9
|
-
* 列表组件
|
|
10
|
-
*/
|
|
11
|
-
const ListItemMeta = forwardRef<HTMLDivElement, ListItemMetaProps>((props, ref) => {
|
|
12
|
-
const { title, image, description, className, style } = props;
|
|
13
|
-
const { classPrefix } = useConfig();
|
|
14
|
-
|
|
15
|
-
const renderAvatar = () => {
|
|
16
|
-
if (image && typeof image === "string") {
|
|
17
|
-
return (
|
|
18
|
-
<div className={`${classPrefix}-list-item__meta-avatar`}>
|
|
19
|
-
<img src={image} alt="" />
|
|
20
|
-
</div>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
return <div className={`${classPrefix}-list-item__meta-avatar`}>{image}</div>;
|
|
24
|
-
};
|
|
25
|
-
return (
|
|
26
|
-
<div ref={ref} className={classNames(`${classPrefix}-list-item__meta`, className)} style={style}>
|
|
27
|
-
{image && renderAvatar()}
|
|
28
|
-
<div className={`${classPrefix}-list-item__meta-content`}>
|
|
29
|
-
<h3 className={`${classPrefix}-list-item__meta-title`}>{title}</h3>
|
|
30
|
-
<div className={`${classPrefix}-list-item__meta-description`}>
|
|
31
|
-
{typeof description === "string" ? <p>{description}</p> : description}
|
|
32
|
-
</div>
|
|
33
|
-
</div>
|
|
34
|
-
</div>
|
|
35
|
-
);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
ListItemMeta.displayName = "ListItemMeta";
|
|
39
|
-
|
|
40
|
-
export default ListItemMeta;
|
|
1
|
+
import React, { forwardRef } from "react";
|
|
2
|
+
import classNames from "classnames";
|
|
3
|
+
import useConfig from "../hooks/useConfig";
|
|
4
|
+
import { TdListItemMetaProps } from "./type";
|
|
5
|
+
import { StyledProps } from "../common";
|
|
6
|
+
|
|
7
|
+
export interface ListItemMetaProps extends TdListItemMetaProps, StyledProps {}
|
|
8
|
+
/**
|
|
9
|
+
* 列表组件
|
|
10
|
+
*/
|
|
11
|
+
const ListItemMeta = forwardRef<HTMLDivElement, ListItemMetaProps>((props, ref) => {
|
|
12
|
+
const { title, image, description, className, style } = props;
|
|
13
|
+
const { classPrefix } = useConfig();
|
|
14
|
+
|
|
15
|
+
const renderAvatar = () => {
|
|
16
|
+
if (image && typeof image === "string") {
|
|
17
|
+
return (
|
|
18
|
+
<div className={`${classPrefix}-list-item__meta-avatar`}>
|
|
19
|
+
<img src={image} alt="" />
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return <div className={`${classPrefix}-list-item__meta-avatar`}>{image}</div>;
|
|
24
|
+
};
|
|
25
|
+
return (
|
|
26
|
+
<div ref={ref} className={classNames(`${classPrefix}-list-item__meta`, className)} style={style}>
|
|
27
|
+
{image && renderAvatar()}
|
|
28
|
+
<div className={`${classPrefix}-list-item__meta-content`}>
|
|
29
|
+
<h3 className={`${classPrefix}-list-item__meta-title`}>{title}</h3>
|
|
30
|
+
<div className={`${classPrefix}-list-item__meta-description`}>
|
|
31
|
+
{typeof description === "string" ? <p>{description}</p> : description}
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
ListItemMeta.displayName = "ListItemMeta";
|
|
39
|
+
|
|
40
|
+
export default ListItemMeta;
|
package/list/defaultProps.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
|
|
3
|
-
* */
|
|
4
|
-
|
|
5
|
-
import { TdListProps, TdListItemProps, TdListItemMetaProps } from "./type";
|
|
6
|
-
|
|
7
|
-
export const listDefaultProps: TdListProps = { layout: "horizontal", size: "medium", split: false, stripe: false };
|
|
8
|
-
|
|
9
|
-
export const listItemDefaultProps: TdListItemProps = {};
|
|
10
|
-
|
|
11
|
-
export const listItemMetaDefaultProps: TdListItemMetaProps = {};
|
|
1
|
+
/**
|
|
2
|
+
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
|
|
3
|
+
* */
|
|
4
|
+
|
|
5
|
+
import { TdListProps, TdListItemProps, TdListItemMetaProps } from "./type";
|
|
6
|
+
|
|
7
|
+
export const listDefaultProps: TdListProps = { layout: "horizontal", size: "medium", split: false, stripe: false };
|
|
8
|
+
|
|
9
|
+
export const listItemDefaultProps: TdListItemProps = {};
|
|
10
|
+
|
|
11
|
+
export const listItemMetaDefaultProps: TdListItemMetaProps = {};
|
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
import React, { useMemo } from "react";
|
|
2
|
-
// import log from "@tdesign/common-js/log/index";
|
|
3
|
-
import useVirtualScroll from "../../hooks/useVirtualScroll";
|
|
4
|
-
import { TdListProps } from "../type";
|
|
5
|
-
import { Styles, type ScrollToElementParams } from "../../common";
|
|
6
|
-
const log = console.log;
|
|
7
|
-
export const useListVirtualScroll = (
|
|
8
|
-
scroll: TdListProps["scroll"],
|
|
9
|
-
listRef: React.MutableRefObject<HTMLElement>,
|
|
10
|
-
listItems: any[]
|
|
11
|
-
) => {
|
|
12
|
-
const virtualScrollParams = useMemo(
|
|
13
|
-
() => ({
|
|
14
|
-
data: listItems,
|
|
15
|
-
scroll
|
|
16
|
-
}),
|
|
17
|
-
[listItems, scroll]
|
|
18
|
-
);
|
|
19
|
-
const virtualConfig = useVirtualScroll(listRef, virtualScrollParams);
|
|
20
|
-
const { isVirtualScroll } = virtualConfig;
|
|
21
|
-
let lastScrollY = -1;
|
|
22
|
-
|
|
23
|
-
const onInnerVirtualScroll = (e: WheelEvent) => {
|
|
24
|
-
const target = (e.target || e.srcElement) as HTMLElement;
|
|
25
|
-
const top = target.scrollTop;
|
|
26
|
-
if (lastScrollY !== top) {
|
|
27
|
-
virtualConfig.isVirtualScroll && virtualConfig.handleScroll();
|
|
28
|
-
} else {
|
|
29
|
-
lastScrollY = -1;
|
|
30
|
-
}
|
|
31
|
-
lastScrollY = top;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const cursorStyle = useMemo(
|
|
35
|
-
() =>
|
|
36
|
-
({
|
|
37
|
-
position: "absolute",
|
|
38
|
-
width: "1px",
|
|
39
|
-
height: "1px",
|
|
40
|
-
transition: "transform 0.2s",
|
|
41
|
-
transform: `translate(0, ${virtualConfig.scrollHeight}px)`,
|
|
42
|
-
msTransform: `translate(0, ${virtualConfig.scrollHeight}px)`,
|
|
43
|
-
MozTransform: `translate(0, ${virtualConfig.scrollHeight}px)`,
|
|
44
|
-
WebkitTransform: `translate(0, ${virtualConfig.scrollHeight}px)`
|
|
45
|
-
}) as Styles,
|
|
46
|
-
[virtualConfig.scrollHeight]
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
const listStyle = useMemo(
|
|
50
|
-
() =>
|
|
51
|
-
({
|
|
52
|
-
transform: `translate(0, ${virtualConfig.translateY}px)`,
|
|
53
|
-
msTransform: `translate(0, ${virtualConfig.translateY}px)`,
|
|
54
|
-
MozTransform: `translate(0, ${virtualConfig.translateY}px)`,
|
|
55
|
-
WebkitTransform: `translate(0, ${virtualConfig.translateY}px)`
|
|
56
|
-
}) as Styles,
|
|
57
|
-
[virtualConfig.translateY]
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const handleScrollTo = (params: ScrollToElementParams) => {
|
|
61
|
-
const { index, key } = params;
|
|
62
|
-
const targetIndex = index === 0 ? index : index ?? Number(key);
|
|
63
|
-
if (!targetIndex && targetIndex !== 0) {
|
|
64
|
-
console.error("List", "scrollTo: `index` or `key` must exist.");
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (targetIndex < 0 || targetIndex >= listItems.length) {
|
|
68
|
-
console.error("List", `${targetIndex} does not exist in data, check \`index\` or \`key\` please.`);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
virtualConfig.scrollToElement({ ...params, index: targetIndex - 1 });
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
virtualConfig,
|
|
76
|
-
cursorStyle,
|
|
77
|
-
listStyle,
|
|
78
|
-
isVirtualScroll,
|
|
79
|
-
onInnerVirtualScroll,
|
|
80
|
-
scrollToElement: handleScrollTo
|
|
81
|
-
};
|
|
82
|
-
};
|
|
1
|
+
import React, { useMemo } from "react";
|
|
2
|
+
// import log from "@tdesign/common-js/log/index";
|
|
3
|
+
import useVirtualScroll from "../../hooks/useVirtualScroll";
|
|
4
|
+
import { TdListProps } from "../type";
|
|
5
|
+
import { Styles, type ScrollToElementParams } from "../../common";
|
|
6
|
+
const log = console.log;
|
|
7
|
+
export const useListVirtualScroll = (
|
|
8
|
+
scroll: TdListProps["scroll"],
|
|
9
|
+
listRef: React.MutableRefObject<HTMLElement>,
|
|
10
|
+
listItems: any[]
|
|
11
|
+
) => {
|
|
12
|
+
const virtualScrollParams = useMemo(
|
|
13
|
+
() => ({
|
|
14
|
+
data: listItems,
|
|
15
|
+
scroll
|
|
16
|
+
}),
|
|
17
|
+
[listItems, scroll]
|
|
18
|
+
);
|
|
19
|
+
const virtualConfig = useVirtualScroll(listRef, virtualScrollParams);
|
|
20
|
+
const { isVirtualScroll } = virtualConfig;
|
|
21
|
+
let lastScrollY = -1;
|
|
22
|
+
|
|
23
|
+
const onInnerVirtualScroll = (e: WheelEvent) => {
|
|
24
|
+
const target = (e.target || e.srcElement) as HTMLElement;
|
|
25
|
+
const top = target.scrollTop;
|
|
26
|
+
if (lastScrollY !== top) {
|
|
27
|
+
virtualConfig.isVirtualScroll && virtualConfig.handleScroll();
|
|
28
|
+
} else {
|
|
29
|
+
lastScrollY = -1;
|
|
30
|
+
}
|
|
31
|
+
lastScrollY = top;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const cursorStyle = useMemo(
|
|
35
|
+
() =>
|
|
36
|
+
({
|
|
37
|
+
position: "absolute",
|
|
38
|
+
width: "1px",
|
|
39
|
+
height: "1px",
|
|
40
|
+
transition: "transform 0.2s",
|
|
41
|
+
transform: `translate(0, ${virtualConfig.scrollHeight}px)`,
|
|
42
|
+
msTransform: `translate(0, ${virtualConfig.scrollHeight}px)`,
|
|
43
|
+
MozTransform: `translate(0, ${virtualConfig.scrollHeight}px)`,
|
|
44
|
+
WebkitTransform: `translate(0, ${virtualConfig.scrollHeight}px)`
|
|
45
|
+
}) as Styles,
|
|
46
|
+
[virtualConfig.scrollHeight]
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const listStyle = useMemo(
|
|
50
|
+
() =>
|
|
51
|
+
({
|
|
52
|
+
transform: `translate(0, ${virtualConfig.translateY}px)`,
|
|
53
|
+
msTransform: `translate(0, ${virtualConfig.translateY}px)`,
|
|
54
|
+
MozTransform: `translate(0, ${virtualConfig.translateY}px)`,
|
|
55
|
+
WebkitTransform: `translate(0, ${virtualConfig.translateY}px)`
|
|
56
|
+
}) as Styles,
|
|
57
|
+
[virtualConfig.translateY]
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const handleScrollTo = (params: ScrollToElementParams) => {
|
|
61
|
+
const { index, key } = params;
|
|
62
|
+
const targetIndex = index === 0 ? index : index ?? Number(key);
|
|
63
|
+
if (!targetIndex && targetIndex !== 0) {
|
|
64
|
+
console.error("List", "scrollTo: `index` or `key` must exist.");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (targetIndex < 0 || targetIndex >= listItems.length) {
|
|
68
|
+
console.error("List", `${targetIndex} does not exist in data, check \`index\` or \`key\` please.`);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
virtualConfig.scrollToElement({ ...params, index: targetIndex - 1 });
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
virtualConfig,
|
|
76
|
+
cursorStyle,
|
|
77
|
+
listStyle,
|
|
78
|
+
isVirtualScroll,
|
|
79
|
+
onInnerVirtualScroll,
|
|
80
|
+
scrollToElement: handleScrollTo
|
|
81
|
+
};
|
|
82
|
+
};
|
package/list/style/css.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import "./index.css";
|
|
1
|
+
import "./index.css";
|
package/list/style/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import "../../styles/components/list/_index.scss";
|
|
1
|
+
import "../../styles/components/list/_index.scss";
|
package/locale/LocalReceiver.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { t as commonT } from "../global-config/t";
|
|
3
|
-
import { ConfigContext, Locale } from "../config-provider";
|
|
4
|
-
|
|
5
|
-
export interface Placement {
|
|
6
|
-
[propName: string]: string | number;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type TransformPattern = string | Function | Array<string>;
|
|
10
|
-
|
|
11
|
-
export function useLocaleReceiver<T extends keyof Locale>(componentName: T, defaultLocale?: Locale[T] | Function) {
|
|
12
|
-
const { globalConfig } = React.useContext(ConfigContext);
|
|
13
|
-
|
|
14
|
-
function transformLocale(pattern: TransformPattern, placement?: Placement): string;
|
|
15
|
-
function transformLocale(pattern: TransformPattern, placement?: number, data?: Placement): string;
|
|
16
|
-
function transformLocale(pattern: TransformPattern, ...args: any[]): string | Array<string> {
|
|
17
|
-
const REGEXP = /\{\s*([\w-]+)\s*\}/g;
|
|
18
|
-
const placement = args[0];
|
|
19
|
-
|
|
20
|
-
if (Array.isArray(pattern)) {
|
|
21
|
-
return pattern.map((p, index) => {
|
|
22
|
-
const translated = p.replace(REGEXP, (_: string, key: string) => {
|
|
23
|
-
if (placement) return String(placement[index][key]);
|
|
24
|
-
return "";
|
|
25
|
-
});
|
|
26
|
-
return translated;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
if (typeof pattern === "function") {
|
|
30
|
-
return pattern(placement);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// use commonT for plural
|
|
34
|
-
const data = args[1];
|
|
35
|
-
if (data) {
|
|
36
|
-
return commonT(pattern, placement, data);
|
|
37
|
-
}
|
|
38
|
-
return commonT(pattern, placement);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** @TypeA => 确保此参数是属于 globalConfig[componentName] 下的子属性 */
|
|
42
|
-
const componentLocale = React.useMemo<Locale[T] | Function>(() => {
|
|
43
|
-
const locale = defaultLocale || {};
|
|
44
|
-
const connectLocaleByName = globalConfig[componentName];
|
|
45
|
-
|
|
46
|
-
const localeFromContext = componentName && globalConfig ? connectLocaleByName : {};
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
...(typeof locale === "function" ? (locale as Function)() : locale),
|
|
50
|
-
...(localeFromContext || {})
|
|
51
|
-
};
|
|
52
|
-
}, [componentName, defaultLocale, globalConfig]);
|
|
53
|
-
|
|
54
|
-
return [componentLocale, transformLocale] as [Locale[T], Function];
|
|
55
|
-
}
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { t as commonT } from "../global-config/t";
|
|
3
|
+
import { ConfigContext, Locale } from "../config-provider";
|
|
4
|
+
|
|
5
|
+
export interface Placement {
|
|
6
|
+
[propName: string]: string | number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type TransformPattern = string | Function | Array<string>;
|
|
10
|
+
|
|
11
|
+
export function useLocaleReceiver<T extends keyof Locale>(componentName: T, defaultLocale?: Locale[T] | Function) {
|
|
12
|
+
const { globalConfig } = React.useContext(ConfigContext);
|
|
13
|
+
|
|
14
|
+
function transformLocale(pattern: TransformPattern, placement?: Placement): string;
|
|
15
|
+
function transformLocale(pattern: TransformPattern, placement?: number, data?: Placement): string;
|
|
16
|
+
function transformLocale(pattern: TransformPattern, ...args: any[]): string | Array<string> {
|
|
17
|
+
const REGEXP = /\{\s*([\w-]+)\s*\}/g;
|
|
18
|
+
const placement = args[0];
|
|
19
|
+
|
|
20
|
+
if (Array.isArray(pattern)) {
|
|
21
|
+
return pattern.map((p, index) => {
|
|
22
|
+
const translated = p.replace(REGEXP, (_: string, key: string) => {
|
|
23
|
+
if (placement) return String(placement[index][key]);
|
|
24
|
+
return "";
|
|
25
|
+
});
|
|
26
|
+
return translated;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (typeof pattern === "function") {
|
|
30
|
+
return pattern(placement);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// use commonT for plural
|
|
34
|
+
const data = args[1];
|
|
35
|
+
if (data) {
|
|
36
|
+
return commonT(pattern, placement, data);
|
|
37
|
+
}
|
|
38
|
+
return commonT(pattern, placement);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** @TypeA => 确保此参数是属于 globalConfig[componentName] 下的子属性 */
|
|
42
|
+
const componentLocale = React.useMemo<Locale[T] | Function>(() => {
|
|
43
|
+
const locale = defaultLocale || {};
|
|
44
|
+
const connectLocaleByName = globalConfig[componentName];
|
|
45
|
+
|
|
46
|
+
const localeFromContext = componentName && globalConfig ? connectLocaleByName : {};
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
...(typeof locale === "function" ? (locale as Function)() : locale),
|
|
50
|
+
...(localeFromContext || {})
|
|
51
|
+
};
|
|
52
|
+
}, [componentName, defaultLocale, globalConfig]);
|
|
53
|
+
|
|
54
|
+
return [componentLocale, transformLocale] as [Locale[T], Function];
|
|
55
|
+
}
|
package/locale/ar_KW.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { GlobalConfigProvider } from "../config-provider/type";
|
|
2
|
-
|
|
3
|
-
// TODO: Import from @tdesign/common-js when available
|
|
4
|
-
const arKW = {} as GlobalConfigProvider;
|
|
5
|
-
|
|
6
|
-
// 需要 GlobalConfigProvider 保证数据类型正确
|
|
7
|
-
export default arKW;
|
|
1
|
+
import { GlobalConfigProvider } from "../config-provider/type";
|
|
2
|
+
|
|
3
|
+
// TODO: Import from @tdesign/common-js when available
|
|
4
|
+
const arKW = {} as GlobalConfigProvider;
|
|
5
|
+
|
|
6
|
+
// 需要 GlobalConfigProvider 保证数据类型正确
|
|
7
|
+
export default arKW;
|
package/locale/en_US.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { GlobalConfigProvider } from "../config-provider/type";
|
|
2
|
-
|
|
3
|
-
// TODO: Import from @tdesign/common-js when available
|
|
4
|
-
const enUS = {} as GlobalConfigProvider;
|
|
5
|
-
|
|
6
|
-
// 需要 GlobalConfigProvider 保证数据类型正确,本次提交就检查出了英文字段缺少
|
|
7
|
-
export default enUS;
|
|
1
|
+
import { GlobalConfigProvider } from "../config-provider/type";
|
|
2
|
+
|
|
3
|
+
// TODO: Import from @tdesign/common-js when available
|
|
4
|
+
const enUS = {} as GlobalConfigProvider;
|
|
5
|
+
|
|
6
|
+
// 需要 GlobalConfigProvider 保证数据类型正确,本次提交就检查出了英文字段缺少
|
|
7
|
+
export default enUS;
|
package/locale/it_IT.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { GlobalConfigProvider } from "../config-provider/type";
|
|
2
|
-
// TODO: Import from @tdesign/common-js when available
|
|
3
|
-
const itIT = {} as GlobalConfigProvider;
|
|
4
|
-
|
|
5
|
-
// 需要 GlobalConfigProvider 保证数据类型正确
|
|
6
|
-
export default itIT as unknown as GlobalConfigProvider;
|
|
1
|
+
import { GlobalConfigProvider } from "../config-provider/type";
|
|
2
|
+
// TODO: Import from @tdesign/common-js when available
|
|
3
|
+
const itIT = {} as GlobalConfigProvider;
|
|
4
|
+
|
|
5
|
+
// 需要 GlobalConfigProvider 保证数据类型正确
|
|
6
|
+
export default itIT as unknown as GlobalConfigProvider;
|
package/locale/ja_JP.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { GlobalConfigProvider } from "../config-provider/type";
|
|
2
|
-
// TODO: Import from @tdesign/common-js when available
|
|
3
|
-
const jaJP = {} as GlobalConfigProvider;
|
|
4
|
-
|
|
5
|
-
// 需要 GlobalConfigProvider 保证数据类型正确
|
|
6
|
-
export default jaJP as unknown as GlobalConfigProvider;
|
|
1
|
+
import { GlobalConfigProvider } from "../config-provider/type";
|
|
2
|
+
// TODO: Import from @tdesign/common-js when available
|
|
3
|
+
const jaJP = {} as GlobalConfigProvider;
|
|
4
|
+
|
|
5
|
+
// 需要 GlobalConfigProvider 保证数据类型正确
|
|
6
|
+
export default jaJP as unknown as GlobalConfigProvider;
|
package/locale/ko_KR.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { GlobalConfigProvider } from "../config-provider/type";
|
|
2
|
-
// TODO: Import from @tdesign/common-js when available
|
|
3
|
-
const koKR = {} as GlobalConfigProvider;
|
|
4
|
-
|
|
5
|
-
// 需要 GlobalConfigProvider 保证数据类型正确
|
|
6
|
-
export default koKR as unknown as GlobalConfigProvider;
|
|
1
|
+
import { GlobalConfigProvider } from "../config-provider/type";
|
|
2
|
+
// TODO: Import from @tdesign/common-js when available
|
|
3
|
+
const koKR = {} as GlobalConfigProvider;
|
|
4
|
+
|
|
5
|
+
// 需要 GlobalConfigProvider 保证数据类型正确
|
|
6
|
+
export default koKR as unknown as GlobalConfigProvider;
|
package/locale/ru_RU.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { GlobalConfigProvider } from "../config-provider/type";
|
|
2
|
-
// TODO: Import from @tdesign/common-js when available
|
|
3
|
-
const ruRU = {} as GlobalConfigProvider;
|
|
4
|
-
|
|
5
|
-
// 需要 GlobalConfigProvider 保证数据类型正确
|
|
6
|
-
export default ruRU as unknown as GlobalConfigProvider;
|
|
1
|
+
import { GlobalConfigProvider } from "../config-provider/type";
|
|
2
|
+
// TODO: Import from @tdesign/common-js when available
|
|
3
|
+
const ruRU = {} as GlobalConfigProvider;
|
|
4
|
+
|
|
5
|
+
// 需要 GlobalConfigProvider 保证数据类型正确
|
|
6
|
+
export default ruRU as unknown as GlobalConfigProvider;
|
package/locale/zh_CN.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import zhCN from "../global-config/locale/zh_CN";
|
|
2
|
-
import { GlobalConfigProvider } from "../config-provider/type";
|
|
3
|
-
|
|
4
|
-
// 需要 GlobalConfigProvider 保证数据类型正确
|
|
5
|
-
export default zhCN as unknown as GlobalConfigProvider;
|
|
1
|
+
import zhCN from "../global-config/locale/zh_CN";
|
|
2
|
+
import { GlobalConfigProvider } from "../config-provider/type";
|
|
3
|
+
|
|
4
|
+
// 需要 GlobalConfigProvider 保证数据类型正确
|
|
5
|
+
export default zhCN as unknown as GlobalConfigProvider;
|
package/locale/zh_TW.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { GlobalConfigProvider } from "../config-provider/type";
|
|
2
|
-
|
|
3
|
-
// TODO: Import from @tdesign/common-js when available
|
|
4
|
-
const zhTW = {} as GlobalConfigProvider;
|
|
5
|
-
|
|
6
|
-
// 需要 GlobalConfigProvider 保证数据类型正确
|
|
7
|
-
export default zhTW;
|
|
1
|
+
import { GlobalConfigProvider } from "../config-provider/type";
|
|
2
|
+
|
|
3
|
+
// TODO: Import from @tdesign/common-js when available
|
|
4
|
+
const zhTW = {} as GlobalConfigProvider;
|
|
5
|
+
|
|
6
|
+
// 需要 GlobalConfigProvider 保证数据类型正确
|
|
7
|
+
export default zhTW;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tendaui/components",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "TendaUI React Components - Source code",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"module": "index.ts",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"**/style/css.js",
|
|
53
53
|
"**/style/all.js"
|
|
54
54
|
],
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "8fe7140af3fafc6ed9347e24fc68577c370d6571"
|
|
56
56
|
}
|
|
@@ -3,11 +3,11 @@ import { Radio } from "@tendaui/react";
|
|
|
3
3
|
|
|
4
4
|
const DefaultDemo = () => {
|
|
5
5
|
return (
|
|
6
|
-
<div>
|
|
6
|
+
<div style={{ display: "flex", gap: "12px" }}>
|
|
7
7
|
<Radio>未选中</Radio>
|
|
8
8
|
<Radio defaultChecked>选中</Radio>
|
|
9
9
|
</div>
|
|
10
10
|
);
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export default DefaultDemo;
|
|
13
|
+
export default DefaultDemo;
|