Skip to content

Commit 014295a

Browse files
LuckyFBBhaiminovoliuxy0551jin-sir
authored
Feat merge 4.x (#593)
* change question mark size to 16px in component blockHeader (#417) * change afterTitle question mark to 16px at blockheader component * change question mark size to 16px in blockTitle component * add parameter 'clearData' to useList mutate function (#418) * optimized useList clear data before mutate request * add unit testing and desc * add demo to mutate options * feat: blockHeader title support ReactNode (#432) * docs: blockHeader docs use size (#468) * fix: using ref to solve closure problems (#497) * refactor: add copyTypes and remove showCopyWithHeader 4.x (#545) * feat(SpreadSheet): add copyTypes and remove showCopyWithHeader * docs: demo and changelog * fix: copy events compatible with old browsers * fix(ellipsisText): ellipsisRef.current may be null (#572) * feat(configprovider): 4.x support locale provider for RC (#548) * feat(configprovider): support provider for RC * feat(configprovider): migrate locale type to useLocale * fix(configprovider): fix unit test error * fix(configprovier): update ConfigProvider ts and en locale text * feat(configprovider): change localeFromContext * feat(configprovider): update ConfigProvider ts and en locale text --------- Co-authored-by: haiminovo <[email protected]> Co-authored-by: 琉易 <[email protected]> Co-authored-by: lalala <[email protected]>
1 parent f687f07 commit 014295a

File tree

18 files changed

+279
-43
lines changed

18 files changed

+279
-43
lines changed

src/blockHeader/__tests__/blockHeader.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('test BlockHeader render', () => {
3737
});
3838
test('should render BlockHeader default BlockHeader render', () => {
3939
const { getByText, rerender } = render(<BlockHeader {...props} />);
40-
expect(getByText(props.title)).toBeTruthy();
40+
expect(getByText(props.title as any)).toBeTruthy();
4141
rerender(<BlockHeader title="标题2" />);
4242
expect(getByText('标题2')).toBeTruthy();
4343
});

src/blockHeader/demos/title.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
import { BlockHeader, EllipsisText } from 'dt-react-component';
3+
4+
export default () => {
5+
return (
6+
<BlockHeader
7+
title={
8+
<EllipsisText
9+
maxWidth={200}
10+
value="标题超长标题超长标题超长标题超长标题超长标题超长标题超长标题超长标题超长标题超长标题超长标题超长标题超长标题超长标题超长标题超长标题超长"
11+
/>
12+
}
13+
/>
14+
);
15+
};

src/blockHeader/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ demo:
2020
<code src="./demos/addonBefore.tsx" description="通过 `addonBefore` 可以设置标题前的图标,不设置时默认是一个色块,设置为假值(`undefined` 除外)不展示图标">自定义 icon</code>
2121
<code src="./demos/addonAfter.tsx" description="通过 `addonAfter` 可以设置后缀自定义内容块">带提示信息的标题</code>
2222
<code src="./demos/expand.tsx" description="通过配置 expand/defaultExpand 控制展开/收起">支持 `children` 做为内容展示</code>
23+
<code src="./demos/title.tsx" description="title 支持 ReactNode">标题超长</code>
2324

2425
## API
2526

@@ -38,8 +39,8 @@ demo:
3839
| contentClassName | 展示内容的样式类名 | `string` | - |
3940
| contentStyle | 展示内容的样式 | `React.CSSProperties` | - |
4041
| background | 是否显示背景 | `boolean` | `true` |
41-
| defaultExpand | 是否默认展开内容 | `boolean` | `-` |
42+
| defaultExpand | 是否默认展开内容 | `boolean` | `-` |
4243
| expand | 当前展开状态 | `boolean` | |
43-
| spaceBottom | 自定义下边距,优先级高于 hasBottom | `number` | `16` |
44+
| spaceBottom | 自定义下边距,优先级高于 hasBottom | `number` | `16` |
4445
| children | 展开/收起的内容 | `React.ReactNode` | - |
4546
| onExpand | 展开/收起时的回调 | `(expand: boolean) => void` | - |

src/blockHeader/index.tsx

Lines changed: 6 additions & 2 deletions
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

@@ -14,7 +15,7 @@ function isControlled(props: IBlockHeaderProps) {
1415

1516
export interface IBlockHeaderProps {
1617
/** 标题 */
17-
title: string;
18+
title: ReactNode;
1819
/** 标题前的图标,默认是一个色块 */
1920
addonBefore?: ReactNode;
2021
/** 标题后的提示说明文字 */
@@ -76,6 +77,7 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
7677
} = props;
7778

7879
const [internalExpand, setInternalExpand] = useState(defaultExpand);
80+
const locale = useLocale('BlockHeader');
7981

8082
const currentExpand = isControlled(props) ? expand : internalExpand;
8183

@@ -124,7 +126,9 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
124126
{addonAfter && <div className={`title__addon-after`}>{addonAfter}</div>}
125127
{showCollapse && (
126128
<div className={`title__collapse`}>
127-
<div className="collapse__text">{currentExpand ? '收起' : '展开'}</div>
129+
<div className="collapse__text">
130+
{currentExpand ? locale.collapse : locale.expand}
131+
</div>
128132
<UpOutlined
129133
className={classNames('collapse__icon', {
130134
'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>

0 commit comments

Comments
 (0)