Can update device general information
This commit is contained in:
		
							
								
								
									
										21
									
								
								central_frontend/src/widgets/forms/CheckboxInput.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								central_frontend/src/widgets/forms/CheckboxInput.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
import { Checkbox, FormControlLabel } from "@mui/material";
 | 
			
		||||
 | 
			
		||||
export function CheckboxInput(p: {
 | 
			
		||||
  editable: boolean;
 | 
			
		||||
  label: string;
 | 
			
		||||
  checked: boolean | undefined;
 | 
			
		||||
  onValueChange: (v: boolean) => void;
 | 
			
		||||
}): React.ReactElement {
 | 
			
		||||
  return (
 | 
			
		||||
    <FormControlLabel
 | 
			
		||||
      control={
 | 
			
		||||
        <Checkbox
 | 
			
		||||
          disabled={!p.editable}
 | 
			
		||||
          checked={p.checked}
 | 
			
		||||
          onChange={(e) => p.onValueChange(e.target.checked)}
 | 
			
		||||
        />
 | 
			
		||||
      }
 | 
			
		||||
      label={p.label}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										61
									
								
								central_frontend/src/widgets/forms/TextInput.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								central_frontend/src/widgets/forms/TextInput.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,61 @@
 | 
			
		||||
import { TextField } from "@mui/material";
 | 
			
		||||
import { LenConstraint } from "../../api/ServerApi";
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Text property edition
 | 
			
		||||
 */
 | 
			
		||||
export function TextInput(p: {
 | 
			
		||||
  label?: string;
 | 
			
		||||
  editable: boolean;
 | 
			
		||||
  value?: string;
 | 
			
		||||
  onValueChange?: (newVal: string | undefined) => void;
 | 
			
		||||
  size?: LenConstraint;
 | 
			
		||||
  checkValue?: (s: string) => boolean;
 | 
			
		||||
  multiline?: boolean;
 | 
			
		||||
  minRows?: number;
 | 
			
		||||
  maxRows?: number;
 | 
			
		||||
  type?: React.HTMLInputTypeAttribute;
 | 
			
		||||
  style?: React.CSSProperties;
 | 
			
		||||
  helperText?: string;
 | 
			
		||||
}): React.ReactElement {
 | 
			
		||||
  if (!p.editable && (p.value ?? "") === "") return <></>;
 | 
			
		||||
 | 
			
		||||
  let valueError = undefined;
 | 
			
		||||
  if (p.value && p.value.length > 0) {
 | 
			
		||||
    if (p.size?.min && p.type !== "number" && p.value.length < p.size.min)
 | 
			
		||||
      valueError = "Value is too short!";
 | 
			
		||||
    if (p.checkValue && !p.checkValue(p.value)) valueError = "Invalid value!";
 | 
			
		||||
    if (
 | 
			
		||||
      p.type === "number" &&
 | 
			
		||||
      p.size &&
 | 
			
		||||
      (Number(p.value) > p.size.max || Number(p.value) < p.size.min)
 | 
			
		||||
    )
 | 
			
		||||
      valueError = "Invalide size range!";
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <TextField
 | 
			
		||||
      label={p.label}
 | 
			
		||||
      value={p.value ?? ""}
 | 
			
		||||
      onChange={(e) =>
 | 
			
		||||
        p.onValueChange?.(
 | 
			
		||||
          e.target.value.length === 0 ? undefined : e.target.value
 | 
			
		||||
        )
 | 
			
		||||
      }
 | 
			
		||||
      inputProps={{
 | 
			
		||||
        maxLength: p.size?.max,
 | 
			
		||||
      }}
 | 
			
		||||
      InputProps={{
 | 
			
		||||
        readOnly: !p.editable,
 | 
			
		||||
        type: p.type,
 | 
			
		||||
      }}
 | 
			
		||||
      variant={"standard"}
 | 
			
		||||
      style={p.style ?? { width: "100%", marginBottom: "15px" }}
 | 
			
		||||
      multiline={p.multiline}
 | 
			
		||||
      minRows={p.minRows}
 | 
			
		||||
      maxRows={p.maxRows}
 | 
			
		||||
      error={valueError !== undefined}
 | 
			
		||||
      helperText={valueError ?? p.helperText}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user