@thecb/components 11.8.1 → 11.10.0-beta.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.
@@ -0,0 +1,25 @@
1
+ import { Canvas, Meta, Title, Story, Controls } from '@storybook/blocks';
2
+
3
+ import * as TooltipV2Stories from './TooltipV2.stories.js';
4
+
5
+ <Meta of={TooltipV2Stories} />
6
+
7
+ <Title />
8
+
9
+ TooltipV2 is an accessible tooltip component implementing the [WAI-ARIA Tooltip Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/). It displays supplemental information when the user hovers over or focuses on a trigger element.
10
+
11
+ The trigger can be either:
12
+ - **Custom children**: Pass any single React element as `children`. It will receive `aria-describedby`, focus, blur, and keyboard handlers automatically.
13
+ - **Default button**: When no `children` are provided, a `ButtonWithAction` is rendered using the `triggerText` prop.
14
+
15
+ The tooltip content (`content` prop) accepts a plain string or a React node for rich content. It is styled similarly to the Popover component, including an arrow pointing toward the trigger.
16
+
17
+ ### Accessibility
18
+ - The trigger element has `aria-describedby` referencing the tooltip.
19
+ - The tooltip container has `role="tooltip"`.
20
+ - Pressing **Escape** dismisses the tooltip.
21
+ - Focus stays on the trigger while the tooltip is displayed.
22
+
23
+ <Controls />
24
+
25
+ <Story />
@@ -0,0 +1,242 @@
1
+ import React from "react";
2
+ import TooltipV2 from "./TooltipV2";
3
+
4
+ const meta = {
5
+ title: "Molecules/TooltipV2",
6
+ component: TooltipV2,
7
+ parameters: {
8
+ layout: "centered"
9
+ },
10
+ tags: ["!autodocs"],
11
+ decorators: [
12
+ Story => (
13
+ <div style={{ padding: "120px 300px" }}>
14
+ <Story />
15
+ </div>
16
+ )
17
+ ],
18
+ args: {
19
+ tooltipID: "tooltip-v2-id",
20
+ triggerText: "Hover me",
21
+ content: "This is the tooltip content.",
22
+ contentPosition: {
23
+ top: "-110px",
24
+ right: "auto",
25
+ bottom: "auto",
26
+ left: "-225px"
27
+ },
28
+ arrowDirection: "down",
29
+ arrowPosition: {
30
+ arrowTop: "auto",
31
+ arrowRight: "10px",
32
+ arrowBottom: "-8px",
33
+ arrowLeft: "auto"
34
+ },
35
+ minWidth: "250px",
36
+ maxWidth: "300px",
37
+ height: "auto",
38
+ containerExtraStyles: "",
39
+ contentExtraStyles: "",
40
+ contentBackgroundColor: ""
41
+ },
42
+ argTypes: {
43
+ children: {
44
+ description:
45
+ "Optional trigger element. When provided, it replaces the default ButtonWithAction trigger. The child element will receive aria-describedby, focus, blur, and keydown handlers.",
46
+ table: {
47
+ type: { summary: "React.ReactNode" },
48
+ defaultValue: { summary: undefined }
49
+ }
50
+ },
51
+ content: {
52
+ description:
53
+ "The content displayed inside the tooltip. Can be a string or a React node/element.",
54
+ table: {
55
+ type: { summary: "string | React.ReactNode" },
56
+ defaultValue: { summary: '""' }
57
+ }
58
+ },
59
+ tooltipID: {
60
+ description:
61
+ "Unique ID for the tooltip content element. Used as the aria-describedby value on the trigger.",
62
+ table: {
63
+ type: { summary: "string" },
64
+ defaultValue: { summary: undefined }
65
+ }
66
+ },
67
+ triggerText: {
68
+ description:
69
+ "Text shown in the default ButtonWithAction trigger. Not needed when children are provided.",
70
+ table: {
71
+ type: { summary: "string" },
72
+ defaultValue: { summary: '""' }
73
+ }
74
+ },
75
+ contentPosition: {
76
+ description:
77
+ "CSS position values (top, right, bottom, left) for the tooltip content box relative to the trigger.",
78
+ table: {
79
+ type: { summary: "object" },
80
+ defaultValue: {
81
+ summary:
82
+ '{ top: "-110px", right: "auto", bottom: "auto", left: "-225px" }'
83
+ }
84
+ }
85
+ },
86
+ arrowDirection: {
87
+ description:
88
+ "Direction the tooltip arrow points (up, down, left, right).",
89
+ control: { type: "select" },
90
+ options: ["up", "down", "left", "right"],
91
+ table: {
92
+ type: { summary: "string" },
93
+ defaultValue: { summary: "down" }
94
+ }
95
+ },
96
+ arrowPosition: {
97
+ description:
98
+ "CSS position values (arrowTop, arrowRight, arrowBottom, arrowLeft) for the arrow element.",
99
+ table: {
100
+ type: { summary: "object" },
101
+ defaultValue: {
102
+ summary:
103
+ '{ arrowTop: "auto", arrowRight: "10px", arrowBottom: "-8px", arrowLeft: "auto" }'
104
+ }
105
+ }
106
+ },
107
+ minWidth: {
108
+ description: "Minimum width of the tooltip content box.",
109
+ table: {
110
+ type: { summary: "string" },
111
+ defaultValue: { summary: "250px" }
112
+ }
113
+ },
114
+ maxWidth: {
115
+ description: "Maximum width of the tooltip content box.",
116
+ table: {
117
+ type: { summary: "string" },
118
+ defaultValue: { summary: "300px" }
119
+ }
120
+ },
121
+ height: {
122
+ description: "Height of the tooltip content box.",
123
+ table: {
124
+ type: { summary: "string" },
125
+ defaultValue: { summary: "auto" }
126
+ }
127
+ },
128
+ containerExtraStyles: {
129
+ description:
130
+ "Additional CSS string applied to the tooltip container element.",
131
+ table: {
132
+ type: { summary: "string" },
133
+ defaultValue: { summary: '""' }
134
+ }
135
+ },
136
+ contentExtraStyles: {
137
+ description:
138
+ "Additional CSS string applied to the tooltip content element.",
139
+ table: {
140
+ type: { summary: "string" },
141
+ defaultValue: { summary: '""' }
142
+ }
143
+ },
144
+ contentBackgroundColor: {
145
+ description: "Background color of the tooltip content box.",
146
+ table: {
147
+ type: { summary: "string" },
148
+ defaultValue: { summary: "white" }
149
+ }
150
+ }
151
+ }
152
+ };
153
+
154
+ export default meta;
155
+
156
+ export const Basic = {
157
+ args: {
158
+ tooltipID: "tooltip-v2-basic",
159
+ triggerText: "What is this?",
160
+ content:
161
+ "This is a detailed explanation of a feature or term that the user may need more context about."
162
+ }
163
+ };
164
+
165
+ export const WithChildren = {
166
+ args: {
167
+ tooltipID: "tooltip-v2-children",
168
+ content: "Extra information about this label.",
169
+ contentPosition: {
170
+ top: "-84px",
171
+ right: "auto",
172
+ bottom: "auto",
173
+ left: "-225px"
174
+ }
175
+ },
176
+ render: args => (
177
+ <TooltipV2 {...args}>
178
+ <button type="button">Custom trigger</button>
179
+ </TooltipV2>
180
+ )
181
+ };
182
+
183
+ export const ReactNodeContent = {
184
+ args: {
185
+ tooltipID: "tooltip-v2-node-content",
186
+ triggerText: "Rich content",
187
+ contentPosition: {
188
+ top: "-126px",
189
+ right: "auto",
190
+ bottom: "auto",
191
+ left: "-225px"
192
+ },
193
+ content: (
194
+ <div style={{ padding: "8px" }}>
195
+ <strong>Bold title</strong>
196
+ <p>With a paragraph of detail below.</p>
197
+ </div>
198
+ )
199
+ }
200
+ };
201
+
202
+ export const TooltipBelow = {
203
+ args: {
204
+ tooltipID: "tooltip-v2-below",
205
+ triggerText: "Hover for info",
206
+ content: "This tooltip appears below the trigger.",
207
+ contentPosition: {
208
+ top: "50px",
209
+ right: "auto",
210
+ bottom: "auto",
211
+ left: "-225px"
212
+ },
213
+ arrowDirection: "up",
214
+ arrowPosition: {
215
+ arrowTop: "-8px",
216
+ arrowRight: "10px",
217
+ arrowBottom: "auto",
218
+ arrowLeft: "auto"
219
+ }
220
+ }
221
+ };
222
+
223
+ export const TooltipRight = {
224
+ args: {
225
+ tooltipID: "tooltip-v2-right",
226
+ triggerText: "Hover for info",
227
+ content: "This tooltip appears to the right.",
228
+ contentPosition: {
229
+ top: "-40px",
230
+ right: "auto",
231
+ bottom: "auto",
232
+ left: "calc(100% + 12px)"
233
+ },
234
+ arrowDirection: "left",
235
+ arrowPosition: {
236
+ arrowTop: "50%",
237
+ arrowRight: "auto",
238
+ arrowBottom: "auto",
239
+ arrowLeft: "-8px"
240
+ }
241
+ }
242
+ };
@@ -0,0 +1,19 @@
1
+ import {
2
+ MATISSE_BLUE,
3
+ PEACOCK_BLUE,
4
+ SAPPHIRE_BLUE
5
+ } from "../../../constants/colors";
6
+
7
+ export const TOOLTIP_V2_THEME_SOURCE = "Popover";
8
+
9
+ const hoverColor = SAPPHIRE_BLUE;
10
+ const activeColor = PEACOCK_BLUE;
11
+ const tooltipTriggerColor = MATISSE_BLUE;
12
+ const borderColor = "rgba(255, 255, 255, 0.85)";
13
+
14
+ export const fallbackValues = {
15
+ hoverColor,
16
+ activeColor,
17
+ tooltipTriggerColor,
18
+ borderColor
19
+ };
@@ -0,0 +1,31 @@
1
+ import React from "react";
2
+ import Expand from "../../../util/expand";
3
+
4
+ export interface TooltipV2Props {
5
+ children?: React.ReactNode;
6
+ content: string | React.ReactNode;
7
+ tooltipID: string;
8
+ triggerText?: string;
9
+ contentPosition?: {
10
+ top: string;
11
+ right: string;
12
+ bottom: string;
13
+ left: string;
14
+ };
15
+ arrowDirection?: string;
16
+ arrowPosition?: {
17
+ arrowTop: string;
18
+ arrowRight: string;
19
+ arrowBottom: string;
20
+ arrowLeft: string;
21
+ };
22
+ minWidth?: string;
23
+ maxWidth?: string;
24
+ height?: string;
25
+ containerExtraStyles?: string;
26
+ contentExtraStyles?: string;
27
+ contentBackgroundColor?: string;
28
+ }
29
+
30
+ export const TooltipV2: React.FC<Expand<TooltipV2Props> &
31
+ React.HTMLAttributes<HTMLElement>>;
@@ -0,0 +1,3 @@
1
+ import TooltipV2 from "./TooltipV2";
2
+
3
+ export default TooltipV2;