@oliasoft-open-source/react-ui-library 3.4.2 → 3.5.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 +176 -135
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -61950,6 +61950,137 @@ const styles$7 = {
61950
61950
  popover,
61951
61951
  disabledPointerEvents
61952
61952
  };
61953
+ const NumberInput = ({
61954
+ name: name2,
61955
+ placeholder: placeholder3,
61956
+ disabled: disabled2,
61957
+ error: error2,
61958
+ left: left2,
61959
+ small: small2,
61960
+ width,
61961
+ value,
61962
+ onChange,
61963
+ onClick,
61964
+ onFocus,
61965
+ testId,
61966
+ warning: warning2,
61967
+ validationCallback,
61968
+ allowEmpty,
61969
+ isInTable: isInTable2
61970
+ }) => {
61971
+ const [displayValue, setDisplayValue] = useState(value);
61972
+ const [validationError, setValidationError] = useState(null);
61973
+ const stringName = (name2 == null ? void 0 : name2.fieldName) || name2;
61974
+ const validateInputValue = (value2) => {
61975
+ let validation = validateNumber(value2);
61976
+ if (allowEmpty && value2 === "" || validation.valid) {
61977
+ return {
61978
+ ...validation,
61979
+ valid: true,
61980
+ errors: void 0
61981
+ };
61982
+ } else {
61983
+ return validation;
61984
+ }
61985
+ };
61986
+ useEffect(() => {
61987
+ const {
61988
+ valid,
61989
+ errors
61990
+ } = validateInputValue(value);
61991
+ if (valid) {
61992
+ setValidationError(null);
61993
+ validationCallback(name2, null);
61994
+ } else {
61995
+ setValidationError(errors[0]);
61996
+ validationCallback(name2, errors[0]);
61997
+ }
61998
+ }, [value, error2]);
61999
+ const onSetValue = (evt) => {
62000
+ const input2 = evt.target;
62001
+ const {
62002
+ value: inputValue
62003
+ } = input2;
62004
+ const {
62005
+ valid,
62006
+ errors
62007
+ } = validateInputValue(inputValue);
62008
+ if (valid) {
62009
+ const newValue = toNum(inputValue);
62010
+ onChange({
62011
+ target: {
62012
+ value: newValue,
62013
+ name: name2
62014
+ }
62015
+ });
62016
+ setDisplayValue(inputValue);
62017
+ setValidationError(null);
62018
+ validationCallback(name2, null);
62019
+ } else {
62020
+ setDisplayValue(inputValue);
62021
+ setValidationError(errors[0]);
62022
+ validationCallback(name2, errors[0]);
62023
+ }
62024
+ };
62025
+ return /* @__PURE__ */ jsx(Input$1, {
62026
+ type: "text",
62027
+ name: stringName,
62028
+ testId,
62029
+ disabled: disabled2,
62030
+ placeholder: placeholder3,
62031
+ onClick: (ev) => {
62032
+ ev.stopPropagation();
62033
+ return onClick && onClick(ev);
62034
+ },
62035
+ value: displayValue,
62036
+ onChange: onSetValue,
62037
+ onFocus,
62038
+ error: error2 || validationError,
62039
+ warning: warning2,
62040
+ right: !left2,
62041
+ small: small2,
62042
+ width,
62043
+ isInTable: isInTable2
62044
+ }, stringName);
62045
+ };
62046
+ NumberInput.defaultProps = {
62047
+ disabled: false,
62048
+ error: false,
62049
+ left: false,
62050
+ onClick: () => {
62051
+ },
62052
+ onFocus: () => {
62053
+ },
62054
+ onChange: () => {
62055
+ },
62056
+ placeholder: "",
62057
+ small: false,
62058
+ width: "100%",
62059
+ testId: void 0,
62060
+ value: void 0,
62061
+ validationCallback: () => {
62062
+ },
62063
+ allowEmpty: false,
62064
+ name: void 0,
62065
+ warning: false
62066
+ };
62067
+ NumberInput.propTypes = {
62068
+ disabled: PropTypes__default.bool,
62069
+ error: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.oneOf([false])]),
62070
+ left: PropTypes__default.bool,
62071
+ name: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.object]),
62072
+ onChange: PropTypes__default.func,
62073
+ onClick: PropTypes__default.func,
62074
+ onFocus: PropTypes__default.func,
62075
+ placeholder: PropTypes__default.string,
62076
+ small: PropTypes__default.bool,
62077
+ value: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number]),
62078
+ width: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number]),
62079
+ testId: PropTypes__default.string,
62080
+ warning: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.oneOf([false])]),
62081
+ validationCallback: PropTypes__default.func,
62082
+ allowEmpty: PropTypes__default.bool
62083
+ };
61953
62084
  const getCellAlignment = (alignment, styles2, isGetText = false) => {
61954
62085
  if (!alignment) {
61955
62086
  return null;
@@ -61990,6 +62121,29 @@ const getHeaderAlignment = (alignments, isHeader, rowIndex) => {
61990
62121
  return [];
61991
62122
  }
61992
62123
  };
62124
+ const NumberInputCell = (props) => {
62125
+ const {
62126
+ cell: cell2,
62127
+ columnAlignment,
62128
+ testId
62129
+ } = props;
62130
+ return /* @__PURE__ */ jsx(NumberInput, {
62131
+ name: cell2.name,
62132
+ value: cell2.value,
62133
+ onChange: (ev) => cell2.onChange(ev),
62134
+ placeholder: cell2.placeholder,
62135
+ error: cell2.error,
62136
+ warning: cell2.warning,
62137
+ disabled: cell2.disabled,
62138
+ isInTable: true,
62139
+ left: cell2.left,
62140
+ testId,
62141
+ tabIndex: cell2.disabled ? -1 : 0,
62142
+ tooltip: cell2.tooltip,
62143
+ validationCallback: cell2.validationCallback,
62144
+ allowEmpty: cell2.allowEmpty
62145
+ });
62146
+ };
61993
62147
  const InputCell = (props) => {
61994
62148
  const {
61995
62149
  cell: cell2,
@@ -62273,6 +62427,10 @@ const InputCellWrapper = (props) => {
62273
62427
  cell: cell2,
62274
62428
  columnAlignment,
62275
62429
  testId
62430
+ }) : cell2.type === "NumberInput" ? /* @__PURE__ */ jsx(NumberInputCell, {
62431
+ cell: cell2,
62432
+ columnAlignment,
62433
+ testId
62276
62434
  }) : cell2.type === "Select" ? /* @__PURE__ */ jsx(SelectCell, {
62277
62435
  cell: cell2,
62278
62436
  columnAlignment,
@@ -62290,6 +62448,7 @@ const CellWrapper = (props) => {
62290
62448
  if (cell2) {
62291
62449
  switch (cell2.type) {
62292
62450
  case "Input":
62451
+ case "NumberInput":
62293
62452
  case "Select":
62294
62453
  return /* @__PURE__ */ jsx(InputCellWrapper, {
62295
62454
  cell: cell2,
@@ -62353,7 +62512,7 @@ const Cell = (props) => {
62353
62512
  };
62354
62513
  const cellAlignmentStyle = getCellAlignment(alignment, styles$7);
62355
62514
  const cellAlignmentText = getCellAlignment(alignment, styles$7, true);
62356
- const className = cx$2(styles$7.cellWrapper, cell2.type === "Input" || cell2.type === "Select" || cell2.type === "Popover" ? styles$7.inputCell : "", cell2.type === "Slider" ? styles$7.sliderCell : "", cell2.type === "CheckBox" ? styles$7.checkBoxCell : "", cell2.type === "Actions" ? styles$7.actionsCell : "", cell2.type === "Icon" ? styles$7.iconCell : "", cell2.type === "Static" || cell2.type === "Link" || !cell2.type ? styles$7.staticCell : "", cell2.hasSort ? styles$7.sortingCell : null, cellAlignmentStyle, cell2.breakWord ? styles$7.breakWord : "");
62515
+ const className = cx$2(styles$7.cellWrapper, cell2.type === "Input" || cell2.type === "NumberInput" || cell2.type === "Select" || cell2.type === "Popover" ? styles$7.inputCell : "", cell2.type === "Slider" ? styles$7.sliderCell : "", cell2.type === "CheckBox" ? styles$7.checkBoxCell : "", cell2.type === "Actions" ? styles$7.actionsCell : "", cell2.type === "Icon" ? styles$7.iconCell : "", cell2.type === "Static" || cell2.type === "Link" || !cell2.type ? styles$7.staticCell : "", cell2.hasSort ? styles$7.sortingCell : null, cellAlignmentStyle, cell2.breakWord ? styles$7.breakWord : "");
62357
62516
  const isWidthCustomSelect = cell2.type === "Select" && cell2.native !== true && cell2.width !== void 0;
62358
62517
  return isHeader ? /* @__PURE__ */ jsx("th", {
62359
62518
  className,
@@ -62397,7 +62556,7 @@ const Cell = (props) => {
62397
62556
  })
62398
62557
  });
62399
62558
  };
62400
- const cellType = PropTypes__default.oneOf(["Static", "Icon", "Select", "Input", "Popover", "CheckBox", "Actions", "Link", "Unit"]);
62559
+ const cellType = PropTypes__default.oneOf(["Static", "Icon", "Select", "Input", "NumberInput", "Popover", "CheckBox", "Actions", "Link", "Unit"]);
62401
62560
  const cellShape = PropTypes__default.oneOfType([PropTypes__default.shape({
62402
62561
  value: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number]),
62403
62562
  type: cellType,
@@ -62447,14 +62606,25 @@ const cellShape = PropTypes__default.oneOfType([PropTypes__default.shape({
62447
62606
  placeholder: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number]),
62448
62607
  error: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number, PropTypes__default.node]),
62449
62608
  warning: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number, PropTypes__default.node]),
62609
+ disabled: PropTypes__default.bool,
62450
62610
  tooltip: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number, PropTypes__default.node]),
62451
- hasSort: PropTypes__default.bool,
62452
- sort: PropTypes__default.oneOf(["", "up", "down"]),
62453
- sortPriority: PropTypes__default.number,
62454
- onSort: PropTypes__default.func,
62455
62611
  colSpan: PropTypes__default.number,
62456
62612
  maxTooltipWidth: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number]),
62457
62613
  testId: PropTypes__default.string
62614
+ }), PropTypes__default.shape({
62615
+ name: PropTypes__default.string,
62616
+ value: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number]),
62617
+ type: cellType.isRequired,
62618
+ onChange: PropTypes__default.func,
62619
+ placeholder: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number]),
62620
+ error: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number, PropTypes__default.node]),
62621
+ warning: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number, PropTypes__default.node]),
62622
+ disabled: PropTypes__default.bool,
62623
+ tooltip: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number, PropTypes__default.node]),
62624
+ left: PropTypes__default.bool,
62625
+ testId: PropTypes__default.string,
62626
+ validationCallback: PropTypes__default.func,
62627
+ allowEmpty: PropTypes__default.bool
62458
62628
  }), PropTypes__default.shape({
62459
62629
  label: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number]),
62460
62630
  checked: PropTypes__default.bool,
@@ -70603,135 +70773,6 @@ Tree.propTypes = {
70603
70773
  testId: PropTypes__default.string,
70604
70774
  isInitialOpen: PropTypes__default.bool
70605
70775
  };
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);
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
- };
70735
70776
  export {
70736
70777
  Accordion,
70737
70778
  AccordionWithDefaultToggle,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/react-ui-library",
3
- "version": "3.4.2",
3
+ "version": "3.5.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": {