@xsolla/xui-tooltip 0.149.1 → 0.150.0-pr271.1778112109
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/README.md +87 -163
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
# Tooltip
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A hover- or focus-triggered popover that displays contextual information next to a trigger element. Web-only rendering (uses a portal); on React Native the trigger is rendered without the tooltip surface.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @xsolla/xui-tooltip
|
|
9
|
-
# or
|
|
10
|
-
yarn add @xsolla/xui-tooltip
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
##
|
|
11
|
+
## Imports
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
```tsx
|
|
14
|
+
import { Tooltip, type TooltipProps, type TooltipPlacement, type TooltipSize } from '@xsolla/xui-tooltip';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
16
18
|
|
|
17
19
|
```tsx
|
|
18
20
|
import * as React from 'react';
|
|
19
21
|
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
20
22
|
import { Button } from '@xsolla/xui-button';
|
|
21
23
|
|
|
22
|
-
export default function
|
|
24
|
+
export default function Example() {
|
|
23
25
|
return (
|
|
24
26
|
<Tooltip content="This is a helpful tip">
|
|
25
27
|
<Button>Hover me</Button>
|
|
@@ -28,128 +30,108 @@ export default function BasicTooltip() {
|
|
|
28
30
|
}
|
|
29
31
|
```
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
## API Reference
|
|
34
|
+
|
|
35
|
+
### `<Tooltip>`
|
|
36
|
+
|
|
37
|
+
| Prop | Type | Default | Description |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| `content` | `ReactNode` | — | **Required.** Tooltip content. Strings/numbers render as themed text. |
|
|
40
|
+
| `children` | `ReactNode` | — | **Required.** Trigger element. |
|
|
41
|
+
| `size` | `"sm" \| "md" \| "lg" \| "xl"` | `"md"` | Typography size. |
|
|
42
|
+
| `placement` | `TooltipPlacement` | `"top"` | Position relative to trigger. |
|
|
43
|
+
| `offset` | `number` | `12` | Distance from trigger in pixels. |
|
|
44
|
+
| `delayEnter` | `number` | `0` | Delay before showing (ms). |
|
|
45
|
+
| `delayLeave` | `number` | `0` | Delay before hiding (ms). |
|
|
46
|
+
| `controlledVisible` | `boolean` | — | Externally controlled visibility. Overrides hover/focus state. |
|
|
47
|
+
| `style` | `CSSProperties` | — | Custom styles applied to the tooltip surface (web only). |
|
|
48
|
+
| `className` | `string` | — | Custom class for the trigger wrapper. |
|
|
49
|
+
| `data-testid` | `string` | — | Test identifier. |
|
|
50
|
+
|
|
51
|
+
Inherits `ThemeOverrideProps` (`themeMode`, `themeProductContext`).
|
|
52
|
+
|
|
53
|
+
`TooltipPlacement` is `"top" | "top-left" | "top-right" | "bottom" | "bottom-left" | "bottom-right" | "left" | "right"`.
|
|
54
|
+
|
|
55
|
+
### Size typography
|
|
56
|
+
|
|
57
|
+
| Size | Font size | Line height |
|
|
58
|
+
| --- | --- | --- |
|
|
59
|
+
| `sm` | 14px | 16px |
|
|
60
|
+
| `md` | 16px | 18px |
|
|
61
|
+
| `lg` | 18px | 20px |
|
|
62
|
+
| `xl` | 20px | 22px |
|
|
63
|
+
|
|
64
|
+
## Examples
|
|
65
|
+
|
|
66
|
+
### Placements
|
|
32
67
|
|
|
33
68
|
```tsx
|
|
34
69
|
import * as React from 'react';
|
|
35
70
|
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
36
71
|
import { Button } from '@xsolla/xui-button';
|
|
37
72
|
|
|
38
|
-
export default function
|
|
73
|
+
export default function Placements() {
|
|
39
74
|
return (
|
|
40
75
|
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 16, padding: 48 }}>
|
|
41
|
-
<Tooltip content="Top left" placement="top-left">
|
|
42
|
-
|
|
43
|
-
</Tooltip>
|
|
44
|
-
<Tooltip content="
|
|
45
|
-
<Button variant="secondary">Top</Button>
|
|
46
|
-
</Tooltip>
|
|
47
|
-
<Tooltip content="Top right" placement="top-right">
|
|
48
|
-
<Button variant="secondary">Top Right</Button>
|
|
49
|
-
</Tooltip>
|
|
50
|
-
|
|
51
|
-
<Tooltip content="Left side" placement="left">
|
|
52
|
-
<Button variant="secondary">Left</Button>
|
|
53
|
-
</Tooltip>
|
|
76
|
+
<Tooltip content="Top left" placement="top-left"><Button variant="secondary">Top Left</Button></Tooltip>
|
|
77
|
+
<Tooltip content="Top centre" placement="top"><Button variant="secondary">Top</Button></Tooltip>
|
|
78
|
+
<Tooltip content="Top right" placement="top-right"><Button variant="secondary">Top Right</Button></Tooltip>
|
|
79
|
+
<Tooltip content="Left" placement="left"><Button variant="secondary">Left</Button></Tooltip>
|
|
54
80
|
<div />
|
|
55
|
-
<Tooltip content="Right
|
|
56
|
-
|
|
57
|
-
</Tooltip>
|
|
58
|
-
|
|
59
|
-
<Tooltip content="Bottom left" placement="bottom-left">
|
|
60
|
-
<Button variant="secondary">Bottom Left</Button>
|
|
61
|
-
</Tooltip>
|
|
62
|
-
<Tooltip content="Bottom center" placement="bottom">
|
|
63
|
-
<Button variant="secondary">Bottom</Button>
|
|
64
|
-
</Tooltip>
|
|
65
|
-
<Tooltip content="Bottom right" placement="bottom-right">
|
|
66
|
-
<Button variant="secondary">Bottom Right</Button>
|
|
67
|
-
</Tooltip>
|
|
81
|
+
<Tooltip content="Right" placement="right"><Button variant="secondary">Right</Button></Tooltip>
|
|
82
|
+
<Tooltip content="Bottom left" placement="bottom-left"><Button variant="secondary">Bottom Left</Button></Tooltip>
|
|
83
|
+
<Tooltip content="Bottom centre" placement="bottom"><Button variant="secondary">Bottom</Button></Tooltip>
|
|
84
|
+
<Tooltip content="Bottom right" placement="bottom-right"><Button variant="secondary">Bottom Right</Button></Tooltip>
|
|
68
85
|
</div>
|
|
69
86
|
);
|
|
70
87
|
}
|
|
71
88
|
```
|
|
72
89
|
|
|
73
|
-
###
|
|
90
|
+
### Sizes
|
|
74
91
|
|
|
75
92
|
```tsx
|
|
76
93
|
import * as React from 'react';
|
|
77
94
|
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
78
95
|
import { Button } from '@xsolla/xui-button';
|
|
79
96
|
|
|
80
|
-
export default function
|
|
97
|
+
export default function Sizes() {
|
|
81
98
|
return (
|
|
82
99
|
<div style={{ display: 'flex', gap: 16 }}>
|
|
83
|
-
<Tooltip content="Small
|
|
84
|
-
|
|
85
|
-
</Tooltip>
|
|
86
|
-
<Tooltip content="
|
|
87
|
-
<Button variant="secondary">Medium</Button>
|
|
88
|
-
</Tooltip>
|
|
89
|
-
<Tooltip content="Large tooltip" size="lg">
|
|
90
|
-
<Button variant="secondary">Large</Button>
|
|
91
|
-
</Tooltip>
|
|
92
|
-
<Tooltip content="Extra large tooltip" size="xl">
|
|
93
|
-
<Button variant="secondary">XL</Button>
|
|
94
|
-
</Tooltip>
|
|
100
|
+
<Tooltip content="Small" size="sm"><Button variant="secondary">Small</Button></Tooltip>
|
|
101
|
+
<Tooltip content="Medium" size="md"><Button variant="secondary">Medium</Button></Tooltip>
|
|
102
|
+
<Tooltip content="Large" size="lg"><Button variant="secondary">Large</Button></Tooltip>
|
|
103
|
+
<Tooltip content="Extra large" size="xl"><Button variant="secondary">XL</Button></Tooltip>
|
|
95
104
|
</div>
|
|
96
105
|
);
|
|
97
106
|
}
|
|
98
107
|
```
|
|
99
108
|
|
|
100
|
-
###
|
|
109
|
+
### With delay
|
|
101
110
|
|
|
102
111
|
```tsx
|
|
103
112
|
import * as React from 'react';
|
|
104
113
|
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
105
114
|
import { Button } from '@xsolla/xui-button';
|
|
106
115
|
|
|
107
|
-
export default function
|
|
116
|
+
export default function Delays() {
|
|
108
117
|
return (
|
|
109
118
|
<div style={{ display: 'flex', gap: 16 }}>
|
|
110
|
-
<Tooltip content="Appears immediately" delayEnter={0}>
|
|
111
|
-
|
|
112
|
-
</Tooltip>
|
|
113
|
-
<Tooltip content="Appears after 500ms" delayEnter={500}>
|
|
114
|
-
<Button variant="secondary">500ms Delay</Button>
|
|
115
|
-
</Tooltip>
|
|
116
|
-
<Tooltip content="Stays visible for 500ms" delayLeave={500}>
|
|
117
|
-
<Button variant="secondary">Slow Hide</Button>
|
|
118
|
-
</Tooltip>
|
|
119
|
+
<Tooltip content="Appears immediately" delayEnter={0}><Button variant="secondary">No delay</Button></Tooltip>
|
|
120
|
+
<Tooltip content="Appears after 500ms" delayEnter={500}><Button variant="secondary">500ms enter</Button></Tooltip>
|
|
121
|
+
<Tooltip content="Stays for 500ms" delayLeave={500}><Button variant="secondary">Slow hide</Button></Tooltip>
|
|
119
122
|
</div>
|
|
120
123
|
);
|
|
121
124
|
}
|
|
122
125
|
```
|
|
123
126
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
Import the component and wrap your trigger element:
|
|
127
|
-
|
|
128
|
-
```jsx
|
|
129
|
-
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
130
|
-
|
|
131
|
-
<Tooltip
|
|
132
|
-
content="Tooltip text" // Content to display
|
|
133
|
-
placement="top" // Position relative to trigger
|
|
134
|
-
size="md" // Size variant
|
|
135
|
-
offset={12} // Distance from trigger
|
|
136
|
-
delayEnter={0} // Delay before showing
|
|
137
|
-
delayLeave={0} // Delay before hiding
|
|
138
|
-
>
|
|
139
|
-
<TriggerElement />
|
|
140
|
-
</Tooltip>
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## Examples
|
|
144
|
-
|
|
145
|
-
### Rich Content Tooltip
|
|
127
|
+
### Rich content
|
|
146
128
|
|
|
147
129
|
```tsx
|
|
148
130
|
import * as React from 'react';
|
|
149
131
|
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
150
132
|
import { Avatar } from '@xsolla/xui-avatar';
|
|
151
133
|
|
|
152
|
-
export default function
|
|
134
|
+
export default function Rich() {
|
|
153
135
|
return (
|
|
154
136
|
<Tooltip
|
|
155
137
|
content={
|
|
@@ -166,64 +148,57 @@ export default function RichContentTooltip() {
|
|
|
166
148
|
}
|
|
167
149
|
```
|
|
168
150
|
|
|
169
|
-
###
|
|
151
|
+
### Icons with tooltip
|
|
170
152
|
|
|
171
153
|
```tsx
|
|
172
154
|
import * as React from 'react';
|
|
173
155
|
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
174
|
-
import { Edit, TrashCan,
|
|
156
|
+
import { Edit, TrashCan, MoreHr } from '@xsolla/xui-icons-base';
|
|
175
157
|
|
|
176
|
-
export default function
|
|
158
|
+
export default function Icons() {
|
|
177
159
|
return (
|
|
178
160
|
<div style={{ display: 'flex', gap: 16 }}>
|
|
179
|
-
<Tooltip content="Edit item">
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
<Tooltip content="Delete item">
|
|
183
|
-
<TrashCan style={{ cursor: 'pointer' }} />
|
|
184
|
-
</Tooltip>
|
|
185
|
-
<Tooltip content="More options">
|
|
186
|
-
<MoreHorizontal style={{ cursor: 'pointer' }} />
|
|
187
|
-
</Tooltip>
|
|
161
|
+
<Tooltip content="Edit item"><Edit style={{ cursor: 'pointer' }} /></Tooltip>
|
|
162
|
+
<Tooltip content="Delete item"><TrashCan style={{ cursor: 'pointer' }} /></Tooltip>
|
|
163
|
+
<Tooltip content="More options"><MoreHr style={{ cursor: 'pointer' }} /></Tooltip>
|
|
188
164
|
</div>
|
|
189
165
|
);
|
|
190
166
|
}
|
|
191
167
|
```
|
|
192
168
|
|
|
193
|
-
### Controlled
|
|
169
|
+
### Controlled visibility
|
|
194
170
|
|
|
195
171
|
```tsx
|
|
196
172
|
import * as React from 'react';
|
|
197
173
|
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
198
174
|
import { Button } from '@xsolla/xui-button';
|
|
199
175
|
|
|
200
|
-
export default function
|
|
176
|
+
export default function Controlled() {
|
|
201
177
|
const [visible, setVisible] = React.useState(false);
|
|
202
|
-
|
|
203
178
|
return (
|
|
204
179
|
<div style={{ display: 'flex', gap: 16 }}>
|
|
205
|
-
<Tooltip content="I'm controlled
|
|
180
|
+
<Tooltip content="I'm controlled" controlledVisible={visible}>
|
|
206
181
|
<Button variant="secondary">Target</Button>
|
|
207
182
|
</Tooltip>
|
|
208
|
-
<Button onPress={() => setVisible(!
|
|
209
|
-
{visible ? 'Hide' : 'Show'} Tooltip
|
|
210
|
-
</Button>
|
|
183
|
+
<Button onPress={() => setVisible((v) => !v)}>{visible ? 'Hide' : 'Show'}</Button>
|
|
211
184
|
</div>
|
|
212
185
|
);
|
|
213
186
|
}
|
|
214
187
|
```
|
|
215
188
|
|
|
216
|
-
### Disabled
|
|
189
|
+
### Disabled trigger
|
|
190
|
+
|
|
191
|
+
`disabled` elements do not emit pointer events; wrap them so the tooltip can still register hover.
|
|
217
192
|
|
|
218
193
|
```tsx
|
|
219
194
|
import * as React from 'react';
|
|
220
195
|
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
221
196
|
import { Button } from '@xsolla/xui-button';
|
|
222
197
|
|
|
223
|
-
export default function
|
|
198
|
+
export default function DisabledTrigger() {
|
|
224
199
|
return (
|
|
225
|
-
<Tooltip content="
|
|
226
|
-
<span>
|
|
200
|
+
<Tooltip content="Complete the form first">
|
|
201
|
+
<span>
|
|
227
202
|
<Button disabled>Submit</Button>
|
|
228
203
|
</span>
|
|
229
204
|
</Tooltip>
|
|
@@ -231,64 +206,13 @@ export default function DisabledButtonTooltip() {
|
|
|
231
206
|
}
|
|
232
207
|
```
|
|
233
208
|
|
|
234
|
-
##
|
|
235
|
-
|
|
236
|
-
### Tooltip
|
|
237
|
-
|
|
238
|
-
A tooltip component that shows on hover/focus.
|
|
239
|
-
|
|
240
|
-
**Tooltip Props:**
|
|
209
|
+
## Accessibility
|
|
241
210
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
| size | `"sm" \| "md" \| "lg" \| "xl"` | `"md"` | Size of the tooltip. |
|
|
247
|
-
| placement | `TooltipPlacement` | `"top"` | Position relative to trigger. |
|
|
248
|
-
| offset | `number` | `12` | Distance from trigger in pixels. |
|
|
249
|
-
| delayEnter | `number` | - | Delay before showing (ms). |
|
|
250
|
-
| delayLeave | `number` | - | Delay before hiding (ms). |
|
|
251
|
-
| controlledVisible | `boolean` | - | Control visibility externally. |
|
|
252
|
-
| style | `CSSProperties` | - | Custom styles. |
|
|
253
|
-
| className | `string` | - | Custom class name. |
|
|
254
|
-
| data-testid | `string` | - | Test identifier. |
|
|
255
|
-
|
|
256
|
-
**TooltipPlacement Options:**
|
|
257
|
-
|
|
258
|
-
| Placement | Description |
|
|
259
|
-
| :-------- | :---------- |
|
|
260
|
-
| `top` | Centered above trigger |
|
|
261
|
-
| `top-left` | Above, aligned to left edge |
|
|
262
|
-
| `top-right` | Above, aligned to right edge |
|
|
263
|
-
| `bottom` | Centered below trigger |
|
|
264
|
-
| `bottom-left` | Below, aligned to left edge |
|
|
265
|
-
| `bottom-right` | Below, aligned to right edge |
|
|
266
|
-
| `left` | Centered to the left |
|
|
267
|
-
| `right` | Centered to the right |
|
|
268
|
-
|
|
269
|
-
**Size Typography:**
|
|
270
|
-
|
|
271
|
-
| Size | Font Size | Line Height |
|
|
272
|
-
| :--- | :-------- | :---------- |
|
|
273
|
-
| sm | 14px | 16px |
|
|
274
|
-
| md | 16px | 18px |
|
|
275
|
-
| lg | 18px | 20px |
|
|
276
|
-
| xl | 20px | 22px |
|
|
277
|
-
|
|
278
|
-
## Theming
|
|
279
|
-
|
|
280
|
-
Tooltip uses the design system theme for colors:
|
|
281
|
-
|
|
282
|
-
```typescript
|
|
283
|
-
// Colors accessed via theme
|
|
284
|
-
theme.colors.background.inverse // Tooltip background
|
|
285
|
-
theme.colors.content.inverse // Tooltip text
|
|
286
|
-
```
|
|
211
|
+
- Tooltip surface uses `role="tooltip"` and `aria-hidden` reflects visibility.
|
|
212
|
+
- Trigger receives `aria-describedby` while the tooltip is visible.
|
|
213
|
+
- Press Escape to dismiss.
|
|
214
|
+
- Tooltip content is non-interactive — for interactive content, prefer [Toggletip](./toggletip.md).
|
|
287
215
|
|
|
288
|
-
##
|
|
216
|
+
## Related
|
|
289
217
|
|
|
290
|
-
-
|
|
291
|
-
- Press Escape to dismiss tooltip
|
|
292
|
-
- Arrow indicator points to trigger element
|
|
293
|
-
- Content is accessible to screen readers
|
|
294
|
-
- Follows WCAG tooltip guidelines
|
|
218
|
+
- [Toggletip](./toggletip.md) — click-triggered popover with rich content.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsolla/xui-tooltip",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.150.0-pr271.1778112109",
|
|
4
4
|
"main": "./web/index.js",
|
|
5
5
|
"module": "./web/index.mjs",
|
|
6
6
|
"types": "./web/index.d.ts",
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"test:coverage": "vitest run --coverage"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@xsolla/xui-button": "0.
|
|
17
|
-
"@xsolla/xui-core": "0.
|
|
18
|
-
"@xsolla/xui-primitives-core": "0.
|
|
16
|
+
"@xsolla/xui-button": "0.150.0-pr271.1778112109",
|
|
17
|
+
"@xsolla/xui-core": "0.150.0-pr271.1778112109",
|
|
18
|
+
"@xsolla/xui-primitives-core": "0.150.0-pr271.1778112109"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": ">=16.8.0",
|