tgui-core 3.0.2 → 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.
|
@@ -12,26 +12,45 @@ type Props = Partial<{
|
|
|
12
12
|
onEnter: (value: number) => void;
|
|
13
13
|
/** Fires once the escape key is pressed */
|
|
14
14
|
onEscape: (value: number) => void;
|
|
15
|
+
/** Fires on input validation change */
|
|
16
|
+
onValidationChange: (isValid: boolean) => void;
|
|
15
17
|
/**
|
|
16
|
-
* Generally, input can handle its own state value.
|
|
18
|
+
* Generally, input can handle its own state value. You might not NEED this.
|
|
17
19
|
*
|
|
18
|
-
* 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:
|
|
19
22
|
*
|
|
23
|
+
* ### Clearing the input
|
|
20
24
|
* ```tsx
|
|
21
|
-
* const [value, setValue] = useState(1;
|
|
25
|
+
* const [value, setValue] = useState(1);
|
|
22
26
|
*
|
|
23
27
|
* return (
|
|
24
28
|
* <>
|
|
25
29
|
* <Button onClick={() => act('inputVal', {inputVal: value})}>
|
|
26
30
|
* Submit
|
|
27
31
|
* </Button>
|
|
28
|
-
* <RestrictedInput
|
|
32
|
+
* <RestrictedInput
|
|
33
|
+
* value={value}
|
|
34
|
+
* onChange={setValue} />
|
|
29
35
|
* <Button onClick={() => setValue(1)}>
|
|
30
36
|
* Clear
|
|
31
37
|
* </Button>
|
|
32
38
|
* </>
|
|
33
39
|
* )
|
|
34
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
|
+
* ```
|
|
35
54
|
*/
|
|
36
55
|
value: number;
|
|
37
56
|
}> & BaseInputProps;
|
|
@@ -40,6 +59,8 @@ type Props = Partial<{
|
|
|
40
59
|
*
|
|
41
60
|
* Creates a numerical input which rejects improper keys.
|
|
42
61
|
*
|
|
62
|
+
* Has a special event for changes in validation states - `onValidationChange`.
|
|
63
|
+
*
|
|
43
64
|
* @see https://github.com/tgstation/tgui-core/blob/main/lib/components/RestrictedInput.tsx
|
|
44
65
|
*/
|
|
45
66
|
export declare function RestrictedInput(props: Props): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"react/jsx-runtime";import*as t from"../common/
|
|
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};
|
package/package.json
CHANGED