From 44ca21e578187949932b6861f2a3be66b78ff290 Mon Sep 17 00:00:00 2001 From: Jafar Mirzaie Date: Thu, 19 Oct 2023 10:28:09 +0200 Subject: [PATCH] fix AutoLine --- Signum/React/Lines/AutoLine.tsx | 4 +- Signum/React/Lines/TextBoxLine.tsx | 87 +++++++----------------------- 2 files changed, 20 insertions(+), 71 deletions(-) diff --git a/Signum/React/Lines/AutoLine.tsx b/Signum/React/Lines/AutoLine.tsx index 83f6f9751a..6e755377c5 100644 --- a/Signum/React/Lines/AutoLine.tsx +++ b/Signum/React/Lines/AutoLine.tsx @@ -1,7 +1,7 @@ import * as React from 'react' import { IsByAll, MemberInfo, PropertyRoute, PseudoType, Type, TypeInfo, TypeReference, isTypeEnum, isTypeModel, tryGetTypeInfos } from '../Reflection' import { LineBaseController, LineBaseProps, tasks } from '../Lines/LineBase' -import { CheckboxLine, DateTimeLine, DateTimeLineController, EntityCheckboxList, EntityCombo, EntityDetail, EntityLine, EntityRepeater, EntityStrip, EntityTable, EnumCheckboxList, EnumLine, GuidLine, MultiValueLine, NumberLine, NumberLineController, PasswordLine, TextBoxLine, TimeLine, TypeContext } from '../Lines' +import { CheckboxLine, ColorLine, DateTimeLine, DateTimeLineController, EntityCheckboxList, EntityCombo, EntityDetail, EntityLine, EntityRepeater, EntityStrip, EntityTable, EnumCheckboxList, EnumLine, GuidLine, MultiValueLine, NumberLine, NumberLineController, PasswordLine, TextBoxLine, TimeLine, TypeContext } from '../Lines' import { Entity, Lite, ModifiableEntity } from '../Signum.Entities' export interface AutoLineProps extends LineBaseProps { @@ -106,7 +106,7 @@ export namespace AutoLine { return p => ; if (pr?.member!.format == "Color") - return p => ; + return p => ; return p => ; } diff --git a/Signum/React/Lines/TextBoxLine.tsx b/Signum/React/Lines/TextBoxLine.tsx index fb2b0d8054..04f1f05aff 100644 --- a/Signum/React/Lines/TextBoxLine.tsx +++ b/Signum/React/Lines/TextBoxLine.tsx @@ -36,9 +36,16 @@ export const TextBoxLine = React.memo(React.forwardRef(function TextBoxLine(prop return LineBaseController.propEquals(prev, next); }); -export const PasswordLine = React.memo(React.forwardRef(function PasswordLine(props: TextBoxLineProps, ref: React.Ref) { +export class PasswordLineController extends ValueBaseController{ + init(p: TextBoxLineProps) { + super.init(p); + this.assertType("PasswordLine", ["string"]); + } +} - const c = useController(TextBoxLineController, props, ref); +export const PasswordLine = React.memo(React.forwardRef(function PasswordLine(props: TextBoxLineProps, ref: React.Ref) { + + const c = useController(PasswordLineController, props, ref); if (c.isHidden) return null; @@ -51,9 +58,16 @@ export const PasswordLine = React.memo(React.forwardRef(function PasswordLine(pr return LineBaseController.propEquals(prev, next); }); -export const GuidLine = React.memo(React.forwardRef(function GuidLine(props: TextBoxLineProps, ref: React.Ref) { +export class GuidLineController extends ValueBaseController{ + init(p: TextBoxLineProps) { + super.init(p); + this.assertType("TextBoxLine", ["Guid"]); + } +} - const c = useController(TextBoxLineController, props, ref); +export const GuidLine = React.memo(React.forwardRef(function GuidLine(props: TextBoxLineProps, ref: React.Ref) { + + const c = useController(GuidLineController, props, ref); if (c.isHidden) return null; @@ -148,68 +162,3 @@ function internalTextBox(vl: TextBoxLineController, type: "password" | "color" | ); } - -export interface ColorTextBoxProps { - value: string | null; - onChange: (newValue: string | null) => void; - formControlClass?: string; - groupClass?: string; - textValueHtmlAttributes?: React.HTMLAttributes; - groupHtmlAttributes?: React.HTMLAttributes; - innerRef?: React.Ref; -} - -export function ColorTextBox(p: ColorTextBoxProps) { - - const [text, setText] = React.useState(undefined); - - const value = text != undefined ? text : p.value != undefined ? p.value : ""; - - return ( - - - - ); - - function handleOnFocus(e: React.FocusEvent) { - const input = e.currentTarget as HTMLInputElement; - - input.setSelectionRange(0, input.value != null ? input.value.length : 0); - - if (p.textValueHtmlAttributes?.onFocus) - p.textValueHtmlAttributes.onFocus(e); - }; - - function handleOnBlur(e: React.FocusEvent) { - - const input = e.currentTarget as HTMLInputElement; - - var result = input.value == undefined || input.value.length == 0 ? null : input.value; - - setText(undefined); - if (p.value != result) - p.onChange(result); - if (p.textValueHtmlAttributes?.onBlur) - p.textValueHtmlAttributes.onBlur(e); - } - - function handleOnChange(e: React.SyntheticEvent) { - const input = e.currentTarget as HTMLInputElement; - setText(input.value); - if (p.onChange) - p.onChange(input.value); - } -}