@swan-io/lake 15.3.1 → 15.5.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.
Files changed (122) hide show
  1. package/package.json +5 -5
  2. package/src/components/Accordion.d.ts +1 -1
  3. package/src/components/AppOpeningAnimation.d.ts +1 -1
  4. package/src/components/AutoWidthImage.d.ts +1 -1
  5. package/src/components/AutocompleteSearchInput.d.ts +1 -1
  6. package/src/components/AutocompleteSearchInput.js +2 -2
  7. package/src/components/Avatar.js +3 -6
  8. package/src/components/BorderedIcon.d.ts +1 -1
  9. package/src/components/BottomPanel.d.ts +1 -1
  10. package/src/components/Box.d.ts +1 -1
  11. package/src/components/Breadcrumbs.d.ts +2 -2
  12. package/src/components/Breadcrumbs.js +4 -6
  13. package/src/components/BulletList.d.ts +10 -0
  14. package/src/components/BulletList.js +12 -0
  15. package/src/components/Cells.d.ts +6 -6
  16. package/src/components/Cells.js +1 -1
  17. package/src/components/ContextMenu.d.ts +2 -2
  18. package/src/components/ContextMenu.js +1 -1
  19. package/src/components/EmptyView.d.ts +1 -1
  20. package/src/components/EmptyView.js +1 -1
  21. package/src/components/Fill.d.ts +1 -1
  22. package/src/components/FlatList.d.ts +1 -1
  23. package/src/components/FlatList.js +3 -3
  24. package/src/components/FlowPresentation.d.ts +1 -1
  25. package/src/components/FocusTrap.d.ts +1 -1
  26. package/src/components/Form.d.ts +120 -123
  27. package/src/components/FullViewportLayer.d.ts +1 -1
  28. package/src/components/Grid.d.ts +1 -1
  29. package/src/components/Icon.js +1 -1
  30. package/src/components/InputError.d.ts +1 -1
  31. package/src/components/LakeAlert.d.ts +1 -1
  32. package/src/components/LakeAlert.js +6 -5
  33. package/src/components/LakeButton.d.ts +2 -2
  34. package/src/components/LakeButton.js +1 -1
  35. package/src/components/LakeCheckbox.d.ts +2 -2
  36. package/src/components/LakeCheckbox.js +2 -2
  37. package/src/components/LakeCombobox.d.ts +1 -1
  38. package/src/components/LakeCopyButton.d.ts +1 -1
  39. package/src/components/LakeDownloadButton.d.ts +1 -1
  40. package/src/components/LakeHeading.d.ts +1 -1
  41. package/src/components/LakeLabel.d.ts +1 -1
  42. package/src/components/LakeLabel.js +2 -2
  43. package/src/components/LakeRadio.d.ts +1 -1
  44. package/src/components/LakeScrollView.d.ts +1 -1
  45. package/src/components/LakeSelect.d.ts +1 -1
  46. package/src/components/LakeSelect.js +8 -10
  47. package/src/components/LakeSlider.d.ts +1 -1
  48. package/src/components/LakeStepper.d.ts +3 -3
  49. package/src/components/LakeStepper.js +3 -3
  50. package/src/components/LakeTagInput.d.ts +1 -1
  51. package/src/components/LakeText.d.ts +1 -1
  52. package/src/components/LakeTextInput.d.ts +1 -1
  53. package/src/components/LakeTextInput.js +1 -1
  54. package/src/components/LakeTooltip.d.ts +4 -3
  55. package/src/components/LakeTooltip.js +4 -4
  56. package/src/components/Link.d.ts +1 -1
  57. package/src/components/ListRightPanel.d.ts +2 -2
  58. package/src/components/LoadingView.d.ts +1 -1
  59. package/src/components/MultiSelect.d.ts +1 -1
  60. package/src/components/MultiSelect.js +2 -2
  61. package/src/components/PlainListView.d.ts +3 -9
  62. package/src/components/PlainListView.js +1 -1
  63. package/src/components/PopoverContent.d.ts +1 -1
  64. package/src/components/Pressable.js +3 -3
  65. package/src/components/ProgressTracker.d.ts +22 -0
  66. package/src/components/ProgressTracker.js +71 -0
  67. package/src/components/ProjectEnvTag.d.ts +1 -1
  68. package/src/components/QuickActions.d.ts +1 -1
  69. package/src/components/QuickActions.js +6 -9
  70. package/src/components/RadioGroup.d.ts +1 -1
  71. package/src/components/RadioGroup.js +1 -1
  72. package/src/components/ReadOnlyFieldList.d.ts +1 -1
  73. package/src/components/ReadOnlyFieldList.js +1 -1
  74. package/src/components/ResponsiveContainer.d.ts +1 -1
  75. package/src/components/RightPanel.d.ts +1 -1
  76. package/src/components/RightPanel.js +1 -1
  77. package/src/components/ScrollView.d.ts +1 -1
  78. package/src/components/SectionList.d.ts +1 -1
  79. package/src/components/SectionList.js +3 -3
  80. package/src/components/SegmentedControl.d.ts +1 -1
  81. package/src/components/SegmentedControl.js +1 -1
  82. package/src/components/Separator.d.ts +1 -1
  83. package/src/components/SidebarNavigationTracker.d.ts +2 -2
  84. package/src/components/SidebarNavigationTracker.js +2 -1
  85. package/src/components/SmsOpeningAnimation.d.ts +1 -1
  86. package/src/components/SortBottomPanel.d.ts +1 -1
  87. package/src/components/Space.d.ts +1 -1
  88. package/src/components/Stack.d.ts +1 -1
  89. package/src/components/StepDots.d.ts +1 -1
  90. package/src/components/Suspendable.d.ts +1 -1
  91. package/src/components/Suspendable.js +1 -1
  92. package/src/components/Svg.d.ts +10 -10
  93. package/src/components/Svg.js +1 -1
  94. package/src/components/SwanLogo.d.ts +1 -1
  95. package/src/components/Switch.d.ts +2 -1
  96. package/src/components/Switch.js +2 -2
  97. package/src/components/TabView.d.ts +1 -1
  98. package/src/components/TabView.js +4 -4
  99. package/src/components/Tag.d.ts +1 -1
  100. package/src/components/Tag.js +1 -1
  101. package/src/components/Tick.d.ts +1 -1
  102. package/src/components/Tile.d.ts +13 -6
  103. package/src/components/Tile.js +32 -6
  104. package/src/components/TilePlaceholder.d.ts +4 -2
  105. package/src/components/TilePlaceholder.js +3 -3
  106. package/src/components/TimePicker.d.ts +2 -2
  107. package/src/components/Toggle.d.ts +1 -1
  108. package/src/components/Toggle.js +1 -1
  109. package/src/components/TransitionGroupView.d.ts +1 -1
  110. package/src/components/TransitionGroupView.js +1 -1
  111. package/src/components/TransitionView.d.ts +1 -1
  112. package/src/components/VirtualizedList.d.ts +2 -2
  113. package/src/components/VirtualizedList.js +2 -2
  114. package/src/components/WithCurrentColor.d.ts +2 -2
  115. package/src/components/WithPartnerAccentColor.d.ts +1 -1
  116. package/src/hooks/useContextualLayer.d.ts +1 -0
  117. package/src/hooks/useContextualLayer.js +16 -8
  118. package/src/hooks/useUpdateEffect.js +1 -2
  119. package/src/utils/array.js +1 -1
  120. package/src/utils/highlights.js +2 -1
  121. package/src/utils/string.js +1 -1
  122. package/src/utils/svg.js +5 -5
