tgui-core 3.0.4 → 3.0.5
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.
- package/dist/components/Box.js +1 -1
- package/dist/components/ImageButton.d.ts +3 -1
- package/dist/components/ImageButton.js +1 -1
- package/dist/components/Input.d.ts +19 -3
- package/dist/components/Input.js +1 -1
- package/dist/components/RestrictedInput.js +1 -1
- package/dist/components/TextArea.js +1 -1
- package/package.json +1 -1
- package/styles/colors.scss +6 -4
- package/styles/components/ImageButton.scss +12 -0
- package/styles/components/Input.scss +0 -20
- package/styles/components/RestrictedInput.scss +19 -0
- package/styles/main.scss +2 -0
- package/styles/vars-colors.scss +5 -2
package/dist/components/Box.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import*as e from"react";import*as o from"../common/ui.js";function m(m){let{as:s="div",className:t,children:a,tw:r,...c}=m,u=(0,e.useMemo)(()=>t?`${t} ${(0,o.computeBoxClassName)(c)}`:(0,o.computeBoxClassName)(c),[t,c]),p=(0,e.useMemo)(()=>(0,o.computeBoxProps)({...c,...(0,o.computeTwClass)(r)}),[c,r]);return(0,e.createElement)(s,{...p,className:u},a)}export{m as Box};
|
|
@@ -44,7 +44,7 @@ type Props = Partial<{
|
|
|
44
44
|
color: string;
|
|
45
45
|
/** Makes button disabled and dark red if true. Also disables onClick. */
|
|
46
46
|
disabled: BooleanLike;
|
|
47
|
-
/** Optional.
|
|
47
|
+
/** Optional. Replaces default "stub" when loading DmIcon. */
|
|
48
48
|
dmFallback: ReactNode;
|
|
49
49
|
/** Parameter `icon` of component `DmIcon`. */
|
|
50
50
|
dmIcon: string | null;
|
|
@@ -57,6 +57,8 @@ type Props = Partial<{
|
|
|
57
57
|
* Allows the use of `title`
|
|
58
58
|
*/
|
|
59
59
|
fluid: boolean;
|
|
60
|
+
/** Replaces default "question" icon when image missing. */
|
|
61
|
+
fallbackIcon: string;
|
|
60
62
|
/** Parameter responsible for the size of the image, component and standard "stubs". */
|
|
61
63
|
imageSize: number;
|
|
62
64
|
/** Prop `src` of Image component. Example: `imageSrc={resolveAsset(thing.image)}` */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as t from"react/jsx-runtime";import*as e from"../common/react.js";import*as s from"../common/ui.js";import*as n from"./DmIcon.js";import*as o from"./Icon.js";import*as a from"./Image.js";import*as
|
|
1
|
+
import*as t from"react/jsx-runtime";import*as e from"../common/react.js";import*as s from"../common/ui.js";import*as n from"./DmIcon.js";import*as o from"./Icon.js";import*as a from"./Image.js";import*as m from"./Tooltip.js";function i(o){let{asset:i,assetSize:l=32,base64:r,buttons:u,buttonsAlt:p,children:x,className:g,color:d,disabled:_,dmFallback:I,dmIcon:h,dmIconState:j,fluid:B,fallbackIcon:f,imageSize:$=64,imageSrc:y,onClick:N,onRightClick:b,selected:v,title:w,tooltip:k,tooltipPosition:D,...z}=o,C=(0,t.jsxs)("div",{className:"ImageButton__container",tabIndex:_?void 0:0,onClick:t=>{!_&&N&&N(t)},onKeyDown:t=>{"Enter"===t.key&&!_&&N&&N(t)},onContextMenu:t=>{t.preventDefault(),!_&&b&&b(t)},style:{width:B?"auto":`calc(${$}px + 0.5em + 2px)`},children:[(0,t.jsx)("div",{className:"ImageButton__image",children:r||y?(0,t.jsx)(a.Image,{src:r?`data:image/png;base64,${r}`:y,height:`${$}px`,width:`${$}px`}):h&&j?(0,t.jsx)(n.DmIcon,{icon:h,icon_state:j,fallback:I||(0,t.jsx)(c,{spin:!0,icon:"spinner",size:$}),height:`${$}px`,width:`${$}px`}):i?(0,t.jsx)(a.Image,{className:(0,e.classes)(i||[]),height:`${$}px`,width:`${$}px`,style:{transform:`scale(${$/l})`,transformOrigin:"top left"}}):(0,t.jsx)(c,{icon:f||"question",size:$})}),B?(0,t.jsxs)("div",{className:"ImageButton__content",children:[w&&(0,t.jsx)("span",{className:(0,e.classes)(["ImageButton__content--title",!!x&&"ImageButton__content--divider"]),children:w}),x&&(0,t.jsx)("span",{className:"ImageButton__content--text",children:x})]}):!!x&&(0,t.jsx)("span",{className:"ImageButton__content",children:x})]});return k&&(C=(0,t.jsx)(m.Tooltip,{content:k,position:D,children:C})),(0,t.jsxs)("div",{className:(0,e.classes)(["ImageButton",B&&"ImageButton--fluid",v&&"ImageButton--selected",_&&"ImageButton--disabled",!x&&"ImageButton--empty",!(N||b)&&"ImageButton--noAction",d&&"string"==typeof d?`ImageButton__color--${d}`:"ImageButton__color--default",g]),...(0,s.computeBoxProps)(z),children:[C,u&&(0,t.jsx)("div",{className:(0,e.classes)(["ImageButton__buttons",!x&&"ImageButton__buttons--empty"]),style:{width:"auto"},children:u}),p&&(0,t.jsx)("div",{className:(0,e.classes)(["ImageButton__buttons","ImageButton__buttons--alt",!x&&"ImageButton__buttons--empty"]),style:{width:`calc(${$}px + ${.5*!B}em)`,maxWidth:B?"auto":`calc(${$}px + 0.5em)`},children:p})]})}function c(e){let{icon:s,spin:n,size:a=64}=e;return(0,t.jsx)(o.Icon,{className:"ImageButton__image--fallback",height:`${a}px`,width:`${a}px`,spin:n,name:s,style:{fontSize:`${a}px`}})}export{i as ImageButton};
|
|
@@ -37,11 +37,12 @@ export type TextInputProps = Partial<{
|
|
|
37
37
|
/** Clears the input value on enter */
|
|
38
38
|
selfClear: boolean;
|
|
39
39
|
/**
|
|
40
|
-
* Generally, input can handle its own state value.
|
|
40
|
+
* Generally, input can handle its own state value. You might not NEED this.
|
|
41
41
|
*
|
|
42
42
|
* Use this if you want to hold the value in the parent for external
|
|
43
|
-
* manipulation.
|
|
43
|
+
* manipulation. For instance:
|
|
44
44
|
*
|
|
45
|
+
* ### Clearing the input
|
|
45
46
|
* ```tsx
|
|
46
47
|
* const [value, setValue] = useState('');
|
|
47
48
|
*
|
|
@@ -50,13 +51,28 @@ export type TextInputProps = Partial<{
|
|
|
50
51
|
* <Button onClick={() => act('inputVal', {inputVal: value})}>
|
|
51
52
|
* Submit
|
|
52
53
|
* </Button>
|
|
53
|
-
* <Input
|
|
54
|
+
* <Input
|
|
55
|
+
* value={value}
|
|
56
|
+
* onChange={setValue} />
|
|
54
57
|
* <Button onClick={() => setValue('')}>
|
|
55
58
|
* Clear
|
|
56
59
|
* </Button>
|
|
57
60
|
* </>
|
|
58
61
|
* )
|
|
59
62
|
* ```
|
|
63
|
+
*
|
|
64
|
+
* ### Updating the value from the backend
|
|
65
|
+
* ```tsx
|
|
66
|
+
* const { data } = useBackend<Data>();
|
|
67
|
+
* const { valveSetting } = data;
|
|
68
|
+
*
|
|
69
|
+
* return (
|
|
70
|
+
* <Input
|
|
71
|
+
* value={valveSetting}
|
|
72
|
+
* onEnter={(value) => act('submit', { valveSetting: value })}
|
|
73
|
+
* />
|
|
74
|
+
* )
|
|
75
|
+
* ```
|
|
60
76
|
*/
|
|
61
77
|
value: string;
|
|
62
78
|
}> & BaseInputProps;
|
package/dist/components/Input.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"react/jsx-runtime";import*as t from"react";import*as r from"../common/keys.js";import*as u from"../common/react.js";import*as o from"../common/timer.js";import*as n from"../common/ui.js";let a=(0,o.debounce)(e=>e(),250);function
|
|
1
|
+
import*as e from"react/jsx-runtime";import*as t from"react";import*as r from"../common/keys.js";import*as u from"../common/react.js";import*as o from"../common/timer.js";import*as n from"../common/ui.js";let a=(0,o.debounce)(e=>e(),250);function c(o){let{autoFocus:c,autoSelect:s,className:m,disabled:l,expensive:p,fluid:f,maxLength:i,monospace:d,onChange:g,onEnter:v,onEscape:x,placeholder:T,ref:j,selfClear:E,value:b,...y}=o,I=(0,t.useRef)(null),h=j??I,[k,C]=(0,t.useState)(b);(0,t.useEffect)(()=>{let e;return(c||s)&&(e=setTimeout(()=>{h.current?.focus(),s&&h.current?.select()},1)),()=>clearTimeout(e)},[]),(0,t.useEffect)(()=>{h.current&&document.activeElement!==h.current&&b!==k&&C(b??"")},[b]);let D=(0,n.computeBoxProps)(y),B=(0,u.classes)(["Input",l&&"Input--disabled",f&&"Input--fluid",d&&"Input--monospace",(0,n.computeBoxClassName)(y),m]);return(0,e.jsx)("input",{...D,autoComplete:"off",className:B,disabled:l,maxLength:i,onChange:function(e){let t=e.currentTarget.value;C(t),p?a(()=>g?.(t)):g?.(t)},onKeyDown:function(e){if(e.key===r.KEY.Enter){e.preventDefault(),v?.(e.currentTarget.value),E&&C(""),e.currentTarget.blur();return}(0,r.isEscape)(e.key)&&(e.preventDefault(),x?.(e.currentTarget.value),e.currentTarget.blur())},placeholder:T,ref:h,spellCheck:!1,type:"text",value:k})}export{c as Input};
|
|
@@ -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 c(r){let{allowFloats:c,autoFocus:m,autoSelect:a,className:i,disabled:l,expensive:f,fluid:p,maxValue:d=1e4,minValue:v=0,monospace:y,onChange:E,onEnter:b,onEscape:I,onValidationChange:j,value:x,...k}=r,C=(0,n.useRef)(null),[D,R]=(0,n.useState)(x??v),[K,N]=(0,n.useState)(!0);(0,n.useEffect)(()=>{let e;return(m||a)&&(e=setTimeout(()=>{C.current?.focus(),a&&C.current?.select()},1)),()=>clearTimeout(e)},[]),(0,n.useEffect)(()=>{if(C.current){let e=C.current.validity.valid;K!==e&&(N(e),j?.(e))}},[D]),(0,n.useEffect)(()=>{C.current&&document.activeElement!==C.current&&x!==D&&R(x??v)},[x]);let g=(0,u.computeBoxProps)(k),h=(0,t.classes)(["Input","RestrictedInput",l&&"Input--disabled",p&&"Input--fluid",y&&"Input--monospace",(0,u.computeBoxClassName)(k),i,!K&&"RestrictedInput--invalid"]);return(0,e.jsx)("input",{...g,autoComplete:"off",className:h,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),C.current?.blur();return}if((0,o.isEscape)(e.key)){e.preventDefault(),I?.(D),C.current?.blur();return}if(e.key===o.KEY.Minus){e.preventDefault(),R(-1*D);return}},ref:C,spellCheck:!1,step:c?"any":"1",type:"number",value:D})}export{c as RestrictedInput};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"react/jsx-runtime";import*as t from"../common/timer.js";import*as r from"react";import*as
|
|
1
|
+
import*as e from"react/jsx-runtime";import*as t from"../common/timer.js";import*as r from"react";import*as n from"../common/keys.js";import*as u from"../common/react.js";import*as a from"../common/ui.js";let s=(0,t.debounce)(e=>e(),250);function o(t){let{autoFocus:o,autoSelect:c,className:l,disabled:m,dontUseTabForIndent:i,expensive:f,fluid:p,maxLength:g,monospace:T,onChange:b,onEnter:v,onEscape:y,placeholder:x,ref:E,selfClear:d,userMarkup:k,value:$,...h}=t,j=(0,r.useRef)(null),K=E??j,[C,D]=(0,r.useState)($??"");(0,r.useEffect)(()=>{(o||c)&&setTimeout(()=>{K.current?.focus(),c&&K.current?.select()},1)},[]),(0,r.useEffect)(()=>{K.current&&document.activeElement!==K.current&&$!==C&&D($??"")},[$]);let I=(0,a.computeBoxProps)(h),A=(0,u.classes)(["Input","TextArea",p&&"Input--fluid",T&&"Input--monospace",m&&"Input--disabled",(0,a.computeBoxClassName)(h),l]);return(0,e.jsx)("textarea",{...I,autoComplete:"off",className:A,maxLength:g,onChange:function(e){let t=e.currentTarget.value;D(t),b&&(f?s(()=>b(t)):b(t))},onKeyDown:function(e){if(e.key===n.KEY.Enter&&!e.shiftKey){e.preventDefault(),v?.(e.currentTarget.value),d&&D(""),e.currentTarget.blur();return}if((0,n.isEscape)(e.key)){y?.(e.currentTarget.value),e.currentTarget.blur();return}if(!i&&e.key===n.KEY.Tab){e.preventDefault();let{value:t,selectionStart:r,selectionEnd:n}=e.currentTarget;D(`${t.substring(0,r)} ${t.substring(n)}`),e.currentTarget.selectionEnd=r+1,b?.(e.currentTarget.value);return}if(k&&(e.ctrlKey||e.metaKey)&&k[e.key]){e.preventDefault();let{selectionStart:t,selectionEnd:r,value:n}=e.currentTarget,u=k[e.key];D(`${n.substring(0,t)}${u}${n.substring(t,r)}${u}${n.substring(r)}`),e.currentTarget.selectionEnd=r+2*u.length,b?.(e.currentTarget.value);return}},placeholder:x,ref:K,spellCheck:!1,value:C})}export{o as TextArea};
|
package/package.json
CHANGED
package/styles/colors.scss
CHANGED
|
@@ -62,10 +62,12 @@ $low-contrast-color-map: ("yellow", "white");
|
|
|
62
62
|
// Color names for which to generate a color map
|
|
63
63
|
$color-map-keys: map.keys($_gen_map) !default;
|
|
64
64
|
@each $color-name in $color-map-keys {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
$color-map: map.merge(
|
|
66
|
+
$color-map,
|
|
67
|
+
(
|
|
68
|
+
$color-name: map.get($_gen_map, $color-name),
|
|
69
|
+
)
|
|
70
|
+
);
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
/**
|
|
@@ -131,6 +131,18 @@ $bg-map: colors.$color-map !default;
|
|
|
131
131
|
border-bottom: none;
|
|
132
132
|
border-color: inherit;
|
|
133
133
|
border-radius: var(--border-radius-medium) var(--border-radius-medium) 0 0;
|
|
134
|
+
|
|
135
|
+
&--fallback {
|
|
136
|
+
text-align: center;
|
|
137
|
+
align-content: center;
|
|
138
|
+
color: var(--color-text-translucent);
|
|
139
|
+
|
|
140
|
+
&:before {
|
|
141
|
+
display: table;
|
|
142
|
+
width: 100%;
|
|
143
|
+
zoom: 0.75;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
134
146
|
}
|
|
135
147
|
|
|
136
148
|
&__content {
|
|
@@ -30,23 +30,3 @@
|
|
|
30
30
|
.Input--monospace {
|
|
31
31
|
font-family: var(--input-font-family-mono);
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
.RestrictedInput {
|
|
35
|
-
border-color: var(--restricted-input-border-color);
|
|
36
|
-
text-align: right;
|
|
37
|
-
&:focus-within {
|
|
38
|
-
border-color: var(--restricted-input-border-color-focus);
|
|
39
|
-
}
|
|
40
|
-
&::-webkit-inner-spin-button,
|
|
41
|
-
&::-webkit-outer-spin-button {
|
|
42
|
-
-webkit-appearance: none;
|
|
43
|
-
margin: 0;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.RestrictedInput--invalid {
|
|
48
|
-
border-color: var(--restricted-input-border-color-invalid);
|
|
49
|
-
&:focus-within {
|
|
50
|
-
border-color: var(--restricted-input-border-color-invalid);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
.RestrictedInput {
|
|
2
|
+
border-color: var(--restricted-input-border-color);
|
|
3
|
+
text-align: right;
|
|
4
|
+
&:focus-within {
|
|
5
|
+
border-color: var(--restricted-input-border-color-focus);
|
|
6
|
+
}
|
|
7
|
+
&::-webkit-inner-spin-button,
|
|
8
|
+
&::-webkit-outer-spin-button {
|
|
9
|
+
-webkit-appearance: none;
|
|
10
|
+
margin: 0;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.RestrictedInput--invalid {
|
|
15
|
+
border-color: var(--restricted-input-border-color-invalid);
|
|
16
|
+
&:focus-within {
|
|
17
|
+
border-color: var(--restricted-input-border-color-invalid);
|
|
18
|
+
}
|
|
19
|
+
}
|
package/styles/main.scss
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
@include meta.load-css("./reset.scss");
|
|
10
10
|
|
|
11
11
|
// Components
|
|
12
|
+
|
|
12
13
|
@include meta.load-css("./components/BlockQuote.scss");
|
|
13
14
|
@include meta.load-css("./components/Button.scss");
|
|
14
15
|
@include meta.load-css("./components/ColorBox.scss");
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
@include meta.load-css("./components/NoticeBox.scss");
|
|
29
30
|
@include meta.load-css("./components/NumberInput.scss");
|
|
30
31
|
@include meta.load-css("./components/ProgressBar.scss");
|
|
32
|
+
@include meta.load-css("./components/RestrictedInput.scss");
|
|
31
33
|
@include meta.load-css("./components/RoundGauge.scss");
|
|
32
34
|
@include meta.load-css("./components/Section.scss");
|
|
33
35
|
@include meta.load-css("./components/Slider.scss");
|
package/styles/vars-colors.scss
CHANGED
|
@@ -74,8 +74,11 @@
|
|
|
74
74
|
--primary-hue: 210;
|
|
75
75
|
--primary-saturation: 37.5%;
|
|
76
76
|
--primary-lightness: 45%;
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
--color-primary: hsl(
|
|
78
|
+
var(--primary-hue),
|
|
79
|
+
var(--primary-saturation),
|
|
80
|
+
var(--primary-lightness)
|
|
81
|
+
);
|
|
79
82
|
--color-good: hsl(95, 62.5%, 40%);
|
|
80
83
|
--color-average: hsl(32.5, 90%, 50%);
|
|
81
84
|
--color-bad: hsl(0, 72.5%, 50%);
|