@krak-stack/registry 0.11.3 → 0.11.4
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/CHANGELOG.md +6 -0
- package/dist/components/hint/react.d.ts +15 -0
- package/dist/components/hint/react.js +133 -0
- package/package.json +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ReactNode, type SVGProps } from "react";
|
|
2
|
+
/*! Solid lightbulb by Font Awesome Free 5.15.2 (https://fontawesome.com), CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Adapted to JSX. */
|
|
3
|
+
export declare const SolidLightbulb: (props: SVGProps<SVGSVGElement>) => import("react").JSX.Element;
|
|
4
|
+
export type HintProps = {
|
|
5
|
+
content: string;
|
|
6
|
+
triggerLabel: string;
|
|
7
|
+
children?: (props: {
|
|
8
|
+
descriptionId: string;
|
|
9
|
+
}) => ReactNode;
|
|
10
|
+
icon?: ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
classNames?: Partial<Record<"target" | "aside" | "trigger" | "icon" | "content", string>>;
|
|
13
|
+
};
|
|
14
|
+
/** Inline supplementary guidance, not a substitute for instructions or errors. */
|
|
15
|
+
export declare const Hint: ({ content, triggerLabel, children, icon, className, classNames, }: HintProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// ../../src/components/hint/react.tsx
|
|
2
|
+
import {
|
|
3
|
+
useEffect,
|
|
4
|
+
useId,
|
|
5
|
+
useRef,
|
|
6
|
+
useState
|
|
7
|
+
} from "react";
|
|
8
|
+
|
|
9
|
+
// ../../src/lib/utils.ts
|
|
10
|
+
import { cn } from "cn";
|
|
11
|
+
|
|
12
|
+
// ../../src/components/hint/react.tsx
|
|
13
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
+
"use client";
|
|
15
|
+
/*! Solid lightbulb by Font Awesome Free 5.15.2 (https://fontawesome.com), CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Adapted to JSX. */
|
|
16
|
+
var SolidLightbulb = (props) => /* @__PURE__ */ jsx("svg", {
|
|
17
|
+
viewBox: "0 0 352 512",
|
|
18
|
+
width: "1em",
|
|
19
|
+
height: "1em",
|
|
20
|
+
fill: "currentColor",
|
|
21
|
+
"aria-hidden": "true",
|
|
22
|
+
...props,
|
|
23
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
24
|
+
d: "M96.06 454.35c.01 6.29 1.87 12.45 5.36 17.69l17.09 25.69a31.99 31.99 0 0 0 26.64 14.28h61.71a31.99 31.99 0 0 0 26.64-14.28l17.09-25.69a31.989 31.989 0 0 0 5.36-17.69l.04-38.35H96.01l.05 38.35zM0 176c0 44.37 16.45 84.85 43.56 115.78 16.52 18.85 42.36 58.23 52.21 91.45.04.26.07.52.11.78h160.24c.04-.26.07-.51.11-.78 9.85-33.22 35.69-72.6 52.21-91.45C335.55 260.85 352 220.37 352 176 352 78.61 272.91-.3 175.45 0 73.44.31 0 82.97 0 176zm176-80c-44.11 0-80 35.89-80 80 0 8.84-7.16 16-16 16s-16-7.16-16-16c0-61.76 50.24-112 112-112 8.84 0 16 7.16 16 16s-7.16 16-16 16z"
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
var Hint = ({
|
|
28
|
+
content,
|
|
29
|
+
triggerLabel,
|
|
30
|
+
children,
|
|
31
|
+
icon = /* @__PURE__ */ jsx(SolidLightbulb, {}),
|
|
32
|
+
className,
|
|
33
|
+
classNames
|
|
34
|
+
}) => {
|
|
35
|
+
const descriptionId = useId();
|
|
36
|
+
const root = useRef(null);
|
|
37
|
+
const [hovered, setHovered] = useState(false);
|
|
38
|
+
const [focused, setFocused] = useState(false);
|
|
39
|
+
const [pinned, setPinned] = useState(false);
|
|
40
|
+
const [dismissed, setDismissed] = useState(false);
|
|
41
|
+
const open = !dismissed && (hovered || focused || pinned);
|
|
42
|
+
const state = open ? "open" : "closed";
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!open)
|
|
45
|
+
return;
|
|
46
|
+
const dismiss = () => {
|
|
47
|
+
setPinned(false);
|
|
48
|
+
setDismissed(true);
|
|
49
|
+
};
|
|
50
|
+
const onKeyDown = (event) => {
|
|
51
|
+
if (event.key === "Escape")
|
|
52
|
+
dismiss();
|
|
53
|
+
};
|
|
54
|
+
const onPointerDown = (event) => {
|
|
55
|
+
if (event.target instanceof Node && !root.current?.contains(event.target)) {
|
|
56
|
+
dismiss();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
document.addEventListener("keydown", onKeyDown);
|
|
60
|
+
document.addEventListener("pointerdown", onPointerDown);
|
|
61
|
+
return () => {
|
|
62
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
63
|
+
document.removeEventListener("pointerdown", onPointerDown);
|
|
64
|
+
};
|
|
65
|
+
}, [open]);
|
|
66
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
67
|
+
ref: root,
|
|
68
|
+
"data-slot": "hint",
|
|
69
|
+
"data-state": state,
|
|
70
|
+
className: cn(children ? "grid items-start gap-3 sm:grid-cols-[minmax(0,1fr)_16rem]" : "inline-flex", className),
|
|
71
|
+
onPointerEnter: (event) => {
|
|
72
|
+
if (event.pointerType === "touch")
|
|
73
|
+
return;
|
|
74
|
+
setHovered(true);
|
|
75
|
+
setDismissed(false);
|
|
76
|
+
},
|
|
77
|
+
onPointerLeave: () => setHovered(false),
|
|
78
|
+
onFocus: () => {
|
|
79
|
+
setFocused(true);
|
|
80
|
+
setDismissed(false);
|
|
81
|
+
},
|
|
82
|
+
onBlur: (event) => {
|
|
83
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
84
|
+
setFocused(false);
|
|
85
|
+
setPinned(false);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
children: [
|
|
89
|
+
children ? /* @__PURE__ */ jsx("div", {
|
|
90
|
+
"data-slot": "hint-target",
|
|
91
|
+
className: cn("min-w-0", classNames?.target),
|
|
92
|
+
children: children({ descriptionId })
|
|
93
|
+
}) : null,
|
|
94
|
+
/* @__PURE__ */ jsxs("div", {
|
|
95
|
+
"data-slot": "hint-aside",
|
|
96
|
+
className: cn("flex items-start gap-2", classNames?.aside),
|
|
97
|
+
children: [
|
|
98
|
+
/* @__PURE__ */ jsx("button", {
|
|
99
|
+
type: "button",
|
|
100
|
+
"data-slot": "hint-trigger",
|
|
101
|
+
"data-state": state,
|
|
102
|
+
"aria-label": triggerLabel,
|
|
103
|
+
"aria-expanded": open,
|
|
104
|
+
"aria-controls": descriptionId,
|
|
105
|
+
"aria-describedby": descriptionId,
|
|
106
|
+
className: cn("focus-visible:outline-ring inline-flex size-8 shrink-0 items-center justify-center rounded-md focus-visible:outline-2 focus-visible:outline-offset-2", open ? "text-primary" : "text-muted-foreground", classNames?.trigger),
|
|
107
|
+
onClick: () => {
|
|
108
|
+
setPinned(!pinned);
|
|
109
|
+
setDismissed(pinned);
|
|
110
|
+
},
|
|
111
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
112
|
+
"data-slot": "hint-icon",
|
|
113
|
+
"aria-hidden": "true",
|
|
114
|
+
className: cn("inline-flex [&>svg]:size-5", classNames?.icon),
|
|
115
|
+
children: icon
|
|
116
|
+
})
|
|
117
|
+
}),
|
|
118
|
+
/* @__PURE__ */ jsx("p", {
|
|
119
|
+
id: descriptionId,
|
|
120
|
+
"data-slot": "hint-content",
|
|
121
|
+
"data-state": state,
|
|
122
|
+
className: cn("text-muted-foreground m-0 min-w-0 pt-1 text-sm leading-relaxed data-[state=closed]:invisible", classNames?.content),
|
|
123
|
+
children: content
|
|
124
|
+
})
|
|
125
|
+
]
|
|
126
|
+
})
|
|
127
|
+
]
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
export {
|
|
131
|
+
Hint,
|
|
132
|
+
SolidLightbulb
|
|
133
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/registry",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.4",
|
|
4
4
|
"description": "Tree-shakable KrakStack components and Effect services.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -465,7 +465,11 @@
|
|
|
465
465
|
"import": "./dist/services/health/index.js"
|
|
466
466
|
},
|
|
467
467
|
"./tailwind.css": "./tailwind.css",
|
|
468
|
-
"./package.json": "./package.json"
|
|
468
|
+
"./package.json": "./package.json",
|
|
469
|
+
"./hint": {
|
|
470
|
+
"types": "./dist/components/hint/react.d.ts",
|
|
471
|
+
"import": "./dist/components/hint/react.js"
|
|
472
|
+
}
|
|
469
473
|
},
|
|
470
474
|
"publishConfig": {
|
|
471
475
|
"access": "public"
|