ods-component-lib 1.20.1 → 1.20.3

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.
@@ -7,6 +7,7 @@ export declare type OdsCurrencyInputProps = InputNumberProps & {
7
7
  defaultValue?: number;
8
8
  asPercentage?: boolean;
9
9
  isOnRight?: boolean;
10
+ fractionDigits?: number;
10
11
  currencySelectProps: CurrencySelectProps;
11
12
  };
12
13
  export declare type CurrencyOptionType = {
@@ -16,10 +16,13 @@ declare type FileUploadProps = {
16
16
  RemoveCancelText?: string;
17
17
  skipSizeValidation?: boolean;
18
18
  maxFileSizeMB?: number;
19
+ minWidth?: number;
20
+ minHeight?: number;
19
21
  };
20
22
  interface IValidationMessageOptions {
21
23
  sizeValidationFailMessage?: string;
22
24
  typeValidationFailMessage?: string;
25
+ dimensionValidationFailMessage?: string;
23
26
  }
24
27
  declare function OdsFileUpload(props: FileUploadProps): React.JSX.Element;
25
28
  export default OdsFileUpload;
package/dist/index.js CHANGED
@@ -872,7 +872,7 @@ var CurrencySelect = function CurrencySelect(_ref) {
872
872
  }));
873
873
  };
874
874
 
875
- var _excluded$1 = ["currencySelectProps", "defaultValue", "locale", "dontFormatValue", "min", "asPercentage", "isOnRight"];
875
+ var _excluded$1 = ["currencySelectProps", "defaultValue", "locale", "dontFormatValue", "min", "asPercentage", "isOnRight", "fractionDigits"];
876
876
  var _templateObject$d;
877
877
  var useStyles$1 = antdStyle.createStyles(function (_ref) {
878
878
  var css = _ref.css;
@@ -891,6 +891,7 @@ var OdsCurrencyInput = function OdsCurrencyInput(_ref2) {
891
891
  min = _ref2$min === void 0 ? 0 : _ref2$min,
892
892
  asPercentage = _ref2.asPercentage,
893
893
  isOnRight = _ref2.isOnRight,
894
+ fractionDigits = _ref2.fractionDigits,
894
895
  props = _objectWithoutPropertiesLoose(_ref2, _excluded$1);
895
896
  var _useStyles = useStyles$1(),
896
897
  styles = _useStyles.styles;
@@ -931,16 +932,19 @@ var OdsCurrencyInput = function OdsCurrencyInput(_ref2) {
931
932
  return props.onChange(value);
932
933
  },
933
934
  formatter: function formatter(value) {
934
- return dontFormatValue ? String(value) : formatValue(value, locale);
935
+ return dontFormatValue ? String(value) : formatValue(value, locale, fractionDigits);
935
936
  },
936
937
  parser: function parser(value) {
937
938
  return dontFormatValue ? value : parseValue(value, locale);
938
939
  }
939
940
  }, props))));
940
941
  };
941
- var formatValue = function formatValue(value, locale) {
942
+ var formatValue = function formatValue(value, locale, fractionDigits) {
942
943
  if (!value) return value;
943
- return new Intl.NumberFormat(locale).format(Number(value));
944
+ return new Intl.NumberFormat(locale, fractionDigits ? {
945
+ minimumFractionDigits: fractionDigits,
946
+ maximumFractionDigits: fractionDigits
947
+ } : {}).format(Number(value));
944
948
  };
945
949
  var parseValue = function parseValue(stringNumber, locale) {
946
950
  if (!stringNumber) return stringNumber;
@@ -1095,25 +1099,50 @@ function OdsFileUpload(props) {
1095
1099
  var fileType = allowDocumentUpload ? ["image/png", "image/jpg", "image/jpeg", "image/svg+xml", "application/pdf", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"] : ["image/png", "image/jpg", "image/jpeg", "image/svg+xml"];
1096
1100
  var isFileSizeOk = skipSizeValidation ? true : file.size / (1024 * 1024) <= maxFileSizeMB;
1097
1101
  var checkType = fileType.includes(file.type);
1098
- if (!checkType) {
1099
- OdsNotification({
1100
- title: "",
1101
- content: customValidationMessages.typeValidationFailMessage,
1102
- type: "warning",
1103
- placement: "bottom"
1104
- });
1105
- return Promise.resolve(antd.Upload.LIST_IGNORE);
1106
- }
1107
- if (!isFileSizeOk) {
1108
- OdsNotification({
1109
- title: "",
1110
- content: customValidationMessages.sizeValidationFailMessage,
1111
- type: "warning",
1112
- placement: "bottom"
1102
+ var checkDimensions = function checkDimensions(file) {
1103
+ return new Promise(function (resolve) {
1104
+ if (file.type.startsWith("image/") && (props.minWidth || props.minHeight)) {
1105
+ var img = new Image();
1106
+ img.src = URL.createObjectURL(file);
1107
+ img.onload = function () {
1108
+ var isValid = (!props.minWidth || img.width >= props.minWidth) && (!props.minHeight || img.height >= props.minHeight);
1109
+ resolve(isValid);
1110
+ };
1111
+ } else {
1112
+ resolve(true);
1113
+ }
1113
1114
  });
1114
- return Promise.resolve(antd.Upload.LIST_IGNORE);
1115
- }
1116
- return Promise.resolve(false);
1115
+ };
1116
+ return Promise.resolve(checkDimensions(file)).then(function (isDimensionsOk) {
1117
+ if (!isDimensionsOk) {
1118
+ OdsNotification({
1119
+ title: "",
1120
+ content: customValidationMessages.dimensionValidationFailMessage || "Image dimensions are too small. Minimum size is " + (props.minWidth || 0) + "px width and " + (props.minHeight || 0) + "px height.",
1121
+ type: "warning",
1122
+ placement: "bottom"
1123
+ });
1124
+ return antd.Upload.LIST_IGNORE;
1125
+ }
1126
+ if (!checkType) {
1127
+ OdsNotification({
1128
+ title: "",
1129
+ content: customValidationMessages.typeValidationFailMessage,
1130
+ type: "warning",
1131
+ placement: "bottom"
1132
+ });
1133
+ return antd.Upload.LIST_IGNORE;
1134
+ }
1135
+ if (!isFileSizeOk) {
1136
+ OdsNotification({
1137
+ title: "",
1138
+ content: customValidationMessages.sizeValidationFailMessage,
1139
+ type: "warning",
1140
+ placement: "bottom"
1141
+ });
1142
+ return antd.Upload.LIST_IGNORE;
1143
+ }
1144
+ return false;
1145
+ });
1117
1146
  } catch (e) {
1118
1147
  return Promise.reject(e);
1119
1148
  }