tgui-core 3.0.2 → 3.0.3
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,6 +12,8 @@ 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
18
|
* Generally, input can handle its own state value.
|
|
17
19
|
*
|
|
@@ -40,6 +42,8 @@ type Props = Partial<{
|
|
|
40
42
|
*
|
|
41
43
|
* Creates a numerical input which rejects improper keys.
|
|
42
44
|
*
|
|
45
|
+
* Has a special event for changes in validation states - `onValidationChange`.
|
|
46
|
+
*
|
|
43
47
|
* @see https://github.com/tgstation/tgui-core/blob/main/lib/components/RestrictedInput.tsx
|
|
44
48
|
*/
|
|
45
49
|
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 c(r){let{allowFloats:c,autoFocus:a,autoSelect:i,className:m,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),[h,C]=(0,n.useState)(!0),K=(0,n.useMemo)(()=>(0,u.computeBoxProps)(k),[k]),M=(0,n.useMemo)(()=>(0,t.classes)(["Input","RestrictedInput",l&&"Input--disabled",p&&"Input--fluid",y&&"Input--monospace",m,!h&&"RestrictedInput--invalid"]),[m,l,p,h,y]);return(0,n.useEffect)(()=>{let e;return(a||i)&&(e=setTimeout(()=>{x.current?.focus(),i&&x.current?.select()},1)),()=>clearTimeout(e)},[]),(0,n.useEffect)(()=>{if(x.current){let e=x.current.validity.valid;h!==e&&(C(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",{...K,autoComplete:"off",className:M,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,style:{color:h?"inherit":"red"},type:"number",value:D})}export{c as RestrictedInput};
|
package/package.json
CHANGED