|
1 | 1 | import { CompAction, SimpleComp } from "lowcoder-core"; |
2 | | -import { ControlParams, ControlPropertyViewWrapper, EditorContext, EditText, PopupCard } from "@lowcoder-ee/index.sdk"; |
| 2 | +import { ControlParams, ControlPropertyViewWrapper, PopupCard } from "@lowcoder-ee/index.sdk"; |
3 | 3 | import { useEffect, useState } from "react"; |
4 | 4 | import { trans } from "@lowcoder-ee/i18n"; |
5 | 5 | import { Input } from "lowcoder-design/src/components/Input"; |
6 | 6 | import { checkName } from "../utils/rename"; |
7 | | -const SimpleVariableHeaderPropertyView = ({params, comp}: any) => { |
8 | | - const [error, setError] = useState<string | undefined>(""); |
| 7 | +const SimpleVariableHeaderPropertyView = ({params, comp, isCheck}: any) => { |
| 8 | + const [error, setError] = useState<string | undefined>(); |
9 | 9 | const [value, setValue] = useState(comp.value); |
10 | 10 | useEffect(() => { |
11 | 11 | setValue(comp.value); |
12 | | - setError(undefined); |
| 12 | + isCheck && setError(undefined); |
13 | 13 | }, [comp]); |
14 | 14 | return ( |
15 | 15 | <ControlPropertyViewWrapper {...params}> |
16 | 16 | <Input |
17 | 17 | value={value} |
18 | 18 | placeholder={params.placeholder} |
19 | 19 | onChange={(e) => { |
20 | | - const error = checkName(e.target.value); |
21 | | - setError(error || undefined); |
| 20 | + const error = isCheck && checkName(e.target.value); |
| 21 | + isCheck && setError(error || undefined); |
22 | 22 | setValue(e.target.value); |
23 | 23 | }} |
24 | 24 | onBlur={(e) => { |
25 | | - if(!error) comp.dispatchChangeValueAction(value); |
| 25 | + if(!isCheck || !error) comp.dispatchChangeValueAction(value); |
26 | 26 | else { |
27 | 27 | setValue(comp.value); |
28 | 28 | setError(undefined); |
29 | 29 | } |
30 | 30 | }} |
31 | 31 | /> |
32 | | - {/* <EditText |
33 | | - // disabled={readOnly} |
34 | | - text={comp.value} |
35 | | - onFinish={(value) => { |
36 | | - if (editorState.rename(comp.value, value)) { |
37 | | - // editorState.setSelectedBottomRes(value, type); |
38 | | - setError(""); |
39 | | - } |
40 | | - }} |
41 | | - onChange={(value) => setError(editorState.checkRename(comp.value, value))} |
42 | | - style={{ maxWidth: '100%', width: '100%' }} |
43 | | - /> */} |
44 | | - <PopupCard |
| 32 | + {isCheck && <PopupCard |
45 | 33 | editorFocus={!!error} |
46 | 34 | title={error ? trans("error") : ""} |
47 | 35 | content={error} |
48 | 36 | hasError={!!error} |
49 | | - /> |
| 37 | + />} |
50 | 38 | </ControlPropertyViewWrapper> |
51 | 39 | ); |
52 | 40 | } |
53 | | -export class SimpleVariableHeaderComp extends SimpleComp<string> { |
54 | | - override reduce(action: CompAction): this { |
55 | | - // if (isBroadcastAction<RenameAction>(action, CompActionTypes.RENAME)) { |
56 | | - // if (this.getView() === action.action.oldName) { |
57 | | - // return super.reduce(this.changeValueAction(action.action.name)); |
58 | | - // } |
59 | | - // } |
60 | | - return super.reduce(action); |
61 | | - } |
| 41 | +export const SimpleVariableHeaderComp = (isCheck: boolean = false) => { |
| 42 | + return class SimpleVariableHeaderComp extends SimpleComp<string> { |
| 43 | + override reduce(action: CompAction): this { |
| 44 | + // if (isBroadcastAction<RenameAction>(action, CompActionTypes.RENAME)) { |
| 45 | + // if (this.getView() === action.action.oldName) { |
| 46 | + // return super.reduce(this.changeValueAction(action.action.name)); |
| 47 | + // } |
| 48 | + // } |
| 49 | + return super.reduce(action); |
| 50 | + } |
62 | 51 |
|
63 | | - readonly IGNORABLE_DEFAULT_VALUE = ""; |
64 | | - protected getDefaultValue(): string { |
65 | | - return ""; |
66 | | - } |
| 52 | + readonly IGNORABLE_DEFAULT_VALUE = ""; |
| 53 | + protected getDefaultValue(): string { |
| 54 | + return ""; |
| 55 | + } |
67 | 56 |
|
68 | | - getPropertyView() { |
69 | | - return this.propertyView({}); |
70 | | - } |
| 57 | + getPropertyView() { |
| 58 | + return this.propertyView({}); |
| 59 | + } |
71 | 60 |
|
72 | | - propertyView(params: ControlParams) { |
73 | | - return <SimpleVariableHeaderPropertyView params={params} comp={this}></SimpleVariableHeaderPropertyView> |
| 61 | + propertyView(params: ControlParams) { |
| 62 | + return <SimpleVariableHeaderPropertyView params={params} comp={this} isCheck={isCheck}></SimpleVariableHeaderPropertyView> |
| 63 | + } |
74 | 64 | } |
75 | 65 | } |
0 commit comments