@firecms/ui 3.0.0-rc.2 → 3.0.0-rc.4

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.
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- export type BadgeColor = "primary" | "secondary" | "error";
2
+ export type BadgeColor = "primary" | "secondary" | "warning" | "error";
3
3
  export interface BadgeProps {
4
4
  color?: BadgeColor;
5
5
  children: React.ReactNode;
package/dist/index.es.js CHANGED
@@ -27718,251 +27718,122 @@ function Typography(t0) {
27718
27718
  }
27719
27719
  return t15;
27720
27720
  }
27721
- const DateTimeField = (t0) => {
27722
- const $ = c(57);
27723
- const {
27724
- value,
27725
- label,
27726
- onChange,
27727
- disabled,
27728
- clearable,
27729
- mode: t1,
27730
- error,
27731
- size: t2,
27732
- className,
27733
- style,
27734
- inputClassName,
27735
- invisible
27736
- } = t0;
27737
- const mode = t1 === void 0 ? "date" : t1;
27738
- const size = t2 === void 0 ? "large" : t2;
27721
+ const DateTimeField = ({
27722
+ value,
27723
+ label,
27724
+ onChange,
27725
+ disabled,
27726
+ clearable,
27727
+ mode = "date",
27728
+ error,
27729
+ size = "large",
27730
+ className,
27731
+ style,
27732
+ inputClassName,
27733
+ invisible
27734
+ }) => {
27739
27735
  const inputRef = useRef(null);
27740
27736
  const [focused, setFocused] = useState(false);
27737
+ const [internalValue, setInternalValue] = useState("");
27738
+ const [isTyping, setIsTyping] = useState(false);
27741
27739
  const invalidValue = value !== void 0 && value !== null && !(value instanceof Date);
27742
27740
  useInjectStyles("DateTimeField", inputStyles);
27743
- let t3;
27744
- if ($[0] !== onChange) {
27745
- t3 = (e) => {
27746
- e.preventDefault();
27741
+ const handleClear = (e) => {
27742
+ e.preventDefault();
27743
+ setInternalValue("");
27744
+ setIsTyping(false);
27745
+ onChange?.(null);
27746
+ };
27747
+ const valueAsInputValue = (dateValue, mode_0) => {
27748
+ if (!dateValue) {
27749
+ return "";
27750
+ }
27751
+ const pad = (n) => n.toString().padStart(2, "0");
27752
+ const year = dateValue.getFullYear();
27753
+ const month = pad(dateValue.getMonth() + 1);
27754
+ const day = pad(dateValue.getDate());
27755
+ if (mode_0 === "date") {
27756
+ return `${year}-${month}-${day}`;
27757
+ } else {
27758
+ const hours = pad(dateValue.getHours());
27759
+ const minutes = pad(dateValue.getMinutes());
27760
+ return `${year}-${month}-${day}T${hours}:${minutes}`;
27761
+ }
27762
+ };
27763
+ const handleInputChange = (e_0) => {
27764
+ const inputValue = e_0.target.value;
27765
+ setInternalValue(inputValue);
27766
+ setIsTyping(true);
27767
+ if (!inputValue) {
27747
27768
  onChange?.(null);
27748
- };
27749
- $[0] = onChange;
27750
- $[1] = t3;
27751
- } else {
27752
- t3 = $[1];
27753
- }
27754
- const handleClear = t3;
27755
- const valueAsInputValue = _temp2$1;
27756
- let t4;
27757
- if ($[2] !== mode || $[3] !== onChange) {
27758
- t4 = (e_0) => {
27759
- const inputValue = e_0.target.value;
27760
- if (!inputValue) {
27761
- onChange?.(null);
27762
- return;
27769
+ return;
27770
+ }
27771
+ try {
27772
+ const parsed = new Date(inputValue);
27773
+ if (isNaN(parsed.getTime())) {
27774
+ throw new Error("Invalid date");
27763
27775
  }
27764
27776
  let newDate;
27765
- try {
27766
- if (mode === "date_time") {
27767
- const [datePart, timePart] = inputValue.split("T");
27768
- const [year_0, month_0, day_0] = datePart.split("-").map(Number);
27769
- const [hours_0, minutes_0] = timePart.split(":").map(Number);
27770
- newDate = new Date(year_0, month_0 - 1, day_0, hours_0, minutes_0);
27771
- } else {
27772
- const [year_1, month_1, day_1] = inputValue.split("-").map(Number);
27773
- newDate = new Date(year_1, month_1 - 1, day_1);
27774
- }
27775
- } catch (t52) {
27776
- newDate = null;
27777
+ if (mode === "date") {
27778
+ const userTimezoneOffset = parsed.getTimezoneOffset() * 6e4;
27779
+ newDate = new Date(parsed.getTime() + userTimezoneOffset);
27780
+ } else {
27781
+ newDate = parsed;
27777
27782
  }
27778
27783
  onChange?.(newDate);
27779
- };
27780
- $[2] = mode;
27781
- $[3] = onChange;
27782
- $[4] = t4;
27783
- } else {
27784
- t4 = $[4];
27785
- }
27786
- const handleInputChange = t4;
27787
- let t5;
27788
- if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
27789
- t5 = /* @__PURE__ */ jsx("style", { children: inputStyles });
27790
- $[5] = t5;
27791
- } else {
27792
- t5 = $[5];
27793
- }
27794
- const t6 = !invisible && fieldBackgroundMixin;
27795
- const t7 = disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin;
27796
- const t8 = size === "smallest";
27797
- const t9 = size === "small";
27798
- const t10 = size === "medium";
27799
- const t11 = size === "large";
27800
- let t12;
27801
- if ($[6] !== className || $[7] !== t10 || $[8] !== t11 || $[9] !== t6 || $[10] !== t7 || $[11] !== t8 || $[12] !== t9) {
27802
- t12 = cls("rounded-md relative max-w-full", t6, t7, {
27803
- "min-h-[28px]": t8,
27804
- "min-h-[32px]": t9,
27805
- "min-h-[42px]": t10,
27806
- "min-h-[64px]": t11
27807
- }, className);
27808
- $[6] = className;
27809
- $[7] = t10;
27810
- $[8] = t11;
27811
- $[9] = t6;
27812
- $[10] = t7;
27813
- $[11] = t8;
27814
- $[12] = t9;
27815
- $[13] = t12;
27816
- } else {
27817
- t12 = $[13];
27818
- }
27819
- let t13;
27820
- if ($[14] !== disabled) {
27821
- t13 = () => {
27784
+ } catch (e_1) {
27785
+ return;
27786
+ }
27787
+ };
27788
+ const handleFocus = () => {
27789
+ setFocused(true);
27790
+ setIsTyping(true);
27791
+ setInternalValue(valueAsInputValue(value ?? null, mode));
27792
+ };
27793
+ const handleBlur = () => {
27794
+ setFocused(false);
27795
+ setIsTyping(false);
27796
+ };
27797
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
27798
+ /* @__PURE__ */ jsx("style", { children: inputStyles }),
27799
+ /* @__PURE__ */ jsxs("div", { className: cls("rounded-md relative max-w-full", !invisible && fieldBackgroundMixin, disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin, {
27800
+ "min-h-[28px]": size === "smallest",
27801
+ "min-h-[32px]": size === "small",
27802
+ "min-h-[42px]": size === "medium",
27803
+ "min-h-[64px]": size === "large"
27804
+ }, className), style, onClick: () => {
27822
27805
  if (!disabled) {
27823
27806
  inputRef.current?.focus();
27824
27807
  }
27825
- };
27826
- $[14] = disabled;
27827
- $[15] = t13;
27828
- } else {
27829
- t13 = $[15];
27830
- }
27831
- let t14;
27832
- if ($[16] !== disabled || $[17] !== error || $[18] !== focused || $[19] !== label) {
27833
- t14 = label && /* @__PURE__ */ jsx(InputLabel, { className: cls("absolute top-1 pointer-events-none", !error ? focused ? "text-primary" : "text-text-secondary dark:text-text-secondary-dark" : "text-red-500 dark:text-red-500", disabled ? "opacity-50" : ""), shrink: true, children: label });
27834
- $[16] = disabled;
27835
- $[17] = error;
27836
- $[18] = focused;
27837
- $[19] = label;
27838
- $[20] = t14;
27839
- } else {
27840
- t14 = $[20];
27841
- }
27842
- const t15 = mode === "date_time" ? "datetime-local" : "date";
27843
- const t16 = valueAsInputValue(value ?? null, mode);
27844
- let t17;
27845
- let t18;
27846
- if ($[21] === Symbol.for("react.memo_cache_sentinel")) {
27847
- t17 = () => setFocused(true);
27848
- t18 = () => setFocused(false);
27849
- $[21] = t17;
27850
- $[22] = t18;
27851
- } else {
27852
- t17 = $[21];
27853
- t18 = $[22];
27854
- }
27855
- const t19 = clearable ? "pr-14" : "pr-12";
27856
- const t20 = size === "smallest";
27857
- const t21 = size === "small";
27858
- const t22 = size === "medium";
27859
- const t23 = size === "large";
27860
- let t24;
27861
- if ($[23] !== disabled || $[24] !== inputClassName || $[25] !== label || $[26] !== t19 || $[27] !== t20 || $[28] !== t21 || $[29] !== t22 || $[30] !== t23) {
27862
- t24 = cls("w-full outline-none bg-transparent leading-normal text-base px-3", t19, "rounded-md", {
27863
- "min-h-[28px]": t20,
27864
- "min-h-[32px]": t21,
27865
- "min-h-[42px]": t22,
27866
- "min-h-[64px]": t23
27867
- }, label ? "pt-8 pb-2" : "py-2", inputClassName, disabled && "border border-transparent outline-none opacity-50 dark:opacity-50 text-surface-accent-600 dark:text-surface-accent-500");
27868
- $[23] = disabled;
27869
- $[24] = inputClassName;
27870
- $[25] = label;
27871
- $[26] = t19;
27872
- $[27] = t20;
27873
- $[28] = t21;
27874
- $[29] = t22;
27875
- $[30] = t23;
27876
- $[31] = t24;
27877
- } else {
27878
- t24 = $[31];
27879
- }
27880
- let t25;
27881
- if ($[32] !== disabled || $[33] !== handleInputChange || $[34] !== t15 || $[35] !== t16 || $[36] !== t24) {
27882
- t25 = /* @__PURE__ */ jsx("input", { ref: inputRef, type: t15, value: t16, onChange: handleInputChange, onFocus: t17, onBlur: t18, disabled, className: t24 });
27883
- $[32] = disabled;
27884
- $[33] = handleInputChange;
27885
- $[34] = t15;
27886
- $[35] = t16;
27887
- $[36] = t24;
27888
- $[37] = t25;
27889
- } else {
27890
- t25 = $[37];
27891
- }
27892
- let t26;
27893
- if ($[38] === Symbol.for("react.memo_cache_sentinel")) {
27894
- t26 = (e_2) => {
27895
- e_2.stopPropagation();
27896
- inputRef.current?.showPicker();
27897
- };
27898
- $[38] = t26;
27899
- } else {
27900
- t26 = $[38];
27901
- }
27902
- let t27;
27903
- if ($[39] === Symbol.for("react.memo_cache_sentinel")) {
27904
- t27 = /* @__PURE__ */ jsx(IconButton, { onClick: t26, className: "absolute right-3 top-1/2 transform -translate-y-1/2 !text-surface-accent-500", children: /* @__PURE__ */ jsx(CalendarMonthIcon, { color: "disabled" }) });
27905
- $[39] = t27;
27906
- } else {
27907
- t27 = $[39];
27908
- }
27909
- let t28;
27910
- if ($[40] !== clearable || $[41] !== handleClear || $[42] !== value) {
27911
- t28 = clearable && value && /* @__PURE__ */ jsx(IconButton, { onClick: handleClear, className: "absolute right-14 top-1/2 transform -translate-y-1/2 text-surface-accent-400 ", children: /* @__PURE__ */ jsx(CloseIcon, {}) });
27912
- $[40] = clearable;
27913
- $[41] = handleClear;
27914
- $[42] = value;
27915
- $[43] = t28;
27916
- } else {
27917
- t28 = $[43];
27918
- }
27919
- let t29;
27920
- if ($[44] !== style || $[45] !== t12 || $[46] !== t13 || $[47] !== t14 || $[48] !== t25 || $[49] !== t28) {
27921
- t29 = /* @__PURE__ */ jsxs("div", { className: t12, style, onClick: t13, children: [
27922
- t14,
27923
- t25,
27924
- t27,
27925
- t28
27926
- ] });
27927
- $[44] = style;
27928
- $[45] = t12;
27929
- $[46] = t13;
27930
- $[47] = t14;
27931
- $[48] = t25;
27932
- $[49] = t28;
27933
- $[50] = t29;
27934
- } else {
27935
- t29 = $[50];
27936
- }
27937
- let t30;
27938
- if ($[51] !== invalidValue || $[52] !== value) {
27939
- t30 = invalidValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center m-2", children: [
27808
+ }, children: [
27809
+ label && /* @__PURE__ */ jsx(
27810
+ InputLabel,
27811
+ {
27812
+ className: cls("absolute top-1 pointer-events-none", !error ? focused ? "text-primary" : "text-text-secondary dark:text-text-secondary-dark" : "text-red-500 dark:text-red-500", disabled ? "opacity-50" : ""),
27813
+ shrink: true,
27814
+ children: label
27815
+ }
27816
+ ),
27817
+ /* @__PURE__ */ jsx("input", { ref: inputRef, type: mode === "date_time" ? "datetime-local" : "date", value: isTyping ? internalValue : valueAsInputValue(value ?? null, mode), onChange: handleInputChange, onFocus: handleFocus, onBlur: handleBlur, disabled, className: cls("w-full outline-none bg-transparent leading-normal text-base px-3", clearable ? "pr-14" : "pr-12", "rounded-md", {
27818
+ "min-h-[28px]": size === "smallest",
27819
+ "min-h-[32px]": size === "small",
27820
+ "min-h-[42px]": size === "medium",
27821
+ "min-h-[64px]": size === "large"
27822
+ }, label ? "pt-8 pb-2" : "py-2", inputClassName, disabled && "border border-transparent outline-none opacity-50 dark:opacity-50 text-surface-accent-600 dark:text-surface-accent-500") }),
27823
+ /* @__PURE__ */ jsx(IconButton, { onClick: (e_2) => {
27824
+ e_2.stopPropagation();
27825
+ inputRef.current?.showPicker();
27826
+ }, className: "absolute right-3 top-1/2 transform -translate-y-1/2 !text-surface-accent-500", children: /* @__PURE__ */ jsx(CalendarMonthIcon, { color: "disabled" }) }),
27827
+ clearable && value && /* @__PURE__ */ jsx(IconButton, { onClick: handleClear, className: "absolute right-14 top-1/2 transform -translate-y-1/2 text-surface-accent-400 ", children: /* @__PURE__ */ jsx(CloseIcon, {}) })
27828
+ ] }),
27829
+ invalidValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center m-2", children: [
27940
27830
  /* @__PURE__ */ jsx(ErrorIcon, { size: "small", color: "error" }),
27941
27831
  /* @__PURE__ */ jsxs("div", { className: "pl-2", children: [
27942
27832
  /* @__PURE__ */ jsx(Typography, { variant: "body2", children: "Invalid date value for this field" }),
27943
27833
  /* @__PURE__ */ jsx(Typography, { variant: "body2", children: `The provided value is: ${JSON.stringify(value)}` })
27944
27834
  ] })
27945
- ] });
27946
- $[51] = invalidValue;
27947
- $[52] = value;
27948
- $[53] = t30;
27949
- } else {
27950
- t30 = $[53];
27951
- }
27952
- let t31;
27953
- if ($[54] !== t29 || $[55] !== t30) {
27954
- t31 = /* @__PURE__ */ jsxs(Fragment, { children: [
27955
- t5,
27956
- t29,
27957
- t30
27958
- ] });
27959
- $[54] = t29;
27960
- $[55] = t30;
27961
- $[56] = t31;
27962
- } else {
27963
- t31 = $[56];
27964
- }
27965
- return t31;
27835
+ ] })
27836
+ ] });
27966
27837
  };
