aidos-ui 4.0.5 → 4.0.6

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.js CHANGED
@@ -564,7 +564,9 @@ var sizes2 = {
564
564
  small: 6,
565
565
  medium: 12,
566
566
  large: 18,
567
- xlarge: 24
567
+ xlarge: 24,
568
+ xxlarge: 32,
569
+ xxxlarge: 40
568
570
  };
569
571
  function Badge({
570
572
  size = "medium",
@@ -771,12 +773,13 @@ var BaseButton = React34.forwardRef(
771
773
  disabled,
772
774
  animateInteraction = true,
773
775
  padding,
776
+ type = "button",
774
777
  ...otherProps
775
778
  }, ref) => {
776
779
  return /* @__PURE__ */ jsx(
777
780
  "button",
778
781
  {
779
- type: "button",
782
+ type,
780
783
  ...otherProps,
781
784
  "aria-disabled": disabled ? true : void 0,
782
785
  ref,
@@ -931,12 +934,12 @@ var BaseLink = React34.forwardRef(
931
934
  href,
932
935
  role,
933
936
  ref,
934
- onClick: onClick ? (event) => {
937
+ onClick: (event) => {
935
938
  if (disabled) {
936
939
  return;
937
940
  }
938
- onClick(event);
939
- } : void 0,
941
+ onClick && onClick(event);
942
+ },
940
943
  className: toClassnames([
941
944
  ...getInteractableJSS({
942
945
  color,
@@ -1133,15 +1136,20 @@ var focusElement = (focusables, index) => {
1133
1136
  };
1134
1137
  function useRefEffect(callback) {
1135
1138
  const unsubscribeRef = useRef(null);
1136
- const refCallback = useCallback((root) => {
1137
- if (root === null) {
1138
- unsubscribeRef.current && unsubscribeRef.current();
1139
- } else {
1140
- const unsubscribe = callback(root);
1141
- unsubscribeRef.current = unsubscribe;
1142
- }
1143
- }, []);
1144
- return refCallback;
1139
+ return useCallback(
1140
+ (root) => {
1141
+ if (root === null) {
1142
+ const unsubscribe = unsubscribeRef.current;
1143
+ if (unsubscribe) {
1144
+ unsubscribe();
1145
+ }
1146
+ unsubscribeRef.current = null;
1147
+ } else {
1148
+ unsubscribeRef.current = callback(root);
1149
+ }
1150
+ },
1151
+ [callback]
1152
+ );
1145
1153
  }
1146
1154
 
1147
1155
  // src/useNavigation.tsx
@@ -1150,72 +1158,78 @@ function useNavigation({
1150
1158
  rowLength = 1,
1151
1159
  enabled = true
1152
1160
  } = {}) {
1153
- return useRefEffect((root) => {
1154
- if (!enabled) {
1155
- return;
1156
- }
1157
- let index = 0;
1158
- const elements = queryFocusables(root);
1159
- if (elements.length === 0) {
1160
- return;
1161
- }
1162
- if (elements.length !== 0 && autofocus) {
1163
- focusElement(elements, index);
1164
- } else {
1165
- normalizeElements(elements, index);
1166
- }
1167
- const onKeyDown = (e) => {
1168
- const elements2 = queryFocusables(root);
1169
- if (elements2.length === 0) {
1170
- return;
1171
- }
1172
- let newIndex = -1;
1173
- if (e.code === "ArrowUp") {
1174
- if (index - rowLength < 0) {
1175
- newIndex = elements2.length - elements2.length % rowLength + index;
1176
- } else {
1177
- newIndex = index - rowLength;
1178
- }
1179
- } else if (e.code === "ArrowLeft") {
1180
- if (index <= 0) {
1181
- newIndex = elements2.length - 1;
1182
- } else {
1183
- newIndex = index - 1;
1161
+ return useRefEffect(
1162
+ useCallback(
1163
+ (root) => {
1164
+ if (!enabled) {
1165
+ return;
1184
1166
  }
1185
- } else if (e.code === "ArrowRight") {
1186
- if (index >= elements2.length - 1) {
1187
- newIndex = 0;
1188
- } else {
1189
- newIndex = index + 1;
1167
+ let index = 0;
1168
+ const elements = queryFocusables(root);
1169
+ if (elements.length === 0) {
1170
+ return;
1190
1171
  }
1191
- } else if (e.code === "ArrowDown") {
1192
- if (index + rowLength > elements2.length - 1) {
1193
- newIndex = (index + rowLength) % rowLength;
1172
+ if (elements.length !== 0 && autofocus) {
1173
+ focusElement(elements, index);
1194
1174
  } else {
1195
- newIndex = index + rowLength;
1175
+ normalizeElements(elements, index);
1196
1176
  }
1197
- }
1198
- if (newIndex !== -1 && index !== newIndex) {
1199
- index = newIndex;
1200
- focusElement(elements2, index);
1201
- e.preventDefault();
1202
- e.stopPropagation();
1203
- }
1204
- };
1205
- root.addEventListener("keydown", onKeyDown);
1206
- const observer = new MutationObserver((mutationList) => {
1207
- if (mutationList.filter((m) => m.type === "childList").length > 0) {
1208
- const elements2 = queryFocusables(root);
1209
- if (elements2.length > 0) {
1210
- normalizeElements(elements2, index);
1211
- }
1212
- }
1213
- });
1214
- observer.observe(root, { childList: true });
1215
- return () => {
1216
- root.removeEventListener("keydown", onKeyDown);
1217
- };
1218
- });
1177
+ const onKeyDown = (e) => {
1178
+ const elements2 = queryFocusables(root);
1179
+ if (elements2.length === 0) {
1180
+ return;
1181
+ }
1182
+ let newIndex = -1;
1183
+ if (e.code === "ArrowUp") {
1184
+ if (index - rowLength < 0) {
1185
+ newIndex = elements2.length - elements2.length % rowLength + index;
1186
+ } else {
1187
+ newIndex = index - rowLength;
1188
+ }
1189
+ } else if (e.code === "ArrowLeft") {
1190
+ if (index <= 0) {
1191
+ newIndex = elements2.length - 1;
1192
+ } else {
1193
+ newIndex = index - 1;
1194
+ }
1195
+ } else if (e.code === "ArrowRight") {
1196
+ if (index >= elements2.length - 1) {
1197
+ newIndex = 0;
1198
+ } else {
1199
+ newIndex = index + 1;
1200
+ }
1201
+ } else if (e.code === "ArrowDown") {
1202
+ if (index + rowLength > elements2.length - 1) {
1203
+ newIndex = (index + rowLength) % rowLength;
1204
+ } else {
1205
+ newIndex = index + rowLength;
1206
+ }
1207
+ }
1208
+ if (newIndex !== -1 && index !== newIndex) {
1209
+ index = newIndex;
1210
+ focusElement(elements2, index);
1211
+ e.preventDefault();
1212
+ e.stopPropagation();
1213
+ }
1214
+ };
1215
+ root.addEventListener("keydown", onKeyDown);
1216
+ const observer = new MutationObserver((mutationList) => {
1217
+ if (mutationList.filter((m) => m.type === "childList").length > 0) {
1218
+ const elements2 = queryFocusables(root);
1219
+ if (elements2.length > 0) {
1220
+ normalizeElements(elements2, index);
1221
+ }
1222
+ }
1223
+ });
1224
+ observer.observe(root, { childList: true });
1225
+ return () => {
1226
+ root.removeEventListener("keydown", onKeyDown);
1227
+ observer.disconnect();
1228
+ };
1229
+ },
1230
+ [autofocus, enabled, rowLength]
1231
+ )
1232
+ );
1219
1233
  }
1220
1234
  var ListContext = React34.createContext({ bare: false, carded: true });
1221
1235
  function List({
@@ -1488,7 +1502,7 @@ var Button = React34.forwardRef(
1488
1502
  );
1489
1503
  }
1490
1504
  );
1491
- var dateFormatter = Intl.DateTimeFormat("en-UK", {
1505
+ var dateFormatter = Intl.DateTimeFormat("en-GB", {
1492
1506
  weekday: "short"
1493
1507
  });
1494
1508
  var MON = dateFormatter.format(new Date(2e3, 1, 7));
@@ -1635,7 +1649,9 @@ var sizes3 = {
1635
1649
  small: 24,
1636
1650
  medium: 32,
1637
1651
  large: 40,
1638
- xlarge: 48
1652
+ xlarge: 48,
1653
+ xxlarge: 56,
1654
+ xxxlarge: 64
1639
1655
  };
1640
1656
  function StaticCheckbox({
1641
1657
  checked,
@@ -1859,6 +1875,32 @@ function DarkModeToggle() {
1859
1875
  }
1860
1876
  );
1861
1877
  }
1878
+
1879
+ // src/dateInputValue.ts
1880
+ var pad = (value) => value.toString().padStart(2, "0");
1881
+ function formatDateInputValue(date) {
1882
+ return `${date.getFullYear().toString().padStart(4, "0")}-${pad(
1883
+ date.getMonth() + 1
1884
+ )}-${pad(date.getDate())}`;
1885
+ }
1886
+ function parseDateInputValue(value) {
1887
+ const [year, month, day] = value.split("-").map(Number);
1888
+ return new Date(year, month - 1, day);
1889
+ }
1890
+ function formatDatetimeInputValue(date) {
1891
+ return `${formatDateInputValue(date)}T${pad(date.getHours())}:${pad(
1892
+ date.getMinutes()
1893
+ )}`;
1894
+ }
1895
+ function parseDatetimeInputValue(value) {
1896
+ const [date, time] = value.split("T");
1897
+ const [year, month, day] = date.split("-").map(Number);
1898
+ const [hour, minute] = time.split(":").map(Number);
1899
+ return new Date(year, month - 1, day, hour, minute);
1900
+ }
1901
+ function formatTimeInputValue(date) {
1902
+ return `${pad(date.getHours())}:${pad(date.getMinutes())}`;
1903
+ }
1862
1904
  var DateInput = React34.forwardRef(
1863
1905
  ({ date, onDateChange, jss, icon, addOn, ...inputProps }, ref) => {
1864
1906
  return /* @__PURE__ */ jsxs(
@@ -1875,8 +1917,12 @@ var DateInput = React34.forwardRef(
1875
1917
  ...inputProps,
1876
1918
  type: "date",
1877
1919
  ref,
1878
- value: date.toISOString().substring(0, 10),
1879
- onChange: (e) => onDateChange(new Date(e.target.value)),
1920
+ value: formatDateInputValue(date),
1921
+ onChange: (e) => {
1922
+ if (e.target.value) {
1923
+ onDateChange(parseDateInputValue(e.target.value));
1924
+ }
1925
+ },
1880
1926
  jss: [
1881
1927
  {
1882
1928
  flexGrow: 1,
@@ -1920,12 +1966,15 @@ function DatePicker({
1920
1966
  date,
1921
1967
  onDateChange
1922
1968
  }) {
1923
- const initialDate = useRef(date);
1924
- const year = initialDate.current.getFullYear();
1925
- const month = initialDate.current.getMonth();
1926
- const day = initialDate.current.getDate();
1927
- const min = new Date(year - 1, month, day).toISOString().substring(0, 10);
1928
- const max = new Date(year + 1, month, day).toISOString().substring(0, 10);
1969
+ const [{ min, max }] = useState(() => {
1970
+ const year = date.getFullYear();
1971
+ const month = date.getMonth();
1972
+ const day = date.getDate();
1973
+ return {
1974
+ min: formatDateInputValue(new Date(year - 1, month, day)),
1975
+ max: formatDateInputValue(new Date(year + 1, month, day))
1976
+ };
1977
+ });
1929
1978
  return /* @__PURE__ */ jsxs(Fragment, { children: [
1930
1979
  /* @__PURE__ */ jsx("label", { htmlFor: id, children: /* @__PURE__ */ jsx(Text, { size: "small", color, children: label }) }),
1931
1980
  /* @__PURE__ */ jsx(
@@ -1936,15 +1985,10 @@ function DatePicker({
1936
1985
  className: toClassnames(styles6.dateInput),
1937
1986
  type: "date",
1938
1987
  id,
1939
- value: date.toISOString().substring(0, 10),
1988
+ value: formatDateInputValue(date),
1940
1989
  onChange: (event) => {
1941
- let parsedDate;
1942
- try {
1943
- parsedDate = new Date(event.target.value);
1944
- } finally {
1945
- if (parsedDate != null) {
1946
- onDateChange(parsedDate);
1947
- }
1990
+ if (event.target.value) {
1991
+ onDateChange(parseDateInputValue(event.target.value));
1948
1992
  }
1949
1993
  }
1950
1994
  }
@@ -1982,8 +2026,12 @@ var DatetimeInput = React34.forwardRef(
1982
2026
  ...inputProps,
1983
2027
  type: "datetime-local",
1984
2028
  ref,
1985
- value: date.toISOString().substring(0, 16),
1986
- onChange: (e) => onDateChange(new Date(e.target.value)),
2029
+ value: formatDatetimeInputValue(date),
2030
+ onChange: (e) => {
2031
+ if (e.target.value) {
2032
+ onDateChange(parseDatetimeInputValue(e.target.value));
2033
+ }
2034
+ },
1987
2035
  jss: [styles7.input, jss]
1988
2036
  }
1989
2037
  ),
@@ -2147,15 +2195,17 @@ function Dropdown({
2147
2195
  const triggerRef = useRef(null);
2148
2196
  const [expanded, setExpanded] = useState(false);
2149
2197
  const dropdownRef = useNavigation({ autofocus: true });
2150
- const rootRef = useRefEffect((root) => {
2151
- const onKeyDown = (e) => {
2152
- if (e.code === "Escape") {
2153
- setExpanded(false);
2154
- }
2155
- };
2156
- root.addEventListener("keydown", onKeyDown);
2157
- return () => root.removeEventListener("keydown", onKeyDown);
2158
- });
2198
+ const rootRef = useRefEffect(
2199
+ useCallback((root) => {
2200
+ const onKeyDown = (e) => {
2201
+ if (e.code === "Escape") {
2202
+ setExpanded(false);
2203
+ }
2204
+ };
2205
+ root.addEventListener("keydown", onKeyDown);
2206
+ return () => root.removeEventListener("keydown", onKeyDown);
2207
+ }, [])
2208
+ );
2159
2209
  useEffect(() => {
2160
2210
  if (!expanded) {
2161
2211
  triggerRef.current && triggerRef.current.focus();
@@ -2263,7 +2313,9 @@ var sizes5 = {
2263
2313
  small: 24,
2264
2314
  medium: 32,
2265
2315
  large: 40,
2266
- xlarge: 48
2316
+ xlarge: 48,
2317
+ xxlarge: 56,
2318
+ xxxlarge: 64
2267
2319
  };
2268
2320
  var IconLink = React34.forwardRef(
2269
2321
  ({ icon, size, color, bare, disabled, jss, ...otherProps }, ref) => {
@@ -2667,47 +2719,53 @@ var styles11 = {
2667
2719
  };
2668
2720
  function Popover({ children, close }) {
2669
2721
  const activeElementRef = useRef(null);
2670
- const focusTrapRoot = useRefEffect((root) => {
2671
- activeElementRef.current = document.activeElement;
2672
- const [element] = queryFocusables(root);
2673
- element ? element.focus() : root.focus();
2674
- const keydown = (e) => {
2675
- if (e.key === "Escape") {
2676
- close();
2677
- } else if (e.key === "Tab") {
2678
- const focusables = queryFocusables(root).filter(
2679
- (element2) => element2.tabIndex !== -1
2680
- );
2681
- if (focusables.length === 0) {
2682
- e.stopPropagation();
2683
- e.preventDefault();
2684
- }
2685
- const focusedIndex = focusables.findIndex(
2686
- (x) => x === document.activeElement
2687
- );
2688
- if (focusables.length === 0) {
2689
- e.stopPropagation();
2690
- e.preventDefault();
2691
- } else if (focusedIndex === focusables.length - 1) {
2692
- focusables[0].focus();
2693
- e.stopPropagation();
2694
- e.preventDefault();
2695
- } else ;
2696
- }
2697
- };
2698
- const click = () => {
2699
- close();
2700
- };
2701
- setTimeout(() => {
2702
- window.addEventListener("keydown", keydown);
2703
- window.addEventListener("click", click);
2704
- }, 0);
2705
- return () => {
2706
- activeElementRef.current && activeElementRef.current.focus();
2707
- window.removeEventListener("keydown", keydown);
2708
- window.removeEventListener("click", click);
2709
- };
2710
- });
2722
+ const focusTrapRoot = useRefEffect(
2723
+ useCallback(
2724
+ (root) => {
2725
+ activeElementRef.current = document.activeElement;
2726
+ const [element] = queryFocusables(root);
2727
+ element ? element.focus() : root.focus();
2728
+ const keydown = (e) => {
2729
+ if (e.key === "Escape") {
2730
+ close();
2731
+ } else if (e.key === "Tab") {
2732
+ const focusables = queryFocusables(root).filter(
2733
+ (element2) => element2.tabIndex !== -1
2734
+ );
2735
+ if (focusables.length === 0) {
2736
+ e.stopPropagation();
2737
+ e.preventDefault();
2738
+ }
2739
+ const focusedIndex = focusables.findIndex(
2740
+ (x) => x === document.activeElement
2741
+ );
2742
+ if (focusables.length === 0) {
2743
+ e.stopPropagation();
2744
+ e.preventDefault();
2745
+ } else if (focusedIndex === focusables.length - 1) {
2746
+ focusables[0].focus();
2747
+ e.stopPropagation();
2748
+ e.preventDefault();
2749
+ } else ;
2750
+ }
2751
+ };
2752
+ const click = () => {
2753
+ close();
2754
+ };
2755
+ const timeout = window.setTimeout(() => {
2756
+ window.addEventListener("keydown", keydown);
2757
+ window.addEventListener("click", click);
2758
+ }, 0);
2759
+ return () => {
2760
+ window.clearTimeout(timeout);
2761
+ activeElementRef.current && activeElementRef.current.focus();
2762
+ window.removeEventListener("keydown", keydown);
2763
+ window.removeEventListener("click", click);
2764
+ };
2765
+ },
2766
+ [close]
2767
+ )
2768
+ );
2711
2769
  return /* @__PURE__ */ jsx(BaseView, { ref: focusTrapRoot, children });
2712
2770
  }
2713
2771
  function PopoverTrigger({
@@ -2795,7 +2853,9 @@ var sizes6 = {
2795
2853
  small: 8,
2796
2854
  medium: 12,
2797
2855
  large: 16,
2798
- xlarge: 20
2856
+ xlarge: 20,
2857
+ xxlarge: 28,
2858
+ xxxlarge: 36
2799
2859
  };
2800
2860
  function ProgressBar({
2801
2861
  color,
@@ -3493,7 +3553,6 @@ var TextArea = React34.forwardRef(
3493
3553
  jss,
3494
3554
  onValueChange,
3495
3555
  value,
3496
- onChange,
3497
3556
  padding = "medium",
3498
3557
  ...otherProps
3499
3558
  }, ref) => {
@@ -3647,9 +3706,10 @@ function TextInputWithState({
3647
3706
  );
3648
3707
  return /* @__PURE__ */ jsx(TextInput, { ...otherProps, value, onValueChange });
3649
3708
  }
3650
- var timeFormatter = Intl.DateTimeFormat("en-UK", {
3709
+ var timeFormatter = Intl.DateTimeFormat("en-GB", {
3651
3710
  hour: "2-digit",
3652
- minute: "2-digit"
3711
+ minute: "2-digit",
3712
+ hourCycle: "h23"
3653
3713
  });
3654
3714
  function TimeInputInternal({
3655
3715
  time: date,
@@ -3695,7 +3755,7 @@ function TimeInputInternal({
3695
3755
  ...inputProps,
3696
3756
  type: "time",
3697
3757
  ref,
3698
- value: timeFormatter.format(date),
3758
+ value: formatTimeInputValue(date),
3699
3759
  onChange: (e) => {
3700
3760
  const value = e.target.value;
3701
3761
  const [hour, minute] = value.split(":");
@@ -3754,34 +3814,37 @@ var styles13 = {
3754
3814
  function Tooltip({ content, jss, tag, children }) {
3755
3815
  const [tooltip, setTooltip] = useState(null);
3756
3816
  const dialogRef = useRef(null);
3757
- const focusTrapRoot = useRefEffect((root) => {
3758
- dialogRef.current = root;
3759
- const keydown = (e) => {
3760
- if (e.key === "Escape") {
3761
- dialogRef.current?.close();
3762
- } else if (e.key === "Tab") {
3817
+ const focusTrapRoot = useRefEffect(
3818
+ useCallback((root) => {
3819
+ dialogRef.current = root;
3820
+ const keydown = (e) => {
3821
+ if (e.key === "Escape") {
3822
+ dialogRef.current?.close();
3823
+ } else if (e.key === "Tab") {
3824
+ dialogRef.current?.close();
3825
+ }
3826
+ };
3827
+ const click = () => {
3763
3828
  dialogRef.current?.close();
3764
- }
3765
- };
3766
- const click = () => {
3767
- dialogRef.current?.close();
3768
- };
3769
- window.addEventListener("keydown", keydown);
3770
- window.addEventListener("click", click);
3771
- const activeElement = document.activeElement;
3772
- root.show();
3773
- activeElement.focus();
3774
- return () => {
3775
- window.removeEventListener("keydown", keydown);
3776
- window.removeEventListener("click", click);
3777
- };
3778
- });
3829
+ };
3830
+ window.addEventListener("keydown", keydown);
3831
+ window.addEventListener("click", click);
3832
+ const activeElement = document.activeElement;
3833
+ root.show();
3834
+ activeElement.focus();
3835
+ return () => {
3836
+ window.removeEventListener("keydown", keydown);
3837
+ window.removeEventListener("click", click);
3838
+ };
3839
+ }, [])
3840
+ );
3779
3841
  const toggle = () => {
3780
3842
  if (tooltip == null) {
3781
3843
  setTooltip(
3782
3844
  /* @__PURE__ */ jsx(
3783
3845
  "dialog",
3784
3846
  {
3847
+ role: "tooltip",
3785
3848
  ref: (ref) => {
3786
3849
  dialogRef.current = ref;
3787
3850
  focusTrapRoot(ref);
@@ -3825,35 +3888,38 @@ function Tooltip({ content, jss, tag, children }) {
3825
3888
  }
3826
3889
  );
3827
3890
  }
3828
-
3829
- // src/useKeyboard.tsx
3830
3891
  function useKeyboard(shortcuts) {
3831
- return useRefEffect((root) => {
3832
- const onKeyDown = (e) => {
3833
- for (const {
3834
- metaKey,
3835
- key,
3836
- action,
3837
- ctrlKey,
3838
- onlyWhenFocused
3839
- } of shortcuts) {
3840
- if (metaKey && e.metaKey !== true) {
3841
- continue;
3842
- } else if (ctrlKey && e.ctrlKey !== true) {
3843
- continue;
3844
- } else if (onlyWhenFocused && document.activeElement !== root) {
3845
- continue;
3846
- }
3847
- if (e.key.toLowerCase() === key.toLowerCase()) {
3848
- action(root);
3849
- }
3850
- }
3851
- };
3852
- window.addEventListener("keydown", onKeyDown);
3853
- return () => {
3854
- window.removeEventListener("keydown", onKeyDown);
3855
- };
3856
- });
3892
+ return useRefEffect(
3893
+ useCallback(
3894
+ (root) => {
3895
+ const onKeyDown = (e) => {
3896
+ for (const {
3897
+ metaKey,
3898
+ key,
3899
+ action,
3900
+ ctrlKey,
3901
+ onlyWhenFocused
3902
+ } of shortcuts) {
3903
+ if (metaKey && e.metaKey !== true) {
3904
+ continue;
3905
+ } else if (ctrlKey && e.ctrlKey !== true) {
3906
+ continue;
3907
+ } else if (onlyWhenFocused && document.activeElement !== root) {
3908
+ continue;
3909
+ }
3910
+ if (e.key.toLowerCase() === key.toLowerCase()) {
3911
+ action(root);
3912
+ }
3913
+ }
3914
+ };
3915
+ window.addEventListener("keydown", onKeyDown);
3916
+ return () => {
3917
+ window.removeEventListener("keydown", onKeyDown);
3918
+ };
3919
+ },
3920
+ [shortcuts]
3921
+ )
3922
+ );
3857
3923
  }
3858
3924
  function usePromise(promiseFactory, inputs, initialValue) {
3859
3925
  const [value, setValue] = useState(initialValue);