@zac-apps/commons 1.1.0 → 1.3.0

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 (2) hide show
  1. package/dist/index.js +69 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -32,6 +32,8 @@ import Menu from '@mui/material/Menu';
32
32
  import Divider from '@mui/material/Divider';
33
33
  import MenuIcon from '@mui/icons-material/Menu';
34
34
  import MenuOpenIcon from '@mui/icons-material/MenuOpen';
35
+ import TextField from '@mui/material/TextField';
36
+ import InputAdornment from '@mui/material/InputAdornment';
35
37
  import CircularProgress from '@mui/material/CircularProgress';
36
38
  import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
37
39
  import ToggleButton from '@mui/material/ToggleButton';
@@ -335,6 +337,72 @@ function DivTitle(_ref) {
335
337
  });
336
338
  }
337
339
 
340
+ function NumField(_ref) {
341
+ var input = _ref.input,
342
+ SetInput = _ref.SetInput,
343
+ error = _ref.error,
344
+ SetError = _ref.SetError,
345
+ minValue = _ref.minValue,
346
+ maxValue = _ref.maxValue,
347
+ adornment = _ref.adornment,
348
+ helperText = _ref.helperText,
349
+ size = _ref.size;
350
+ var _useState = useState(""),
351
+ _useState2 = _slicedToArray(_useState, 2),
352
+ errorMessage = _useState2[0],
353
+ SetErrorMessage = _useState2[1];
354
+ var _useState3 = useState(false),
355
+ _useState4 = _slicedToArray(_useState3, 2),
356
+ alert = _useState4[0],
357
+ SetAlert = _useState4[1];
358
+ var sx = {};
359
+ if (size === "small") {
360
+ sx = {
361
+ maxWidth: 75
362
+ };
363
+ }
364
+ function handleEntry(e) {
365
+ var errorFound = false;
366
+ var inputVal = e.target.value;
367
+ if (!inputVal.match(/[0-9-]*/)[0] || inputVal.match(/[0-9-]*/)[0] !== inputVal) {
368
+ errorFound = true;
369
+ SetErrorMessage("Input is not numerical.");
370
+ }
371
+ if (inputVal > maxValue || inputVal < minValue) {
372
+ errorFound = true;
373
+ SetErrorMessage("Input is outside allowed boundaries.");
374
+ }
375
+ SetInput(inputVal);
376
+ SetError(errorFound);
377
+ SetAlert(errorFound);
378
+ }
379
+ return /*#__PURE__*/jsxs(React__default.Fragment, {
380
+ children: [/*#__PURE__*/jsx(TextField, {
381
+ size: "small",
382
+ sx: sx,
383
+ onChange: function onChange(e) {
384
+ return handleEntry(e);
385
+ },
386
+ value: input,
387
+ error: error,
388
+ helperText: helperText,
389
+ inputProps: {
390
+ inputMode: "numeric"
391
+ },
392
+ InputProps: {
393
+ endAdornment: /*#__PURE__*/jsx(InputAdornment, {
394
+ position: "end",
395
+ children: adornment
396
+ })
397
+ }
398
+ }), /*#__PURE__*/jsx(ErrorAlert, {
399
+ alert: alert,
400
+ SetAlert: SetAlert,
401
+ message: errorMessage
402
+ })]
403
+ });
404
+ }
405
+
338
406
  function Percentage(number) {
339
407
  var resultStr = number.toString() + " %";
340
408
  return resultStr;
@@ -603,4 +671,4 @@ function AppDrawer(_ref) {
603
671
  });
604
672
  }
605
673
 
606
- export { ErrorAlert as Alert, AppCard, AppDrawer, AppGrid, AppMenu, AppTable, AppTheme, AppWrapper, DivTitle, Footer, MenuButton, NextListMenu, Percentage, Progress, PublicFetch, RespGrid, SpecSwitch, Start, TableHeadCell, useFetch };
674
+ export { ErrorAlert as Alert, AppCard, AppDrawer, AppGrid, AppMenu, AppTable, AppTheme, AppWrapper, DivTitle, Footer, MenuButton, NextListMenu, NumField, Percentage, Progress, PublicFetch, RespGrid, SpecSwitch, Start, TableHeadCell, useFetch };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zac-apps/commons",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "scripts": {
5
5
  "rollup": "node_modules/rollup/dist/rollup.js",
6
6
  "dev": "next dev",