tgui-core 1.1.11 → 1.1.13

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.
Files changed (292) hide show
  1. package/dist/ProgressBar.module-BkAFfFy0.js +29 -0
  2. package/dist/Section.module-CLVHJ4yA.js +15 -0
  3. package/dist/assets/BlockQuote.css +1 -0
  4. package/dist/assets/Button.css +1 -0
  5. package/dist/assets/ColorBox.css +1 -0
  6. package/dist/assets/Dialog.css +1 -0
  7. package/dist/assets/Dimmer.css +1 -0
  8. package/dist/assets/Divider.css +1 -0
  9. package/dist/assets/Flex.css +1 -0
  10. package/dist/assets/Icon.css +6 -0
  11. package/dist/assets/Input.css +1 -0
  12. package/dist/assets/Knob.css +1 -0
  13. package/dist/assets/LabeledList.css +1 -0
  14. package/dist/assets/MenuBar.css +1 -0
  15. package/dist/assets/Modal.css +1 -0
  16. package/dist/assets/NoticeBox.css +1 -0
  17. package/dist/assets/NumberInput.css +1 -0
  18. package/dist/assets/ProgressBar.css +1 -0
  19. package/dist/assets/RoundGauge.css +1 -0
  20. package/dist/assets/Section.css +1 -0
  21. package/dist/assets/Slider.css +1 -0
  22. package/dist/assets/Stack.css +1 -0
  23. package/dist/assets/Table.css +1 -0
  24. package/dist/assets/Tabs.css +1 -0
  25. package/dist/assets/TextArea.css +1 -0
  26. package/dist/assets/Tooltip.css +1 -0
  27. package/dist/common/assets.d.ts +4 -0
  28. package/dist/common/assets.js +25 -0
  29. package/dist/common/collections.d.ts +10 -0
  30. package/dist/common/collections.js +15 -0
  31. package/dist/common/color.d.ts +25 -0
  32. package/dist/common/color.js +69 -0
  33. package/dist/common/constants.d.ts +102 -0
  34. package/dist/common/constants.js +312 -0
  35. package/dist/common/events.d.ts +33 -0
  36. package/dist/common/events.js +147 -0
  37. package/{lib/common/exhaustive.ts → dist/common/exhaustive.d.ts} +1 -3
  38. package/dist/common/exhaustive.js +6 -0
  39. package/dist/common/format.d.ts +11 -0
  40. package/dist/common/format.js +114 -0
  41. package/{lib/common/fp.ts → dist/common/fp.d.ts} +2 -16
  42. package/dist/common/fp.js +9 -0
  43. package/dist/common/hotkeys.d.ts +25 -0
  44. package/dist/common/hotkeys.js +112 -0
  45. package/dist/common/http.d.ts +4 -0
  46. package/dist/common/http.js +10 -0
  47. package/dist/common/keycodes.d.ts +85 -0
  48. package/dist/common/keycodes.js +88 -0
  49. package/{lib/common/keys.ts → dist/common/keys.d.ts} +21 -24
  50. package/dist/common/keys.js +8 -0
  51. package/dist/common/math.d.ts +39 -0
  52. package/dist/common/math.js +41 -0
  53. package/dist/common/perf.d.ts +24 -0
  54. package/dist/common/perf.js +33 -0
  55. package/dist/common/random.d.ts +16 -0
  56. package/dist/common/random.js +18 -0
  57. package/dist/common/react.d.ts +23 -0
  58. package/dist/common/react.js +30 -0
  59. package/dist/common/redux.d.ts +64 -0
  60. package/dist/common/redux.js +72 -0
  61. package/dist/common/storage.d.ts +24 -0
  62. package/dist/common/storage.js +133 -0
  63. package/dist/common/string.d.ts +65 -0
  64. package/dist/common/string.js +83 -0
  65. package/dist/common/timer.d.ts +18 -0
  66. package/dist/common/timer.js +28 -0
  67. package/dist/common/type-utils.d.ts +9 -0
  68. package/dist/common/type-utils.js +25 -0
  69. package/dist/common/uuid.d.ts +9 -0
  70. package/dist/common/uuid.js +10 -0
  71. package/dist/components/AnimatedNumber.d.ts +60 -0
  72. package/dist/components/AnimatedNumber.js +76 -0
  73. package/dist/components/Autofocus.d.ts +4 -0
  74. package/dist/components/Autofocus.js +17 -0
  75. package/dist/components/Blink.d.ts +26 -0
  76. package/dist/components/Blink.js +56 -0
  77. package/dist/components/BlockQuote.d.ts +3 -0
  78. package/dist/components/BlockQuote.js +13 -0
  79. package/dist/components/BodyZoneSelector.d.ts +28 -0
  80. package/dist/components/BodyZoneSelector.js +115 -0
  81. package/dist/components/Box.d.ts +91 -0
  82. package/dist/components/Box.js +133 -0
  83. package/dist/components/Button.d.ts +93 -0
  84. package/dist/components/Button.js +298 -0
  85. package/dist/components/ByondUi.js +73 -0
  86. package/dist/components/Chart.d.ts +28 -0
  87. package/dist/components/Chart.js +95 -0
  88. package/dist/components/Collapsible.d.ts +15 -0
  89. package/dist/components/Collapsible.js +27 -0
  90. package/dist/components/ColorBox.d.ts +8 -0
  91. package/dist/components/ColorBox.js +24 -0
  92. package/dist/components/Dialog.d.ts +24 -0
  93. package/dist/components/Dialog.js +67 -0
  94. package/dist/components/Dimmer.d.ts +3 -0
  95. package/dist/components/Dimmer.js +13 -0
  96. package/dist/components/Divider.d.ts +6 -0
  97. package/dist/components/Divider.js +22 -0
  98. package/dist/components/DmIcon.d.ts +33 -0
  99. package/dist/components/DmIcon.js +29 -0
  100. package/dist/components/DraggableControl.js +176 -0
  101. package/dist/components/Dropdown.d.ts +48 -0
  102. package/dist/components/Dropdown.js +152 -0
  103. package/dist/components/FakeTerminal.js +38 -0
  104. package/dist/components/FitText.d.ts +22 -0
  105. package/dist/components/FitText.js +63 -0
  106. package/dist/components/Flex.d.ts +93 -0
  107. package/dist/components/Flex.js +72 -0
  108. package/dist/components/Icon.d.ts +30 -0
  109. package/dist/components/Icon.js +51 -0
  110. package/dist/components/Image.d.ts +14 -0
  111. package/dist/components/Image.js +35 -0
  112. package/dist/components/InfinitePlane.js +139 -0
  113. package/dist/components/Input.d.ts +61 -0
  114. package/dist/components/Input.js +89 -0
  115. package/dist/components/KeyListener.d.ts +15 -0
  116. package/dist/components/KeyListener.js +23 -0
  117. package/dist/components/Knob.d.ts +49 -0
  118. package/dist/components/Knob.js +162 -0
  119. package/dist/components/LabeledControls.d.ts +11 -0
  120. package/dist/components/LabeledControls.js +39 -0
  121. package/dist/components/LabeledList.d.ts +57 -0
  122. package/dist/components/LabeledList.js +94 -0
  123. package/dist/components/MenuBar.d.ts +28 -0
  124. package/dist/components/MenuBar.js +174 -0
  125. package/dist/components/Modal.d.ts +3 -0
  126. package/dist/components/Modal.js +25 -0
  127. package/dist/components/NoticeBox.d.ts +20 -0
  128. package/dist/components/NoticeBox.js +49 -0
  129. package/dist/components/NumberInput.d.ts +45 -0
  130. package/dist/components/NumberInput.js +221 -0
  131. package/dist/components/Popper.d.ts +27 -0
  132. package/dist/components/Popper.js +177 -0
  133. package/dist/components/ProgressBar.d.ts +46 -0
  134. package/dist/components/ProgressBar.js +37 -0
  135. package/dist/components/RestrictedInput.js +155 -0
  136. package/dist/components/RoundGauge.d.ts +53 -0
  137. package/dist/components/RoundGauge.js +147 -0
  138. package/dist/components/Section.d.ts +63 -0
  139. package/dist/components/Section.js +62 -0
  140. package/dist/components/Slider.d.ts +46 -0
  141. package/dist/components/Slider.js +124 -0
  142. package/dist/components/Stack.d.ts +27 -0
  143. package/dist/components/Stack.js +67 -0
  144. package/dist/components/StyleableSection.d.ts +11 -0
  145. package/dist/components/StyleableSection.js +16 -0
  146. package/dist/components/Table.d.ts +29 -0
  147. package/dist/components/Table.js +67 -0
  148. package/dist/components/Tabs.d.ts +23 -0
  149. package/dist/components/Tabs.js +89 -0
  150. package/dist/components/TextArea.d.ts +39 -0
  151. package/dist/components/TextArea.js +118 -0
  152. package/dist/components/TimeDisplay.js +34 -0
  153. package/dist/components/Tooltip.d.ts +29 -0
  154. package/dist/components/Tooltip.js +83 -0
  155. package/dist/components/TrackOutsideClicks.d.ts +13 -0
  156. package/dist/components/TrackOutsideClicks.js +24 -0
  157. package/dist/components/VirtualList.d.ts +8 -0
  158. package/dist/components/VirtualList.js +34 -0
  159. package/dist/components/index.js +92 -0
  160. package/dist/popper-CiqSDJTE.js +906 -0
  161. package/package.json +8 -10
  162. package/lib/common/assets.ts +0 -38
  163. package/lib/common/collections.ts +0 -27
  164. package/lib/common/color.ts +0 -88
  165. package/lib/common/constants.ts +0 -349
  166. package/lib/common/events.ts +0 -262
  167. package/lib/common/format.ts +0 -167
  168. package/lib/common/hotkeys.ts +0 -207
  169. package/lib/common/http.ts +0 -16
  170. package/lib/common/keycodes.ts +0 -86
  171. package/lib/common/math.ts +0 -76
  172. package/lib/common/perf.ts +0 -72
  173. package/lib/common/random.ts +0 -32
  174. package/lib/common/react.ts +0 -59
  175. package/lib/common/redux.ts +0 -187
  176. package/lib/common/storage.ts +0 -207
  177. package/lib/common/string.ts +0 -169
  178. package/lib/common/timer.ts +0 -63
  179. package/lib/common/type-utils.ts +0 -41
  180. package/lib/common/types.d.ts +0 -12
  181. package/lib/common/uuid.ts +0 -18
  182. package/lib/components/AnimatedNumber.tsx +0 -180
  183. package/lib/components/Autofocus.tsx +0 -23
  184. package/lib/components/Blink.tsx +0 -91
  185. package/lib/components/BlockQuote.tsx +0 -9
  186. package/lib/components/BodyZoneSelector.tsx +0 -149
  187. package/lib/components/Box.tsx +0 -252
  188. package/lib/components/Button.tsx +0 -425
  189. package/lib/components/ByondUi.jsx +0 -110
  190. package/lib/components/Chart.tsx +0 -155
  191. package/lib/components/Collapsible.tsx +0 -43
  192. package/lib/components/ColorBox.tsx +0 -29
  193. package/lib/components/Dialog.tsx +0 -81
  194. package/lib/components/Dimmer.tsx +0 -13
  195. package/lib/components/Divider.tsx +0 -20
  196. package/lib/components/DmIcon.tsx +0 -86
  197. package/lib/components/DraggableControl.jsx +0 -276
  198. package/lib/components/Dropdown.tsx +0 -246
  199. package/lib/components/FakeTerminal.jsx +0 -52
  200. package/lib/components/FitText.tsx +0 -99
  201. package/lib/components/Flex.tsx +0 -159
  202. package/lib/components/Icon.tsx +0 -95
  203. package/lib/components/Image.tsx +0 -54
  204. package/lib/components/InfinitePlane.jsx +0 -192
  205. package/lib/components/Input.tsx +0 -176
  206. package/lib/components/KeyListener.tsx +0 -40
  207. package/lib/components/Knob.tsx +0 -178
  208. package/lib/components/LabeledControls.tsx +0 -44
  209. package/lib/components/LabeledList.tsx +0 -154
  210. package/lib/components/MenuBar.tsx +0 -228
  211. package/lib/components/Modal.tsx +0 -23
  212. package/lib/components/NoticeBox.tsx +0 -45
  213. package/lib/components/NumberInput.tsx +0 -328
  214. package/lib/components/Popper.tsx +0 -100
  215. package/lib/components/ProgressBar.tsx +0 -105
  216. package/lib/components/RestrictedInput.jsx +0 -301
  217. package/lib/components/RoundGauge.tsx +0 -180
  218. package/lib/components/Section.tsx +0 -120
  219. package/lib/components/Slider.tsx +0 -169
  220. package/lib/components/Stack.tsx +0 -96
  221. package/lib/components/StyleableSection.tsx +0 -33
  222. package/lib/components/Table.tsx +0 -84
  223. package/lib/components/Tabs.tsx +0 -89
  224. package/lib/components/TextArea.tsx +0 -182
  225. package/lib/components/TimeDisplay.jsx +0 -64
  226. package/lib/components/Tooltip.tsx +0 -152
  227. package/lib/components/TrackOutsideClicks.tsx +0 -35
  228. package/lib/components/VirtualList.tsx +0 -69
  229. package/lib/styles/atomic/candystripe.scss +0 -8
  230. package/lib/styles/atomic/centered-image.scss +0 -7
  231. package/lib/styles/atomic/color.scss +0 -21
  232. package/lib/styles/atomic/debug-layout.scss +0 -17
  233. package/lib/styles/atomic/fit-text.scss +0 -14
  234. package/lib/styles/atomic/links.scss +0 -12
  235. package/lib/styles/atomic/outline.scss +0 -47
  236. package/lib/styles/atomic/text.scss +0 -44
  237. package/lib/styles/base.scss +0 -32
  238. package/lib/styles/colors.scss +0 -92
  239. package/lib/styles/components/BlockQuote.module.scss +0 -20
  240. package/lib/styles/components/BlockQuote.module.scss.d.ts +0 -4
  241. package/lib/styles/components/Button.module.scss +0 -157
  242. package/lib/styles/components/Button.module.scss.d.ts +0 -46
  243. package/lib/styles/components/ColorBox.module.scss +0 -12
  244. package/lib/styles/components/ColorBox.module.scss.d.ts +0 -4
  245. package/lib/styles/components/Dialog.module.scss +0 -60
  246. package/lib/styles/components/Dialog.module.scss.d.ts +0 -10
  247. package/lib/styles/components/Dimmer.module.scss +0 -22
  248. package/lib/styles/components/Dimmer.module.scss.d.ts +0 -4
  249. package/lib/styles/components/Divider.module.scss +0 -27
  250. package/lib/styles/components/Divider.module.scss.d.ts +0 -6
  251. package/lib/styles/components/Dropdown.scss +0 -72
  252. package/lib/styles/components/Flex.module.scss +0 -13
  253. package/lib/styles/components/Flex.module.scss.d.ts +0 -5
  254. package/lib/styles/components/Icon.module.scss +0 -25
  255. package/lib/styles/components/Icon.module.scss.d.ts +0 -5
  256. package/lib/styles/components/Input.module.scss +0 -64
  257. package/lib/styles/components/Input.module.scss.d.ts +0 -8
  258. package/lib/styles/components/Knob.module.scss +0 -131
  259. package/lib/styles/components/Knob.module.scss.d.ts +0 -33
  260. package/lib/styles/components/LabeledList.module.scss +0 -49
  261. package/lib/styles/components/LabeledList.module.scss.d.ts +0 -8
  262. package/lib/styles/components/MenuBar.module.scss +0 -75
  263. package/lib/styles/components/MenuBar.module.scss.d.ts +0 -14
  264. package/lib/styles/components/Modal.module.scss +0 -14
  265. package/lib/styles/components/Modal.module.scss.d.ts +0 -4
  266. package/lib/styles/components/NoticeBox.module.scss +0 -65
  267. package/lib/styles/components/NoticeBox.module.scss.d.ts +0 -27
  268. package/lib/styles/components/NumberInput.module.scss +0 -71
  269. package/lib/styles/components/NumberInput.module.scss.d.ts +0 -9
  270. package/lib/styles/components/ProgressBar.module.scss +0 -63
  271. package/lib/styles/components/ProgressBar.module.scss.d.ts +0 -27
  272. package/lib/styles/components/RoundGauge.module.scss +0 -85
  273. package/lib/styles/components/RoundGauge.module.scss.d.ts +0 -49
  274. package/lib/styles/components/Section.module.scss +0 -130
  275. package/lib/styles/components/Section.module.scss.d.ts +0 -13
  276. package/lib/styles/components/Slider.module.scss +0 -54
  277. package/lib/styles/components/Slider.module.scss.d.ts +0 -8
  278. package/lib/styles/components/Stack.module.scss +0 -60
  279. package/lib/styles/components/Stack.module.scss.d.ts +0 -12
  280. package/lib/styles/components/Table.module.scss +0 -44
  281. package/lib/styles/components/Table.module.scss.d.ts +0 -10
  282. package/lib/styles/components/Tabs.module.scss +0 -144
  283. package/lib/styles/components/Tabs.module.scss.d.ts +0 -35
  284. package/lib/styles/components/TextArea.module.scss +0 -86
  285. package/lib/styles/components/TextArea.module.scss.d.ts +0 -11
  286. package/lib/styles/components/Tooltip.module.scss +0 -24
  287. package/lib/styles/components/Tooltip.module.scss.d.ts +0 -4
  288. package/lib/styles/functions.scss +0 -79
  289. package/lib/styles/input.scss +0 -9
  290. package/lib/styles/main.scss +0 -20
  291. package/lib/styles/reset.scss +0 -68
  292. /package/{lib/components/index.ts → dist/components/index.d.ts} +0 -0
