tgui-core 3.0.3 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,25 +15,42 @@ type Props = Partial<{
|
|
|
15
15
|
/** Fires on input validation change */
|
|
16
16
|
onValidationChange: (isValid: boolean) => void;
|
|
17
17
|
/**
|
|
18
|
-
* Generally, input can handle its own state value.
|
|
18
|
+
* Generally, input can handle its own state value. You might not NEED this.
|
|
19
19
|
*
|
|
20
|
-
* Use this if you want to hold the value in the parent for external
|
|
20
|
+
* Use this if you want to hold the value in the parent for external
|
|
21
|
+
* manipulation. For instance:
|
|
21
22
|
*
|
|
23
|
+
* ### Clearing the input
|
|
22
24
|
* ```tsx
|
|
23
|
-
* const [value, setValue] = useState(1;
|
|
25
|
+
* const [value, setValue] = useState(1);
|
|
24
26
|
*
|
|
25
27
|
* return (
|
|
26
28
|
* <>
|
|
27
29
|
* <Button onClick={() => act('inputVal', {inputVal: value})}>
|
|
28
30
|
* Submit
|
|
29
31
|
* </Button>
|
|
30
|
-
* <RestrictedInput
|
|
32
|
+
* <RestrictedInput
|
|
33
|
+
* value={value}
|
|
34
|
+
* onChange={setValue} />
|
|
31
35
|
* <Button onClick={() => setValue(1)}>
|
|
32
36
|
* Clear
|
|
33
37
|
* </Button>
|
|
34
38
|
* </>
|
|
35
39
|
* )
|
|
36
40
|
* ```
|
|
41
|
+
*
|
|
42
|
+
* ### Updating the value from the backend
|
|
43
|
+
* ```tsx
|
|
44
|
+
* const { data } = useBackend<Data>();
|
|
45
|
+
* const { valveSetting } = data;
|
|
46
|
+
*
|
|
47
|
+
* return (
|
|
48
|
+
* <RestrictedInput
|
|
49
|
+
* value={valveSetting}
|
|
50
|
+
* onEnter={(value) => act('submit', { valveSetting: value })}
|
|
51
|
+
* />
|
|
52
|
+
* )
|
|
53
|
+
* ```
|
|
37
54
|
*/
|
|
38
55
|
value: number;
|
|
39
56
|
}> & BaseInputProps;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"react/jsx-runtime";import*as t from"../common/react.js";import*as r from"../common/timer.js";import*as u from"../common/ui.js";import*as n from"react";import*as o from"../common/keys.js";let s=(0,r.debounce)(e=>e(),250);function
|
|
1
|
+
import*as e from"react/jsx-runtime";import*as t from"../common/react.js";import*as r from"../common/timer.js";import*as u from"../common/ui.js";import*as n from"react";import*as o from"../common/keys.js";let s=(0,r.debounce)(e=>e(),250);function a(r){let{allowFloats:a,autoFocus:c,autoSelect:m,className:i,disabled:l,expensive:f,fluid:p,maxValue:d=1e4,minValue:v=0,monospace:y,onChange:E,onEnter:b,onEscape:I,onValidationChange:j,...k}=r,x=(0,n.useRef)(null),[D,R]=(0,n.useState)(r.value??v),[C,K]=(0,n.useState)(!0),M=(0,n.useMemo)(()=>(0,u.computeBoxProps)(k),[k]),g=(0,n.useMemo)(()=>(0,t.classes)(["Input","RestrictedInput",l&&"Input--disabled",p&&"Input--fluid",y&&"Input--monospace",i,!C&&"RestrictedInput--invalid"]),[i,l,p,C,y]);return(0,n.useEffect)(()=>{let e;return(c||m)&&(e=setTimeout(()=>{x.current?.focus(),m&&x.current?.select()},1)),()=>clearTimeout(e)},[]),(0,n.useEffect)(()=>{if(x.current){let e=x.current.validity.valid;C!==e&&(K(e),j?.(e))}},[D]),(0,n.useEffect)(()=>{x.current&&document.activeElement!==x.current&&r.value!==D&&R(r.value??v)},[r.value]),(0,e.jsx)("input",{...M,autoComplete:"off",className:g,disabled:l,max:d,min:v,onChange:function(e){let t=Number(e.target.value);R(t),E&&(f?s(()=>E(t)):E(t))},onKeyDown:function(e){if(e.key===o.KEY.Enter){e.preventDefault(),b?.(D),x.current?.blur();return}if((0,o.isEscape)(e.key)){e.preventDefault(),I?.(D),x.current?.blur();return}if(e.key===o.KEY.Minus){e.preventDefault(),R(-1*D);return}},ref:x,spellCheck:!1,step:a?"any":"1",type:"number",value:D})}export{a as RestrictedInput};
|