Skip to content

Commit 44ca21e

Browse files
committed
fix AutoLine
1 parent 1d83bed commit 44ca21e

File tree

2 files changed

+20
-71
lines changed

2 files changed

+20
-71
lines changed

Signum/React/Lines/AutoLine.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react'
22
import { IsByAll, MemberInfo, PropertyRoute, PseudoType, Type, TypeInfo, TypeReference, isTypeEnum, isTypeModel, tryGetTypeInfos } from '../Reflection'
33
import { LineBaseController, LineBaseProps, tasks } from '../Lines/LineBase'
4-
import { CheckboxLine, DateTimeLine, DateTimeLineController, EntityCheckboxList, EntityCombo, EntityDetail, EntityLine, EntityRepeater, EntityStrip, EntityTable, EnumCheckboxList, EnumLine, GuidLine, MultiValueLine, NumberLine, NumberLineController, PasswordLine, TextBoxLine, TimeLine, TypeContext } from '../Lines'
4+
import { CheckboxLine, ColorLine, DateTimeLine, DateTimeLineController, EntityCheckboxList, EntityCombo, EntityDetail, EntityLine, EntityRepeater, EntityStrip, EntityTable, EnumCheckboxList, EnumLine, GuidLine, MultiValueLine, NumberLine, NumberLineController, PasswordLine, TextBoxLine, TimeLine, TypeContext } from '../Lines'
55
import { Entity, Lite, ModifiableEntity } from '../Signum.Entities'
66

77
export interface AutoLineProps extends LineBaseProps {
@@ -106,7 +106,7 @@ export namespace AutoLine {
106106
return p => <PasswordLine {...p} />;
107107

108108
if (pr?.member!.format == "Color")
109-
return p => <PasswordLine {...p} />;
109+
return p => <ColorLine {...p} />;
110110

111111
return p => <TextBoxLine {...p} />;
112112
}

Signum/React/Lines/TextBoxLine.tsx

Lines changed: 18 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,16 @@ export const TextBoxLine = React.memo(React.forwardRef(function TextBoxLine(prop
3636
return LineBaseController.propEquals(prev, next);
3737
});
3838

39-
export const PasswordLine = React.memo(React.forwardRef(function PasswordLine(props: TextBoxLineProps, ref: React.Ref<TextBoxLineController>) {
39+
export class PasswordLineController extends ValueBaseController<TextBoxLineProps>{
40+
init(p: TextBoxLineProps) {
41+
super.init(p);
42+
this.assertType("PasswordLine", ["string"]);
43+
}
44+
}
4045

41-
const c = useController(TextBoxLineController, props, ref);
46+
export const PasswordLine = React.memo(React.forwardRef(function PasswordLine(props: TextBoxLineProps, ref: React.Ref<PasswordLineController>) {
47+
48+
const c = useController(PasswordLineController, props, ref);
4249

4350
if (c.isHidden)
4451
return null;
@@ -51,9 +58,16 @@ export const PasswordLine = React.memo(React.forwardRef(function PasswordLine(pr
5158
return LineBaseController.propEquals(prev, next);
5259
});
5360

54-
export const GuidLine = React.memo(React.forwardRef(function GuidLine(props: TextBoxLineProps, ref: React.Ref<TextBoxLineController>) {
61+
export class GuidLineController extends ValueBaseController<TextBoxLineProps>{
62+
init(p: TextBoxLineProps) {
63+
super.init(p);
64+
this.assertType("TextBoxLine", ["Guid"]);
65+
}
66+
}
5567

56-
const c = useController(TextBoxLineController, props, ref);
68+
export const GuidLine = React.memo(React.forwardRef(function GuidLine(props: TextBoxLineProps, ref: React.Ref<GuidLineController>) {
69+
70+
const c = useController(GuidLineController, props, ref);
5771

5872
if (c.isHidden)
5973
return null;
@@ -148,68 +162,3 @@ function internalTextBox(vl: TextBoxLineController, type: "password" | "color" |
148162
</FormGroup>
149163
);
150164
}
151-
152-
export interface ColorTextBoxProps {
153-
value: string | null;
154-
onChange: (newValue: string | null) => void;
155-
formControlClass?: string;
156-
groupClass?: string;
157-
textValueHtmlAttributes?: React.HTMLAttributes<HTMLInputElement>;
158-
groupHtmlAttributes?: React.HTMLAttributes<HTMLInputElement>;
159-
innerRef?: React.Ref<HTMLInputElement>;
160-
}
161-
162-
export function ColorTextBox(p: ColorTextBoxProps) {
163-
164-
const [text, setText] = React.useState<string | undefined>(undefined);
165-
166-
const value = text != undefined ? text : p.value != undefined ? p.value : "";
167-
168-
return (
169-
<span {...p.groupHtmlAttributes} className={addClass(p.groupHtmlAttributes, classes(p.groupClass))}>
170-
<input type="text"
171-
autoComplete="asdfasf" /*Not in https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill*/
172-
{...p.textValueHtmlAttributes}
173-
className={addClass(p.textValueHtmlAttributes, classes(p.formControlClass))}
174-
value={value}
175-
onBlur={handleOnBlur}
176-
onChange={handleOnChange}
177-
onFocus={handleOnFocus}
178-
ref={p.innerRef} />
179-
<input type="color"
180-
className={classes(p.formControlClass, "sf-color")}
181-
value={value}
182-
onBlur={handleOnBlur}
183-
onChange={handleOnChange}
184-
/>
185-
</span>);
186-
187-
function handleOnFocus(e: React.FocusEvent<any>) {
188-
const input = e.currentTarget as HTMLInputElement;
189-
190-
input.setSelectionRange(0, input.value != null ? input.value.length : 0);
191-
192-
if (p.textValueHtmlAttributes?.onFocus)
193-
p.textValueHtmlAttributes.onFocus(e);
194-
};
195-
196-
function handleOnBlur(e: React.FocusEvent<any>) {
197-
198-
const input = e.currentTarget as HTMLInputElement;
199-
200-
var result = input.value == undefined || input.value.length == 0 ? null : input.value;
201-
202-
setText(undefined);
203-
if (p.value != result)
204-
p.onChange(result);
205-
if (p.textValueHtmlAttributes?.onBlur)
206-
p.textValueHtmlAttributes.onBlur(e);
207-
}
208-
209-
function handleOnChange(e: React.SyntheticEvent<any>) {
210-
const input = e.currentTarget as HTMLInputElement;
211-
setText(input.value);
212-
if (p.onChange)
213-
p.onChange(input.value);
214-
}
215-
}

0 commit comments

Comments
 (0)