@@ -4,5 +4,5 @@ type Props = {
4
4
  children: ReactNode;
5
5
  scoped?: boolean;
6
6
  };
7
- export declare const WithPartnerAccentColor: ({ color, scoped, children }: Props) => import("react/jsx-runtime").JSX.Element;
7
+ export declare const WithPartnerAccentColor: ({ color, scoped, children }: Props) => import("react").JSX.Element;
8
8
  export {};
@@ -33,6 +33,7 @@ export type ContextualLayerPosition = {
33
33
  };
34
34
  type ContextualLayerConfig = {
35
35
  referenceRef: RefObject<View | Text | null>;
36
+ contentRef: RefObject<View | Text | null>;
36
37
  position: Option<ContextualLayerPosition>;
37
38
  };
38
39
  export declare const useContextualLayer: ({ placement, verticalPlacement, visible, matchReferenceWidth, matchReferenceMinWidth, referenceRef: externalReferenceRef, }: Config) => ContextualLayerConfig;
@@ -1,10 +1,10 @@
1
1
  import { Option } from "@swan-io/boxed";
2
2
  import { useCallback, useEffect, useRef, useState } from "react";
3
3
  import { match } from "ts-pattern";
4
- const MAX_OFFSET_FOR_CENTER_PLACEMENT = 100;
5
4
  const HORIZONTAL_SAFETY_MARGIN = 16;
