@canonical/react-ds-core 0.9.0-experimental.5 → 0.9.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 (113) hide show
  1. package/README.md +1 -1
  2. package/dist/esm/ui/Button/Button.js +2 -2
  3. package/dist/esm/ui/Button/Button.js.map +1 -1
  4. package/dist/esm/ui/Button/types.js +10 -0
  5. package/dist/esm/ui/Button/types.js.map +1 -1
  6. package/dist/esm/ui/Tooltip/Tooltip.js +18 -0
  7. package/dist/esm/ui/Tooltip/Tooltip.js.map +1 -0
  8. package/dist/esm/ui/Tooltip/common/TooltipArea/TooltipArea.js +38 -0
  9. package/dist/esm/ui/Tooltip/common/TooltipArea/TooltipArea.js.map +1 -0
  10. package/dist/esm/ui/Tooltip/common/TooltipArea/index.js +4 -0
  11. package/dist/esm/ui/Tooltip/common/TooltipArea/index.js.map +1 -0
  12. package/dist/esm/ui/Tooltip/common/TooltipArea/styles.css +13 -0
  13. package/dist/esm/ui/Tooltip/common/TooltipArea/types.js +2 -0
  14. package/dist/esm/ui/Tooltip/common/TooltipArea/types.js.map +1 -0
  15. package/dist/esm/ui/Tooltip/common/index.js +2 -0
  16. package/dist/esm/ui/Tooltip/common/index.js.map +1 -0
  17. package/dist/esm/ui/Tooltip/index.js +6 -0
  18. package/dist/esm/ui/Tooltip/index.js.map +1 -0
  19. package/dist/esm/ui/Tooltip/styles.css +122 -0
  20. package/dist/esm/ui/Tooltip/types.js +2 -0
  21. package/dist/esm/ui/Tooltip/types.js.map +1 -0
  22. package/dist/esm/ui/Tooltip/withTooltip.js +18 -0
  23. package/dist/esm/ui/Tooltip/withTooltip.js.map +1 -0
  24. package/dist/esm/ui/hooks/index.js +6 -0
  25. package/dist/esm/ui/hooks/index.js.map +1 -0
  26. package/dist/esm/ui/hooks/useDelayedToggle/index.js +3 -0
  27. package/dist/esm/ui/hooks/useDelayedToggle/index.js.map +1 -0
  28. package/dist/esm/ui/hooks/useDelayedToggle/types.js +2 -0
  29. package/dist/esm/ui/hooks/useDelayedToggle/types.js.map +1 -0
  30. package/dist/esm/ui/hooks/useDelayedToggle/useDelayedToggle.js +45 -0
  31. package/dist/esm/ui/hooks/useDelayedToggle/useDelayedToggle.js.map +1 -0
  32. package/dist/esm/ui/hooks/usePopup/index.js +3 -0
  33. package/dist/esm/ui/hooks/usePopup/index.js.map +1 -0
  34. package/dist/esm/ui/hooks/usePopup/types.js +2 -0
  35. package/dist/esm/ui/hooks/usePopup/types.js.map +1 -0
  36. package/dist/esm/ui/hooks/usePopup/usePopup.js +94 -0
  37. package/dist/esm/ui/hooks/usePopup/usePopup.js.map +1 -0
  38. package/dist/esm/ui/hooks/useResizeObserver/index.js +3 -0
  39. package/dist/esm/ui/hooks/useResizeObserver/index.js.map +1 -0
  40. package/dist/esm/ui/hooks/useResizeObserver/types.js +2 -0
  41. package/dist/esm/ui/hooks/useResizeObserver/types.js.map +1 -0
  42. package/dist/esm/ui/hooks/useResizeObserver/useResizeObserver.js +32 -0
  43. package/dist/esm/ui/hooks/useResizeObserver/useResizeObserver.js.map +1 -0
  44. package/dist/esm/ui/hooks/useWindowDimensions/index.js +3 -0
  45. package/dist/esm/ui/hooks/useWindowDimensions/index.js.map +1 -0
  46. package/dist/esm/ui/hooks/useWindowDimensions/types.js +2 -0
  47. package/dist/esm/ui/hooks/useWindowDimensions/types.js.map +1 -0
  48. package/dist/esm/ui/hooks/useWindowDimensions/useWindowDimensions.js +47 -0
  49. package/dist/esm/ui/hooks/useWindowDimensions/useWindowDimensions.js.map +1 -0
  50. package/dist/esm/ui/hooks/useWindowFitment/index.js +3 -0
  51. package/dist/esm/ui/hooks/useWindowFitment/index.js.map +1 -0
  52. package/dist/esm/ui/hooks/useWindowFitment/types.js +2 -0
  53. package/dist/esm/ui/hooks/useWindowFitment/types.js.map +1 -0
  54. package/dist/esm/ui/hooks/useWindowFitment/useWindowFitment.js +221 -0
  55. package/dist/esm/ui/hooks/useWindowFitment/useWindowFitment.js.map +1 -0
  56. package/dist/esm/ui/index.js +1 -0
  57. package/dist/esm/ui/index.js.map +1 -1
  58. package/dist/types/ui/Button/Button.d.ts +1 -1
  59. package/dist/types/ui/Button/Button.d.ts.map +1 -1
  60. package/dist/types/ui/Button/types.d.ts +9 -6
  61. package/dist/types/ui/Button/types.d.ts.map +1 -1
  62. package/dist/types/ui/Chip/Chip.d.ts.map +1 -1
  63. package/dist/types/ui/Tooltip/Tooltip.d.ts +12 -0
  64. package/dist/types/ui/Tooltip/Tooltip.d.ts.map +1 -0
  65. package/dist/types/ui/Tooltip/common/TooltipArea/TooltipArea.d.ts +10 -0
  66. package/dist/types/ui/Tooltip/common/TooltipArea/TooltipArea.d.ts.map +1 -0
  67. package/dist/types/ui/Tooltip/common/TooltipArea/index.d.ts +3 -0
  68. package/dist/types/ui/Tooltip/common/TooltipArea/index.d.ts.map +1 -0
  69. package/dist/types/ui/Tooltip/common/TooltipArea/types.d.ts +35 -0
  70. package/dist/types/ui/Tooltip/common/TooltipArea/types.d.ts.map +1 -0
  71. package/dist/types/ui/Tooltip/common/index.d.ts +2 -0
  72. package/dist/types/ui/Tooltip/common/index.d.ts.map +1 -0
  73. package/dist/types/ui/Tooltip/index.d.ts +5 -0
  74. package/dist/types/ui/Tooltip/index.d.ts.map +1 -0
  75. package/dist/types/ui/Tooltip/types.d.ts +16 -0
  76. package/dist/types/ui/Tooltip/types.d.ts.map +1 -0
  77. package/dist/types/ui/Tooltip/withTooltip.d.ts +11 -0
  78. package/dist/types/ui/Tooltip/withTooltip.d.ts.map +1 -0
  79. package/dist/types/ui/hooks/index.d.ts +6 -0
  80. package/dist/types/ui/hooks/index.d.ts.map +1 -0
  81. package/dist/types/ui/hooks/useDelayedToggle/index.d.ts +3 -0
  82. package/dist/types/ui/hooks/useDelayedToggle/index.d.ts.map +1 -0
  83. package/dist/types/ui/hooks/useDelayedToggle/types.d.ts +27 -0
  84. package/dist/types/ui/hooks/useDelayedToggle/types.d.ts.map +1 -0
  85. package/dist/types/ui/hooks/useDelayedToggle/useDelayedToggle.d.ts +13 -0
  86. package/dist/types/ui/hooks/useDelayedToggle/useDelayedToggle.d.ts.map +1 -0
  87. package/dist/types/ui/hooks/usePopup/index.d.ts +3 -0
  88. package/dist/types/ui/hooks/usePopup/index.d.ts.map +1 -0
  89. package/dist/types/ui/hooks/usePopup/types.d.ts +65 -0
  90. package/dist/types/ui/hooks/usePopup/types.d.ts.map +1 -0
  91. package/dist/types/ui/hooks/usePopup/usePopup.d.ts +19 -0
  92. package/dist/types/ui/hooks/usePopup/usePopup.d.ts.map +1 -0
  93. package/dist/types/ui/hooks/useResizeObserver/index.d.ts +3 -0
  94. package/dist/types/ui/hooks/useResizeObserver/index.d.ts.map +1 -0
  95. package/dist/types/ui/hooks/useResizeObserver/types.d.ts +7 -0
  96. package/dist/types/ui/hooks/useResizeObserver/types.d.ts.map +1 -0
  97. package/dist/types/ui/hooks/useResizeObserver/useResizeObserver.d.ts +8 -0
  98. package/dist/types/ui/hooks/useResizeObserver/useResizeObserver.d.ts.map +1 -0
  99. package/dist/types/ui/hooks/useWindowDimensions/index.d.ts +3 -0
  100. package/dist/types/ui/hooks/useWindowDimensions/index.d.ts.map +1 -0
  101. package/dist/types/ui/hooks/useWindowDimensions/types.d.ts +21 -0
  102. package/dist/types/ui/hooks/useWindowDimensions/types.d.ts.map +1 -0
  103. package/dist/types/ui/hooks/useWindowDimensions/useWindowDimensions.d.ts +6 -0
  104. package/dist/types/ui/hooks/useWindowDimensions/useWindowDimensions.d.ts.map +1 -0
  105. package/dist/types/ui/hooks/useWindowFitment/index.d.ts +3 -0
  106. package/dist/types/ui/hooks/useWindowFitment/index.d.ts.map +1 -0
  107. package/dist/types/ui/hooks/useWindowFitment/types.d.ts +73 -0
  108. package/dist/types/ui/hooks/useWindowFitment/types.d.ts.map +1 -0
  109. package/dist/types/ui/hooks/useWindowFitment/useWindowFitment.d.ts +4 -0
  110. package/dist/types/ui/hooks/useWindowFitment/useWindowFitment.d.ts.map +1 -0
  111. package/dist/types/ui/index.d.ts +1 -0
  112. package/dist/types/ui/index.d.ts.map +1 -1
  113. package/package.json +23 -24
