@behivetech/atoms.tooltip 1.0.0 → 1.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BEhive Tech
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -46,3 +46,11 @@ name, and the explanation is reachable by keyboard and screen reader.
46
46
  ```
47
47
 
48
48
  No wrapper is added when the trigger is enabled.
49
+
50
+ ## On React Native
51
+
52
+ The same `Tooltip` renders in an Expo app through the `react-native` export condition, with the same block and the same `label` and `side` props; there is no `className`, so restyle the tooltip with `styles`. There is no hover on a phone, so the tooltip shows on a long press of the trigger (its `onLongPress` runs too) for a few seconds. A screen reader hears it as the trigger's hint (the trigger's own `accessibilityHint` wins, and an icon-only control needs its own `accessibilityLabel`) and as an announcement when it appears. The tooltip is drawn beside the trigger, with no arrow and no animation, so reduced motion has nothing to reduce.
53
+
54
+ The trigger is your own element with no wrapper around it, so its layout is what it is without the tooltip (as on the web, where no wrapper is added when the trigger is enabled). It is given `onLongPress`, which a `Pressable`, a `Text` and the registry's controls take, the responder handlers that time the hold for an element that takes none (an `Avatar`, a `View`), and a `ref`, which is how the tooltip finds it on screen; its own handlers and `ref` still run. A disabled trigger is the one exception: it is wrapped in a group that takes the long press for it and carries the tooltip as its hint.
55
+
56
+ The tooltip is drawn in the app's `OverlayHost` (`@behivetech/blocks.core/native`, mounted once around the app), above everything else in the window: no ancestor clips it, no sibling paints over it, and inside a Modal or a Drawer it is drawn in the dialog's own layer. Above and below the trigger it is level with the trigger's start edge, or with its end edge when that leaves it more room (a control in the far corner of the screen), and beside the trigger with its top; a long label wraps before it reaches the edge of the screen, in a right-to-left app too. It does not move to another side when the one asked for has no room, so pick a `side` that has some (`bottom` for a control at the top of the screen). An app that mounts no `OverlayHost` shows no tooltip (development says so); the hint and the announcement still reach a screen reader. Android speaks the tooltip through its live region and iOS through an announcement.
package/dist/index.cjs CHANGED
@@ -37,15 +37,72 @@ module.exports = __toCommonJS(index_exports);
37
37
  // tooltip.tsx
38
38
  var import_react = require("react");
39
39
  var RadixTooltip = __toESM(require("@radix-ui/react-tooltip"), 1);
40
- var import_get_class_name = require("@behivetech/get-class-name");
40
+ var import_blocks2 = require("@behivetech/blocks.core");
41
41
 
42
- // tooltip.module.scss
43
- var tooltip_module_default = {
44
- "BHT__Tooltip__content": "BHT__Tooltip__content",
45
- "tooltip-in": "tooltip-in",
46
- "BHT__Tooltip__arrow": "BHT__Tooltip__arrow",
47
- "BHT__Tooltip__disabledTrigger": "BHT__Tooltip__disabledTrigger"
48
- };
42
+ // tooltip.block.ts
43
+ var import_blocks = require("@behivetech/blocks.core");
44
+ var import_tokens = require("@behivetech/blocks.core/tokens");
45
+ var { color, motion, shape, spacing, type } = import_tokens.tokens;
46
+ var tooltip = (0, import_blocks.defineBlock)("BHT__Tooltip", {
47
+ children: {
48
+ content: {
49
+ padding: [spacing[1], spacing[2]],
50
+ backgroundColor: color.inverseSurface,
51
+ color: color.inverseOnSurface,
52
+ borderRadius: shape.cornerExtraSmall,
53
+ fontFamily: type.bodySmall.font,
54
+ fontSize: type.bodySmall.size,
55
+ fontWeight: type.bodySmall.weight,
56
+ lineHeight: type.bodySmall.lineHeight,
57
+ letterSpacing: type.bodySmall.tracking,
58
+ maxWidth: "16rem",
59
+ web: {
60
+ zIndex: "var(--z-tooltip, 600)",
61
+ userSelect: "none",
62
+ "&[data-state=delayed-open]": {
63
+ animation: import_blocks.css`tooltip-in ${motion.durationShort3} ${motion.easingStandardDecelerate}`
64
+ }
65
+ },
66
+ // Native: the bubble is drawn in the overlay layer, which places it against the trigger.
67
+ native: { elevation: 8, minWidth: "6rem", textAlign: "center" }
68
+ },
69
+ arrow: { web: { fill: color.inverseSurface } },
70
+ // A focusable wrapper around a disabled control: a group, so a screen reader announces it as the
71
+ // container of the control it explains (the span's markup carries the role on the web).
72
+ disabledTrigger: {
73
+ a11y: { role: "group" },
74
+ display: "inline-flex",
75
+ states: {
76
+ focusVisible: {
77
+ outlineWidth: 3,
78
+ outlineStyle: "solid",
79
+ outlineColor: color.secondary,
80
+ outlineOffset: 2
81
+ }
82
+ },
83
+ web: { "& > *": { pointerEvents: "none" } }
84
+ }
85
+ },
86
+ // Native only: the gap between the trigger and the tooltip, on the side the tooltip sits on (the overlay
87
+ // layer places the tooltip against that edge of the trigger).
88
+ variants: {
89
+ sideTop: {
90
+ children: { content: { native: { marginBottom: spacing[2] } } }
91
+ },
92
+ sideBottom: {
93
+ children: { content: { native: { marginTop: spacing[2] } } }
94
+ },
95
+ sideLeft: {
96
+ children: { content: { native: { marginRight: spacing[2] } } }
97
+ },
98
+ sideRight: {
99
+ children: { content: { native: { marginLeft: spacing[2] } } }
100
+ }
101
+ },
102
+ web: {
103
+ "@keyframes tooltip-in": { from: { opacity: 0 }, to: { opacity: 1 } }
104
+ }
105
+ });
49
106
 
50
107
  // tooltip.tsx
51
108
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -59,26 +116,23 @@ var Tooltip = ({
59
116
  label,
60
117
  side = "top",
61
118
  children,
62
- className
119
+ className,
120
+ styles
63
121
  }) => {
64
- const [, getChildClass] = (0, import_get_class_name.getClassName)({
65
- className,
66
- rootClass: "BHT__Tooltip",
67
- styles: tooltip_module_default
68
- });
122
+ const [, childProps] = (0, import_blocks2.useBlock)(tooltip, {}, { styles });
69
123
  const disabled = isDisabled(children);
70
- const trigger = disabled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: getChildClass("disabledTrigger"), tabIndex: 0, children }) : children;
124
+ const trigger = disabled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { ...childProps("disabledTrigger"), role: "group", tabIndex: 0, children }) : children;
71
125
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RadixTooltip.Provider, { delayDuration: DELAY_DURATION, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(RadixTooltip.Root, { children: [
72
126
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RadixTooltip.Trigger, { asChild: true, children: trigger }),
73
127
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RadixTooltip.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
74
128
  RadixTooltip.Content,
75
129
  {
76
- className: getChildClass("content"),
130
+ ...childProps("content", { className }),
77
131
  side,
78
132
  sideOffset: 6,
79
133
  children: [
80
134
  label,
81
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RadixTooltip.Arrow, { className: getChildClass("arrow") })
135
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RadixTooltip.Arrow, { ...childProps("arrow") })
82
136
  ]
83
137
  }
84
138
  ) })
package/dist/index.css CHANGED
@@ -1,39 +1,43 @@
1
- /* esbuild-sass-plugin:css-chunktooltip.module.scss */
2
- .BHT__Tooltip__content {
3
- padding: var(--spacing-1, 0.25rem) var(--spacing-2, 0.5rem);
4
- background: var(--md-sys-color-inverse-surface, var(--color-on-surface));
5
- color: var(--md-sys-color-inverse-on-surface, var(--color-surface));
6
- border-radius: var(--md-sys-shape-corner-extra-small, 4px);
7
- font-family: var(--md-sys-typescale-body-small-font, var(--font-body));
8
- font-size: var(--md-sys-typescale-body-small-size, 0.75rem);
9
- font-weight: var(--md-sys-typescale-body-small-weight, 400);
10
- line-height: var(--md-sys-typescale-body-small-line-height, 1rem);
11
- letter-spacing: var(--md-sys-typescale-body-small-tracking, 0.0333em);
12
- max-width: 16rem;
13
- z-index: var(--z-tooltip, 600);
14
- user-select: none;
15
- }
16
- .BHT__Tooltip__content[data-state=delayed-open] {
17
- animation: tooltip-in var(--md-sys-motion-duration-short-3, 150ms) var(--md-sys-motion-easing-standard-decelerate, ease-out);
18
- }
19
- .BHT__Tooltip__arrow {
20
- fill: var(--md-sys-color-inverse-surface, var(--color-on-surface));
21
- }
22
- .BHT__Tooltip__disabledTrigger {
23
- display: inline-flex;
24
- }
25
- .BHT__Tooltip__disabledTrigger > * {
26
- pointer-events: none;
27
- }
28
- .BHT__Tooltip__disabledTrigger:focus-visible {
29
- outline: 3px solid var(--md-sys-color-secondary, var(--color-border-focus));
30
- outline-offset: 2px;
31
- }
32
- @keyframes tooltip-in {
33
- from {
34
- opacity: 0;
1
+ /* tooltip.block.css */
2
+ @layer bht {
3
+ .BHT__Tooltip__content {
4
+ padding: var(--spacing-1, 0.25rem) var(--spacing-2, 0.5rem);
5
+ background-color: var(--md-sys-color-inverse-surface, #303030);
6
+ color: var(--md-sys-color-inverse-on-surface, #f1f1f1);
7
+ border-radius: var(--md-sys-shape-corner-extra-small, 4px);
8
+ font-family: var( --md-sys-typescale-body-small-font, "Inter", system-ui, -apple-system, sans-serif );
9
+ font-size: var(--md-sys-typescale-body-small-size, 0.75rem);
10
+ font-weight: var(--md-sys-typescale-body-small-weight, 400);
11
+ line-height: var(--md-sys-typescale-body-small-line-height, 1rem);
12
+ letter-spacing: var(--md-sys-typescale-body-small-tracking, 0.0333em);
13
+ max-width: 16rem;
14
+ z-index: var(--z-tooltip, 600);
15
+ user-select: none;
16
+ }
17
+ .BHT__Tooltip__content[data-state=delayed-open] {
18
+ animation: tooltip-in var(--md-sys-motion-duration-short-3, 150ms) var(--md-sys-motion-easing-standard-decelerate, cubic-bezier(0, 0, 0, 1));
19
+ }
20
+ .BHT__Tooltip__arrow {
21
+ fill: var(--md-sys-color-inverse-surface, #303030);
22
+ }
23
+ .BHT__Tooltip__disabled-trigger {
24
+ display: inline-flex;
25
+ }
26
+ .BHT__Tooltip__disabled-trigger:focus-visible {
27
+ outline-width: 3px;
28
+ outline-style: solid;
29
+ outline-color: var(--md-sys-color-secondary, #615b71);
30
+ outline-offset: 2px;
31
+ }
32
+ .BHT__Tooltip__disabled-trigger > * {
33
+ pointer-events: none;
35
34
  }
36
- to {
37
- opacity: 1;
35
+ @keyframes tooltip-in {
36
+ from {
37
+ opacity: 0;
38
+ }
39
+ to {
40
+ opacity: 1;
41
+ }
38
42
  }
39
43
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,108 @@
1
1
  import * as react from 'react';
2
2
  import { ReactElement } from 'react';
3
+ import * as _behivetech_blocks_core from '@behivetech/blocks.core';
4
+ import { StylesFor } from '@behivetech/blocks.core';
5
+
6
+ declare const tooltip: _behivetech_blocks_core.Block<"BHT__Tooltip", {
7
+ readonly children: {
8
+ readonly content: {
9
+ readonly padding: readonly [_behivetech_blocks_core.Token<"length">, _behivetech_blocks_core.Token<"length">];
10
+ readonly backgroundColor: _behivetech_blocks_core.Token<"color">;
11
+ readonly color: _behivetech_blocks_core.Token<"color">;
12
+ readonly borderRadius: _behivetech_blocks_core.Token<"length">;
13
+ readonly fontFamily: _behivetech_blocks_core.Token<"font">;
14
+ readonly fontSize: _behivetech_blocks_core.Token<"length">;
15
+ readonly fontWeight: _behivetech_blocks_core.Token<"weight">;
16
+ readonly lineHeight: _behivetech_blocks_core.Token<"length">;
17
+ readonly letterSpacing: _behivetech_blocks_core.Token<"tracking">;
18
+ readonly maxWidth: "16rem";
19
+ readonly web: {
20
+ readonly zIndex: "var(--z-tooltip, 600)";
21
+ readonly userSelect: "none";
22
+ readonly "&[data-state=delayed-open]": {
23
+ readonly animation: _behivetech_blocks_core.CssValue;
24
+ };
25
+ };
26
+ readonly native: {
27
+ readonly elevation: 8;
28
+ readonly minWidth: "6rem";
29
+ readonly textAlign: "center";
30
+ };
31
+ };
32
+ readonly arrow: {
33
+ readonly web: {
34
+ readonly fill: _behivetech_blocks_core.Token<"color">;
35
+ };
36
+ };
37
+ readonly disabledTrigger: {
38
+ readonly a11y: {
39
+ readonly role: "group";
40
+ };
41
+ readonly display: "inline-flex";
42
+ readonly states: {
43
+ readonly focusVisible: {
44
+ readonly outlineWidth: 3;
45
+ readonly outlineStyle: "solid";
46
+ readonly outlineColor: _behivetech_blocks_core.Token<"color">;
47
+ readonly outlineOffset: 2;
48
+ };
49
+ };
50
+ readonly web: {
51
+ readonly "& > *": {
52
+ readonly pointerEvents: "none";
53
+ };
54
+ };
55
+ };
56
+ };
57
+ readonly variants: {
58
+ readonly sideTop: {
59
+ readonly children: {
60
+ readonly content: {
61
+ readonly native: {
62
+ readonly marginBottom: _behivetech_blocks_core.Token<"length">;
63
+ };
64
+ };
65
+ };
66
+ };
67
+ readonly sideBottom: {
68
+ readonly children: {
69
+ readonly content: {
70
+ readonly native: {
71
+ readonly marginTop: _behivetech_blocks_core.Token<"length">;
72
+ };
73
+ };
74
+ };
75
+ };
76
+ readonly sideLeft: {
77
+ readonly children: {
78
+ readonly content: {
79
+ readonly native: {
80
+ readonly marginRight: _behivetech_blocks_core.Token<"length">;
81
+ };
82
+ };
83
+ };
84
+ };
85
+ readonly sideRight: {
86
+ readonly children: {
87
+ readonly content: {
88
+ readonly native: {
89
+ readonly marginLeft: _behivetech_blocks_core.Token<"length">;
90
+ };
91
+ };
92
+ };
93
+ };
94
+ };
95
+ readonly web: {
96
+ readonly "@keyframes tooltip-in": {
97
+ readonly from: {
98
+ readonly opacity: 0;
99
+ };
100
+ readonly to: {
101
+ readonly opacity: 1;
102
+ };
103
+ };
104
+ };
105
+ }>;
3
106
 
4
107
  type TooltipSide = "top" | "right" | "bottom" | "left";
5
108
  interface TooltipProps {
@@ -11,6 +114,8 @@ interface TooltipProps {
11
114
  children: ReactElement;
12
115
  /** Additional class names to merge with the tooltip content element */
13
116
  className?: string;
117
+ /** An override block made with `defineBlock`, typed to this component's children and variants; it wins over the block's own styles. */
118
+ styles?: StylesFor<typeof tooltip>;
14
119
  }
15
120
  /**
16
121
  * Names a control on hover and on keyboard focus, built on Radix's `Tooltip`.
@@ -25,6 +130,6 @@ interface TooltipProps {
25
130
  * matters most — when the control is unavailable and the user wants to know
26
131
  * why — including by keyboard, since a disabled control is not focusable.
27
132
  */
28
- declare const Tooltip: ({ label, side, children, className, }: TooltipProps) => react.JSX.Element;
133
+ declare const Tooltip: ({ label, side, children, className, styles, }: TooltipProps) => react.JSX.Element;
29
134
 
30
135
  export { Tooltip, type TooltipProps, type TooltipSide };
package/dist/index.js CHANGED
@@ -1,15 +1,72 @@
1
1
  // tooltip.tsx
2
2
  import { isValidElement } from "react";
3
3
  import * as RadixTooltip from "@radix-ui/react-tooltip";
4
- import { getClassName } from "@behivetech/get-class-name";
4
+ import { useBlock } from "@behivetech/blocks.core";
5
5
 
6
- // tooltip.module.scss
7
- var tooltip_module_default = {
8
- "BHT__Tooltip__content": "BHT__Tooltip__content",
9
- "tooltip-in": "tooltip-in",
10
- "BHT__Tooltip__arrow": "BHT__Tooltip__arrow",
11
- "BHT__Tooltip__disabledTrigger": "BHT__Tooltip__disabledTrigger"
12
- };
6
+ // tooltip.block.ts
7
+ import { css, defineBlock } from "@behivetech/blocks.core";
8
+ import { tokens } from "@behivetech/blocks.core/tokens";
9
+ var { color, motion, shape, spacing, type } = tokens;
10
+ var tooltip = defineBlock("BHT__Tooltip", {
11
+ children: {
12
+ content: {
13
+ padding: [spacing[1], spacing[2]],
14
+ backgroundColor: color.inverseSurface,
15
+ color: color.inverseOnSurface,
16
+ borderRadius: shape.cornerExtraSmall,
17
+ fontFamily: type.bodySmall.font,
18
+ fontSize: type.bodySmall.size,
19
+ fontWeight: type.bodySmall.weight,
20
+ lineHeight: type.bodySmall.lineHeight,
21
+ letterSpacing: type.bodySmall.tracking,
22
+ maxWidth: "16rem",
23
+ web: {
24
+ zIndex: "var(--z-tooltip, 600)",
25
+ userSelect: "none",
26
+ "&[data-state=delayed-open]": {
27
+ animation: css`tooltip-in ${motion.durationShort3} ${motion.easingStandardDecelerate}`
28
+ }
29
+ },
30
+ // Native: the bubble is drawn in the overlay layer, which places it against the trigger.
31
+ native: { elevation: 8, minWidth: "6rem", textAlign: "center" }
32
+ },
33
+ arrow: { web: { fill: color.inverseSurface } },
34
+ // A focusable wrapper around a disabled control: a group, so a screen reader announces it as the
35
+ // container of the control it explains (the span's markup carries the role on the web).
36
+ disabledTrigger: {
37
+ a11y: { role: "group" },
38
+ display: "inline-flex",
39
+ states: {
40
+ focusVisible: {
41
+ outlineWidth: 3,
42
+ outlineStyle: "solid",
43
+ outlineColor: color.secondary,
44
+ outlineOffset: 2
45
+ }
46
+ },
47
+ web: { "& > *": { pointerEvents: "none" } }
48
+ }
49
+ },
50
+ // Native only: the gap between the trigger and the tooltip, on the side the tooltip sits on (the overlay
51
+ // layer places the tooltip against that edge of the trigger).
52
+ variants: {
53
+ sideTop: {
54
+ children: { content: { native: { marginBottom: spacing[2] } } }
55
+ },
56
+ sideBottom: {
57
+ children: { content: { native: { marginTop: spacing[2] } } }
58
+ },
59
+ sideLeft: {
60
+ children: { content: { native: { marginRight: spacing[2] } } }
61
+ },
62
+ sideRight: {
63
+ children: { content: { native: { marginLeft: spacing[2] } } }
64
+ }
65
+ },
66
+ web: {
67
+ "@keyframes tooltip-in": { from: { opacity: 0 }, to: { opacity: 1 } }
68
+ }
69
+ });
13
70
 
14
71
  // tooltip.tsx
15
72
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -23,26 +80,23 @@ var Tooltip = ({
23
80
  label,
24
81
  side = "top",
25
82
  children,
26
- className
83
+ className,
84
+ styles
27
85
  }) => {
28
- const [, getChildClass] = getClassName({
29
- className,
30
- rootClass: "BHT__Tooltip",
31
- styles: tooltip_module_default
32
- });
86
+ const [, childProps] = useBlock(tooltip, {}, { styles });
33
87
  const disabled = isDisabled(children);
34
- const trigger = disabled ? /* @__PURE__ */ jsx("span", { className: getChildClass("disabledTrigger"), tabIndex: 0, children }) : children;
88
+ const trigger = disabled ? /* @__PURE__ */ jsx("span", { ...childProps("disabledTrigger"), role: "group", tabIndex: 0, children }) : children;
35
89
  return /* @__PURE__ */ jsx(RadixTooltip.Provider, { delayDuration: DELAY_DURATION, children: /* @__PURE__ */ jsxs(RadixTooltip.Root, { children: [
36
90
  /* @__PURE__ */ jsx(RadixTooltip.Trigger, { asChild: true, children: trigger }),
37
91
  /* @__PURE__ */ jsx(RadixTooltip.Portal, { children: /* @__PURE__ */ jsxs(
38
92
  RadixTooltip.Content,
39
93
  {
40
- className: getChildClass("content"),
94
+ ...childProps("content", { className }),
41
95
  side,
42
96
  sideOffset: 6,
43
97
  children: [
44
98
  label,
45
- /* @__PURE__ */ jsx(RadixTooltip.Arrow, { className: getChildClass("arrow") })
99
+ /* @__PURE__ */ jsx(RadixTooltip.Arrow, { ...childProps("arrow") })
46
100
  ]
47
101
  }
48
102
  ) })