@-reddacted-/react-ui 0.3.1 → 0.4.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.
- package/dist/components/Accordion.d.ts +27 -0
- package/dist/components/Accordion.d.ts.map +1 -0
- package/dist/components/Accordion.js +35 -0
- package/dist/components/Badge.d.ts +15 -0
- package/dist/components/Badge.d.ts.map +1 -0
- package/dist/components/Badge.js +7 -0
- package/dist/components/Button.d.ts +15 -2
- package/dist/components/Button.d.ts.map +1 -1
- package/dist/components/Button.js +76 -44
- package/dist/components/Card.d.ts +21 -0
- package/dist/components/Card.d.ts.map +1 -0
- package/dist/components/Card.js +17 -0
- package/dist/components/ColorField.d.ts.map +1 -1
- package/dist/components/ColorField.js +1 -1
- package/dist/components/ConfirmDeleteButton.d.ts +4 -1
- package/dist/components/ConfirmDeleteButton.d.ts.map +1 -1
- package/dist/components/ConfirmDeleteButton.js +6 -7
- package/dist/components/Drawer.d.ts +33 -0
- package/dist/components/Drawer.d.ts.map +1 -0
- package/dist/components/Drawer.js +123 -0
- package/dist/components/DropdownMenu.d.ts +61 -0
- package/dist/components/DropdownMenu.d.ts.map +1 -0
- package/dist/components/DropdownMenu.js +302 -0
- package/dist/components/Modal.d.ts.map +1 -1
- package/dist/components/Modal.js +102 -134
- package/dist/components/NavBar.d.ts.map +1 -1
- package/dist/components/NavBar.js +4 -2
- package/dist/components/PageStatus.d.ts +12 -12
- package/dist/components/PageStatus.d.ts.map +1 -1
- package/dist/components/PageStatus.js +9 -29
- package/dist/components/Pagination.d.ts +44 -0
- package/dist/components/Pagination.d.ts.map +1 -0
- package/dist/components/Pagination.js +57 -0
- package/dist/components/Skeleton.d.ts +13 -0
- package/dist/components/Skeleton.d.ts.map +1 -0
- package/dist/components/Skeleton.js +15 -0
- package/dist/components/Spinner.d.ts +14 -0
- package/dist/components/Spinner.d.ts.map +1 -0
- package/dist/components/Spinner.js +14 -0
- package/dist/components/Stack.d.ts +13 -0
- package/dist/components/Stack.d.ts.map +1 -0
- package/dist/components/Stack.js +15 -0
- package/dist/components/Table.d.ts +54 -0
- package/dist/components/Table.d.ts.map +1 -0
- package/dist/components/Table.js +101 -0
- package/dist/components/Tabs.d.ts +34 -0
- package/dist/components/Tabs.d.ts.map +1 -0
- package/dist/components/Tabs.js +82 -0
- package/dist/components/Tag.d.ts +10 -0
- package/dist/components/Tag.d.ts.map +1 -0
- package/dist/components/Tag.js +7 -0
- package/dist/components/Tooltip.d.ts +22 -0
- package/dist/components/Tooltip.d.ts.map +1 -0
- package/dist/components/Tooltip.js +76 -0
- package/dist/components/drawerStore.d.ts +11 -0
- package/dist/components/drawerStore.d.ts.map +1 -0
- package/dist/components/drawerStore.js +40 -0
- package/dist/components/paginationItems.d.ts +18 -0
- package/dist/components/paginationItems.d.ts.map +1 -0
- package/dist/components/paginationItems.js +32 -0
- package/dist/index.d.ts +22 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -2
- package/dist/popup/PopupHost.d.ts +19 -3
- package/dist/popup/PopupHost.d.ts.map +1 -1
- package/dist/popup/PopupHost.js +65 -44
- package/dist/popup/PopupProvider.d.ts +19 -2
- package/dist/popup/PopupProvider.d.ts.map +1 -1
- package/dist/popup/PopupProvider.js +69 -17
- package/dist/popup/usePopup.d.ts +11 -4
- package/dist/popup/usePopup.d.ts.map +1 -1
- package/dist/style/accordionCss.d.ts +2 -0
- package/dist/style/accordionCss.d.ts.map +1 -0
- package/dist/style/accordionCss.js +101 -0
- package/dist/style/badgeCss.d.ts +5 -0
- package/dist/style/badgeCss.d.ts.map +1 -0
- package/dist/style/badgeCss.js +68 -0
- package/dist/style/breadcrumbCss.d.ts +2 -0
- package/dist/style/breadcrumbCss.d.ts.map +1 -0
- package/dist/style/breadcrumbCss.js +53 -0
- package/dist/style/cardCss.d.ts +2 -0
- package/dist/style/cardCss.d.ts.map +1 -0
- package/dist/style/cardCss.js +49 -0
- package/dist/style/inputCss.d.ts +2 -0
- package/dist/style/inputCss.d.ts.map +1 -0
- package/dist/style/inputCss.js +107 -0
- package/dist/style/loaderCss.d.ts +2 -0
- package/dist/style/loaderCss.d.ts.map +1 -0
- package/dist/style/loaderCss.js +39 -0
- package/dist/style/menuCss.d.ts +2 -0
- package/dist/style/menuCss.d.ts.map +1 -0
- package/dist/style/menuCss.js +71 -0
- package/dist/style/paginationCss.d.ts +2 -0
- package/dist/style/paginationCss.d.ts.map +1 -0
- package/dist/style/paginationCss.js +57 -0
- package/dist/style/resolveColor.d.ts +8 -0
- package/dist/style/resolveColor.d.ts.map +1 -0
- package/dist/style/resolveColor.js +13 -0
- package/dist/style/stackCss.d.ts +2 -0
- package/dist/style/stackCss.d.ts.map +1 -0
- package/dist/style/stackCss.js +21 -0
- package/dist/style/statusCss.d.ts +2 -0
- package/dist/style/statusCss.d.ts.map +1 -0
- package/dist/style/statusCss.js +38 -0
- package/dist/style/tableCss.d.ts +2 -0
- package/dist/style/tableCss.d.ts.map +1 -0
- package/dist/style/tableCss.js +92 -0
- package/dist/style/tabsCss.d.ts +2 -0
- package/dist/style/tabsCss.d.ts.map +1 -0
- package/dist/style/tabsCss.js +72 -0
- package/dist/style/toLength.d.ts +4 -0
- package/dist/style/toLength.d.ts.map +1 -0
- package/dist/style/toLength.js +3 -0
- package/dist/style/tooltipCss.d.ts +2 -0
- package/dist/style/tooltipCss.d.ts.map +1 -0
- package/dist/style/tooltipCss.js +44 -0
- package/dist/style/useStyle.d.ts +7 -0
- package/dist/style/useStyle.d.ts.map +1 -0
- package/dist/style/useStyle.js +16 -0
- package/dist/theme/ThemeProvider.d.ts.map +1 -1
- package/dist/theme/ThemeProvider.js +32 -0
- package/dist/theme/palette.d.ts.map +1 -1
- package/dist/theme/palette.js +0 -2
- package/dist/tooltip/attributeTooltips.d.ts +7 -0
- package/dist/tooltip/attributeTooltips.d.ts.map +1 -0
- package/dist/tooltip/attributeTooltips.js +76 -0
- package/dist/tooltip/tooltipEngine.d.ts +41 -0
- package/dist/tooltip/tooltipEngine.d.ts.map +1 -0
- package/dist/tooltip/tooltipEngine.js +128 -0
- package/dist/utils/childRef.d.ts +5 -0
- package/dist/utils/childRef.d.ts.map +1 -0
- package/dist/utils/childRef.js +14 -0
- package/dist/utils/isDev.d.ts +3 -0
- package/dist/utils/isDev.d.ts.map +1 -0
- package/dist/utils/isDev.js +4 -0
- package/package.json +5 -4
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { arrow, autoUpdate, computePosition, flip, offset, shift } from "@floating-ui/dom";
|
|
2
|
+
import { resolveColor } from "../style/resolveColor.js";
|
|
3
|
+
import { toLength } from "../style/toLength.js";
|
|
4
|
+
const TOUCH_HIDE_DELAY = 1500;
|
|
5
|
+
const STATIC_SIDE = { top: "bottom", bottom: "top", left: "right", right: "left" };
|
|
6
|
+
let nextId = 0;
|
|
7
|
+
/**
|
|
8
|
+
* One tooltip bubble (a detached DOM element, appended to the body while open) with its
|
|
9
|
+
* timers, positioning and dismissal. Shared by the Tooltip component and the
|
|
10
|
+
* `data-rui-tooltip` attribute mode so both behave the same.
|
|
11
|
+
*/
|
|
12
|
+
export class TooltipEngine {
|
|
13
|
+
constructor(onOpenChange) {
|
|
14
|
+
this.onOpenChange = onOpenChange;
|
|
15
|
+
this.id = `rui-tooltip-${nextId++}`;
|
|
16
|
+
this.bubble = document.createElement("div");
|
|
17
|
+
/** Where the content goes: text in attribute mode, a portal for the component. */
|
|
18
|
+
this.content = document.createElement("div");
|
|
19
|
+
this.arrowEl = document.createElement("div");
|
|
20
|
+
this.placement = "top";
|
|
21
|
+
this.anchorEl = null;
|
|
22
|
+
// Capture phase: Escape closes the tooltip only, not the modal or menu it sits in.
|
|
23
|
+
this.onKeyDown = (event) => {
|
|
24
|
+
if (event.key !== "Escape")
|
|
25
|
+
return;
|
|
26
|
+
event.stopPropagation();
|
|
27
|
+
this.hide();
|
|
28
|
+
};
|
|
29
|
+
// Touching (or clicking) anywhere else closes the bubble.
|
|
30
|
+
this.onPointerDown = (event) => {
|
|
31
|
+
if (!this.anchorEl?.contains(event.target))
|
|
32
|
+
this.hide();
|
|
33
|
+
};
|
|
34
|
+
this.bubble.id = this.id;
|
|
35
|
+
this.bubble.className = "rui-tooltip";
|
|
36
|
+
this.bubble.setAttribute("role", "tooltip");
|
|
37
|
+
// Never interactive, whatever the content.
|
|
38
|
+
this.bubble.inert = true;
|
|
39
|
+
this.arrowEl.className = "rui-tooltip-arrow";
|
|
40
|
+
this.bubble.append(this.content, this.arrowEl);
|
|
41
|
+
}
|
|
42
|
+
get anchor() {
|
|
43
|
+
return this.anchorEl;
|
|
44
|
+
}
|
|
45
|
+
setLook({ placement = "top", color, textColor, maxWidth }) {
|
|
46
|
+
this.placement = placement;
|
|
47
|
+
const style = this.bubble.style;
|
|
48
|
+
style.setProperty("--rui-tooltip-bg", color ? resolveColor(color) : null);
|
|
49
|
+
style.setProperty("--rui-tooltip-color", textColor ? resolveColor(textColor) : null);
|
|
50
|
+
style.setProperty("--rui-tooltip-max-width", maxWidth === undefined ? null : toLength(maxWidth));
|
|
51
|
+
if (this.anchorEl)
|
|
52
|
+
void this.position();
|
|
53
|
+
}
|
|
54
|
+
/** Opens on `anchor` after `delay` ms (right away when 0). */
|
|
55
|
+
scheduleShow(anchor, delay, beforeShow) {
|
|
56
|
+
if (this.anchorEl === anchor)
|
|
57
|
+
return;
|
|
58
|
+
this.clearTimers();
|
|
59
|
+
const open = () => {
|
|
60
|
+
beforeShow?.();
|
|
61
|
+
this.show(anchor);
|
|
62
|
+
};
|
|
63
|
+
if (delay <= 0)
|
|
64
|
+
open();
|
|
65
|
+
else
|
|
66
|
+
this.showTimer = setTimeout(open, delay);
|
|
67
|
+
}
|
|
68
|
+
/** Opens on a touch, closing by itself shortly after. */
|
|
69
|
+
showForTouch(anchor) {
|
|
70
|
+
this.show(anchor);
|
|
71
|
+
this.hideTimer = setTimeout(() => this.hide(), TOUCH_HIDE_DELAY);
|
|
72
|
+
}
|
|
73
|
+
show(anchor) {
|
|
74
|
+
// Already open there: keep a pending touch auto-hide (a touch also focuses the anchor).
|
|
75
|
+
if (this.anchorEl === anchor)
|
|
76
|
+
return;
|
|
77
|
+
this.hide();
|
|
78
|
+
this.anchorEl = anchor;
|
|
79
|
+
document.body.append(this.bubble);
|
|
80
|
+
this.stopAutoUpdate = autoUpdate(anchor, this.bubble, () => void this.position());
|
|
81
|
+
document.addEventListener("keydown", this.onKeyDown, true);
|
|
82
|
+
document.addEventListener("pointerdown", this.onPointerDown, true);
|
|
83
|
+
this.onOpenChange?.(true, anchor);
|
|
84
|
+
}
|
|
85
|
+
hide() {
|
|
86
|
+
this.clearTimers();
|
|
87
|
+
const anchor = this.anchorEl;
|
|
88
|
+
if (!anchor)
|
|
89
|
+
return;
|
|
90
|
+
this.anchorEl = null;
|
|
91
|
+
this.stopAutoUpdate?.();
|
|
92
|
+
this.stopAutoUpdate = undefined;
|
|
93
|
+
this.bubble.remove();
|
|
94
|
+
delete this.bubble.dataset.placement;
|
|
95
|
+
document.removeEventListener("keydown", this.onKeyDown, true);
|
|
96
|
+
document.removeEventListener("pointerdown", this.onPointerDown, true);
|
|
97
|
+
this.onOpenChange?.(false, anchor);
|
|
98
|
+
}
|
|
99
|
+
clearTimers() {
|
|
100
|
+
clearTimeout(this.showTimer);
|
|
101
|
+
clearTimeout(this.hideTimer);
|
|
102
|
+
}
|
|
103
|
+
async position() {
|
|
104
|
+
const anchor = this.anchorEl;
|
|
105
|
+
if (!anchor)
|
|
106
|
+
return;
|
|
107
|
+
const { x, y, placement, middlewareData } = await computePosition(anchor, this.bubble, {
|
|
108
|
+
strategy: "fixed",
|
|
109
|
+
placement: this.placement,
|
|
110
|
+
middleware: [offset(8), flip(), shift({ padding: 8 }), arrow({ element: this.arrowEl, padding: 6 })],
|
|
111
|
+
});
|
|
112
|
+
// Closed or moved to another anchor while computing.
|
|
113
|
+
if (this.anchorEl !== anchor)
|
|
114
|
+
return;
|
|
115
|
+
this.bubble.style.left = `${x}px`;
|
|
116
|
+
this.bubble.style.top = `${y}px`;
|
|
117
|
+
this.bubble.dataset.placement = placement;
|
|
118
|
+
const side = placement.split("-")[0];
|
|
119
|
+
const arrowData = middlewareData.arrow;
|
|
120
|
+
Object.assign(this.arrowEl.style, {
|
|
121
|
+
left: arrowData?.x != null ? `${arrowData.x}px` : "",
|
|
122
|
+
top: arrowData?.y != null ? `${arrowData.y}px` : "",
|
|
123
|
+
right: "",
|
|
124
|
+
bottom: "",
|
|
125
|
+
[STATIC_SIDE[side]]: "-4px",
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ReactElement, Ref } from "react";
|
|
2
|
+
/** The ref set on a child element: React 18 keeps it on the element, React 19 in its props (reading element.ref warns there). */
|
|
3
|
+
export declare function getElementRef<T>(element: ReactElement): Ref<T> | undefined;
|
|
4
|
+
export declare function assignRef<T>(ref: Ref<T> | undefined, value: T | null): void;
|
|
5
|
+
//# sourceMappingURL=childRef.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"childRef.d.ts","sourceRoot":"","sources":["../../src/utils/childRef.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAI9C,iIAAiI;AACjI,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAI1E;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,CAG3E"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { version } from "react";
|
|
2
|
+
const REF_IN_PROPS = Number.parseInt(version, 10) >= 19;
|
|
3
|
+
/** The ref set on a child element: React 18 keeps it on the element, React 19 in its props (reading element.ref warns there). */
|
|
4
|
+
export function getElementRef(element) {
|
|
5
|
+
return REF_IN_PROPS
|
|
6
|
+
? element.props.ref
|
|
7
|
+
: element.ref;
|
|
8
|
+
}
|
|
9
|
+
export function assignRef(ref, value) {
|
|
10
|
+
if (typeof ref === "function")
|
|
11
|
+
ref(value);
|
|
12
|
+
else if (ref)
|
|
13
|
+
ref.current = value;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isDev.d.ts","sourceRoot":"","sources":["../../src/utils/isDev.ts"],"names":[],"mappings":"AAEA,2FAA2F;AAC3F,wBAAgB,KAAK,IAAI,OAAO,CAE/B"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@-reddacted-/react-ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Themed React UI: theming system, Button, Modal, Drawer, Tooltip, DropdownMenu, Tabs, Table, Pagination, Accordion, Card, Stack, Badge, Tag, Spinner, Skeleton, PageStatus, NavBar, ColorPicker, grouped toasts (imperative, REST or GraphQL fetch) and rui-* classes for native elements",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -23,8 +23,9 @@
|
|
|
23
23
|
"react-dom": ">=18"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"react-
|
|
27
|
-
"
|
|
26
|
+
"@-reddacted-/react-hooks": "^0.3.0",
|
|
27
|
+
"@floating-ui/dom": "^1.8.0",
|
|
28
|
+
"react-colorful": "^5.6.1"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@types/react": "^18.3.1",
|