@@ -0,0 +1,65 @@
1
+ import type { CSSProperties, FocusEventHandler, PointerEventHandler, RefObject } from "react";
2
+ import type { UseDelayedToggleProps } from "../useDelayedToggle/index.js";
3
+ import type { UseWindowFitmentProps, UseWindowFitmentResult } from "../useWindowFitment/index.js";
4
+ export interface UsePopupProps extends UseWindowFitmentProps, UseDelayedToggleProps {
5
+ /** A callback to be called when the target element is focused. */
6
+ onFocus?: FocusEventHandler;
7
+ /** A callback to be called when the target element loses focus. */
8
+ onBlur?: FocusEventHandler;
9
+ /** A callback to be called when the mouse enters the target element. */
10
+ onEnter?: PointerEventHandler;
11
+ /** A callback to be called when the mouse leaves the target */
12
+ onLeave?: PointerEventHandler;
13
+ /** A callback to be called when the popup is shown. */
14
+ onShow?: (event?: Event) => void;
15
+ /** A callback to be called when the popup is hidden. */
16
+ onHide?: (event?: Event) => void;
17
+ /** Whether the popup should close when the escape key is pressed. Defaults to true. */
18
+ closeOnEscape?: boolean;
19
+ }
20
+ export type DisableableElement = HTMLElement & {
21
+ disabled: boolean;
22
+ };
23
+ export interface UsePopupResult extends UseWindowFitmentResult {
24
+ /**
25
+ * A ref to be attached to the target element.
26
+ */
27
+ targetRef: RefObject<HTMLDivElement | null>;
28
+ /**
29
+ * A ref to be attached to the popup element.
30
+ */
31
+ popupRef: RefObject<HTMLDivElement | null>;
32
+ /**
33
+ * The style object to be applied to the popup element.
34
+ */
35
+ popupPositionStyle: CSSProperties;
36
+ /**
37
+ * A unique ID for the popup element. This can be used to associate a trigger with a popup, using `aria-describedby`.
38
+ */
39
+ popupId: string;
40
+ /**
41
+ * Whether the popup is currently open.
42
+ */
43
+ isOpen: boolean;
44
+ /**
45
+ * Whether the target element is currently focused.
46
+ */
47
+ isFocused: boolean;
48
+ /**
49
+ * Event handler for when the target element is focused.
50
+ */
51
+ handleTriggerFocus: FocusEventHandler;
52
+ /**
53
+ * Event handler for when the target element loses focus.
54
+ */
55
+ handleTriggerBlur: FocusEventHandler;
56
+ /**
57
+ * Event handler for when the mouse enters the target element.
58
+ */
59
+ handleTriggerEnter: PointerEventHandler;
60
+ /**
61
+ * Event handler for when the mouse leaves the target element.
62
+ */
63
+ handleTriggerLeave: PointerEventHandler;
64
+ }
65
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/usePopup/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,EACV,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EACV,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,WAAW,aACf,SAAQ,qBAAqB,EAC3B,qBAAqB;IACvB,kEAAkE;IAClE,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,mEAAmE;IACnE,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,wEAAwE;IACxE,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,+DAA+D;IAC/D,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,uDAAuD;IACvD,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,wDAAwD;IACxD,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,uFAAuF;IACvF,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG;IAC7C,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,cAAe,SAAQ,sBAAsB;IAC5D;;OAEG;IACH,SAAS,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC5C;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC3C;;OAEG;IACH,kBAAkB,EAAE,aAAa,CAAC;IAClC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,SAAS,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,kBAAkB,EAAE,iBAAiB,CAAC;IACtC;;OAEG;IACH,iBAAiB,EAAE,iBAAiB,CAAC;IACrC;;OAEG;IACH,kBAAkB,EAAE,mBAAmB,CAAC;IACxC;;OAEG;IACH,kBAAkB,EAAE,mBAAmB,CAAC;CACzC"}
@@ -0,0 +1,19 @@
1
+ import type { UsePopupProps, UsePopupResult } from "./types.js";
2
+ /**
3
+ * Manages the state of a popup.
4
+ * @param isOpen An override for the open state.
5
+ * @param deactivateDelay The delay in milliseconds before setting the flag to false.
6
+ * @param activateDelay The delay in milliseconds before setting the flag to true.
7
+ * @param onEnter A callback to be called when the mouse enters the target element.
8
+ * @param onLeave A callback to be called when the mouse leaves the target element.
9
+ * @param onFocus A callback to be called when the target element is focused.
10
+ * @param onBlur A callback to be called when the target element loses focus.
11
+ * @param onShow A callback to be called when the popup is shown.
12
+ * @param onHide A callback to be called when the popup is hidden.
13
+ * @param closeOnEscape Whether the popup should close when the escape key is pressed. Defaults to true.
14
+ * @param props The props to be passed to the useWindowFitment hook.
15
+ * @returns The current state of the popup, and event handlers for the target element.
16
+ */
17
+ declare const usePopup: ({ isOpen: isOpenProp, deactivateDelay, activateDelay, onEnter, onLeave, onFocus, onBlur, onShow, onHide, closeOnEscape, ...props }: UsePopupProps) => UsePopupResult;
18
+ export default usePopup;
19
+ //# sourceMappingURL=usePopup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePopup.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/usePopup/usePopup.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAEV,aAAa,EACb,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;GAcG;AACH,QAAA,MAAM,QAAQ,GAAI,oIAYf,aAAa,KAAG,cA4FlB,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { default as useResizeObserver } from "./useResizeObserver.js";
2
+ export * from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/useResizeObserver/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACtE,cAAc,YAAY,CAAC"}
@@ -0,0 +1,7 @@
1
+ export interface UseResizeObserverResult {
2
+ /** The width of the observed element */
3
+ width: number;
4
+ /** The height of the observed element */
5
+ height: number;
6
+ }
7
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/useResizeObserver/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,uBAAuB;IACtC,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,8 @@
1
+ import type { UseResizeObserverResult } from "./types.js";
2
+ /**
3
+ * Hook to observe the size of an element.
4
+ * @param element The element to observe.
5
+ * @returns The size of the element.
6
+ */
7
+ export default function useResizeObserver<TElement extends HTMLElement>(element?: TElement | null): UseResizeObserverResult;
8
+ //# sourceMappingURL=useResizeObserver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useResizeObserver.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/useResizeObserver/useResizeObserver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAE1D;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,QAAQ,SAAS,WAAW,EACpE,OAAO,CAAC,EAAE,QAAQ,GAAG,IAAI,GACxB,uBAAuB,CA4BzB"}
@@ -0,0 +1,3 @@
1
+ export { default as useWindowDimensions } from "./useWindowDimensions.js";
2
+ export * from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/useWindowDimensions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC1E,cAAc,YAAY,CAAC"}
@@ -0,0 +1,21 @@
1
+ export interface UseWindowDimensionProps {
2
+ /** Delay in milliseconds before the resize event is triggered */
3
+ resizeDelay?: number;
4
+ /** Delay in milliseconds before the scroll event is triggered */
5
+ scrollDelay?: number;
6
+ /** Callback to be called when the window is resized */
7
+ onResize?: (dimensions: UseWindowDimensionsResult) => void;
8
+ /** Callback to be called when the window is scrolled */
9
+ onScroll?: (dimensions: UseWindowDimensionsResult) => void;
10
+ }
11
+ export interface UseWindowDimensionsResult {
12
+ /** The width of the window */
13
+ windowWidth: number;
14
+ /** The height of the window */
15
+ windowHeight: number;
16
+ /** The horizontal scroll position */
17
+ scrollWidth: number;
18
+ /** The vertical scroll position */
19
+ scrollHeight: number;
20
+ }
21
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/useWindowDimensions/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,uBAAuB;IACtC,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,yBAAyB,KAAK,IAAI,CAAC;IAC3D,wDAAwD;IACxD,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,yBAAyB,KAAK,IAAI,CAAC;CAC5D;AAED,MAAM,WAAW,yBAAyB;IACxC,8BAA8B;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,qCAAqC;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,YAAY,EAAE,MAAM,CAAC;CACtB"}
@@ -0,0 +1,6 @@
1
+ import type { UseWindowDimensionProps, UseWindowDimensionsResult } from "./types.js";
2
+ /**
3
+ * Hook to get the window dimensions and scroll position.
4
+ */
5
+ export default function useWindowDimensions({ onResize, onScroll, resizeDelay, scrollDelay, }?: UseWindowDimensionProps): UseWindowDimensionsResult;
6
+ //# sourceMappingURL=useWindowDimensions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWindowDimensions.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/useWindowDimensions/useWindowDimensions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,uBAAuB,EACvB,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,QAAQ,EACR,QAAQ,EACR,WAAiB,EACjB,WAAiB,GAClB,GAAE,uBAA4B,GAAG,yBAAyB,CAqD1D"}
@@ -0,0 +1,3 @@
1
+ export { default as useWindowFitment } from "./useWindowFitment.js";
2
+ export * from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/useWindowFitment/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACpE,cAAc,YAAY,CAAC"}
@@ -0,0 +1,73 @@
1
+ import type { CSSProperties, RefObject } from "react";
2
+ export interface UseWindowFitmentProps {
3
+ /**
4
+ * Whether the popup should automatically fit into the viewport.
5
+ * If true, the hook will try to fit the popup into the viewport if it doesn't fit in the preferred directions.
6
+ * Defaults to false.
7
+ */
8
+ autoFit?: boolean;
9
+ /**
10
+ * An array of preferred directions for the popup.
11
+ * The hook will try to position the popup in these directions in order.
12
+ * Defaults to ['top', 'bottom', 'left', 'right'].
13
+ */
14
+ preferredDirections?: WindowFitmentDirection[];
15
+ /**
16
+ * The distance, in pixels between the target and the popup.
17
+ * @TODO support non-px units. E.G., someone should be able to request '1em`.
18
+ */
19
+ distance?: string;
20
+ /**
21
+ * The gutter (padding) around the viewport, preventing the popup from being too close to the edges.
22
+ * A CSS padding-like string (e.g., '10px', '10px 20px', '10px 20px 30px 40px').
23
+ * Assumes that each value is in pixels.
24
+ * @TODO support non-px units and change this to a string. E.G., someone should be able to request '0.5rem 1rem 1rem 0.5rem`.
25
+ */
26
+ gutter?: string;
27
+ /**
28
+ * The maximum width of the popup content.
29
+ * Can be a CSS width value (e.g., '300px', '50%').
30
+ * Defaults to '350px'.
31
+ */
32
+ maxWidth?: string;
33
+ /** How long wait before processing actions called by resize events. Defaults to 150ms. */
34
+ resizeDelay?: number;
35
+ /** How long to wait before processing actions called by scroll events Defaults to 150ms. */
36
+ scrollDelay?: number;
37
+ /** Whether the popup is open or not. */
38
+ isOpen?: boolean;
39
+ /**
40
+ * An optional callback to be called when the best position of the popup changes.
41
+ */
42
+ onBestPositionChange?: (bestPosition?: BestPosition) => void;
43
+ }
44
+ export type WindowFitmentDirection = "top" | "bottom" | "left" | "right";
45
+ export interface UseWindowFitmentResult {
46
+ /**
47
+ * A ref to be attached to the target element.
48
+ */
49
+ targetRef: RefObject<HTMLDivElement | null>;
50
+ /**
51
+ * A ref to be attached to the popup element.
52
+ */
53
+ popupRef: RefObject<HTMLDivElement | null>;
54
+ /**
55
+ * The calculated best possible position of the popup element.
56
+ */
57
+ bestPosition?: BestPosition;
58
+ /**
59
+ * The style object to be applied to the popup element.
60
+ */
61
+ popupPositionStyle: CSSProperties;
62
+ }
63
+ export type RelativePosition = {
64
+ top: number;
65
+ left: number;
66
+ };
67
+ export interface BestPosition {
68
+ position: RelativePosition;
69
+ positionName: WindowFitmentDirection;
70
+ fits: boolean;
71
+ autoFitOffset: RelativePosition;
72
+ }
73
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/useWindowFitment/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtD,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAC/C;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,0FAA0F;IAC1F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4FAA4F;IAC5F,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,wCAAwC;IACxC,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,oBAAoB,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;CAC9D;AAED,MAAM,MAAM,sBAAsB,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAEzE,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,SAAS,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC5C;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC3C;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B;;OAEG;IACH,kBAAkB,EAAE,aAAa,CAAC;CAOnC;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,YAAY,EAAE,sBAAsB,CAAC;IACrC,IAAI,EAAE,OAAO,CAAC;IACd,aAAa,EAAE,gBAAgB,CAAC;CACjC"}
@@ -0,0 +1,4 @@
1
+ import type { UseWindowFitmentProps, UseWindowFitmentResult } from "./types.js";
2
+ declare const useWindowFitment: ({ preferredDirections, distance, gutter, maxWidth, resizeDelay, scrollDelay, onBestPositionChange, autoFit, }: UseWindowFitmentProps) => UseWindowFitmentResult;
3
+ export default useWindowFitment;
4
+ //# sourceMappingURL=useWindowFitment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWindowFitment.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/useWindowFitment/useWindowFitment.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAGV,qBAAqB,EACrB,sBAAsB,EAEvB,MAAM,YAAY,CAAC;AAEpB,QAAA,MAAM,gBAAgB,GAAI,+GASvB,qBAAqB,KAAG,sBAgR1B,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export * from "./Button/index.js";
2
2
  export * from "./Chip/index.js";
