Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(configprovider): support provider for RC #528

Open
wants to merge 3 commits into
base: 3.x-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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/"
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;
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;
10 changes: 9 additions & 1 deletion 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 Down Expand Up @@ -33,3 +34,10 @@ export default class GoBackButton extends React.Component<GoBackButtonProps, any
);
}
}

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';
11 changes: 6 additions & 5 deletions src/components/loadError/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import React from 'react';
import useLocale from '../locale/useLocale';

const LoadError: React.FC = function () {
const locale = useLocale('LoadError');
return (
<div className="error" data-testid="test-error">
<div>

<h2 style={{ textAlign: 'center' }} data-testid="test-error">
发现新版本,请
{locale.please}
<a
onClick={() => {
location.reload();
}}
>
刷新
{locale.refresh}
</a>
获取新版本。
{locale.get}
</h2>
<h4 style={{ textAlign: 'center' }}>若该提示长时间存在,请联系管理员。</h4>
<h4 style={{ textAlign: 'center' }}>{locale.title}</h4>
</div>
</div>
);
Expand Down
Loading
Loading