Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .yarnrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
registry "https://registry.yarnpkg.com"

sass_binary_site "https://npm.taobao.org/mirrors/node-sass/"
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
transformIgnorePatterns: ['/node_modules/', 'lib', 'dist'],
testPathIgnorePatterns: ['/node_modules/'],
transform: {
'^.+\\.[jt]s?(x)$': 'babel-jest',
'^.+\\.(ts|tsx|js|jsx)$': 'babel-jest',
},
testMatch: [
'**/__tests__/**/(*.)+(spec|test).[jt]s?(x)',
Expand Down
6 changes: 5 additions & 1 deletion src/components/blockHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react';
import { QuestionCircleOutlined, UpOutlined } from '@ant-design/icons';
import { Tooltip } from 'antd';
import useLocale from '../locale/useLocale';

export interface BlockHeaderProps {
// 标题
Expand Down Expand Up @@ -60,6 +61,9 @@ const BlockHeader: React.FC<BlockHeaderProps> = function (props) {
let bottomStyle;
if (hasBottom) bottomStyle = { marginBottom: 16 };
if (spaceBottom) bottomStyle = { marginBottom: spaceBottom };

const locale = useLocale('BlockHeader');

const [expand, setExpand] = useState(defaultExpand);

const handleExpand = (expand) => {
Expand Down Expand Up @@ -87,7 +91,7 @@ const BlockHeader: React.FC<BlockHeaderProps> = function (props) {
{addonAfter && <div className={`${prefixCls}-addonAfter-box`}>{addonAfter}</div>}
{children && (
<div className={`${prefixCls}-collapse-box`}>
<div className="text">{expand ? '收起' : '展开'}</div>
<div className="text">{expand ? locale.collapse : locale.expand}</div>
<UpOutlined className={`icon ${expand ? 'up' : 'down'}`} />
</div>
)}
Expand Down
21 changes: 14 additions & 7 deletions src/components/chromeDownload/index.tsx

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/components/configProvider/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import { LocaleContext } from '../locale/useLocale';

const ConfigProvider = ({ locale, children }) => {
return <LocaleContext.Provider value={{ ...locale }}>{children}</LocaleContext.Provider>;
};

export default ConfigProvider;
20 changes: 15 additions & 5 deletions src/components/copyIcon/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import * as React from 'react';
import { Tooltip, message } from 'antd';
import { CopyOutlined } from '@ant-design/icons';
import useLocale, { Locale } from '../locale/useLocale';

export interface CopyIconProps {
text: string;
style?: React.CSSProperties;
title?: string;
customRender?: React.ReactNode;
locale?: Locale['CopyIcon'];
}

export default class CopyIcon extends React.Component<any, any> {
class CopyIcon extends React.Component<CopyIconProps, any> {
fakeHandlerCallback: () => void;
fakeHandler: EventListener | void;
fakeElem: HTMLTextAreaElement;
Expand Down Expand Up @@ -82,15 +84,16 @@ export default class CopyIcon extends React.Component<any, any> {
}

handleResult(succeeded: any) {
const { locale } = this.props;
if (succeeded) {
message.success('复制成功');
message.success(locale.copied);
} else {
message.error('不支持');
message.error(locale.notSupport);
}
}

render() {
let { customRender, text, style, title, ...rest } = this.props;
let { customRender, text, style, title, locale, ...rest } = this.props;

style = {
cursor: 'pointer',
Expand All @@ -101,7 +104,7 @@ export default class CopyIcon extends React.Component<any, any> {
return customRender ? (
<span onClick={this.copy.bind(this, text)}>{customRender}</span>
) : (
<Tooltip placement="right" title={title || '复制'}>
<Tooltip placement="right" title={title || locale.copy}>
<CopyOutlined
{...rest}
className="c-copyIcon"
Expand All @@ -112,3 +115,10 @@ export default class CopyIcon extends React.Component<any, any> {
);
}
}

const CopyIconWrapper = (props: Omit<CopyIconProps, 'locale'>) => {
const locale = useLocale('CopyIcon');
return <CopyIcon {...props} locale={locale} />;
};

export default CopyIconWrapper;
19 changes: 14 additions & 5 deletions src/components/editCell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ import React from 'react';
import { Input } from 'antd';
import EllipsisText from '../ellipsisText';
import classNames from 'classnames';
import useLocale, { Locale } from '../locale/useLocale';

type EditType = string | number;
export interface EditCellProps {
className?: string;
value: string;
keyField: string;
isView?: boolean;
locale?: Locale['EditCell'];
onHandleEdit: (keyField: string, editValue: EditType) => void;
}
export interface EditCellStates {
isEdit: boolean;
editValue: EditType;
}

export default class EditCell extends React.PureComponent<EditCellProps, EditCellStates> {
class EditCell extends React.PureComponent<EditCellProps, EditCellStates> {
state: EditCellStates = {
isEdit: false,
editValue: '',
Expand Down Expand Up @@ -47,7 +49,7 @@ export default class EditCell extends React.PureComponent<EditCellProps, EditCel

render() {
const { isEdit, editValue } = this.state;
const { isView, className = '' } = this.props;
const { isView, className = '', locale } = this.props;
return (
<div className={classNames('dtc-edit-Cell', className)}>
{isEdit ? (
Expand All @@ -57,16 +59,23 @@ export default class EditCell extends React.PureComponent<EditCellProps, EditCel
style={{ width: 150, lineHeight: 24, height: 24 }}
onChange={this.onChangeEdit}
/>
<a onClick={this.onOkEdit}>完成</a>
<a onClick={this.onCancelEdit}>取消</a>
<a onClick={this.onOkEdit}>{locale.complete}</a>
<a onClick={this.onCancelEdit}>{locale.cancel}</a>
</div>
) : (
<>
<EllipsisText value={editValue} maxWidth={120} />
{!isView && <a onClick={this.onEdit}>修改</a>}
{!isView && <a onClick={this.onEdit}>{locale.modify}</a>}
</>
)}
</div>
);
}
}

const EditCellWrapper = (props: Omit<EditCellProps, 'locale'>) => {
const locale = useLocale('EditCell');
return <EditCell {...props} locale={locale} />;
};

export default EditCellWrapper;
2 changes: 1 addition & 1 deletion src/components/editInput/__tests__/editInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('test edit input', () => {
});
test('should render message when length more then max', () => {
fireEvent.change(element, { target: { value: '12345678910' } });
expect(wrapper.getByText('字符长度不可超过10')).toBeInTheDocument();
expect(wrapper.getByText('字符长度不可超过${max}')).toBeInTheDocument();
expect(element.value).toEqual('1234567891');
});

Expand Down
14 changes: 12 additions & 2 deletions src/components/editInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import React from 'react';
import { Input, message } from 'antd';
import useLocale, { Locale } from '../locale/useLocale';
export interface EditInputProps {
value?: string | number;
onChange?: (e) => void;
max?: number;
locale?: Locale['EditInput'];
[propName: string]: any;
}

export interface EditInputPropsStates {
value: string | number;
}
export default class EditInput extends React.PureComponent<EditInputProps, EditInputPropsStates> {
class EditInput extends React.PureComponent<EditInputProps, EditInputPropsStates> {
constructor(props: EditInputProps) {
super(props);
this.state = {
Expand All @@ -34,10 +36,11 @@ export default class EditInput extends React.PureComponent<EditInputProps, EditI
this.props.onChange(e);
};
onChangeValue = (e: React.ChangeEvent<HTMLInputElement>) => {
const { locale } = this.props;
const value = e.target.value;
const { max = 64 } = this.props;
if (value && max && value.length > max) {
message.warning(`字符长度不可超过${max}`);
message.warning(locale.description);
this.setState({
value: value.substring(0, max),
});
Expand All @@ -61,3 +64,10 @@ export default class EditInput extends React.PureComponent<EditInputProps, EditI
);
}
}

const EditInputWrapper = (props: Omit<EditInputProps, 'locale'>) => {
const locale = useLocale('EditInput');
return <EditInput {...props} locale={locale} />;
};

export default EditInputWrapper;
15 changes: 12 additions & 3 deletions src/components/fullscreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Button } from 'antd';

import MyIcon from './icon';
import KeyEventListener from '../keyEventListener';
import useLocale, { Locale } from '../locale/useLocale';

const { KeyCombiner } = KeyEventListener;
declare let document: any;
Expand All @@ -14,12 +15,13 @@ export interface FullscreenProps {
iconStyle?: object;
fullIcon?: React.ReactNode;
exitFullIcon?: React.ReactNode;
locale?: Locale['Fullscreen'];
[propName: string]: any;
}
export interface FullscreenState {
isFullScreen: boolean;
}
export default class Fullscreen extends React.Component<FullscreenProps, FullscreenState> {
class Fullscreen extends React.Component<FullscreenProps, FullscreenState> {
state: FullscreenState = {
isFullScreen: false,
};
Expand Down Expand Up @@ -136,8 +138,8 @@ export default class Fullscreen extends React.Component<FullscreenProps, Fullscr
};

render() {
const { themeDark, fullIcon, exitFullIcon, iconStyle, ...other } = this.props;
const title = this.state.isFullScreen ? '退出全屏' : '全屏';
const { themeDark, fullIcon, exitFullIcon, iconStyle, locale, ...other } = this.props;
const title = this.state.isFullScreen ? locale.exitFull : locale.full;
// const iconType = this.state.isFullScreen ? 'exit-fullscreen' : 'fullscreen';
const customIcon = this.state.isFullScreen ? exitFullIcon : fullIcon;
return (
Expand Down Expand Up @@ -167,3 +169,10 @@ export default class Fullscreen extends React.Component<FullscreenProps, Fullscr
);
}
}

const FullscreenWrapper = (props: Omit<FullscreenProps, 'locale'>) => {
const locale = useLocale('Fullscreen');
return <Fullscreen {...props} locale={locale} />;
};

export default FullscreenWrapper;
18 changes: 15 additions & 3 deletions src/components/globalLoading/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import classNames from 'classnames';
import React from 'react';
import useLocale, { Locale } from '../locale/useLocale';

export interface GlobalLoadingProps {
className?: string;
Expand All @@ -8,19 +9,23 @@ export interface GlobalLoadingProps {
mainBackground?: string;
circleBackground?: string;
titleColor?: string;
locale?: Locale['GlobalLoading'];
}

export default class GlobalLoading extends React.Component<GlobalLoadingProps, any> {
class GlobalLoading extends React.Component<GlobalLoadingProps, any> {
render() {
const {
prefix = '',
loadingTitle = '应用加载中,请等候~',
loadingTitle,
mainBackground = '#F2F7FA',
circleBackground = '#1D78FF',
titleColor = '#3D446E',
className = '',
locale,
} = this.props;

const newLoadingTitle = loadingTitle || locale.loading;

return (
<div
className={classNames('dtc-loading-wrapper', className)}
Expand All @@ -31,7 +36,7 @@ export default class GlobalLoading extends React.Component<GlobalLoadingProps, a
<div
className="dtc-loading-title"
style={{ color: titleColor }}
>{`${prefix} ${loadingTitle}`}</div>
>{`${prefix} ${newLoadingTitle}`}</div>
<div className="dtc-bouncy-wrap">
<div className="dtc-dot-icon dtc-dc1">
<div className="dtc-dot" style={{ background: circleBackground }}></div>
Expand All @@ -48,3 +53,10 @@ export default class GlobalLoading extends React.Component<GlobalLoadingProps, a
);
}
}

const GlobalLoadingWrapper = (props: Omit<GlobalLoadingProps, 'locale'>) => {
const locale = useLocale('GlobalLoading');
return <GlobalLoading {...props} locale={locale} />;
};

export default GlobalLoadingWrapper;
14 changes: 11 additions & 3 deletions src/components/goBack/goBackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import * as React from 'react';
import { Button } from 'antd';
import { browserHistory, hashHistory } from 'react-router';
import { GoBackButtonProps } from './index';
import useLocale from '../locale/useLocale';

export default class GoBackButton extends React.Component<GoBackButtonProps, any> {
class GoBackButton extends React.Component<GoBackButtonProps, any> {
go = () => {
const { url, history, autoClose } = this.props;

Expand All @@ -25,11 +26,18 @@ export default class GoBackButton extends React.Component<GoBackButtonProps, any
};

render() {
const { title } = this.props;
const { title, locale } = this.props;
return (
<Button {...this.props} onClick={this.go}>
{title || '返回'}
{title || locale.back}
</Button>
);
}
}

const GoBackButtonWrapper = (props: Omit<GoBackButtonProps, 'locale'>) => {
const locale = useLocale('GoBack');
return <GoBackButton {...props} locale={locale} />;
};

export default GoBackButtonWrapper;
2 changes: 2 additions & 0 deletions src/components/goBack/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Locale } from '../locale/useLocale';
import GoBack from './goBack';
import GoBackButton from './goBackButton';

Expand All @@ -9,6 +10,7 @@ export interface GoBackProps {
}
export interface GoBackButtonProps extends GoBackProps {
title?: string;
locale?: Locale['GoBack'];
}

GoBack.GoBackButton = GoBackButton;
Expand Down
3 changes: 3 additions & 0 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ export { default as TextMark } from './textMark';
export { default as ToolModal } from './toolModal';
export { default as ProgressLine } from './progressLine';
export { default as Empty } from './empty';
export { default as ConfigProvider } from './configProvider';
export { default as zhCN } from './locale/zh-CN';
export { default as enUS } from './locale/en-US';
Loading