3
+ export * from "./Tooltip/index.js";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-ds-core",
3
- "version": "0.9.0-experimental.5",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -22,9 +22,10 @@
22
22
  "homepage": "https://github.com/canonical/ds25#readme",
23
23
  "scripts": {
24
24
  "build": "bun run build:package",
25
+ "build:all": "bun run build:package && bun run build:storybook",
25
26
  "build:storybook": "storybook build",
26
27
  "build:package": "bun run build:package:tsc && bun run build:package:copycss",
27
- "build:package:copycss": "copyfiles -u 1 src/ui/**/*.css dist/esm",
28
+ "build:package:copycss": "copyfiles -u 1 'src/ui/{,**/}*.css' dist/esm",
28
29
  "build:package:tsc": "tsc -p tsconfig.build.json",
29
30
  "check": "bun run check:biome && bun run check:ts",
30
31
  "check:fix": "bun run check:biome:fix && bun run check:ts",
@@ -38,33 +39,31 @@
38
39
  "test:vitest:watch": "vitest"
39
40
  },
40
41
  "dependencies": {
41
- "@canonical/storybook-config": "^0.9.0-experimental.5",
42
- "@canonical/styles": "^0.9.0-experimental.2",
43
- "react": "^19.0.0",
44
- "react-dom": "^19.0.0"
42
+ "@canonical/storybook-config": "^0.9.0",
43
+ "@canonical/styles": "^0.9.0",
44
+ "@canonical/utils": "^0.9.0",
45
+ "react": "^19.1.0",
46
+ "react-dom": "^19.1.0"
45
47
  },