@@ -1,301 +0,0 @@
1
- import { KEY_ENTER, KEY_ESCAPE } from '../common/keycodes';
2
- import { clamp } from '../common/math';
3
- import { classes } from '../common/react';
4
- import { Component, createRef } from 'react';
5
-
6
- import { Box } from './Box';
7
-
8
- const DEFAULT_MIN = 0;
9
- const DEFAULT_MAX = 10000;
10
-
11
- /**
12
- * Sanitize a number without interfering with writing negative or floating point numbers.
13
- * Handling dots and minuses in a user friendly way
14
- * @param value {String}
15
- * @param minValue {Number}
16
- * @param maxValue {Number}
17
- * @param allowFloats {Boolean}
18
- * @returns {String}
19
- */
20
- function softSanitizeNumber(value, minValue, maxValue, allowFloats) {
21
- const minimum = minValue || DEFAULT_MIN;
22
- const maximum = maxValue || maxValue === 0 ? maxValue : DEFAULT_MAX;
23
-
24
- let sanitizedString = allowFloats
25
- ? value.replace(/[^\-\d.]/g, '')
26
- : value.replace(/[^\-\d]/g, '');
27
-
28
- if (allowFloats) {
29
- sanitizedString = maybeLeadWithMin(sanitizedString, minimum);
30
- sanitizedString = keepOnlyFirstOccurrence('.', sanitizedString);
31
- }
32
- if (minValue < 0) {
33
- sanitizedString = maybeMoveMinusSign(sanitizedString);
34
- sanitizedString = keepOnlyFirstOccurrence('-', sanitizedString);
35
- } else {
36
- sanitizedString = sanitizedString.replaceAll('-', '');
37
- }
38
- if (minimum <= 1 && maximum >= 0) {
39
- return clampGuessedNumber(sanitizedString, minimum, maximum, allowFloats);
40
- }
41
- return sanitizedString;
42
- }
43
-
44
- /**
45
- * Clamping the input to the restricted range, making the Input smart for min <= 1 and max >= 0
46
- * @param softSanitizedNumber {String}
47
- * @param allowFloats {Boolean}
48
- * @returns {string}
49
- */
50
- const clampGuessedNumber = (
51
- softSanitizedNumber,
52
- minValue,
53
- maxValue,
54
- allowFloats,
55
- ) => {
56
- let parsed = allowFloats
57
- ? parseFloat(softSanitizedNumber)
58
- : parseInt(softSanitizedNumber, 10);
59
- if (
60
- !isNaN(parsed) &&
61
- (softSanitizedNumber.slice(-1) !== '.' || parsed < Math.floor(minValue))
62
- ) {
63
- let clamped = clamp(parsed, minValue, maxValue);
64
- if (parsed !== clamped) {
65
- return String(clamped);
66
- }
67
- }
68
- return softSanitizedNumber;
69
- };
70
-
71
- /**
72
- * Translate x- to -x and -x- to x
73
- * @param string {String}
74
- * @returns {string}
75
- */
76
- function maybeMoveMinusSign(string) {
77
- let retString = string;
78
- // if minus sign is present but not first
79
- let minusIdx = string.indexOf('-');
80
- if (minusIdx > 0) {
81
- string = string.replace('-', '');
82
- retString = '-'.concat(string);
83
- } else if (minusIdx === 0) {
84
- if (string.indexOf('-', minusIdx + 1) > 0) {
85
- retString = string.replaceAll('-', '');
86
- }
87
- }
88
- return retString;
89
- }
90
-
91
- /**
92
- * Translate . to min. or .x to mim.x or -. to -min.
93
- * @param string {String}
94
- */
95
- function maybeLeadWithMin(string, min) {
96
- let retString = string;
97
- let cuttedVal = Math.sign(min) * Math.floor(Math.abs(min));
98
- if (string.indexOf('.') === 0) {
99
- retString = String(cuttedVal).concat(string);
100
- } else if (string.indexOf('-') === 0 && string.indexOf('.') === 1) {
101
- retString = cuttedVal + '.'.concat(string.slice(2));
102
- }
103
- return retString;
104
- }
105
-
106
- /**
107
- * Keep only the first occurrence of a string in another string.
108
- * @param needle {String}
109
- * @param haystack {String}
110
- * @returns {string}
111
- */
112
- function keepOnlyFirstOccurrence(needle, haystack) {
113
- const idx = haystack.indexOf(needle);
114
- const len = haystack.length;
115
- let newHaystack = haystack;
116
- if (idx !== -1 && idx < len - 1) {
117
- let trailingString = haystack.slice(idx + 1, len);
118
- trailingString = trailingString.replaceAll(needle, '');
119
- newHaystack = haystack.slice(0, idx + 1).concat(trailingString);
120
- }
121
- return newHaystack;
122
- }
123
-
124
- /**
125
- * Takes a string input and parses integers or floats from it.
126
- * If none: Minimum is set.
127
- * Else: Clamps it to the given range.
128
- */
129
- function getClampedNumber(value, minValue, maxValue, allowFloats) {
130
- const minimum = minValue || DEFAULT_MIN;
131
- const maximum = maxValue || maxValue === 0 ? maxValue : DEFAULT_MAX;
132
- if (!value || !value.length) {
133
- return String(minimum);
134
- }
135
- let parsedValue = allowFloats
136
- ? parseFloat(value.replace(/[^\-\d.]/g, ''))
137
- : parseInt(value.replace(/[^\-\d]/g, ''), 10);
138
- if (isNaN(parsedValue)) {
139
- return String(minimum);
140
- } else {
141
- return String(clamp(parsedValue, minimum, maximum));
142
- }
143
- }
144
-
145
- export class RestrictedInput extends Component {
146
- constructor(props) {
147
- super(props);
148
- this.inputRef = createRef();
149
- this.state = {
150
- editing: false,
151
- };
152
- this.handleBlur = (e) => {
153
- const { maxValue, minValue, onBlur, allowFloats } = this.props;
154
- const { editing } = this.state;
155
- if (editing) {
156
- this.setEditing(false);
157
- }
158
- const safeNum = getClampedNumber(
159
- e.target.value,
160
- minValue,
161
- maxValue,
162
- allowFloats,
163
- );
164
- if (onBlur) {
165
- onBlur(e, +safeNum);
166
- }
167
- };
168
- this.handleChange = (e) => {
169
- const { maxValue, minValue, onChange, allowFloats } = this.props;
170
- e.target.value = softSanitizeNumber(
171
- e.target.value,
172
- minValue,
173
- maxValue,
174
- allowFloats,
175
- );
176
- if (onChange) {
177
- onChange(e, +e.target.value);
178
- }
179
- };
180
- this.handleFocus = (e) => {
181
- const { editing } = this.state;
182
- if (!editing) {
183
- this.setEditing(true);
184
- }
185
- };
186
- this.handleInput = (e) => {
187
- const { editing } = this.state;
188
- const { onInput } = this.props;
189
- if (!editing) {
190
- this.setEditing(true);
191
- }
192
- if (onInput) {
193
- onInput(e, +e.target.value);
194
- }
195
- };
196
- this.handleKeyDown = (e) => {
197
- const { maxValue, minValue, onChange, onEnter, allowFloats } = this.props;
198
- if (e.keyCode === KEY_ENTER) {
199
- const safeNum = getClampedNumber(
200
- e.target.value,
201
- minValue,
202
- maxValue,
203
- allowFloats,
204
- );
205
- this.setEditing(false);
206
- if (onChange) {
207
- onChange(e, +safeNum);
208
- }
209
- if (onEnter) {
210
- onEnter(e, +safeNum);
211
- }
212
- e.target.blur();
213
- return;
214
- }
215
- if (e.keyCode === KEY_ESCAPE) {
216
- if (this.props.onEscape) {
217
- this.props.onEscape(e);
218
- return;
219
- }
220
- this.setEditing(false);
221
- e.target.value = this.props.value;
222
- e.target.blur();
223
- return;
224
- }
225
- };
226
- }
227
-
228
- componentDidMount() {
229
- const { maxValue, minValue, allowFloats } = this.props;
230
- const nextValue = this.props.value?.toString();
231
- const input = this.inputRef.current;
232
- if (input) {
233
- input.value = getClampedNumber(
234
- nextValue,
235
- minValue,
236
- maxValue,
237
- allowFloats,
238
- );
239
- }
240
- if (this.props.autoFocus || this.props.autoSelect) {
241
- setTimeout(() => {
242
- input.focus();
243
-
244
- if (this.props.autoSelect) {
245
- input.select();
246
- }
247
- }, 1);
248
- }
249
- }
250
-
251
- componentDidUpdate(prevProps, _) {
252
- const { maxValue, minValue, allowFloats } = this.props;
253
- const { editing } = this.state;
254
- const prevValue = prevProps.value?.toString();
255
- const nextValue = this.props.value?.toString();
256
- const input = this.inputRef.current;
257
- if (input && !editing) {
258
- if (nextValue !== prevValue && nextValue !== input.value) {
259
- input.value = getClampedNumber(
260
- nextValue,
261
- minValue,
262
- maxValue,
263
- allowFloats,
264
- );
265
- }
266
- }
267
- }
268
-
269
- setEditing(editing) {
270
- this.setState({ editing });
271
- }
272
-
273
- render() {
274
- const { props } = this;
275
- const { onChange, onEnter, onInput, onBlur, value, ...boxProps } = props;
276
- const { className, fluid, monospace, ...rest } = boxProps;
277
- return (
278
- <Box
279
- className={classes([
280
- 'Input',
281
- fluid && 'Input--fluid',
282
- monospace && 'Input--monospace',
283
- className,
284
- ])}
285
- {...rest}
286
- >
287
- <div className="Input__baseline">.</div>
288
- <input
289
- className="Input__input"
290
- onChange={this.handleChange}
291
- onInput={this.handleInput}
292
- onFocus={this.handleFocus}
293
- onBlur={this.handleBlur}
294
- onKeyDown={this.handleKeyDown}
295
- ref={this.inputRef}
296
- type="number | string"
297
- />
298
- </Box>
299
- );
300
- }
301
- }
@@ -1,180 +0,0 @@
1
- /**
2
- * @file
3
- * @copyright 2020 bobbahbrown (https://github.com/bobbahbrown)
4
- * @license MIT
5
- */
6
- import { clamp01, keyOfMatchingRange, scale } from '../common/math';
7
- import { classes } from '../common/react';
8
- import styles from '../styles/components/RoundGauge.module.scss';
9
- import { AnimatedNumber } from './AnimatedNumber';
10
- import { Box, BoxProps, computeBoxClassName, computeBoxProps } from './Box';
11
-
12
- type Props = {
13
- /** The current value of the metric. */
14
- value: number;
15
- } & Partial<{
16
- /** When provided, will cause an alert symbol on the gauge to begin flashing in the color upon which the needle currently rests, as defined in `ranges`. */
17
- alertAfter: number;
18
- /** As with alertAfter, but alerts below a value. If both are set, and alertAfter comes earlier, the alert will only flash when the needle is between both values. Otherwise, the alert will flash when on the active side of either threshold. */
19
- alertBefore: number;
20
- /** CSS style. */
21
- className: string;
22
- /** When provided, will be used to format the value of the metric for display. */
23
- format: (value: number) => string;
24
- /** The upper bound of the gauge. */
25
- maxValue: number;
26
- /** The lower bound of the gauge. */
27
- minValue: number;
28
- /** Provide regions of the gauge to color between two specified values of the metric. */
29
- ranges: Record<string, [number, number]>;
30
- /** When provided scales the gauge. */
31
- size: number;
32
- /** Custom css */
33
- style: React.CSSProperties;
34
- }> &
35
- BoxProps;
36
-
37
- /**
38
- * ## RoundGauge
39
- * The RoundGauge component provides a visual representation of a single metric, as well as being capable of showing
40
- * informational or cautionary boundaries related to that metric.
41
- *
42
- * @example
43
- * ```tsx
44
- * <RoundGauge
45
- * size={1.75}
46
- * value={tankPressure}
47
- * minValue={0}
48
- * maxValue={pressureLimit}
49
- * alertAfter={pressureLimit * 0.7}
50
- * ranges={{
51
- * good: [0, pressureLimit * 0.7],
52
- * average: [pressureLimit * 0.7, pressureLimit * 0.85],
53
- * bad: [pressureLimit * 0.85, pressureLimit],
54
- * }}
55
- * format={formatPressure}
56
- * />
57
- * ```
58
- *
59
- * The alert on the gauge is optional, and will only be shown if the `alertAfter` prop is defined. When defined, the alert
60
- * will begin to flash the respective color upon which the needle currently rests, as defined in the `ranges` prop.
61
- *
62
- */
63
- export function RoundGauge(props: Props) {
64
- const {
65
- alertAfter,
66
- alertBefore,
67
- className,
68
- format,
69
- maxValue = 1,
70
- minValue = 1,
71
- ranges,
72
- size = 1,
73
- style,
74
- value,
75
- ...rest
76
- } = props;
77
-
78
- const scaledValue = scale(value, minValue, maxValue);
79
- const clampedValue = clamp01(scaledValue);
80
- const scaledRanges = ranges ? {} : { primary: [0, 1] };
81
-
82
- if (ranges) {
83
- Object.keys(ranges).forEach((x) => {
84
- const range = ranges[x];
85
- scaledRanges[x] = [
86
- scale(range[0], minValue, maxValue),
87
- scale(range[1], minValue, maxValue),
88
- ];
89
- });
90
- }
91
-
92
- function shouldShowAlert() {
93
- // If both after and before alert props are set, and value is between them
94
- if (
95
- alertAfter &&
96
- alertBefore &&
97
- value > alertAfter &&
98
- value < alertBefore
99
- ) {
100
- return true;
101
- }
102
- // If only alertAfter is set and value is greater than alertAfter
103
- else if (alertAfter && value > alertAfter) {
104
- return true;
105
- }
106
- // If only alertBefore is set and value is less than alertBefore
107
- else if (alertBefore && value < alertBefore) {
108
- return true;
109
- }
110
- // If none of the above conditions are met
111
- return false;
112
- }
113
-
114
- const alertColor =
115
- shouldShowAlert() && keyOfMatchingRange(clampedValue, scaledRanges);
116
-
117
- return (
118
- <Box inline>
119
- <div
120
- className={classes([
121
- styles.roundGauge,
122
- className,
123
- computeBoxClassName(rest),
124
- ])}
125
- {...computeBoxProps({
126
- style: {
127
- fontSize: size + 'em',
128
- ...style,
129
- },
130
- ...rest,
131
- })}
132
- >
133
- <svg viewBox="0 0 100 50">
134
- {(alertAfter || alertBefore) && (
135
- <g
136
- className={classes([
137
- styles.alert,
138
- alertColor ? styles['alert__' + alertColor] : '',
139
- ])}
140
- >
141
- <path d="M48.211,14.578C48.55,13.9 49.242,13.472 50,13.472C50.758,13.472 51.45,13.9 51.789,14.578C54.793,20.587 60.795,32.589 63.553,38.106C63.863,38.726 63.83,39.462 63.465,40.051C63.101,40.641 62.457,41 61.764,41C55.996,41 44.004,41 38.236,41C37.543,41 36.899,40.641 36.535,40.051C36.17,39.462 36.137,38.726 36.447,38.106C39.205,32.589 45.207,20.587 48.211,14.578ZM50,34.417C51.426,34.417 52.583,35.574 52.583,37C52.583,38.426 51.426,39.583 50,39.583C48.574,39.583 47.417,38.426 47.417,37C47.417,35.574 48.574,34.417 50,34.417ZM50,32.75C50,32.75 53,31.805 53,22.25C53,20.594 51.656,19.25 50,19.25C48.344,19.25 47,20.594 47,22.25C47,31.805 50,32.75 50,32.75Z" />
142
- </g>
143
- )}
144
- <g>
145
- <circle className={styles.ringTrack} cx="50" cy="50" r="45" />
146
- </g>
147
- <g>
148
- {Object.keys(scaledRanges).map((x, i) => {
149
- const col_ranges = scaledRanges[x];
150
- return (
151
- <circle
152
- className={classes([styles.ringFill, styles['color__' + x]])}
153
- key={i}
154
- style={{
155
- strokeDashoffset: Math.max(
156
- (2.0 - (col_ranges[1] - col_ranges[0])) * Math.PI * 50,
157
- 0,
158
- ),
159
- }}
160
- transform={`rotate(${180 + 180 * col_ranges[0]} 50 50)`}
161
- cx="50"
162
- cy="50"
163
- r="45"
164
- />
165
- );
166
- })}
167
- </g>
168
- <g
169
- className={styles.needle}
170
- transform={`rotate(${clampedValue * 180 - 90} 50 50)`}
171
- >
172
- <polygon className={styles.needleLine} points="46,50 50,0 54,50" />
173
- <circle className={styles.needleMiddle} cx="50" cy="50" r="8" />
174
- </g>
175
- </svg>
176
- </div>
177
- <AnimatedNumber value={value} format={format} />
178
- </Box>
179
- );
180
- }
@@ -1,120 +0,0 @@
1
- import { forwardRef, ReactNode, RefObject, useEffect } from 'react';
2
-
3
- import { addScrollableNode, removeScrollableNode } from '../common/events';
4
- import { canRender, classes } from '../common/react';
5
- import styles from '../styles/components/Section.module.scss';
6
- import { BoxProps, computeBoxClassName, computeBoxProps } from './Box';
7
-
8
- type Props = Partial<{
9
- /** Buttons to render aside the section title. */
10
- buttons: ReactNode;
11
- /** id to assosiate with the parent div element used by this section, for uses with procs like getElementByID */
12
- container_id: string;
13
- /** If true, fills all available vertical space. */
14
- fill: boolean;
15
- /** If true, removes all section padding. */
16
- fitted: boolean;
17
- /** @member Callback function for the `scroll` event */
18
- onScroll: ((this: GlobalEventHandlers, ev: Event) => any) | null;
19
- /** Shows or hides the scrollbar. */
20
- scrollable: boolean;
21
- /** Shows or hides the horizontal scrollbar. */
22
- scrollableHorizontal: boolean;
23
- /** Title of the section. */
24
- title: ReactNode;
25
- }> &
26
- BoxProps;
27
-
28
- /**
29
- * ## Section
30
- * Section is a surface that displays content and actions on a single topic.
31
- *
32
- * They should be easy to scan for relevant and actionable information.
33
- * Elements, like text and images, should be placed in them in a way that
34
- * clearly indicates hierarchy.
35
- *
36
- * Sections can now be nested, and will automatically font size of the
37
- * header according to their nesting level. Previously this was done via `level`
38
- * prop, but now it is automatically calculated.
39
- *
40
- * Section can also be titled to clearly define its purpose.
41
- *
42
- * ```tsx
43
- * <Section title="Cargo">Here you can order supply crates.</Section>
44
- * ```
45
- *
46
- * If you want to have a button on the right side of an section title
47
- * (for example, to perform some sort of action), there is a way to do that:
48
- *
49
- * ```tsx
50
- * <Section title="Cargo" buttons={<Button>Send shuttle</Button>}>
51
- * Here you can order supply crates.
52
- * </Section>
53
- * ```
54
- */
55
- export const Section = forwardRef(
56
- (props: Props, forwardedRef: RefObject<HTMLDivElement>) => {
57
- const {
58
- buttons,
59
- children,
60
- className,
61
- fill,
62
- fitted,
63
- onScroll,
64
- scrollable,
65
- scrollableHorizontal,
66
- title,
67
- container_id,
68
- ...rest
69
- } = props;
70
-
71
- const hasTitle = canRender(title) || canRender(buttons);
72
-
73
- /** We want to be able to scroll on hover, but using focus will steal it from inputs */
74
- useEffect(() => {
75
- if (!forwardedRef?.current) return;
76
- if (!scrollable && !scrollableHorizontal) return;
77
-
78
- addScrollableNode(forwardedRef.current);
79
-
80
- return () => {
81
- if (!forwardedRef?.current) return;
82
- removeScrollableNode(forwardedRef.current!);
83
- };
84
- }, []);
85
-
86
- return (
87
- <div
88
- id={container_id || ''}
89
- className={classes([
90
- styles.section,
91
- fill && styles.fill,
92
- fitted && styles.fitted,
93
- scrollable && styles.scrollable,
94
- scrollableHorizontal && styles.scrollableHorizontal,
95
- className,
96
- computeBoxClassName(rest),
97
- ])}
98
- {...computeBoxProps(rest)}
99
- >
100
- {hasTitle && (
101
- <div className={styles.title}>
102
- <span className={styles.titleText}>{title}</span>
103
- <div className={styles.buttons}>{buttons}</div>
104
- </div>
105
- )}
106
- <div className={styles.rest}>
107
- <div
108
- className={styles.content}
109
- onScroll={onScroll}
110
- // For posterity: the forwarded ref needs to be here specifically
111
- // to actually let things interact with the scrolling.
112
- ref={forwardedRef}
113
- >
114
- {children}
115
- </div>
116
- </div>
117
- </div>
118
- );
119
- },
120
- );