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 #548

Open
wants to merge 4 commits into
base: 4.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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,6 @@
},
"resolutions": {
"rc-motion": "2.6.2"
}
},
"packageManager": "[email protected]"
}
5 changes: 4 additions & 1 deletion src/blockHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { QuestionCircleOutlined, UpOutlined } from '@ant-design/icons';
import { Tooltip } from 'antd';
import classNames from 'classnames';

import useLocale from '../locale/useLocale';
import './style.scss';

export declare type SizeType = 'small' | 'middle' | undefined;
Expand Down Expand Up @@ -59,6 +60,8 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {

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

const locale = useLocale('BlockHeader');

const preTitleRowCls = `${prefixCls}-title-row`;

const questionTooltip = tooltip && (
Expand Down Expand Up @@ -103,7 +106,7 @@ const BlockHeader: React.FC<IBlockHeaderProps> = 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
9 changes: 9 additions & 0 deletions src/configProvider/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

import { Locale, LocaleContext } from '../locale/useLocale';

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

export default ConfigProvider;
6 changes: 4 additions & 2 deletions src/copy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { message, Tooltip } from 'antd';
import classNames from 'classnames';
import useClippy from 'use-clippy';

import useLocale from '../locale/useLocale';
import './style.scss';

export interface ICopyProps {
Expand All @@ -17,14 +18,15 @@ export interface ICopyProps {
}

const Copy: React.FC<ICopyProps> = (props) => {
const locale = useLocale('Copy');
const {
button = <CopyOutlined className="dtc-copy__default-icon" />,
text,
title = '复制',
title = locale.copy,
hideTooltip,
style,
className,
onCopy = () => message.success('复制成功'),
onCopy = () => message.success(locale.copied),
} = props;
const [_, setClipboard] = useClippy();

Expand Down
9 changes: 6 additions & 3 deletions src/dropdown/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import classNames from 'classnames';
import { isEqual } from 'lodash';
import List from 'rc-virtual-list';

import useLocale from '../locale/useLocale';
import './style.scss';

interface IDropdownSelectProps
Expand All @@ -31,6 +32,8 @@ export default function Select({
}: IDropdownSelectProps) {
const [visible, setVisible] = useState(false);

const locale = useLocale('Dropdown');

const handleCheckedAll = (e: CheckboxChangeEvent) => {
if (e.target.checked) {
onChange?.(options?.map((i) => i.value) || []);
Expand Down Expand Up @@ -119,7 +122,7 @@ export default function Select({
checked={checkAll}
indeterminate={indeterminate}
>
全选
{locale.selectAll}
</Checkbox>
</Col>
<Col span={24} className={`${prefix}__menu`}>
Expand Down Expand Up @@ -158,10 +161,10 @@ export default function Select({
</Row>
<Space size={8} className={`${prefix}__btns`}>
<Button size="small" disabled={resetDisabled} onClick={handleReset}>
重置
{locale.resetText}
</Button>
<Button size="small" type="primary" onClick={handleSubmit}>
确定
{locale.okText}
</Button>
</Space>
</>
Expand Down
12 changes: 7 additions & 5 deletions src/errorBoundary/loadError.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import React from 'react';

import useLocale from '../locale/useLocale';

const LoadError: React.FC = function () {
const locale = useLocale('LoadError');
return (
<div className="dtc-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
7 changes: 6 additions & 1 deletion src/fullscreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { CSSProperties, HTMLAttributes, ReactNode, useEffect, useState }
import { Button } from 'antd';

import KeyEventListener from '../keyEventListener';
import useLocale from '../locale/useLocale';
import MyIcon from './icon';

const { KeyCombiner } = KeyEventListener;
Expand Down Expand Up @@ -44,7 +45,11 @@ export default function Fullscreen({
...other
}: IFullscreenProps) {
const [isFullScreen, setIsFullScreen] = useState(false);

const locale = useLocale('Fullscreen');

const customIcon = isFullScreen ? exitFullIcon : fullIcon;

useEffect(() => {
const propsDom = document.getElementById(target);
const domEle = propsDom || document.body;
Expand Down Expand Up @@ -188,7 +193,7 @@ export default function Fullscreen({
) : (
<Button onClick={handleFullScreen}>
<MyIcon style={iconStyle} type={isFullScreen} themeDark={themeDark} />
{isFullScreen ? '退出全屏' : '全屏'}
{isFullScreen ? locale.exitFull : locale.full}
</Button>
)}
</KeyCombiner>
Expand Down
5 changes: 4 additions & 1 deletion src/globalLoading/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import classNames from 'classnames';

import useLocale from '../locale/useLocale';
import './style.scss';

export interface IGlobalLoadingProps {
Expand All @@ -12,8 +13,10 @@ export interface IGlobalLoadingProps {
}

const GlobalLoading: React.FC<IGlobalLoadingProps> = function (props) {
const locale = useLocale('GlobalLoading');

const {
loadingTitle = '应用加载中,请等候~',
loadingTitle = locale.loading,
mainBackground = '#F2F7FA',
circleBackground = '#1D78FF',
titleColor = '#3D446E',
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { default as BlockHeader } from './blockHeader';
export { default as CollapsibleActionItems } from './collapsibleActionItems';
export { default as ConfigProvider } from './configProvider';
export { default as ContextMenu } from './contextMenu';
export { default as useCookieListener } from './cookies';
export { default as Copy } from './copy';
Expand All @@ -13,6 +14,8 @@ export { default as Fullscreen } from './fullscreen';
export { default as GlobalLoading } from './globalLoading';
export { default as Input } from './input';
export { default as KeyEventListener } from './keyEventListener';
export { default as enUS } from './locale/en-US';
export { default as zhCN } from './locale/zh-CN';
export { default as MarkdownRender } from './markdownRender';
export { default as Modal } from './modal';
export { default as MxGraphContainer, WIDGETS_PREFIX } from './mxGraph';
Expand Down
45 changes: 25 additions & 20 deletions src/input/match.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState } from 'react';
import { Input, type InputProps, Tooltip } from 'antd';
import classNames from 'classnames';

import useLocale from '../locale/useLocale';
import { CaseSensitiveIcon, FrontIcon, PreciseIcon, TailIcon } from './icons';
import './match.scss';

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

const searchTypeList = [
{
key: 'caseSensitive',
tip: '区分大小写匹配',
},
{
key: 'precise',
tip: '精确匹配',
},
{
key: 'front',
tip: '头部匹配',
},
{
key: 'tail',
tip: '尾部匹配',
},
] as const;

export default function Match({
className,
value,
searchType,
filterOptions = searchTypeList.map((i) => i.key),
filterOptions: propFilterOptions,
onTypeChange,
onSearch,
onChange,
Expand All @@ -62,12 +44,35 @@ export default function Match({
const [internalValue, setValue] = useState<string>('');
const [internalSearchType, setSearchType] = useState<SearchType>('fuzzy');

const locale = useLocale('Input');

const handleTypeChange = (key: SearchType) => {
const next = realSearchType === key ? 'fuzzy' : key;
onTypeChange?.(next);
setSearchType(next);
};

const searchTypeList = [
{
key: 'caseSensitive',
tip: locale.case,
},
{
key: 'precise',
tip: locale.precise,
},
{
key: 'front',
tip: locale.front,
},
{
key: 'tail',
tip: locale.tail,
},
] as const;

const filterOptions = propFilterOptions || searchTypeList.map((i) => i.key);

const options = searchTypeList.filter((i) => filterOptions.includes(i.key));

const realSearchType = searchType || internalSearchType;
Expand Down
56 changes: 56 additions & 0 deletions src/locale/en-US.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Locale } from './useLocale';

const localeValues: Locale = {
locale: 'en-US',
BlockHeader: {
expand: 'Expand',
collapse: 'Collapse',
},

Copy: {
copied: 'Copied',

copy: 'Copy',
},
Fullscreen: {
exitFull: 'Exit Full Screen',
full: 'Full Screen',
},
GlobalLoading: {
loading: 'The application is loading, please wait~',
},
LoadError: {
please: 'A new version has been found. Please',
get: 'to get the new version.',
refresh: ' refresh ',
title: 'If this prompt persists for a long time, please contact the administrator.',
},
Modal: {
okText: 'Ok',
cancelText: 'Cancel',
},
Dropdown: {
resetText: 'Cancel',
okText: 'Ok',
selectAll: 'Select All',
},
Input: {
case: 'Case-sensitive match',
precise: 'Exact match',
front: 'Head match',
tail: 'Tail match',
},
MxGraph: {
newNode: 'New node',
},
NotFound: {
description: 'Dear, did you go to the wrong place?',
},
SpreadSheet: {
description: 'No Data',
copy: 'Copy',
copyAll: 'Copy values ​​and column names',
},
};

export default localeValues;
Loading
Loading