46
48
  "devDependencies": {
47
49
  "@biomejs/biome": "^1.9.4",
48
- "@canonical/biome-config": "^0.9.0-experimental.2",
49
- "@canonical/typescript-config-react": "^0.9.0-experimental.2",
50
- "@chromatic-com/storybook": "^3.2.2",
51
- "@storybook/blocks": "^8.4.7",
52
- "@storybook/react": "^8.4.7",
53
- "@storybook/test": "^8.4.7",
50
+ "@canonical/biome-config": "^0.9.0",
51
+ "@canonical/typescript-config-react": "^0.9.0",
52
+ "@chromatic-com/storybook": "^4.0.0",
54
53
  "@testing-library/jest-dom": "^6.6.3",
55
- "@testing-library/react": "^16.1.0",
56
- "@types/node": "^22.10.1",
57
- "@types/react": "^19.0.1",
58
- "@types/react-dom": "^19.0.2",
59
- "@vitejs/plugin-react": "^4.3.4",
54
+ "@testing-library/react": "^16.3.0",
55
+ "@types/node": "^24.0.0",
56
+ "@types/react": "^19.1.8",
57
+ "@types/react-dom": "^19.1.6",
58
+ "@vitejs/plugin-react": "^4.5.2",
60
59
  "copyfiles": "^2.4.1",
61
- "globals": "^15.13.0",
62
- "jsdom": "^25.0.1",
63
- "storybook": "^8.4.7",
64
- "typescript": "^5.7.2",
65
- "vite": "^6.0.3",
60
+ "globals": "^16.2.0",
61
+ "jsdom": "^26.1.0",
62
+ "storybook": "^9.0.8",
63
+ "typescript": "^5.8.3",
64
+ "vite": "^6.3.5",
66
65
  "vite-tsconfig-paths": "^5.1.4",
67
- "vitest": "^2.1.8"
66
+ "vitest": "^3.2.3"
68
67
  },
69
- "gitHead": "bc797d0c134200c372d31a8db89659caba2d6384"
68
+ "gitHead": "59f31f7d58a1794d36dae3cf99691b6eeb3f4042"
70
69
  }