Skip to content

Commit

Permalink
fix: form status reset、MessagePlugin import (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
honkinglin authored Dec 22, 2021
1 parent 47e4779 commit 8114ac9
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/anchor/AnchorTarget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { FunctionComponent } from 'react';
import classNames from 'classnames';
import { FileCopyIcon } from 'tdesign-icons-react';
import Popup from '../popup';
import Message from '../message';
import { MessagePlugin } from '../message';
import useConfig from '../_util/useConfig';

import { TdAnchorTargetProps } from './type';
Expand All @@ -23,7 +23,7 @@ const AnchorTarget: FunctionComponent<AnchorTargetProps> = (props) => {
const a = document.createElement('a');
a.href = `#${id}`;
copyText(a.href);
Message.success('链接复制成功', 1000);
MessagePlugin.success('链接复制成功', 1000);
};

const Content = () => (
Expand Down
4 changes: 2 additions & 2 deletions src/dropdown/_example/base.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Dropdown, Button, Message } from 'tdesign-react';
import { Dropdown, Button, MessagePlugin } from 'tdesign-react';
import { Icon } from 'tdesign-icons-react';

export default function BasicDropdown() {
Expand All @@ -23,7 +23,7 @@ export default function BasicDropdown() {
},
];
const clickHandler = (data) => {
Message.success(`选中【${data.value}】`);
MessagePlugin.success(`选中【${data.value}】`);
};
return (
<Dropdown options={options} onClick={clickHandler}>
Expand Down
4 changes: 2 additions & 2 deletions src/dropdown/_example/button.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Dropdown, Button, Message } from 'tdesign-react';
import { Dropdown, Button, MessagePlugin } from 'tdesign-react';
import { Icon } from 'tdesign-icons-react';

export default function BasicDropdown() {
Expand All @@ -23,7 +23,7 @@ export default function BasicDropdown() {
},
];
const clickHandler = (data) => {
Message.success(`选中【${data.value}】`);
MessagePlugin.success(`选中【${data.value}】`);
};
return (
<Dropdown options={options} onClick={clickHandler}>
Expand Down
10 changes: 5 additions & 5 deletions src/dropdown/_example/click.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import {
Dropdown, Button, Message,
Dropdown, Button, MessagePlugin,
} from 'tdesign-react';

export default function BasicDropdown() {
Expand All @@ -9,22 +9,22 @@ export default function BasicDropdown() {
{
content: '操作一',
value: 1,
onClick: () => Message.success('操作一'),
onClick: () => MessagePlugin.success('操作一'),
},
{
content: '操作二',
value: 2,
onClick: () => Message.success('操作二'),
onClick: () => MessagePlugin.success('操作二'),
},
{
content: '操作三',
value: 3,
onClick: () => Message.success('操作三'),
onClick: () => MessagePlugin.success('操作三'),
},
{
content: getContent(),
value: 4,
onClick: () => Message.success('操作四'),
onClick: () => MessagePlugin.success('操作四'),
},
];
return (
Expand Down
4 changes: 2 additions & 2 deletions src/dropdown/_example/disabled.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Dropdown, Button, Message } from 'tdesign-react';
import { Dropdown, Button, MessagePlugin } from 'tdesign-react';
import { Icon } from 'tdesign-icons-react';

export default function BasicDropdown() {
Expand All @@ -25,7 +25,7 @@ export default function BasicDropdown() {
},
];
const clickHandler = (data) => {
Message.success(`选中【${data.value}】`);
MessagePlugin.success(`选中【${data.value}】`);
};
return (
<Dropdown options={options} onClick={clickHandler}>
Expand Down
4 changes: 2 additions & 2 deletions src/dropdown/_example/long.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import {
Dropdown, Button, Message,
Dropdown, Button, MessagePlugin,
} from 'tdesign-react';

export default function BasicDropdown() {
Expand All @@ -9,7 +9,7 @@ export default function BasicDropdown() {
value: k + 1,
}));
const clickHandler = (data) => {
Message.success(`选中【${data.value}】`);
MessagePlugin.success(`选中【${data.value}】`);
};
return (
<Dropdown options={options} onClick={clickHandler} maxHeight={400} minColumnWidth={90}>
Expand Down
4 changes: 2 additions & 2 deletions src/dropdown/_example/multiple.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Dropdown, Button, Message } from 'tdesign-react';
import { Dropdown, Button, MessagePlugin } from 'tdesign-react';
import { Icon } from 'tdesign-icons-react';

export default function BasicDropdown() {
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function BasicDropdown() {
},
];
const clickHandler = (data) => {
Message.success(`选中【${data.value}】`);
MessagePlugin.success(`选中【${data.value}】`);
};
return (
<Dropdown options={options} onClick={clickHandler}>
Expand Down
4 changes: 2 additions & 2 deletions src/dropdown/_example/split.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Dropdown, Button, Message } from 'tdesign-react';
import { Dropdown, Button, MessagePlugin } from 'tdesign-react';
import { Icon } from 'tdesign-icons-react';

export default function BasicDropdown() {
Expand All @@ -24,7 +24,7 @@ export default function BasicDropdown() {
},
];
const clickHandler = (data) => {
Message.success(`选中【${data.value}】`);
MessagePlugin.success(`选中【${data.value}】`);
};
return (
<Dropdown options={options} onClick={clickHandler}>
Expand Down
6 changes: 3 additions & 3 deletions src/form/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ const FormItem = forwardRef<HTMLDivElement, FormItemProps>((props, ref) => {

function setField(field: { value?: string; status?: ValidateStatus }) {
const { value, status } = field;
if (typeof value !== 'undefined') {
setFormValue(value);
}
// 手动设置 status 则不需要校验 交给用户判断
if (typeof status !== 'undefined') {
shouldValidate.current = false;
Expand All @@ -246,6 +243,9 @@ const FormItem = forwardRef<HTMLDivElement, FormItemProps>((props, ref) => {
setNeedResetField(false);
setVerifyStatus(status);
}
if (typeof value !== 'undefined') {
setFormValue(value);
}
}

// 暴露 ref 实例方法
Expand Down
6 changes: 3 additions & 3 deletions src/form/_example/base.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useRef } from 'react';
import { Form, Input, Radio, Checkbox, Button, Switch, Message, DatePicker } from 'tdesign-react';
import { Form, Input, Radio, Checkbox, Button, Switch, MessagePlugin, DatePicker } from 'tdesign-react';

const { FormItem } = Form;

Expand All @@ -9,14 +9,14 @@ export default function BaseForm() {
const onSubmit = (e) => {
console.log(e);
if (e.validateResult === true) {
Message.info('提交成功');
MessagePlugin.info('提交成功');
}
console.log(formRef.current.getAllFieldsValue());
};

const onReset = (e) => {
console.log(e);
Message.info('重置成功');
MessagePlugin.info('重置成功');
};

return (
Expand Down
6 changes: 3 additions & 3 deletions src/form/_example/custom-validator.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Form, Input, Button, Message } from 'tdesign-react';
import { Form, Input, Button, MessagePlugin } from 'tdesign-react';

const { FormItem } = Form;

Expand All @@ -9,13 +9,13 @@ export default function BaseForm() {
const onSubmit = (e) => {
console.log(e);
if (e.validateResult === true) {
Message.info('提交成功');
MessagePlugin.info('提交成功');
}
};

const onReset = (e) => {
console.log(e);
Message.info('重置成功');
MessagePlugin.info('重置成功');
};

// 自定义异步校验器
Expand Down
6 changes: 3 additions & 3 deletions src/form/_example/login.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Form, Input, Button, Message } from 'tdesign-react';
import { Form, Input, Button, MessagePlugin } from 'tdesign-react';
import { DesktopIcon, LockOnIcon } from 'tdesign-icons-react';

const { FormItem } = Form;
Expand All @@ -8,13 +8,13 @@ export default function BaseForm() {
const onSubmit = (e) => {
console.log(e);
if (e.validateResult === true) {
Message.info('提交成功');
MessagePlugin.info('提交成功');
}
};

const onReset = (e) => {
console.log(e);
Message.info('重置成功');
MessagePlugin.info('重置成功');
};

return (
Expand Down
6 changes: 3 additions & 3 deletions src/form/_example/validator-status.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { Form, Input, Button, Message } from 'tdesign-react';
import { Form, Input, Button, MessagePlugin } from 'tdesign-react';
import { LoadingIcon, AddRectangleIcon, HelpCircleIcon } from 'tdesign-icons-react';

const { FormItem } = Form;
Expand All @@ -8,13 +8,13 @@ export default function BaseForm() {
const onSubmit = (e) => {
console.log(e);
if (e.validateResult === true) {
Message.info('提交成功');
MessagePlugin.info('提交成功');
}
};

const onReset = (e) => {
console.log(e);
Message.info('重置成功');
MessagePlugin.info('重置成功');
};

const rules = {
Expand Down
6 changes: 3 additions & 3 deletions src/form/_example/validator.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useRef } from 'react';
import { Form, Input, Radio, Checkbox, Button, Message } from 'tdesign-react';
import { Form, Input, Radio, Checkbox, Button, MessagePlugin } from 'tdesign-react';
import debounce from 'lodash/debounce';

const { FormItem } = Form;
Expand All @@ -9,13 +9,13 @@ export default function BaseForm() {
const onSubmit = (e) => {
console.log(e);
if (e.validateResult === true) {
Message.info('提交成功');
MessagePlugin.info('提交成功');
}
};

const onReset = (e) => {
console.log(e);
Message.info('重置成功');
MessagePlugin.info('重置成功');
};

function asyncValidate(val) {
Expand Down
4 changes: 2 additions & 2 deletions src/menu/_example/single.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-nocheck
import React, { Fragment, useState } from 'react';
import { Menu, Message } from 'tdesign-react';
import { Menu, MessagePlugin } from 'tdesign-react';
import { UserAddIcon, AppIcon, CallIcon } from 'tdesign-icons-react';

const { HeadMenu, MenuItem } = Menu;
Expand All @@ -25,7 +25,7 @@ function Single() {
}
style={{ marginBottom: 20 }}
>
<MenuItem value={'0'} onClick={() => Message.info('click 菜单1')}>
<MenuItem value={'0'} onClick={() => MessagePlugin.info('click 菜单1')}>
<span>菜单1</span>
</MenuItem>
<MenuItem value={'1'}>
Expand Down
8 changes: 4 additions & 4 deletions src/popconfirm/_example/base.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useState } from 'react';
import { Button, PopConfirm, Message } from 'tdesign-react';
import { Button, PopConfirm, MessagePlugin } from 'tdesign-react';

export default function BasicExample() {
const [visible, setVisible] = useState(false);

const deleteClickHandler = () => {
const msg = Message.info('提交中', 0);
const msg = MessagePlugin.info('提交中', 0);
setTimeout(() => {
Message.close(msg);
Message.success('提交成功!');
MessagePlugin.close(msg);
MessagePlugin.success('提交成功!');
setVisible(false);
}, 1000);
};
Expand Down

0 comments on commit 8114ac9

Please sign in to comment.