6
- export const useContextualLayer = ({ placement, verticalPlacement, visible, matchReferenceWidth = false, matchReferenceMinWidth = false, referenceRef: externalReferenceRef, }) => {
5
+ export const useContextualLayer = ({ placement = "left", verticalPlacement, visible, matchReferenceWidth = false, matchReferenceMinWidth = false, referenceRef: externalReferenceRef, }) => {
7
6
  const referenceRef = useRef(null);
7
+ const contentRef = useRef(null);
8
8
  const usedRef = externalReferenceRef !== null && externalReferenceRef !== void 0 ? externalReferenceRef : referenceRef;
9
9
  const [position, setPosition] = useState(Option.None());
10
10
  const getPosition = useCallback(() => {
@@ -21,12 +21,19 @@ export const useContextualLayer = ({ placement, verticalPlacement, visible, matc
21
21
  const availableSpaceAfter = viewportWidth - rect.right;
22
22
  const height = rect.bottom - rect.top;
23
23
  const width = rect.right - rect.left;
24
- const isCenteredEnough = Math.abs(availableSpaceBefore - availableSpaceAfter) < MAX_OFFSET_FOR_CENTER_PLACEMENT;
25
- const inferedPlacement = placement !== null && placement !== void 0 ? placement : (isCenteredEnough
26
- ? "center"
27
- : availableSpaceBefore > availableSpaceAfter
28
- ? "right"
29
- : "left");
24
+ const contentElement = contentRef.current;
25
+ // if contentRef isn't used in the component, we don't infer the placement depending on content size
26
+ const contentRect = contentElement != null ? contentElement.getBoundingClientRect() : { width: 0, height: 0 };
27
+ const contentWidth = contentRect.width;
28
+ const contentMidWidth = contentWidth / 2;
29
+ const isCenteredEnough = availableSpaceBefore > contentMidWidth && availableSpaceAfter > contentMidWidth;
30
+ const bestPlacement = availableSpaceBefore > availableSpaceAfter ? "right" : "left";
31
+ const inferedPlacement = match(placement)
32
+ .returnType()
33
+ .with("center", () => (isCenteredEnough ? "center" : bestPlacement))
34
+ .with("left", () => (availableSpaceBefore > contentWidth ? "left" : bestPlacement))
35
+ .with("right", () => (availableSpaceAfter > contentWidth ? "right" : bestPlacement))
36
+ .exhaustive();
30
37
  const openAbove = verticalPlacement === "above"
31
38
  ? true
32
39
  : verticalPlacement === "below"
@@ -93,6 +100,7 @@ export const useContextualLayer = ({ placement, verticalPlacement, visible, matc
93
100
  }, [visible, getPosition]);
94
101
  return {
95
102
  referenceRef: usedRef,
103
+ contentRef,
96
104
  position,
97
105
  };
98
106
  };
@@ -2,11 +2,10 @@ import { useEffect } from "react";
2
2
  import { useFirstMountState } from "./useFirstMountState";
3
3
  export const useUpdateEffect = (effect, deps) => {
4
4
  const isFirstMount = useFirstMountState();
5
- // biome-ignore lint/correctness/useExhaustiveDependencies(effect):
6
- // biome-ignore lint/correctness/useExhaustiveDependencies(isFirstMount):
7
5
  useEffect(() => {
8
6
  if (!isFirstMount) {
9
7
  return effect();
10
8
  }
9
+ // biome-ignore lint/correctness/useExhaustiveDependencies: rerun effect only when deps change
11
10
  }, deps);
12
11
  };
@@ -1,5 +1,5 @@
1
1
  export const sortBy = (array, keys) => {
2
- return [...array].sort((a, b) => {
2
+ return array.toSorted((a, b) => {
3
3
  let index = -1;
4
4
  while (++index < keys.length) {
5
5
  const key = keys[index];
@@ -1,7 +1,8 @@
1
1
  import { isNullishOrEmpty } from "./nullish";
2
2
  const highlightName = "lake-highlight";
3
3
  export const setHighlightApi = (text, element, minLength = 2) => {
4
- var _a, _b;
4
+ var _a;
5
+ var _b;
5
6
  if (!("highlights" in CSS)) {
6
7
  return;
7
8
  }
@@ -233,4 +233,4 @@ export const upperCase = (value) => value.toUpperCase();
233
233
  export const capitalize = (value) => `${value.charAt(0).toUpperCase()}${value.slice(1)}`;
234
234
  export const uncapitalize = (value) => `${value.charAt(0).toLowerCase()}${value.slice(1)}`;
235
235
  export const optionFromString = (value) => value !== "" ? Option.Some(value) : Option.None();
236
- export const getFlagGlyphName = (flag) => { var _a, _b, _c, _d; return `${(_b = (_a = flag.codePointAt(0)) === null || _a === void 0 ? void 0 : _a.toString(16)) !== null && _b !== void 0 ? _b : ""}-${(_d = (_c = flag.codePointAt(2)) === null || _c === void 0 ? void 0 : _c.toString(16)) !== null && _d !== void 0 ? _d : ""}`; };
236
+ export const getFlagGlyphName = (flag) => { var _a, _b; var _c, _d; return `${(_c = (_a = flag.codePointAt(0)) === null || _a === void 0 ? void 0 : _a.toString(16)) !== null && _c !== void 0 ? _c : ""}-${(_d = (_b = flag.codePointAt(2)) === null || _b === void 0 ? void 0 : _b.toString(16)) !== null && _d !== void 0 ? _d : ""}`; };
package/src/utils/svg.js CHANGED
@@ -11,16 +11,16 @@ export const getSvgSize = (svg) => {
11
11
  // first we try to get width and height from "width" and "height" attributes
12
12
  const widthAttr = svg.getAttribute("width");
13
13
  const heightAttr = svg.getAttribute("height");
14
- const width = isNotNullish(widthAttr) ? Number.parseInt(widthAttr) : Number.NaN;
15
- const height = isNotNullish(heightAttr) ? Number.parseInt(heightAttr) : Number.NaN;
14
+ const width = isNotNullish(widthAttr) ? Number.parseInt(widthAttr, 10) : Number.NaN;
15
+ const height = isNotNullish(heightAttr) ? Number.parseInt(heightAttr, 10) : Number.NaN;
16
16
  if (!Number.isNaN(width) || !Number.isNaN(height)) {
17
17
  return Result.Ok({ width, height });
18
18
  }
19
19
  // if height and width aren't provided, we get values from viewBox attribute
20
20
  const viewBox = svg.getAttribute("viewBox");
21
21
  const [, , boxWidthAttr, boxHeightAttr] = (_a = viewBox === null || viewBox === void 0 ? void 0 : viewBox.split(" ")) !== null && _a !== void 0 ? _a : [];
22
- const boxWidth = isNotNullish(boxWidthAttr) ? Number.parseInt(boxWidthAttr) : Number.NaN;
23
- const boxHeight = isNotNullish(boxHeightAttr) ? Number.parseInt(boxHeightAttr) : Number.NaN;
22
+ const boxWidth = isNotNullish(boxWidthAttr) ? Number.parseInt(boxWidthAttr, 10) : Number.NaN;
23
+ const boxHeight = isNotNullish(boxHeightAttr) ? Number.parseInt(boxHeightAttr, 10) : Number.NaN;
24
24
  if (Number.isNaN(boxWidth) || Number.isNaN(boxHeight)) {
25
25
  return Result.Error("VIEWBOX_MISSING");
26
26
  }
@@ -68,7 +68,7 @@ const getMatrixColor = (color) => {
68
68
  const green = colorIntensity;
69
69
  const blue = colorIntensity;
70
70
  const alpha = 1;
71
- // prettier-ignore
71
+ // biome-ignore format: keep matrix format for readability
72
72
  const matrix = [
73
73
  red, red, red, red, red, // R
74
74
  green, green, green, green, green, // G