Skip to content

Commit 904c9ff

Browse files
committed
Merge remote-tracking branch 'upstream/4.x-stable' into feat_merge_4.x
2 parents f687f07 + e88c400 commit 904c9ff

File tree

15 files changed

+260
-39
lines changed

15 files changed

+260
-39
lines changed

src/blockHeader/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { QuestionOutlined, UpOutlined } from '@dtinsight/react-icons';
33
import { Tooltip } from 'antd';
44
import classNames from 'classnames';
55

6+
import useLocale from '../locale/useLocale';
67
import { LabelTooltipType, toTooltipProps } from '../utils';
78
import './style.scss';
89

@@ -77,6 +78,8 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
7778

7879
const [internalExpand, setInternalExpand] = useState(defaultExpand);
7980

81+
const locale = useLocale('BlockHeader');
82+
8083
const currentExpand = isControlled(props) ? expand : internalExpand;
8184

8285
// 只有在有了 children 并且设置了 expand/defaultExpand 的时候才能够展开收起
@@ -124,7 +127,9 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
124127
{addonAfter && <div className={`title__addon-after`}>{addonAfter}</div>}
125128
{showCollapse && (
126129
<div className={`title__collapse`}>
127-
<div className="collapse__text">{currentExpand ? '收起' : '展开'}</div>
130+
<div className="collapse__text">
131+
{currentExpand ? locale.collapse : locale.expand}
132+
</div>
128133
<UpOutlined
129134
className={classNames('collapse__icon', {
130135
'collapse__icon--up': currentExpand,

src/configProvider/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
3+
import { Locale, LocaleContext } from '../locale/useLocale';
4+
5+
const ConfigProvider = ({ locale, children }: { locale: Locale; children: React.ReactNode }) => {
6+
return <LocaleContext.Provider value={{ locale }}>{children}</LocaleContext.Provider>;
7+
};
8+
9+
export default ConfigProvider;

src/copy/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CopyOutlined } from '@dtinsight/react-icons';
44
import { message, Tooltip } from 'antd';
55
import classNames from 'classnames';
66

7+
import useLocale from '../locale/useLocale';
78
import { LabelTooltipType, toTooltipProps } from '../utils';
89
import './style.scss';
910

@@ -18,14 +19,15 @@ export interface ICopyProps {
1819
}
1920

2021
const Copy: React.FC<ICopyProps> = (props) => {
22+
const locale = useLocale('Copy');
2123
const {
2224
button = <CopyOutlined className="dtc-copy__default-icon" />,
2325
text,
24-
tooltip = '复制',
26+
tooltip = locale.copy,
2527
style,
2628
className,
2729
disabled = false,
28-
onCopy = () => message.success('复制成功'),
30+
onCopy = () => message.success(locale.copied),
2931
} = props;
3032

3133
const handleCopy = () => {

src/dropdown/select.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import classNames from 'classnames';
1010
import { isEqual } from 'lodash-es';
1111
import List from 'rc-virtual-list';
1212

13+
import useLocale from '../locale/useLocale';
1314
import './style.scss';
1415

1516
interface IDropdownSelectProps
@@ -35,6 +36,8 @@ export default function Select({
3536
const [visible, setVisible] = useState(false);
3637
const [selected, setSelected] = useState<CheckboxValueType[]>(value || defaultValue || []);
3738

39+
const locale = useLocale('Dropdown');
40+
3841
const handleCheckedAll = (e: CheckboxChangeEvent) => {
3942
if (e.target.checked) {
4043
setSelected(options?.map((i) => i.value) || []);
@@ -130,7 +133,7 @@ export default function Select({
130133
checked={checkAll}
131134
indeterminate={indeterminate}
132135
>
133-
全选
136+
{locale.selectAll}
134137
</Checkbox>
135138
</Col>
136139
<Col span={24} className={`${prefix}__menu`}>
@@ -169,10 +172,10 @@ export default function Select({
169172
</Row>
170173
<Space size={8} className={`${prefix}__btns`}>
171174
<Button size="small" disabled={resetDisabled} onClick={handleReset}>
172-
重置
175+
{locale.resetText}
173176
</Button>
174177
<Button size="small" type="primary" onClick={handleSubmit}>
175-
确定
178+
{locale.okText}
176179
</Button>
177180
</Space>
178181
</>

src/ellipsisText/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ const EllipsisText = (props: IEllipsisTextProps) => {
7878
* @return {*}
7979
*/
8080
const getStyle = (dom: NewHTMLElement, attr: string) => {
81+
if (!dom) {
82+
return null;
83+
}
8184
// Compatible width IE8
8285
// @ts-ignore
8386
return window.getComputedStyle(dom)[attr] || dom.currentStyle[attr];
@@ -203,7 +206,11 @@ const EllipsisText = (props: IEllipsisTextProps) => {
203206
* @return {*}
204207
*/
205208
const onResize = () => {
206-
const ellipsisNode = ellipsisRef.current!;
209+
if (!ellipsisRef.current) {
210+
return;
211+
}
212+
213+
const ellipsisNode = ellipsisRef.current;
207214
const parentElement = ellipsisNode.parentElement!;
208215
const rangeWidth = getRangeWidth(ellipsisNode);
209216
const containerWidth = getContainerWidth(parentElement);

src/errorBoundary/loadError.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import React from 'react';
22

3+
import useLocale from '../locale/useLocale';
4+
35
const LoadError: React.FC = function () {
6+
const locale = useLocale('LoadError');
47
return (
58
<div className="dtc-error" data-testid="test-error">
69
<div>
7-

810
<h2 style={{ textAlign: 'center' }} data-testid="test-error">
9-
发现新版本,请
11+
{locale.please}
1012
<a
1113
onClick={() => {
1214
location.reload();
1315
}}
1416
>
15-
刷新
17+
{locale.refresh}
1618
</a>
17-
获取新版本。
19+
{locale.get}
1820
</h2>
19-
<h4 style={{ textAlign: 'center' }}>若该提示长时间存在,请联系管理员。</h4>
21+
<h4 style={{ textAlign: 'center' }}>{locale.title}</h4>
2022
</div>
2123
</div>
2224
);

src/fullscreen/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { CSSProperties, HTMLAttributes, ReactNode, useEffect, useState }
22
import { Button } from 'antd';
33

44
import KeyEventListener from '../keyEventListener';
5+
import useLocale from '../locale/useLocale';
56
import MyIcon from './icon';
67

78
const { KeyCombiner } = KeyEventListener;
@@ -44,7 +45,11 @@ export default function Fullscreen({
4445
...other
4546
}: IFullscreenProps) {
4647
const [isFullScreen, setIsFullScreen] = useState(false);
48+
49+
const locale = useLocale('Fullscreen');
50+
4751
const customIcon = isFullScreen ? exitFullIcon : fullIcon;
52+
4853
useEffect(() => {
4954
const propsDom = document.getElementById(target);
5055
const domEle = propsDom || document.body;
@@ -188,7 +193,7 @@ export default function Fullscreen({
188193
) : (
189194
<Button onClick={handleFullScreen}>
190195
<MyIcon style={iconStyle} type={isFullScreen} themeDark={themeDark} />
191-
{isFullScreen ? '退出全屏' : '全屏'}
196+
{isFullScreen ? locale.exitFull : locale.full}
192197
</Button>
193198
)}
194199
</KeyCombiner>

src/globalLoading/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import classNames from 'classnames';
33

4+
import useLocale from '../locale/useLocale';
45
import './style.scss';
56

67
export interface IGlobalLoadingProps {
@@ -13,8 +14,10 @@ export interface IGlobalLoadingProps {
1314
}
1415

1516
const GlobalLoading: React.FC<IGlobalLoadingProps> = function (props) {
17+
const locale = useLocale('GlobalLoading');
18+
1619
const {
17-
loadingTitle = '应用加载中,请等候~',
20+
loadingTitle = locale.loading,
1821
mainBackground = '#F2F7FA',
1922
circleBackground = '#1D78FF',
2023
titleColor = '#3D446E',

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export { default as Button } from './button';
55
export { default as Catalogue } from './catalogue';
66
export { default as Chat } from './chat';
77
export { default as CollapsibleActionItems } from './collapsibleActionItems';
8+
export { default as ConfigProvider } from './configProvider';
89
export { default as ContentLayout } from './contentLayout';
910
export { default as ContextMenu } from './contextMenu';
1011
export { default as Copy } from './copy';
@@ -24,6 +25,8 @@ export { default as GlobalLoading } from './globalLoading';
2425
export { default as Image } from './image';
2526
export { default as Input } from './input';
2627
export { default as KeyEventListener } from './keyEventListener';
28+
export { default as enUS } from './locale/en-US';
29+
export { default as zhCN } from './locale/zh-CN';
2730
export { default as MarkdownRender } from './markdownRender';
2831
export { default as Modal } from './modal/modal';
2932
export { default as NotFound } from './notFound';

src/input/match.tsx

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState } from 'react';
22
import { Input, type InputProps, Tooltip } from 'antd';
33
import classNames from 'classnames';
44

5+
import useLocale from '../locale/useLocale';
56
import { CaseSensitiveIcon, FrontIcon, PreciseIcon, TailIcon } from './icons';
67
import './match.scss';
78

@@ -29,30 +30,11 @@ interface IMatchProps extends Omit<InputProps, 'suffix'> {
2930
onSearch?: (value: string, searchType: SearchType) => void;
3031
}
3132

32-
const searchTypeList = [
33-
{
34-
key: 'caseSensitive',
35-
tip: '区分大小写匹配',
36-
},
37-
{
38-
key: 'precise',
39-
tip: '精确匹配',
40-
},
41-
{
42-
key: 'front',
43-
tip: '头部匹配',
44-
},
45-
{
46-
key: 'tail',
47-
tip: '尾部匹配',
48-
},
49-
] as const;
50-
5133
export default function Match({
5234
className,
5335
value,
5436
searchType,
55-
filterOptions = searchTypeList.map((i) => i.key),
37+
filterOptions: propFilterOptions,
5638
onTypeChange,
5739
onSearch,
5840
onChange,
@@ -62,12 +44,35 @@ export default function Match({
6244
const [internalValue, setValue] = useState<string>('');
6345
const [internalSearchType, setSearchType] = useState<SearchType>('fuzzy');
6446

47+
const locale = useLocale('Input');
48+
6549
const handleTypeChange = (key: SearchType) => {
6650
const next = realSearchType === key ? 'fuzzy' : key;
6751
onTypeChange?.(next);
6852
setSearchType(next);
6953
};
7054

55+
const searchTypeList = [
56+
{
57+
key: 'caseSensitive',
58+
tip: locale.case,
59+
},
60+
{
61+
key: 'precise',
62+
tip: locale.precise,
63+
},
64+
{
65+
key: 'front',
66+
tip: locale.front,
67+
},
68+
{
69+
key: 'tail',
70+
tip: locale.tail,
71+
},
72+
] as const;
73+
74+
const filterOptions = propFilterOptions || searchTypeList.map((i) => i.key);
75+
7176
const options = searchTypeList.filter((i) => filterOptions.includes(i.key));
7277

7378
const realSearchType = searchType || internalSearchType;

0 commit comments

Comments
 (0)