Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@ export function BindingField({
const hasKey = useMemo(() => !!key, [key]);

return (
<div className="editable-container">
<div
className={`input-container-bg ${
hovering && hasKey ? "input-container-bg-hover" : ""
}`}
onMouseEnter={() => setHovering(true)}
onMouseLeave={() => setHovering(false)}
>
<img alt={icon} className="general-setting-item-icon" src={icon} />
<span className="general-setting-item-icon-desc">{desc}</span>
{hasKey ? (
<span>{key}</span>
) : (
<Button type="link" onClick={handleShowModel}>
{msg}
</Button>
)}
{hovering && hasKey && (
<Button type="link" onClick={() => unbind(content, type)}>
<img alt="close" src={closeSVG} />
</Button>
)}
</div>
<div
className={`input-container-bg ${hovering && hasKey ? "input-container-bg-hover" : ""}`}
onMouseEnter={() => setHovering(true)}
onMouseLeave={() => setHovering(false)}
>
<img alt={icon} className="general-setting-item-icon" src={icon} />
<span className="general-setting-item-icon-desc">{desc}</span>
{hasKey ? (
<span className="general-setting-item-key">{key}</span>
) : (
<Button type="link" onClick={handleShowModel}>
{msg}
</Button>
)}
{hovering && hasKey && (
<Button
className="general-setting-item-btn"
type="link"
onClick={() => unbind(content, type)}
>
<img alt="close" src={closeSVG} />
</Button>
)}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { Button, Input } from "antd";
import React, { useState } from "react";
import React, { useEffect, useState } from "react";

import editSVG from "./icons/edit.svg";
import closeSVG from "./icons/close.svg";
import checkSVG from "./icons/check.svg";

const nicknameRegx = /^.{1,15}$/;

export function nicknameValidator(name: string): boolean {
return nicknameRegx.test(name);
}

// input editable
interface EditableInputProps {
value: string;
Expand All @@ -27,6 +33,15 @@ export function EditableInput({
}: EditableInputProps): React.ReactElement {
const [editing, setEditing] = useState(false);
const [hovering, setHovering] = useState(false);
const [keyValidate, setKeyValidate] = useState(false);

useEffect(() => {
if (editing && !nicknameValidator(value)) {
setKeyValidate(false);
} else {
setKeyValidate(true);
}
}, [editing, keyValidate, value]);

return (
<div
Expand All @@ -38,9 +53,17 @@ export function EditableInput({
<span className="general-setting-item-icon-desc">{desc}</span>
{editing ? (
<>
<Input id={desc} spellCheck={false} value={value} onChange={setValue} />
<Input
id={desc}
spellCheck={false}
status={keyValidate ? void 0 : "error"}
value={value}
onChange={setValue}
/>

<Button
className="general-setting-item-btn"
disabled={!keyValidate}
type="link"
onClick={async () => {
await updateValue();
Expand All @@ -51,6 +74,7 @@ export function EditableInput({
<img alt="check" src={checkSVG} />
</Button>
<Button
className="general-setting-item-btn"
type="link"
onClick={() => {
cancelUpdate();
Expand All @@ -62,10 +86,14 @@ export function EditableInput({
</Button>
</>
) : (
<span>{value}</span>
<span className="general-setting-item-key">{value}</span>
)}
{hovering && !editing && (
<Button type="link" onClick={() => setEditing(true)}>
<Button
className="general-setting-item-btn"
type="link"
onClick={() => setEditing(true)}
>
<img alt="edit" src={editSVG} />
</Button>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@
}

&-icon-desc {
margin-right: 124px;
width: 150px;
}

&-text .ant-btn-link {
padding: 0;
&-key {
max-width: 160px;
}

&-btn {
margin-left: 4px;
}
}

Expand Down Expand Up @@ -107,17 +111,26 @@
display: inline-block;
border-radius: 6px;
transition: all 0.3s ease;
padding-right: 4px;
padding: 4px;
line-height: 38px;

img,
span,
.ant-btn-link {
vertical-align: middle;
}

.ant-input {
width: 150px;
}

>span {
line-height: 45px;
display: inline-block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
word-break: keep-all;
white-space: nowrap;
}

.ant-btn-link {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const GeneralSettingPage = observer(function GeneralSettingPage() {
unbind,
})}
</div>
<div className="general-setting-item-text">
<div className="general-setting-item-text input-container-bg">
<img alt="password" className="general-setting-item-icon" src={lockSVG} />
<span className="general-setting-item-icon-desc">{t("password")}</span>
<Button type="link" onClick={() => setShowPasswordModel(true)}>
Expand Down