@canonical/react-ds-core 0.9.0-experimental.2 → 0.9.0-experimental.9
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/README.md +28 -91
- package/dist/esm/ui/Tooltip/Tooltip.js +18 -0
- package/dist/esm/ui/Tooltip/Tooltip.js.map +1 -0
- package/dist/esm/ui/Tooltip/common/TooltipArea/TooltipArea.js +29 -0
- package/dist/esm/ui/Tooltip/common/TooltipArea/TooltipArea.js.map +1 -0
- package/dist/esm/ui/Tooltip/common/TooltipArea/index.js +4 -0
- package/dist/esm/ui/Tooltip/common/TooltipArea/index.js.map +1 -0
- package/dist/esm/ui/Tooltip/common/TooltipArea/styles.css +13 -0
- package/dist/esm/ui/Tooltip/common/TooltipArea/types.js +2 -0
- package/dist/esm/ui/Tooltip/common/TooltipArea/types.js.map +1 -0
- package/dist/esm/ui/Tooltip/common/index.js +2 -0
- package/dist/esm/ui/Tooltip/common/index.js.map +1 -0
- package/dist/esm/ui/Tooltip/index.js +6 -0
- package/dist/esm/ui/Tooltip/index.js.map +1 -0
- package/dist/esm/ui/Tooltip/styles.css +111 -0
- package/dist/esm/ui/Tooltip/types.js +2 -0
- package/dist/esm/ui/Tooltip/types.js.map +1 -0
- package/dist/esm/ui/Tooltip/withTooltip.js +18 -0
- package/dist/esm/ui/Tooltip/withTooltip.js.map +1 -0
- package/dist/esm/ui/hooks/index.js +6 -0
- package/dist/esm/ui/hooks/index.js.map +1 -0
- package/dist/esm/ui/hooks/useDelayedToggle/index.js +3 -0
- package/dist/esm/ui/hooks/useDelayedToggle/index.js.map +1 -0
- package/dist/esm/ui/hooks/useDelayedToggle/types.js +2 -0
- package/dist/esm/ui/hooks/useDelayedToggle/types.js.map +1 -0
- package/dist/esm/ui/hooks/useDelayedToggle/useDelayedToggle.js +37 -0
- package/dist/esm/ui/hooks/useDelayedToggle/useDelayedToggle.js.map +1 -0
- package/dist/esm/ui/hooks/usePopup/index.js +3 -0
- package/dist/esm/ui/hooks/usePopup/index.js.map +1 -0
- package/dist/esm/ui/hooks/usePopup/types.js +2 -0
- package/dist/esm/ui/hooks/usePopup/types.js.map +1 -0
- package/dist/esm/ui/hooks/usePopup/usePopup.js +71 -0
- package/dist/esm/ui/hooks/usePopup/usePopup.js.map +1 -0
- package/dist/esm/ui/hooks/useResizeObserver/index.js +3 -0
- package/dist/esm/ui/hooks/useResizeObserver/index.js.map +1 -0
- package/dist/esm/ui/hooks/useResizeObserver/types.js +2 -0
- package/dist/esm/ui/hooks/useResizeObserver/types.js.map +1 -0
- package/dist/esm/ui/hooks/useResizeObserver/useResizeObserver.js +33 -0
- package/dist/esm/ui/hooks/useResizeObserver/useResizeObserver.js.map +1 -0
- package/dist/esm/ui/hooks/useWindowDimensions/index.js +3 -0
- package/dist/esm/ui/hooks/useWindowDimensions/index.js.map +1 -0
- package/dist/esm/ui/hooks/useWindowDimensions/types.js +2 -0
- package/dist/esm/ui/hooks/useWindowDimensions/types.js.map +1 -0
- package/dist/esm/ui/hooks/useWindowDimensions/useWindowDimensions.js +50 -0
- package/dist/esm/ui/hooks/useWindowDimensions/useWindowDimensions.js.map +1 -0
- package/dist/esm/ui/hooks/useWindowFitment/index.js +3 -0
- package/dist/esm/ui/hooks/useWindowFitment/index.js.map +1 -0
- package/dist/esm/ui/hooks/useWindowFitment/types.js +2 -0
- package/dist/esm/ui/hooks/useWindowFitment/types.js.map +1 -0
- package/dist/esm/ui/hooks/useWindowFitment/useWindowFitment.js +192 -0
- package/dist/esm/ui/hooks/useWindowFitment/useWindowFitment.js.map +1 -0
- package/dist/esm/ui/index.js +1 -0
- package/dist/esm/ui/index.js.map +1 -1
- package/dist/types/ui/Tooltip/Tooltip.d.ts +12 -0
- package/dist/types/ui/Tooltip/Tooltip.d.ts.map +1 -0
- package/dist/types/ui/Tooltip/common/TooltipArea/TooltipArea.d.ts +10 -0
- package/dist/types/ui/Tooltip/common/TooltipArea/TooltipArea.d.ts.map +1 -0
- package/dist/types/ui/Tooltip/common/TooltipArea/index.d.ts +3 -0
- package/dist/types/ui/Tooltip/common/TooltipArea/index.d.ts.map +1 -0
- package/dist/types/ui/Tooltip/common/TooltipArea/types.d.ts +31 -0
- package/dist/types/ui/Tooltip/common/TooltipArea/types.d.ts.map +1 -0
- package/dist/types/ui/Tooltip/common/index.d.ts +2 -0
- package/dist/types/ui/Tooltip/common/index.d.ts.map +1 -0
- package/dist/types/ui/Tooltip/index.d.ts +5 -0
- package/dist/types/ui/Tooltip/index.d.ts.map +1 -0
- package/dist/types/ui/Tooltip/types.d.ts +16 -0
- package/dist/types/ui/Tooltip/types.d.ts.map +1 -0
- package/dist/types/ui/Tooltip/withTooltip.d.ts +11 -0
- package/dist/types/ui/Tooltip/withTooltip.d.ts.map +1 -0
- package/dist/types/ui/hooks/index.d.ts +6 -0
- package/dist/types/ui/hooks/index.d.ts.map +1 -0
- package/dist/types/ui/hooks/useDelayedToggle/index.d.ts +3 -0
- package/dist/types/ui/hooks/useDelayedToggle/index.d.ts.map +1 -0
- package/dist/types/ui/hooks/useDelayedToggle/types.d.ts +27 -0
- package/dist/types/ui/hooks/useDelayedToggle/types.d.ts.map +1 -0
- package/dist/types/ui/hooks/useDelayedToggle/useDelayedToggle.d.ts +13 -0
- package/dist/types/ui/hooks/useDelayedToggle/useDelayedToggle.d.ts.map +1 -0
- package/dist/types/ui/hooks/usePopup/index.d.ts +3 -0
- package/dist/types/ui/hooks/usePopup/index.d.ts.map +1 -0
- package/dist/types/ui/hooks/usePopup/types.d.ts +60 -0
- package/dist/types/ui/hooks/usePopup/types.d.ts.map +1 -0
- package/dist/types/ui/hooks/usePopup/usePopup.d.ts +18 -0
- package/dist/types/ui/hooks/usePopup/usePopup.d.ts.map +1 -0
- package/dist/types/ui/hooks/useResizeObserver/index.d.ts +3 -0
- package/dist/types/ui/hooks/useResizeObserver/index.d.ts.map +1 -0
- package/dist/types/ui/hooks/useResizeObserver/types.d.ts +7 -0
- package/dist/types/ui/hooks/useResizeObserver/types.d.ts.map +1 -0
- package/dist/types/ui/hooks/useResizeObserver/useResizeObserver.d.ts +8 -0
- package/dist/types/ui/hooks/useResizeObserver/useResizeObserver.d.ts.map +1 -0
- package/dist/types/ui/hooks/useWindowDimensions/index.d.ts +3 -0
- package/dist/types/ui/hooks/useWindowDimensions/index.d.ts.map +1 -0
- package/dist/types/ui/hooks/useWindowDimensions/types.d.ts +21 -0
- package/dist/types/ui/hooks/useWindowDimensions/types.d.ts.map +1 -0
- package/dist/types/ui/hooks/useWindowDimensions/useWindowDimensions.d.ts +6 -0
- package/dist/types/ui/hooks/useWindowDimensions/useWindowDimensions.d.ts.map +1 -0
- package/dist/types/ui/hooks/useWindowFitment/index.d.ts +3 -0
- package/dist/types/ui/hooks/useWindowFitment/index.d.ts.map +1 -0
- package/dist/types/ui/hooks/useWindowFitment/types.d.ts +66 -0
- package/dist/types/ui/hooks/useWindowFitment/types.d.ts.map +1 -0
- package/dist/types/ui/hooks/useWindowFitment/useWindowFitment.d.ts +4 -0
- package/dist/types/ui/hooks/useWindowFitment/useWindowFitment.d.ts.map +1 -0
- package/dist/types/ui/index.d.ts +1 -0
- package/dist/types/ui/index.d.ts.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
@@ -1,91 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
This
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
Storybook files are excluded from builds in [tsconfig.build.json](tsconfig.build.json).
|
31
|
-
Library type-checking is enabled for builds.
|
32
|
-
|
33
|
-
|
34
|
-
### Bun
|
35
|
-
|
36
|
-
[Bun](https://bun.sh/) is being experimentally used as a package manager.
|
37
|
-
|
38
|
-
### Build tool
|
39
|
-
|
40
|
-
Bun includes a [native JS bundler](https://bun.sh/docs/bundler) that can
|
41
|
-
transpile Typescript.
|
42
|
-
|
43
|
-
#### Downsides
|
44
|
-
|
45
|
-
We are not currently considering using `bun build` for production builds for
|
46
|
-
the following reasons:
|
47
|
-
|
48
|
-
##### Globstar
|
49
|
-
|
50
|
-
Bun's [implementation of globstar](https://bun.sh/docs/api/glob) is non-standard.
|
51
|
-
It is difficult to build arbitrarily deep filepaths, as Bun expects a globstar
|
52
|
-
for each level of supported nesting. Most glob implementations treat a globstar
|
53
|
-
as representing an arbitrary number of non-hidden directories. However, with
|
54
|
-
Bun, matching `.ts` files in `src/ui/Button` requires the glob pattern
|
55
|
-
`**/**/*.ts`, which does not match files in other levels of nesting.
|
56
|
-
|
57
|
-
##### Dist Depth
|
58
|
-
|
59
|
-
Generating `dist/` output that has the correct folder structure (i.e.,
|
60
|
-
`dist/ui/Button/`) is non-trivial. `bun build` generates output with folder
|
61
|
-
structure starting from matching the shallowest source file. However, this is
|
62
|
-
not always desired. For example, if `ui/` is inside `src/`, one must `cd` into
|
63
|
-
`src` before running `bun build` to generate the appropriate folder structure.
|
64
|
-
You must then set build output to `../dist` to place build results in the
|
65
|
-
project root. This makes the build script unnecessarily complex.
|
66
|
-
|
67
|
-
##### Type emitting
|
68
|
-
|
69
|
-
`bun build` does not generate types, so it must be accompanied by the usage of
|
70
|
-
some other tool that generates type declarations.
|
71
|
-
|
72
|
-
#### Upsides
|
73
|
-
|
74
|
-
##### Speed
|
75
|
-
|
76
|
-
Bun builds slightly faster than the Typescript compiler.
|
77
|
-
|
78
|
-
| Tool | Command | Real Time | User Time | Sys Time |
|
79
|
-
| ---- | --------------------------------------------------------------------| --------- | --------- | -------- |
|
80
|
-
| Bun | `bun run build:package:bun` | 0m0.648s | 0m1.498s | 0m0.117s |
|
81
|
-
| Typescript | `bun run build:package:tsc && bun run build:package:copycss` | 0m0.707s | 0m1.615s | 0m0.094s |
|
82
|
-
|
83
|
-
Note that the bun build must also call `tsc` to generate type declarations, and
|
84
|
-
the tsc build must call the external `copyfiles` dependency to copy assets into
|
85
|
-
`dist/`.
|
86
|
-
|
87
|
-
##### Non-TS bundling
|
88
|
-
|
89
|
-
`bun build` copies non-TS assets (such as images, stylesheets, etc) into `dist`.
|
90
|
-
`tsc` must be followed up with a manual step that copies non-TS files (currently,
|
91
|
-
this is only CSS) into `dist`.
|
1
|
+
## Canonical Design System - React Core
|
2
|
+
|
3
|
+
This package provides the core React components and utilities for Canonical's Design System.
|
4
|
+
|
5
|
+
## Getting Started
|
6
|
+
|
7
|
+
Install the package in a React 19 project with `bun add @canonical/react-ds-core`.
|
8
|
+
|
9
|
+
Then, import components from the package and use them in your React components.
|
10
|
+
An example of a component using the `Button` component:
|
11
|
+
```tsx
|
12
|
+
// MyComponent.tsx
|
13
|
+
import { Button } from "@canonical/react-ds-core";
|
14
|
+
|
15
|
+
function MyComponent() {
|
16
|
+
return (
|
17
|
+
<div>
|
18
|
+
<Button
|
19
|
+
appearance={"positive"}
|
20
|
+
label={"Click me"}
|
21
|
+
onClick={() => alert("hello world!")}
|
22
|
+
/>
|
23
|
+
</div>
|
24
|
+
);
|
25
|
+
}
|
26
|
+
|
27
|
+
export default MyComponent;
|
28
|
+
```
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import "./styles.css";
|
3
|
+
const componentCssClassName = "ds tooltip";
|
4
|
+
/**
|
5
|
+
* The Tooltip component is used to display a message.
|
6
|
+
* This component is just the "message" part of the tooltip, and has no interactivity or positioning logic. It is generally not consumed directly, but rather in one of two ways
|
7
|
+
* - The [TooltipArea](?path=/docs/tooltip-tooltiparea--docs) component
|
8
|
+
* - The [withTooltip](?path=/docs/tooltip-withtooltip--docs) HOC
|
9
|
+
*/
|
10
|
+
const Tooltip = ({ id, children, className, style, ref, isOpen = false, zIndex, onPointerEnter, onFocus, }) => {
|
11
|
+
return (_jsx("div", { className: [componentCssClassName, className].filter(Boolean).join(" "), ref: ref, id: id, "aria-hidden": !isOpen, onPointerEnter: onPointerEnter, onFocus: onFocus, role: "tooltip", style: {
|
12
|
+
...style,
|
13
|
+
visibility: isOpen ? "visible" : "hidden",
|
14
|
+
zIndex,
|
15
|
+
}, children: children }));
|
16
|
+
};
|
17
|
+
export default Tooltip;
|
18
|
+
//# sourceMappingURL=Tooltip.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../../src/ui/Tooltip/Tooltip.tsx"],"names":[],"mappings":";AAEA,OAAO,cAAc,CAAC;AAGtB,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,OAAO,GAAG,CAAC,EACf,EAAE,EACF,QAAQ,EACR,SAAS,EACT,KAAK,EACL,GAAG,EACH,MAAM,GAAG,KAAK,EACd,MAAM,EACN,cAAc,EACd,OAAO,GACM,EAAsB,EAAE;IACrC,OAAO,CACL,cACE,SAAS,EAAE,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EACvE,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,EAAE,iBACO,CAAC,MAAM,EACpB,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAC,SAAS,EACd,KAAK,EAAE;YACL,GAAG,KAAK;YACR,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ;YACzC,MAAM;SACP,YAEA,QAAQ,GACL,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { usePopup } from "../../../hooks/index.js";
|
3
|
+
import { Tooltip } from "../../index.js";
|
4
|
+
import "./styles.css";
|
5
|
+
import { createPortal } from "react-dom";
|
6
|
+
const componentCssClassName = "ds tooltip-area";
|
7
|
+
/**
|
8
|
+
* Wraps a target element with a tooltip.
|
9
|
+
* This component allows you to attach a tooltip to any JSX fragment.
|
10
|
+
*/
|
11
|
+
const TooltipArea = ({ children, Message, distance = "6px", targetElementId, targetElementClassName, targetElementStyle, messageElementClassName, messageElementStyle, parentElement, ...props }) => {
|
12
|
+
const { targetRef, popupRef, popupPositionStyle, popupId, isOpen, handleTriggerFocus, handleTriggerBlur, handleTriggerEnter, handleTriggerLeave, bestPosition, } = usePopup({ distance, ...props });
|
13
|
+
const TooltipMessageElement = (_jsx(Tooltip, { id: popupId, className: [bestPosition?.positionName, messageElementClassName]
|
14
|
+
.filter(Boolean)
|
15
|
+
.join(" "), onPointerEnter: handleTriggerEnter, onFocus: handleTriggerFocus, ref: popupRef, style: {
|
16
|
+
...messageElementStyle,
|
17
|
+
...popupPositionStyle,
|
18
|
+
// @ts-ignore allow binding arrow size to distance, as it is needed both in JS and CSS calculations
|
19
|
+
"--tooltip-spacing-arrow-size": distance,
|
20
|
+
}, isOpen: isOpen, children: Message }));
|
21
|
+
return (_jsxs("span", { className: [componentCssClassName].filter(Boolean).join(" "), onFocus: handleTriggerFocus, onBlur: handleTriggerBlur, onPointerEnter: handleTriggerEnter, onPointerLeave: handleTriggerLeave, children: [_jsx("span", { id: targetElementId, className: ["target"].filter(Boolean).join(" "), ref: targetRef, "aria-describedby": popupId, children: children }), typeof window !== "undefined"
|
22
|
+
? // Portals allow the tooltip to be rendered outside the parent element
|
23
|
+
// This is helpful when the parent element is a scrollable container or has bounds that may be
|
24
|
+
// overflown by the tooltip message.
|
25
|
+
createPortal(TooltipMessageElement, parentElement || document.body)
|
26
|
+
: TooltipMessageElement] }));
|
27
|
+
};
|
28
|
+
export default TooltipArea;
|
29
|
+
//# sourceMappingURL=TooltipArea.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"TooltipArea.js","sourceRoot":"","sources":["../../../../../../src/ui/Tooltip/common/TooltipArea/TooltipArea.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,qBAAqB,GAAG,iBAAiB,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,GAAG,CAAC,EACnB,QAAQ,EACR,OAAO,EACP,QAAQ,GAAG,KAAK,EAChB,eAAe,EACf,sBAAsB,EACtB,kBAAkB,EAClB,uBAAuB,EACvB,mBAAmB,EACnB,aAAa,EACb,GAAG,KAAK,EACS,EAAgB,EAAE;IACnC,MAAM,EACJ,SAAS,EACT,QAAQ,EACR,kBAAkB,EAClB,OAAO,EACP,MAAM,EACN,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,GACb,GAAG,QAAQ,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;IAErC,MAAM,qBAAqB,GAAG,CAC5B,KAAC,OAAO,IACN,EAAE,EAAE,OAAO,EACX,SAAS,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,uBAAuB,CAAC;aAC7D,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,EACZ,cAAc,EAAE,kBAAkB,EAClC,OAAO,EAAE,kBAAkB,EAC3B,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE;YACL,GAAG,mBAAmB;YACtB,GAAG,kBAAkB;YACrB,mGAAmG;YACnG,8BAA8B,EAAE,QAAQ;SACzC,EACD,MAAM,EAAE,MAAM,YAEb,OAAO,GACA,CACX,CAAC;IAEF,OAAO,CACL,gBACE,SAAS,EAAE,CAAC,qBAAqB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAC5D,OAAO,EAAE,kBAAkB,EAC3B,MAAM,EAAE,iBAAiB,EACzB,cAAc,EAAE,kBAAkB,EAClC,cAAc,EAAE,kBAAkB,aAElC,eACE,EAAE,EAAE,eAAe,EACnB,SAAS,EAAE,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAC/C,GAAG,EAAE,SAAS,sBACI,OAAO,YAExB,QAAQ,GACJ,EAIN,OAAO,MAAM,KAAK,WAAW;gBAC5B,CAAC,CAAC,sEAAsE;oBACtE,8FAA8F;oBAC9F,oCAAoC;oBACpC,YAAY,CAAC,qBAAqB,EAAE,aAAa,IAAI,QAAQ,CAAC,IAAI,CAAC;gBACrE,CAAC,CAAC,qBAAqB,IACpB,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/ui/Tooltip/common/TooltipArea/index.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC1D,cAAc,YAAY,CAAC"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
.ds.tooltip-area {
|
2
|
+
position: relative;
|
3
|
+
& .target {
|
4
|
+
cursor: pointer;
|
5
|
+
position: relative;
|
6
|
+
display: inline-block;
|
7
|
+
|
8
|
+
& > * {
|
9
|
+
/* The tooltip targets must have no margin in order for tooltip placements to work correctly */
|
10
|
+
margin: 0 !important;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/ui/Tooltip/common/TooltipArea/types.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/ui/Tooltip/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ui/Tooltip/index.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC1D,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
|
@@ -0,0 +1,111 @@
|
|
1
|
+
/* @canonical/generator-ds 0.9.0-experimental.4 */
|
2
|
+
|
3
|
+
/* component variables
|
4
|
+
--tooltip-color-background: background color of the tooltip
|
5
|
+
--tooltip-color-background-hover: background color of the tooltip on hover
|
6
|
+
--tooltip-color-background-active: background color of the tooltip on active
|
7
|
+
--tooltip-color-text: text color of the tooltip
|
8
|
+
--tooltip-color-border: border color of the tooltip
|
9
|
+
--tooltip-color-border-hover: border color of the tooltip on hover
|
10
|
+
--tooltip-color-border-active: border color of the tooltip on active
|
11
|
+
|
12
|
+
--tooltip-margin-left: left margin of the tooltip
|
13
|
+
--tooltip-margin-bottom: bottom margin of the tooltip
|
14
|
+
--tooltip-padding-vertical: vertical padding of the tooltip
|
15
|
+
--tooltip-padding-horizontal: horizontal padding of the tooltip
|
16
|
+
--tooltip-font-size: font size of the tooltip
|
17
|
+
--tooltip-font-weight: font weight of the tooltip
|
18
|
+
--tooltip-line-height: line height of the tooltip
|
19
|
+
|
20
|
+
--tooltip-spacing-arrow-size: size of the arrow
|
21
|
+
*/
|
22
|
+
|
23
|
+
.ds.tooltip {
|
24
|
+
--tooltip-spacing-arrow-middle: calc(50% - var(--tooltip-spacing-arrow-size));
|
25
|
+
--tooltip-spacing-arrow-edge: calc(-2 * var(--tooltip-spacing-arrow-size));
|
26
|
+
--tooltip-border-arrow-visible: var(--tooltip-spacing-arrow-size) solid
|
27
|
+
var(--tooltip-color-background);
|
28
|
+
--tooltip-border-arrow-hidden: var(--tooltip-spacing-arrow-size) solid
|
29
|
+
transparent;
|
30
|
+
|
31
|
+
color: var(
|
32
|
+
--intent-color-text,
|
33
|
+
var(--tooltip-color-text, var(--color-text-default))
|
34
|
+
);
|
35
|
+
background-color: var(
|
36
|
+
--intent-color,
|
37
|
+
var(--tooltip-color-background, var(--color-background-default))
|
38
|
+
);
|
39
|
+
border-color: var(
|
40
|
+
--intent-color-border,
|
41
|
+
var(--tooltip-color-border, transparent)
|
42
|
+
);
|
43
|
+
border-style: solid;
|
44
|
+
border-radius: var(--tooltip-border-radius);
|
45
|
+
border-width: var(--tooltip-border-width, 1px);
|
46
|
+
font-size: var(--tooltip-font-size, var(--font-size-small));
|
47
|
+
font-weight: var(--tooltip-font-weight, var(--font-weight-default));
|
48
|
+
line-height: var(--tooltip-line-height, var(--line-height-small));
|
49
|
+
margin-block-end: var(--tooltip-margin-bottom, 0);
|
50
|
+
margin-inline-end: var(--tooltip-margin-left, 0);
|
51
|
+
padding-block: var(--tooltip-padding-vertical, 5px);
|
52
|
+
padding-inline: var(--tooltip-padding-horizontal, 10px);
|
53
|
+
white-space: pre;
|
54
|
+
text-align: left;
|
55
|
+
text-decoration: initial;
|
56
|
+
pointer-events: auto;
|
57
|
+
display: inline-block;
|
58
|
+
transition: opacity 0.1s ease-in-out;
|
59
|
+
position: absolute;
|
60
|
+
|
61
|
+
&[aria-hidden="true"] {
|
62
|
+
opacity: 0;
|
63
|
+
pointer-events: none;
|
64
|
+
visibility: hidden;
|
65
|
+
}
|
66
|
+
|
67
|
+
&[aria-hidden="false"] {
|
68
|
+
opacity: 1;
|
69
|
+
pointer-events: auto;
|
70
|
+
visibility: visible;
|
71
|
+
}
|
72
|
+
|
73
|
+
/* triangle */
|
74
|
+
&::before {
|
75
|
+
content: "";
|
76
|
+
width: 0;
|
77
|
+
height: 0;
|
78
|
+
border: var(--tooltip-border-arrow-hidden);
|
79
|
+
position: absolute;
|
80
|
+
}
|
81
|
+
|
82
|
+
&.top::before {
|
83
|
+
border-top: var(--tooltip-border-arrow-visible);
|
84
|
+
bottom: var(--tooltip-spacing-arrow-edge);
|
85
|
+
}
|
86
|
+
|
87
|
+
&.right::before {
|
88
|
+
border-right: var(--tooltip-border-arrow-visible);
|
89
|
+
left: var(--tooltip-spacing-arrow-edge);
|
90
|
+
}
|
91
|
+
|
92
|
+
&.bottom::before {
|
93
|
+
border-bottom: var(--tooltip-border-arrow-visible);
|
94
|
+
top: var(--tooltip-spacing-arrow-edge);
|
95
|
+
}
|
96
|
+
|
97
|
+
&.left::before {
|
98
|
+
border-left: var(--tooltip-border-arrow-visible);
|
99
|
+
right: var(--tooltip-spacing-arrow-edge);
|
100
|
+
}
|
101
|
+
|
102
|
+
&.top::before,
|
103
|
+
&.bottom::before {
|
104
|
+
left: var(--tooltip-spacing-arrow-middle);
|
105
|
+
}
|
106
|
+
|
107
|
+
&.left::before,
|
108
|
+
&.right::before {
|
109
|
+
top: var(--tooltip-spacing-arrow-middle);
|
110
|
+
}
|
111
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/ui/Tooltip/types.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { TooltipArea } from "./common/TooltipArea/index.js";
|
3
|
+
/**
|
4
|
+
* A higher-order component that wraps a component with a tooltip.
|
5
|
+
* @param Component The component function to wrap. If you need to use a Node instead of a function, use [`TooltipArea`](/?path=/docs/tooltip-withtooltip--docs) instead.
|
6
|
+
* @param Message The content of the tooltip
|
7
|
+
* @param popupProps The props to pass to the usePopup hook
|
8
|
+
*/
|
9
|
+
const withTooltip = (Component, Message, popupProps = {}) => {
|
10
|
+
const WrappedComponent = (props, ref) => {
|
11
|
+
return (_jsx(TooltipArea, { Message: Message, ...popupProps, children: _jsx(Component, { ...props, ref: ref }) }));
|
12
|
+
};
|
13
|
+
// Set the displayName for easier debugging
|
14
|
+
WrappedComponent.displayName = `withTooltip(${Component.displayName || Component.name || "Component"})`;
|
15
|
+
return WrappedComponent;
|
16
|
+
};
|
17
|
+
export default withTooltip;
|
18
|
+
//# sourceMappingURL=withTooltip.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"withTooltip.js","sourceRoot":"","sources":["../../../../src/ui/Tooltip/withTooltip.tsx"],"names":[],"mappings":";AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,GAAG,CAClB,SAAgC,EAChC,OAAkB,EAClB,aAA4B,EAAE,EAClB,EAAE;IACd,MAAM,gBAAgB,GAAG,CACvB,KAAa,EACb,GAA4B,EACN,EAAE;QACxB,OAAO,CACL,KAAC,WAAW,IAAC,OAAO,EAAE,OAAO,KAAM,UAAU,YAC3C,KAAC,SAAS,OAAK,KAAK,EAAE,GAAG,EAAE,GAAG,GAAI,GACtB,CACf,CAAC;IACJ,CAAC,CAAC;IAEF,2CAA2C;IAC3C,gBAAgB,CAAC,WAAW,GAAG,eAC7B,SAAS,CAAC,WAAW,IAAI,SAAS,CAAC,IAAI,IAAI,WAC7C,GAAG,CAAC;IAEJ,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ui/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/ui/hooks/useDelayedToggle/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACpE,cAAc,YAAY,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/ui/hooks/useDelayedToggle/types.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { useCallback, useRef, useState } from "react";
|
2
|
+
/**
|
3
|
+
* Hook to toggle a flag with a delay.
|
4
|
+
* Allows the caller to `activate()` or `deactivate()` some flag
|
5
|
+
* @param activateDelay The delay in milliseconds before setting the flag to true.
|
6
|
+
* @param deactivateDelay The delay in milliseconds before setting the flag to false.
|
7
|
+
* @param onActivate A callback to be called when the flag is set to true.
|
8
|
+
* @param onDeactivate A callback to be called when the flag is set to false.
|
9
|
+
* @returns The current state of the flag, functions to activate and deactivate the flag.
|
10
|
+
*/
|
11
|
+
const useDelayedToggle = ({ activateDelay = 150, deactivateDelay = 150, onActivate, onDeactivate, }) => {
|
12
|
+
const [flag, setFlag] = useState(false);
|
13
|
+
const flagTimeout = useRef(undefined);
|
14
|
+
const replaceTimer = useCallback((newTimer) => {
|
15
|
+
if (flagTimeout.current) {
|
16
|
+
clearTimeout(flagTimeout.current);
|
17
|
+
}
|
18
|
+
flagTimeout.current = newTimer;
|
19
|
+
}, []);
|
20
|
+
const activate = useCallback((event) => {
|
21
|
+
replaceTimer(setTimeout(() => {
|
22
|
+
setFlag(true);
|
23
|
+
if (onActivate)
|
24
|
+
onActivate(event);
|
25
|
+
}, activateDelay));
|
26
|
+
}, [activateDelay, replaceTimer, onActivate]);
|
27
|
+
const deactivate = useCallback((event) => {
|
28
|
+
replaceTimer(setTimeout(() => {
|
29
|
+
setFlag(false);
|
30
|
+
if (onDeactivate)
|
31
|
+
onDeactivate(event);
|
32
|
+
}, deactivateDelay));
|
33
|
+
}, [deactivateDelay, replaceTimer, onDeactivate]);
|
34
|
+
return { flag, activate, deactivate };
|
35
|
+
};
|
36
|
+
export default useDelayedToggle;
|
37
|
+
//# sourceMappingURL=useDelayedToggle.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useDelayedToggle.js","sourceRoot":"","sources":["../../../../../src/ui/hooks/useDelayedToggle/useDelayedToggle.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAa,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGjE;;;;;;;;GAQG;AACH,MAAM,gBAAgB,GAAG,CAAC,EACxB,aAAa,GAAG,GAAG,EACnB,eAAe,GAAG,GAAG,EACrB,UAAU,EACV,YAAY,GACU,EAA0B,EAAE;IAClD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxC,MAAM,WAAW,GAAG,MAAM,CACxB,SAAS,CACV,CAAC;IAEF,MAAM,YAAY,GAAG,WAAW,CAC9B,CAAC,QAAwC,EAAE,EAAE;QAC3C,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;YACxB,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;QACD,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC;IACjC,CAAC,EACD,EAAE,CACH,CAAC;IAEF,MAAM,QAAQ,GAAG,WAAW,CAC1B,CAAC,KAAY,EAAE,EAAE;QACf,YAAY,CACV,UAAU,CAAC,GAAG,EAAE;YACd,OAAO,CAAC,IAAI,CAAC,CAAC;YACd,IAAI,UAAU;gBAAE,UAAU,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC,EAAE,aAAa,CAAC,CAClB,CAAC;IACJ,CAAC,EACD,CAAC,aAAa,EAAE,YAAY,EAAE,UAAU,CAAC,CAC1C,CAAC;IAEF,MAAM,UAAU,GAAG,WAAW,CAC5B,CAAC,KAAY,EAAE,EAAE;QACf,YAAY,CACV,UAAU,CAAC,GAAG,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,CAAC;YACf,IAAI,YAAY;gBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC,EAAE,eAAe,CAAC,CACpB,CAAC;IACJ,CAAC,EACD,CAAC,eAAe,EAAE,YAAY,EAAE,YAAY,CAAC,CAC9C,CAAC;IAEF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;AACxC,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/ui/hooks/usePopup/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,cAAc,YAAY,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/ui/hooks/usePopup/types.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,71 @@
|
|
1
|
+
import { useCallback, useId, } from "react";
|
2
|
+
import { useState } from "react";
|
3
|
+
import { useDelayedToggle } from "../useDelayedToggle/index.js";
|
4
|
+
import { useWindowFitment } from "../useWindowFitment/index.js";
|
5
|
+
/**
|
6
|
+
* Manages the state of a popup.
|
7
|
+
* @param isOpen An override for the open state.
|
8
|
+
* @param deactivateDelay The delay in milliseconds before setting the flag to false.
|
9
|
+
* @param activateDelay The delay in milliseconds before setting the flag to true.
|
10
|
+
* @param onEnter A callback to be called when the mouse enters the target element.
|
11
|
+
* @param onLeave A callback to be called when the mouse leaves the target element.
|
12
|
+
* @param onFocus A callback to be called when the target element is focused.
|
13
|
+
* @param onBlur A callback to be called when the target element loses focus.
|
14
|
+
* @param onShow A callback to be called when the popup is shown.
|
15
|
+
* @param onHide A callback to be called when the popup is hidden.
|
16
|
+
* @param props The props to be passed to the useWindowFitment hook.
|
17
|
+
* @returns The current state of the popup, and event handlers for the target element.
|
18
|
+
*/
|
19
|
+
const usePopup = ({ isOpen: isOpenProp, deactivateDelay, activateDelay, onEnter, onLeave, onFocus, onBlur, onShow, onHide, ...props }) => {
|
20
|
+
const [isFocused, setIsFocused] = useState(false);
|
21
|
+
const popupId = useId();
|
22
|
+
const { flag: isOpenHook, deactivate: close, activate: open, } = useDelayedToggle({
|
23
|
+
activateDelay,
|
24
|
+
deactivateDelay,
|
25
|
+
onActivate: onShow,
|
26
|
+
onDeactivate: onHide,
|
27
|
+
});
|
28
|
+
// Apply open override
|
29
|
+
const isOpen = typeof isOpenProp === "boolean" ? isOpenProp : isOpenHook;
|
30
|
+
const { targetRef, popupRef, bestPosition, popupPositionStyle } = useWindowFitment({
|
31
|
+
...props,
|
32
|
+
isOpen: isOpen,
|
33
|
+
});
|
34
|
+
const handleTriggerFocus = useCallback((event) => {
|
35
|
+
setIsFocused(true);
|
36
|
+
open(event.nativeEvent);
|
37
|
+
if (onFocus)
|
38
|
+
onFocus(event);
|
39
|
+
}, [open, onFocus]);
|
40
|
+
const handleTriggerBlur = useCallback((event) => {
|
41
|
+
setIsFocused(false);
|
42
|
+
close(event.nativeEvent);
|
43
|
+
if (onBlur)
|
44
|
+
onBlur(event);
|
45
|
+
}, [close, onBlur]);
|
46
|
+
const handleTriggerEnter = useCallback((event) => {
|
47
|
+
open(event.nativeEvent);
|
48
|
+
if (onEnter)
|
49
|
+
onEnter(event);
|
50
|
+
}, [open, onEnter]);
|
51
|
+
const handleTriggerLeave = useCallback((event) => {
|
52
|
+
close(event.nativeEvent);
|
53
|
+
if (onLeave)
|
54
|
+
onLeave(event);
|
55
|
+
}, [close, onLeave]);
|
56
|
+
return {
|
57
|
+
handleTriggerBlur,
|
58
|
+
handleTriggerEnter,
|
59
|
+
handleTriggerFocus,
|
60
|
+
handleTriggerLeave,
|
61
|
+
isFocused,
|
62
|
+
isOpen,
|
63
|
+
popupId,
|
64
|
+
popupRef,
|
65
|
+
targetRef,
|
66
|
+
bestPosition,
|
67
|
+
popupPositionStyle,
|
68
|
+
};
|
69
|
+
};
|
70
|
+
export default usePopup;
|
71
|
+
//# sourceMappingURL=usePopup.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"usePopup.js","sourceRoot":"","sources":["../../../../../src/ui/hooks/usePopup/usePopup.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,WAAW,EACX,KAAK,GACN,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAGhE;;;;;;;;;;;;;GAaG;AACH,MAAM,QAAQ,GAAG,CAAC,EAChB,MAAM,EAAE,UAAU,EAClB,eAAe,EACf,aAAa,EACb,OAAO,EACP,OAAO,EACP,OAAO,EACP,MAAM,EACN,MAAM,EACN,MAAM,EACN,GAAG,KAAK,EACM,EAAkB,EAAE;IAClC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,KAAK,EAAE,CAAC;IAExB,MAAM,EACJ,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,KAAK,EACjB,QAAQ,EAAE,IAAI,GACf,GAAG,gBAAgB,CAAC;QACnB,aAAa;QACb,eAAe;QACf,UAAU,EAAE,MAAM;QAClB,YAAY,EAAE,MAAM;KACrB,CAAC,CAAC;IAEH,sBAAsB;IACtB,MAAM,MAAM,GAAG,OAAO,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC;IAEzE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,kBAAkB,EAAE,GAC7D,gBAAgB,CAAC;QACf,GAAG,KAAK;QACR,MAAM,EAAE,MAAM;KACf,CAAC,CAAC;IAEL,MAAM,kBAAkB,GAAsB,WAAW,CACvD,CAAC,KAAK,EAAE,EAAE;QACR,YAAY,CAAC,IAAI,CAAC,CAAC;QACnB,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACxB,IAAI,OAAO;YAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC,EACD,CAAC,IAAI,EAAE,OAAO,CAAC,CAChB,CAAC;IAEF,MAAM,iBAAiB,GAAsB,WAAW,CACtD,CAAC,KAAK,EAAE,EAAE;QACR,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACzB,IAAI,MAAM;YAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC,EACD,CAAC,KAAK,EAAE,MAAM,CAAC,CAChB,CAAC;IAEF,MAAM,kBAAkB,GAAwB,WAAW,CACzD,CAAC,KAAK,EAAE,EAAE;QACR,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACxB,IAAI,OAAO;YAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC,EACD,CAAC,IAAI,EAAE,OAAO,CAAC,CAChB,CAAC;IAEF,MAAM,kBAAkB,GAAwB,WAAW,CACzD,CAAC,KAAK,EAAE,EAAE;QACR,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACzB,IAAI,OAAO;YAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC,EACD,CAAC,KAAK,EAAE,OAAO,CAAC,CACjB,CAAC;IAEF,OAAO;QACL,iBAAiB;QACjB,kBAAkB;QAClB,kBAAkB;QAClB,kBAAkB;QAClB,SAAS;QACT,MAAM;QACN,OAAO;QACP,QAAQ;QACR,SAAS;QACT,YAAY;QACZ,kBAAkB;KACnB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","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 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/ui/hooks/useResizeObserver/types.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { useEffect, useState } from "react";
|
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(element) {
|
8
|
+
const [size, setSize] = useState({
|
9
|
+
width: 0,
|
10
|
+
height: 0,
|
11
|
+
});
|
12
|
+
if (typeof window === "undefined")
|
13
|
+
return size;
|
14
|
+
useEffect(() => {
|
15
|
+
if (!element)
|
16
|
+
return;
|
17
|
+
const observer = new ResizeObserver(([entry]) => {
|
18
|
+
if (entry) {
|
19
|
+
const rect = entry.contentRect;
|
20
|
+
setSize({
|
21
|
+
width: rect.width,
|
22
|
+
height: rect.height,
|
23
|
+
});
|
24
|
+
}
|
25
|
+
});
|
26
|
+
observer.observe(element);
|
27
|
+
return () => {
|
28
|
+
observer.disconnect();
|
29
|
+
};
|
30
|
+
}, [element]);
|
31
|
+
return size;
|
32
|
+
}
|
33
|
+
//# sourceMappingURL=useResizeObserver.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useResizeObserver.js","sourceRoot":"","sources":["../../../../../src/ui/hooks/useResizeObserver/useResizeObserver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG5C;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,OAAyB;IAEzB,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAA0B;QACxD,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;KACV,CAAC,CAAC;IAEH,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IAE/C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO;YAAE,OAAO;QAErB,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE;YAC9C,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAAC;gBAC/B,OAAO,CAAC;oBACN,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,MAAM,EAAE,IAAI,CAAC,MAAM;iBACpB,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAE1B,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,UAAU,EAAE,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO,IAAI,CAAC;AACd,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","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 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/ui/hooks/useWindowDimensions/types.ts"],"names":[],"mappings":""}
|