Add panel error message component

This commit is contained in:
2022-03-09 11:45:00 +08:00
parent f87da8cbab
commit 8e3330b398
6 changed files with 36 additions and 18 deletions
+8 -1
View File
@@ -24,6 +24,13 @@ class AttrInput extends Component<IAttrInputProps> {
private value: string = "";
private error: ReactNode;
private numberTestReg = [/\.0*$/, /[1-9]+0+$/];
private numberTester(value: string) {
return isNaN((value as any) / 1) ||
this.numberTestReg[0].test(value) ||
this.numberTestReg[1].test(value);
}
private check(value: string): ReactNode {
@@ -37,7 +44,7 @@ class AttrInput extends Component<IAttrInputProps> {
const praseNumber = (value as any) / 1;
// 数字校验
if (isNaN(praseNumber) || /\.0*$/.test(value)) {
if (this.numberTester(value)) {
return <Localization i18nKey="Input.Error.Not.Number" />
}
@@ -0,0 +1,3 @@
div.panel-error-message {
padding-top: 5px;
}
@@ -0,0 +1,16 @@
import { AllI18nKeys, Localization } from "@Component/Localization/Localization";
import { FunctionComponent } from "react";
import "./ErrorMessage.scss";
interface IErrorMessageProps {
i18nKey: AllI18nKeys;
options?: Record<string, string>;
}
const ErrorMessage: FunctionComponent<IErrorMessageProps> = (props) => {
return <div className="panel-error-message">
<Localization i18nKey={props.i18nKey} options={props.options}/>
</div>
}
export { ErrorMessage };