@oliasoft-open-source/react-ui-library 3.3.23 → 3.4.1

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 +131 -0
  2. package/package.json +3 -1
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ import * as PropTypes from "prop-types";
10
10
  import PropTypes__default from "prop-types";
11
11
  import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
12
12
  import ReactDOM, { createPortal, unstable_batchedUpdates, findDOMNode as findDOMNode$2, render } from "react-dom";
13
+ import { validateNumber, validNumberSchema, toNum } from "@oliasoft-open-source/units";
13
14
  const global$2 = "";
14
15
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
15
16
  function getDefaultExportFromCjs(x2) {
@@ -70602,6 +70603,135 @@ Tree.propTypes = {
70602
70603
  testId: PropTypes__default.string,
70603
70604
  isInitialOpen: PropTypes__default.bool
70604
70605
  };
70606
+ const NumberInput = ({
70607
+ name: name2,
70608
+ placeholder: placeholder3,
70609
+ disabled: disabled2,
70610
+ error: error2,
70611
+ left: left2,
70612
+ small: small2,
70613
+ width,
70614
+ value,
70615
+ onChange,
70616
+ onClick,
70617
+ onFocus,
70618
+ testId,
70619
+ warning: warning2,
70620
+ validationCallback,
70621
+ allowEmpty
70622
+ }) => {
70623
+ const [displayValue, setDisplayValue] = useState(value);
70624
+ const [validationError, setValidationError] = useState(null);
70625
+ const stringName = (name2 == null ? void 0 : name2.fieldName) || name2;
70626
+ const validateInputValue = (value2) => {
70627
+ let validation = validateNumber(value2, validNumberSchema);
70628
+ if (allowEmpty && value2 === "" || validation.valid) {
70629
+ return {
70630
+ ...validation,
70631
+ valid: true,
70632
+ errors: void 0
70633
+ };
70634
+ } else {
70635
+ return validation;
70636
+ }
70637
+ };
70638
+ useEffect(() => {
70639
+ const {
70640
+ valid,
70641
+ errors
70642
+ } = validateInputValue(value);
70643
+ if (valid) {
70644
+ setValidationError(null);
70645
+ validationCallback(name2, null);
70646
+ } else {
70647
+ setValidationError(errors[0]);
70648
+ validationCallback(name2, errors[0]);
70649
+ }
70650
+ }, [value, error2]);
70651
+ const onSetValue = (evt) => {
70652
+ const input2 = evt.target;
70653
+ const {
70654
+ value: inputValue
70655
+ } = input2;
70656
+ const {
70657
+ valid,
70658
+ errors
70659
+ } = validateInputValue(inputValue);
70660
+ if (valid) {
70661
+ const newValue = toNum(inputValue);
70662
+ onChange({
70663
+ target: {
70664
+ value: newValue,
70665
+ name: name2
70666
+ }
70667
+ });
70668
+ setDisplayValue(inputValue);
70669
+ setValidationError(null);
70670
+ validationCallback(name2, null);
70671
+ } else {
70672
+ setDisplayValue(inputValue);
70673
+ setValidationError(errors[0]);
70674
+ validationCallback(name2, errors[0]);
70675
+ }
70676
+ };
70677
+ return /* @__PURE__ */ jsx(Input$1, {
70678
+ type: "text",
70679
+ name: stringName,
70680
+ testId,
70681
+ disabled: disabled2,
70682
+ placeholder: placeholder3,
70683
+ onClick: (ev) => {
70684
+ ev.stopPropagation();
70685
+ return onClick && onClick(ev);
70686
+ },
70687
+ value: displayValue,
70688
+ onChange: onSetValue,
70689
+ onFocus,
70690
+ error: error2 || validationError,
70691
+ warning: warning2,
70692
+ right: !left2,
70693
+ small: small2,
70694
+ width
70695
+ }, stringName);
70696
+ };
70697
+ NumberInput.defaultProps = {
70698
+ disabled: false,
70699
+ error: false,
70700
+ left: false,
70701
+ onClick: () => {
70702
+ },
70703
+ onFocus: () => {
70704
+ },
70705
+ onChange: () => {
70706
+ },
70707
+ placeholder: "",
70708
+ small: false,
70709
+ width: "100%",
70710
+ testId: void 0,
70711
+ value: void 0,
70712
+ validationCallback: () => {
70713
+ },
70714
+ allowEmpty: false,
70715
+ name: void 0,
70716
+ warning: false
70717
+ };
70718
+ NumberInput.propTypes = {
70719
+ disabled: PropTypes__default.bool,
70720
+ error: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.oneOf([false])]),
70721
+ left: PropTypes__default.bool,
70722
+ name: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.object]),
70723
+ onChange: PropTypes__default.func,
70724
+ onClick: PropTypes__default.func,
70725
+ onFocus: PropTypes__default.func,
70726
+ placeholder: PropTypes__default.string,
70727
+ small: PropTypes__default.bool,
70728
+ value: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number]),
70729
+ width: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number]),
70730
+ testId: PropTypes__default.string,
70731
+ warning: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.oneOf([false])]),
70732
+ validationCallback: PropTypes__default.func,
70733
+ allowEmpty: PropTypes__default.bool
70734
+ };
70605
70735
  export {
70606
70736
  Accordion,
70607
70737
  AccordionWithDefaultToggle,
@@ -70638,6 +70768,7 @@ export {
70638
70768
  Message,
70639
70769
  Modal,
70640
70770
  NativeSelect,
70771
+ NumberInput,
70641
70772
  OptionDropdown,
70642
70773
  Page,
70643
70774
  Pagination,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/react-ui-library",
3
- "version": "3.3.23",
3
+ "version": "3.4.1",
4
4
  "description": "Reusable UI components for React projects",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/react-ui-library",
6
6
  "bugs": {
@@ -70,6 +70,7 @@
70
70
  "styled-components": "^5.3.1"
71
71
  },
72
72
  "devDependencies": {
73
+ "@oliasoft-open-source/units": "^2.6.1",
73
74
  "@storybook/addon-actions": "^6.5.10",
74
75
  "@storybook/addon-essentials": "^6.5.10",
75
76
  "@storybook/addon-links": "^6.5.13",
@@ -112,6 +113,7 @@
112
113
  "vitest": "^0.25.1"
113
114
  },
114
115
  "peerDependencies": {
116
+ "@oliasoft-open-source/units": "^2.6.1",
115
117
  "immer": "^9",
116
118
  "prop-types": "^15",
117
119
  "react": "^17",