27967
27838
  const inputStyles = `
27968
27839
  /* Hide the default calendar icon in Chrome, Safari, Edge, Opera */
@@ -27977,25 +27848,6 @@ const inputStyles = `
27977
27848
  -moz-appearance:textfield;
27978
27849
  }
27979
27850
  `;
27980
- function _temp$3(n) {
27981
- return n.toString().padStart(2, "0");
27982
- }
27983
- function _temp2$1(dateValue, mode_0) {
27984
- if (!dateValue) {
27985
- return "";
27986
- }
27987
- const pad = _temp$3;
27988
- const year = dateValue.getFullYear();
27989
- const month = pad(dateValue.getMonth() + 1);
27990
- const day = pad(dateValue.getDate());
27991
- if (mode_0 === "date") {
27992
- return `${year}-${month}-${day}`;
27993
- } else {
27994
- const hours = pad(dateValue.getHours());
27995
- const minutes = pad(dateValue.getMinutes());
27996
- return `${year}-${month}-${day}T${hours}:${minutes}`;
27997
- }
27998
- }
27999
27851
  const widthClasses = {
28000
27852
  xs: "max-w-xs min-w-xs w-xs",
28001
27853
  sm: "max-w-sm min-w-sm w-sm",
@@ -28126,7 +27978,7 @@ const Dialog = (t0) => {
28126
27978
  const t22 = maxWidth && !fullScreen ? widthClasses[maxWidth] : void 0;
28127
27979
  let t23;
28128
27980
  if ($[16] !== className || $[17] !== t17 || $[18] !== t18 || $[19] !== t19 || $[20] !== t20 || $[21] !== t21 || $[22] !== t22) {
28129
- t23 = cls(paperMixin, "z-30", "relative", "outline-none focus:outline-none", t17, t18, "text-surface-accent-900 dark:text-white", "justify-center items-center", t19, "ease-in-out duration-200", t20, t21, t22, className);
27981
+ t23 = cls(paperMixin, "rounded-2xl", "z-30", "relative", "overflow-hidden", "outline-none focus:outline-none", t17, t18, "text-surface-accent-900 dark:text-white", "justify-center items-center", t19, "ease-in-out duration-200", t20, t21, t22, className);
28130
27982
  $[16] = className;
28131
27983
  $[17] = t17;
28132
27984
  $[18] = t18;
@@ -28200,7 +28052,7 @@ function DialogActions(t0) {
28200
28052
  const t3 = translucent ? "backdrop-blur-sm" : "";
28201
28053
  let t4;
28202
28054
  if ($[0] !== className || $[1] !== position || $[2] !== t3) {
28203
- t4 = cls(defaultBorderMixin, "py-3 px-4 border-t flex flex-row items-center justify-end bottom-0 right-0 left-0 text-right z-2 gap-2", position, "bg-white bg-opacity-60 dark:bg-surface-900 dark:bg-opacity-60", t3, className);
28055
+ t4 = cls(defaultBorderMixin, "pt-2 pb-4 px-4 border-t flex flex-row items-center justify-end bottom-0 right-0 left-0 text-right z-2 gap-2", position, "bg-white bg-opacity-60 dark:bg-surface-900 dark:bg-opacity-60", t3, className);
28204
28056
  $[0] = className;
28205
28057
  $[1] = position;
28206
28058
  $[2] = t3;
@@ -28242,7 +28094,7 @@ function DialogContent(t0) {
28242
28094
  let t2;
28243
28095
  if ($[2] !== className || $[3] !== includeMargin) {
28244
28096
  t2 = cls("flex-grow", {
28245
- "my-6 mx-6": includeMargin
28097
+ "my-8 mx-8": includeMargin
28246
28098
  }, className);
28247
28099
  $[2] = className;
28248
28100
  $[3] = includeMargin;
@@ -28303,7 +28155,7 @@ function DialogTitle(t0) {
28303
28155
  let t4;
28304
28156
  if ($[8] !== className || $[9] !== includeMargin) {
28305
28157
  t4 = cls({
28306
- "mt-6 mx-6": includeMargin
28158
+ "mt-8 mx-8": includeMargin
28307
28159
  }, className);
28308
28160
  $[8] = className;
28309
28161
  $[9] = includeMargin;
@@ -28901,7 +28753,7 @@ const Menu = React__default.forwardRef((t0, ref) => {
28901
28753
  }
28902
28754
  let t3;
28903
28755
  if ($[3] !== className) {
28904
- t3 = cls(paperMixin, focusedDisabled, "shadow py-2 z-30", className);
28756
+ t3 = cls(paperMixin, focusedDisabled, "py-2 z-30", className);
28905
28757
  $[3] = className;
28906
28758
  $[4] = t3;
28907
28759
  } else {
@@ -28956,7 +28808,7 @@ function MenuItem(t0) {
28956
28808
  } = t0;
28957
28809
  const dense = t1 === void 0 ? false : t1;
28958
28810
  const t2 = onClick && "cursor-pointer";
28959
- const t3 = dense ? "px-3 py-1.5" : "px-4 py-2";
28811
+ const t3 = dense ? "px-4 py-1.5" : "px-4 py-2";
28960
28812
  let t4;
28961
28813
  if ($[0] !== className || $[1] !== t2 || $[2] !== t3) {
28962
28814
  t4 = cls(t2, "rounded-md text-sm font-medium text-surface-accent-700 dark:text-surface-accent-300 hover:bg-surface-accent-100 dark:hover:bg-surface-accent-900 flex items-center gap-4", t3, className);
@@ -32090,6 +31942,8 @@ const getColor = (color) => {
32090
31942
  return "bg-primary";
32091
31943
  case "secondary":
32092
31944
  return "bg-secondary";
31945
+ case "warning":
31946
+ return "bg-orange-500";
32093
31947
  case "error":
32094
31948
  return "bg-red-500";
32095
31949
  default: