Recode attr input with text field component

This commit is contained in:
2022-03-15 15:26:53 +08:00
parent 66102a9936
commit 469ebd2ac9
6 changed files with 277 additions and 164 deletions
+84
View File
@@ -0,0 +1,84 @@
@import "../Theme/Theme.scss";
$line-min-height: 26px;
div.text-field-root {
min-height: $line-min-height;
width: 100%;
display: flex;
padding: 5px 0;
div.text-field-intro {
min-height: $line-min-height;
width: 50%;
height: 100%;
max-width: 220px;
display: flex;
align-items: center;
padding-right: 5px;
box-sizing: border-box;
}
div.text-field-container {
min-height: $line-min-height;
width: 50%;
height: 100%;
max-width: 180px;
div.text-field-content {
min-height: $line-min-height;
width: 100%;
height: 100%;
}
div.text-field-content-styled {
box-sizing: border-box;
border: 1px solid transparent;
border-radius: 3px;
overflow: hidden;
display: flex;
}
div.text-field-content-disable {
align-items: center;
span {
display: block;
padding-left: 8px;
}
}
div.text-field-content-error {
border: 1px solid $lt-red;
}
div.text-field-error-message {
padding-top: 5px;
color: $lt-red;
}
}
}
div.dark.text-field-root {
div.text-field-content-styled {
background-color: $lt-bg-color-lvl3-dark;
color: $lt-font-color-normal-dark;
}
div.text-field-content-hover-styled:hover {
background-color: $lt-bg-color-lvl2-dark;
}
}
div.light.text-field-root {
div.text-field-content-styled {
background-color: $lt-bg-color-lvl3-light;
color: $lt-font-color-normal-light;
}
div.text-field-content-hover-styled:hover {
background-color: $lt-bg-color-lvl2-light;
}
}
+104
View File
@@ -0,0 +1,104 @@
import { Component, ReactNode, RefObject } from "react";
import { FontLevel, Theme } from "@Component/Theme/Theme";
import { AllI18nKeys, Localization } from "@Component/Localization/Localization";
import "./TextField.scss";
interface ITextFieldProps {
className?: string;
keyI18n: AllI18nKeys;
infoI18n?: AllI18nKeys;
disableI18n?: AllI18nKeys;
disableI18nOption?: Record<string, string>;
errorI18n?: AllI18nKeys;
errorI18nOption?: Record<string, string>;
targetRef?: RefObject<HTMLDivElement>;
customStyle?: boolean;
customHoverStyle?: boolean;
onClick?: () => any;
}
class TextField extends Component<ITextFieldProps> {
private renderInput() {
const classList: string[] = ["text-field-content"];
if (this.props.className) {
classList.push(this.props.className);
}
if (!this.props.customStyle) {
classList.push("text-field-content-styled");
}
if (!this.props.customHoverStyle) {
classList.push("text-field-content-hover-styled");
}
if (this.props.errorI18n) {
classList.push("text-field-content-error");
}
return <div
className={classList.join(" ")}
ref={this.props.targetRef}
style={{ cursor: "pointer" }}
onClick={this.props.onClick}
>
{ this.props.children }
</div>
}
private renderDisable() {
return <div
className={
`${
"text-field-content"
} ${
"text-field-content-styled"
} ${
"text-field-content-hover-styled"
} ${
"text-field-content-disable"
}`
}
ref={this.props.targetRef}
style={{ cursor: "not-allowed" }}
onClick={this.props.onClick}
>
<Localization
i18nKey={this.props.disableI18n ?? "Common.No.Unknown.Error"}
options={this.props.disableI18nOption}
/>
</div>
}
private renderError() {
return <div className="text-field-error-message">
<Localization
i18nKey={this.props.errorI18n ?? "Common.No.Unknown.Error"}
options={this.props.errorI18nOption}
/>
</div>
}
public render(): ReactNode {
return <>
<Theme className="text-field-root" fontLevel={FontLevel.normal}>
<div className="text-field-intro">
<Localization i18nKey={this.props.keyI18n}/>
</div>
<div className="text-field-container">
{
this.props.disableI18n ?
this.renderDisable() :
this.renderInput()
}
{
this.props.errorI18n ?
this.renderError() :
undefined
}
</div>
</Theme>
</>
}
}
export { TextField, ITextFieldProps };