@pindoba/astro-tooltip 0.0.0-alpha-20260426220647
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/LICENSE +12 -0
- package/index.ts +7 -0
- package/package.json +51 -0
- package/src/demos/default.astro +11 -0
- package/src/demos/group.astro +34 -0
- package/src/demos/index.ts +3 -0
- package/src/demos/placement.astro +21 -0
- package/src/env.d.ts +2 -0
- package/src/tooltip.astro +106 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Copyright 2025 Eduardo Lopes
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
8
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
9
|
+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
10
|
+
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
11
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
12
|
+
DEALINGS IN THE SOFTWARE.
|
package/index.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pindoba/astro-tooltip",
|
|
3
|
+
"version": "0.0.0-alpha-20260426220647",
|
|
4
|
+
"homepage": "https://github.com/EduardoLopes/pindoba/tree/main/packages/ui/astro/tooltip#README.md",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/EduardoLopes/pindoba.git",
|
|
8
|
+
"directory": "packages/ui/astro/tooltip"
|
|
9
|
+
},
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./index.ts",
|
|
15
|
+
"./use-tooltip": "./src/useTooltip.ts",
|
|
16
|
+
"./demos": "./src/demos/index.ts",
|
|
17
|
+
"./demos/default": "./src/demos/default.astro",
|
|
18
|
+
"./demos/placement": "./src/demos/placement.astro",
|
|
19
|
+
"./demos/group": "./src/demos/group.astro"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"src",
|
|
23
|
+
"index.ts"
|
|
24
|
+
],
|
|
25
|
+
"keywords": [
|
|
26
|
+
"astro-component"
|
|
27
|
+
],
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@astrojs/check": "^0.9.8",
|
|
30
|
+
"astro": "^6.1.9",
|
|
31
|
+
"typescript": "^6.0.3"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"astro": "^4.0.0"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@pindoba/core-tooltip": "0.0.0-alpha-20260426220647",
|
|
38
|
+
"@pindoba/styles-tooltip": "0.0.0-alpha-20260426220647",
|
|
39
|
+
"@pindoba/utils": "0.0.0-alpha-20260426220647",
|
|
40
|
+
"@pindoba/styled-system": "0.0.0-alpha-20260426220647"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"lint": "TIMING=1 eslint . --max-warnings 0",
|
|
44
|
+
"lint:fix": "TIMING=1 eslint . --fix --max-warnings 0",
|
|
45
|
+
"format": "prettier --write .",
|
|
46
|
+
"format:fix": "prettier --write .",
|
|
47
|
+
"check": "astro check",
|
|
48
|
+
"dev": "astro check --watch",
|
|
49
|
+
"clean": "rm -rf .astro && rm -rf node_modules && rm -rf .turbo"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
import Tooltip from "../tooltip.astro";
|
|
3
|
+
import { stack } from "@pindoba/styled-system/patterns";
|
|
4
|
+
import { css } from "@pindoba/styled-system/css";
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<div class={stack({ gap: "md", direction: "row", align: "center" })}>
|
|
8
|
+
<Tooltip id="astro-demo-tooltip-default" content="Save the document (⌘S)">
|
|
9
|
+
<button class={css({ px: "sm", py: "xs" })}>Save</button>
|
|
10
|
+
</Tooltip>
|
|
11
|
+
</div>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
import Tooltip from "../tooltip.astro";
|
|
3
|
+
import { stack } from "@pindoba/styled-system/patterns";
|
|
4
|
+
import { css } from "@pindoba/styled-system/css";
|
|
5
|
+
|
|
6
|
+
const actions = [
|
|
7
|
+
{ id: "bold", label: "Bold (⌘B)", icon: "B" },
|
|
8
|
+
{ id: "italic", label: "Italic (⌘I)", icon: "I" },
|
|
9
|
+
{ id: "underline", label: "Underline (⌘U)", icon: "U" },
|
|
10
|
+
{ id: "strike", label: "Strikethrough", icon: "S" },
|
|
11
|
+
{ id: "link", label: "Insert link (⌘K)", icon: "🔗" },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const buttonClass = css({
|
|
15
|
+
px: "sm",
|
|
16
|
+
py: "xs",
|
|
17
|
+
minWidth: "2.25rem",
|
|
18
|
+
borderRadius: "sm",
|
|
19
|
+
fontFamily: "mono",
|
|
20
|
+
fontSize: "sm",
|
|
21
|
+
});
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
<div class={stack({ gap: "2xs", direction: "row", align: "center" })}>
|
|
25
|
+
{
|
|
26
|
+
actions.map((action) => (
|
|
27
|
+
<Tooltip id={`astro-tt-group-${action.id}`} content={action.label}>
|
|
28
|
+
<button class={buttonClass} aria-label={action.label}>
|
|
29
|
+
{action.icon}
|
|
30
|
+
</button>
|
|
31
|
+
</Tooltip>
|
|
32
|
+
))
|
|
33
|
+
}
|
|
34
|
+
</div>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
import Tooltip from "../tooltip.astro";
|
|
3
|
+
import { stack } from "@pindoba/styled-system/patterns";
|
|
4
|
+
import { css } from "@pindoba/styled-system/css";
|
|
5
|
+
|
|
6
|
+
const placements = ["top", "right", "bottom", "left"] as const;
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
<div class={stack({ gap: "md", direction: "row", align: "center" })}>
|
|
10
|
+
{
|
|
11
|
+
placements.map((placement) => (
|
|
12
|
+
<Tooltip
|
|
13
|
+
id={`astro-tt-placement-${placement}`}
|
|
14
|
+
content={`Tooltip on ${placement}`}
|
|
15
|
+
placement={placement}
|
|
16
|
+
>
|
|
17
|
+
<button class={css({ px: "sm", py: "xs" })}>{placement}</button>
|
|
18
|
+
</Tooltip>
|
|
19
|
+
))
|
|
20
|
+
}
|
|
21
|
+
</div>
|
package/src/env.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { cx } from "@pindoba/styled-system/css";
|
|
3
|
+
import { tooltipStyles, type TooltipStyleProps } from "@pindoba/styles-tooltip";
|
|
4
|
+
import type { Placement, TooltipTriggerStrategy } from "@pindoba/core-tooltip";
|
|
5
|
+
import { generateUUID } from "@pindoba/utils";
|
|
6
|
+
|
|
7
|
+
export interface Props {
|
|
8
|
+
id?: string;
|
|
9
|
+
content: string;
|
|
10
|
+
placement?: Placement;
|
|
11
|
+
triggerStrategy?: TooltipTriggerStrategy;
|
|
12
|
+
openDelay?: number;
|
|
13
|
+
closeDelay?: number;
|
|
14
|
+
offset?: number;
|
|
15
|
+
size?: TooltipStyleProps["size"];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
id = `tooltip-${generateUUID()}`,
|
|
20
|
+
content,
|
|
21
|
+
placement = "top",
|
|
22
|
+
triggerStrategy,
|
|
23
|
+
openDelay,
|
|
24
|
+
closeDelay,
|
|
25
|
+
offset: offsetProp,
|
|
26
|
+
size = "md",
|
|
27
|
+
} = Astro.props;
|
|
28
|
+
|
|
29
|
+
const classes = tooltipStyles({ size });
|
|
30
|
+
const rootClassName = cx(classes.root);
|
|
31
|
+
const triggerClassName = cx(classes.trigger);
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
<span
|
|
35
|
+
data-tooltip-trigger
|
|
36
|
+
data-tooltip-id={id}
|
|
37
|
+
data-tooltip-content={content}
|
|
38
|
+
data-tooltip-placement={placement}
|
|
39
|
+
data-tooltip-strategy={triggerStrategy ?? ""}
|
|
40
|
+
data-tooltip-open-delay={openDelay ?? ""}
|
|
41
|
+
data-tooltip-close-delay={closeDelay ?? ""}
|
|
42
|
+
data-tooltip-offset={offsetProp ?? ""}
|
|
43
|
+
data-tooltip-classname={rootClassName}
|
|
44
|
+
class={triggerClassName}
|
|
45
|
+
>
|
|
46
|
+
<slot />
|
|
47
|
+
</span>
|
|
48
|
+
|
|
49
|
+
<script>
|
|
50
|
+
import { createTooltip } from "@pindoba/core-tooltip";
|
|
51
|
+
|
|
52
|
+
function boot() {
|
|
53
|
+
const triggers = document.querySelectorAll<HTMLElement>(
|
|
54
|
+
"[data-tooltip-trigger]:not([data-tooltip-initialized])",
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const instances: Array<{ destroy: () => void }> = [];
|
|
58
|
+
|
|
59
|
+
triggers.forEach((trigger) => {
|
|
60
|
+
trigger.setAttribute("data-tooltip-initialized", "true");
|
|
61
|
+
const tooltipId = trigger.getAttribute("data-tooltip-id");
|
|
62
|
+
if (!tooltipId) return;
|
|
63
|
+
|
|
64
|
+
const content = trigger.getAttribute("data-tooltip-content") ?? "";
|
|
65
|
+
const placement = (trigger.getAttribute("data-tooltip-placement") ||
|
|
66
|
+
"top") as never;
|
|
67
|
+
const strategy =
|
|
68
|
+
trigger.getAttribute("data-tooltip-strategy") || undefined;
|
|
69
|
+
const openDelay = trigger.getAttribute("data-tooltip-open-delay");
|
|
70
|
+
const closeDelay = trigger.getAttribute("data-tooltip-close-delay");
|
|
71
|
+
const offsetAttr = trigger.getAttribute("data-tooltip-offset");
|
|
72
|
+
const rootClassName =
|
|
73
|
+
trigger.getAttribute("data-tooltip-classname") ?? "";
|
|
74
|
+
|
|
75
|
+
const tooltip = createTooltip({
|
|
76
|
+
id: tooltipId,
|
|
77
|
+
placement,
|
|
78
|
+
triggerStrategy: strategy as never,
|
|
79
|
+
openDelay: openDelay ? Number(openDelay) : undefined,
|
|
80
|
+
closeDelay: closeDelay ? Number(closeDelay) : undefined,
|
|
81
|
+
offset: offsetAttr ? Number(offsetAttr) : undefined,
|
|
82
|
+
rootClassName,
|
|
83
|
+
getContent: () => content,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Wrapper is `display: contents` — its own getBoundingClientRect is
|
|
87
|
+
// 0×0, which would place the tooltip at viewport origin. Use the first
|
|
88
|
+
// element child as the floating-ui reference so positioning tracks the
|
|
89
|
+
// visible target. Falls back to the wrapper if no child element exists
|
|
90
|
+
// (e.g., text-only triggers).
|
|
91
|
+
const reference =
|
|
92
|
+
(trigger.firstElementChild as HTMLElement | null) ?? trigger;
|
|
93
|
+
tooltip.setTriggerElement(reference);
|
|
94
|
+
instances.push(tooltip);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const teardown = () => {
|
|
98
|
+
for (const t of instances) t.destroy();
|
|
99
|
+
};
|
|
100
|
+
window.addEventListener("pagehide", teardown, { once: true });
|
|
101
|
+
document.addEventListener("astro:before-swap", teardown, { once: true });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
boot();
|
|
105
|
+
document.addEventListener("astro:page-load", boot);
|
|
106
|
+
</script>
|