@sustaina/shared-ui 1.59.2 → 1.60.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.
package/dist/index.d.mts CHANGED
@@ -149,7 +149,10 @@ type DropdownFieldSchema = FieldSchemaBase<"dropdown"> & ({
149
149
  interface TextFieldSchema extends FieldSchemaBase<"text"> {
150
150
  allowRegex?: RegExp;
151
151
  }
152
- type NumberFieldSchema = FieldSchemaBase<"number">;
152
+ interface NumberFieldSchema extends FieldSchemaBase<"number"> {
153
+ min?: number;
154
+ max?: number;
155
+ }
153
156
  type DateFieldSchema = FieldSchemaBase<"date">;
154
157
  type DateTimeFieldSchema = FieldSchemaBase<"datetime">;
155
158
  type DateMonthFieldSchema = FieldSchemaBase<"datemonth">;
package/dist/index.d.ts CHANGED
@@ -149,7 +149,10 @@ type DropdownFieldSchema = FieldSchemaBase<"dropdown"> & ({
149
149
  interface TextFieldSchema extends FieldSchemaBase<"text"> {
150
150
  allowRegex?: RegExp;
151
151
  }
152
- type NumberFieldSchema = FieldSchemaBase<"number">;
152
+ interface NumberFieldSchema extends FieldSchemaBase<"number"> {
153
+ min?: number;
154
+ max?: number;
155
+ }
153
156
  type DateFieldSchema = FieldSchemaBase<"date">;
154
157
  type DateTimeFieldSchema = FieldSchemaBase<"datetime">;
155
158
  type DateMonthFieldSchema = FieldSchemaBase<"datemonth">;
package/dist/index.js CHANGED
@@ -4946,7 +4946,7 @@ var ConditionTextInput = ({ row, control, onClear }) => /* @__PURE__ */ jsxRunti
4946
4946
  }
4947
4947
  }
4948
4948
  );
4949
- var ConditionNumberInput = ({ row, control, onClear }) => /* @__PURE__ */ jsxRuntime.jsx(
4949
+ var ConditionNumberInput = ({ row, control, onClear, fieldSchema }) => /* @__PURE__ */ jsxRuntime.jsx(
4950
4950
  FormField,
4951
4951
  {
4952
4952
  control,
@@ -4966,6 +4966,17 @@ var ConditionNumberInput = ({ row, control, onClear }) => /* @__PURE__ */ jsxRun
4966
4966
  value: field.value ?? "",
4967
4967
  autoComplete: "off",
4968
4968
  inputMode: "numeric",
4969
+ min: fieldSchema?.min,
4970
+ max: fieldSchema?.max,
4971
+ onKeyDown: (e) => {
4972
+ const blocked = ["e", "E"];
4973
+ if (fieldSchema?.min !== void 0 && fieldSchema.min >= 0) {
4974
+ blocked.push("-");
4975
+ }
4976
+ if (blocked.includes(e.key)) {
4977
+ e.preventDefault();
4978
+ }
4979
+ },
4969
4980
  className: "w-full h-9 rounded-md bg-white pr-8 text-sm text-gray-700 shadow-none focus-visible:ring-0 focus-visible:ring-offset-0 "
4970
4981
  }
4971
4982
  ) }),
@@ -5515,6 +5526,7 @@ var ConditionDateInput = ({
5515
5526
  onClear,
5516
5527
  shortDateFormat = fallbackShortDateFormat
5517
5528
  }) => {
5529
+ const dateFormat = /D/i.test(shortDateFormat) ? shortDateFormat : fallbackShortDateFormat;
5518
5530
  const isBetween = row.operator === "between";
5519
5531
  const buildAriaLabel = (isEnd) => {
5520
5532
  if (isEnd) return "Select end date";
@@ -5546,11 +5558,11 @@ var ConditionDateInput = ({
5546
5558
  ...field,
5547
5559
  value: field.value || void 0,
5548
5560
  onValueChange: handleValueChange,
5549
- placeholder: shortDateFormat,
5561
+ placeholder: dateFormat,
5550
5562
  ariaLabel: buildAriaLabel(options?.isEnd),
5551
5563
  clearAriaLabel: buildClearLabel(options?.isEnd),
5552
5564
  invalid: Boolean(fieldState.error),
5553
- displayFormatter: (d) => formatISODate(d, shortDateFormat),
5565
+ displayFormatter: (d) => formatISODate(d, dateFormat),
5554
5566
  wrapperClassName: "min-w-0",
5555
5567
  "data-testid": "advsearch-date-value"
5556
5568
  }
@@ -7906,7 +7918,15 @@ var ConditionValue = ({
7906
7918
  }
7907
7919
  switch (fieldType) {
7908
7920
  case "number":
7909
- return /* @__PURE__ */ jsxRuntime.jsx(ConditionNumberInput, { row, control, onClear: onClearValue });
7921
+ return /* @__PURE__ */ jsxRuntime.jsx(
7922
+ ConditionNumberInput,
7923
+ {
7924
+ row,
7925
+ control,
7926
+ onClear: onClearValue,
7927
+ fieldSchema
7928
+ }
7929
+ );
7910
7930
  case "date":
7911
7931
  case "datetime":
7912
7932
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -8558,7 +8578,7 @@ var validateByFieldType = (value, fieldType) => {
8558
8578
  return { valid: true };
8559
8579
  }
8560
8580
  if (numericTypes.includes(fieldType)) {
8561
- if (!/^\d+(\.\d+)?$/.test(value)) {
8581
+ if (!/^-?\d+(\.\d+)?$/.test(value)) {
8562
8582
  return { valid: false, message: "Please enter a valid number." };
8563
8583
  }
8564
8584
  }