@xsolla/xui-tooltip 0.99.0 → 0.100.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/README.md +281 -17
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,36 +1,300 @@
|
|
|
1
|
-
|
|
1
|
+
---
|
|
2
|
+
title: Tooltip
|
|
3
|
+
subtitle: A tooltip that appears on hover or focus.
|
|
4
|
+
description: A cross-platform React tooltip component that shows contextual information when an element is hovered or focused.
|
|
5
|
+
---
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
# Tooltip
|
|
8
|
+
|
|
9
|
+
A cross-platform React tooltip component that displays contextual information when a user hovers over or focuses on an element. Supports multiple placements and animations.
|
|
4
10
|
|
|
5
11
|
## Installation
|
|
6
12
|
|
|
7
13
|
```bash
|
|
14
|
+
npm install @xsolla/xui-tooltip
|
|
15
|
+
# or
|
|
8
16
|
yarn add @xsolla/xui-tooltip
|
|
9
17
|
```
|
|
10
18
|
|
|
11
|
-
##
|
|
19
|
+
## Demo
|
|
20
|
+
|
|
21
|
+
### Basic Tooltip
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import * as React from 'react';
|
|
25
|
+
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
26
|
+
import { Button } from '@xsolla/xui-button';
|
|
27
|
+
|
|
28
|
+
export default function BasicTooltip() {
|
|
29
|
+
return (
|
|
30
|
+
<Tooltip content="This is a helpful tip">
|
|
31
|
+
<Button>Hover me</Button>
|
|
32
|
+
</Tooltip>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Tooltip Placements
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import * as React from 'react';
|
|
41
|
+
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
42
|
+
import { Button } from '@xsolla/xui-button';
|
|
43
|
+
|
|
44
|
+
export default function TooltipPlacements() {
|
|
45
|
+
return (
|
|
46
|
+
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 16, padding: 48 }}>
|
|
47
|
+
<Tooltip content="Top left" placement="top-left">
|
|
48
|
+
<Button variant="secondary">Top Left</Button>
|
|
49
|
+
</Tooltip>
|
|
50
|
+
<Tooltip content="Top center" placement="top">
|
|
51
|
+
<Button variant="secondary">Top</Button>
|
|
52
|
+
</Tooltip>
|
|
53
|
+
<Tooltip content="Top right" placement="top-right">
|
|
54
|
+
<Button variant="secondary">Top Right</Button>
|
|
55
|
+
</Tooltip>
|
|
56
|
+
|
|
57
|
+
<Tooltip content="Left side" placement="left">
|
|
58
|
+
<Button variant="secondary">Left</Button>
|
|
59
|
+
</Tooltip>
|
|
60
|
+
<div />
|
|
61
|
+
<Tooltip content="Right side" placement="right">
|
|
62
|
+
<Button variant="secondary">Right</Button>
|
|
63
|
+
</Tooltip>
|
|
64
|
+
|
|
65
|
+
<Tooltip content="Bottom left" placement="bottom-left">
|
|
66
|
+
<Button variant="secondary">Bottom Left</Button>
|
|
67
|
+
</Tooltip>
|
|
68
|
+
<Tooltip content="Bottom center" placement="bottom">
|
|
69
|
+
<Button variant="secondary">Bottom</Button>
|
|
70
|
+
</Tooltip>
|
|
71
|
+
<Tooltip content="Bottom right" placement="bottom-right">
|
|
72
|
+
<Button variant="secondary">Bottom Right</Button>
|
|
73
|
+
</Tooltip>
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Tooltip Sizes
|
|
12
80
|
|
|
13
81
|
```tsx
|
|
82
|
+
import * as React from 'react';
|
|
14
83
|
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
15
84
|
import { Button } from '@xsolla/xui-button';
|
|
16
85
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
<
|
|
20
|
-
|
|
21
|
-
|
|
86
|
+
export default function TooltipSizes() {
|
|
87
|
+
return (
|
|
88
|
+
<div style={{ display: 'flex', gap: 16 }}>
|
|
89
|
+
<Tooltip content="Small tooltip" size="sm">
|
|
90
|
+
<Button variant="secondary">Small</Button>
|
|
91
|
+
</Tooltip>
|
|
92
|
+
<Tooltip content="Medium tooltip" size="md">
|
|
93
|
+
<Button variant="secondary">Medium</Button>
|
|
94
|
+
</Tooltip>
|
|
95
|
+
<Tooltip content="Large tooltip" size="lg">
|
|
96
|
+
<Button variant="secondary">Large</Button>
|
|
97
|
+
</Tooltip>
|
|
98
|
+
<Tooltip content="Extra large tooltip" size="xl">
|
|
99
|
+
<Button variant="secondary">XL</Button>
|
|
100
|
+
</Tooltip>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
22
104
|
```
|
|
23
105
|
|
|
24
|
-
|
|
106
|
+
### Tooltip with Delay
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import * as React from 'react';
|
|
110
|
+
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
111
|
+
import { Button } from '@xsolla/xui-button';
|
|
112
|
+
|
|
113
|
+
export default function TooltipWithDelay() {
|
|
114
|
+
return (
|
|
115
|
+
<div style={{ display: 'flex', gap: 16 }}>
|
|
116
|
+
<Tooltip content="Appears immediately" delayEnter={0}>
|
|
117
|
+
<Button variant="secondary">No Delay</Button>
|
|
118
|
+
</Tooltip>
|
|
119
|
+
<Tooltip content="Appears after 500ms" delayEnter={500}>
|
|
120
|
+
<Button variant="secondary">500ms Delay</Button>
|
|
121
|
+
</Tooltip>
|
|
122
|
+
<Tooltip content="Stays visible for 500ms" delayLeave={500}>
|
|
123
|
+
<Button variant="secondary">Slow Hide</Button>
|
|
124
|
+
</Tooltip>
|
|
125
|
+
</div>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Anatomy
|
|
131
|
+
|
|
132
|
+
Import the component and wrap your trigger element:
|
|
133
|
+
|
|
134
|
+
```jsx
|
|
135
|
+
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
136
|
+
|
|
137
|
+
<Tooltip
|
|
138
|
+
content="Tooltip text" // Content to display
|
|
139
|
+
placement="top" // Position relative to trigger
|
|
140
|
+
size="md" // Size variant
|
|
141
|
+
offset={12} // Distance from trigger
|
|
142
|
+
delayEnter={0} // Delay before showing
|
|
143
|
+
delayLeave={0} // Delay before hiding
|
|
144
|
+
>
|
|
145
|
+
<TriggerElement />
|
|
146
|
+
</Tooltip>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Examples
|
|
150
|
+
|
|
151
|
+
### Rich Content Tooltip
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
import * as React from 'react';
|
|
155
|
+
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
156
|
+
import { Avatar } from '@xsolla/xui-avatar';
|
|
157
|
+
|
|
158
|
+
export default function RichContentTooltip() {
|
|
159
|
+
return (
|
|
160
|
+
<Tooltip
|
|
161
|
+
content={
|
|
162
|
+
<div style={{ textAlign: 'center' }}>
|
|
163
|
+
<strong>John Doe</strong>
|
|
164
|
+
<br />
|
|
165
|
+
<span style={{ opacity: 0.7 }}>Senior Developer</span>
|
|
166
|
+
</div>
|
|
167
|
+
}
|
|
168
|
+
>
|
|
169
|
+
<Avatar text="JD" />
|
|
170
|
+
</Tooltip>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Icon with Tooltip
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
import * as React from 'react';
|
|
179
|
+
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
180
|
+
import { Edit, TrashCan, MoreHorizontal } from '@xsolla/xui-icons-base';
|
|
181
|
+
|
|
182
|
+
export default function IconTooltip() {
|
|
183
|
+
return (
|
|
184
|
+
<div style={{ display: 'flex', gap: 16 }}>
|
|
185
|
+
<Tooltip content="Edit item">
|
|
186
|
+
<Edit style={{ cursor: 'pointer' }} />
|
|
187
|
+
</Tooltip>
|
|
188
|
+
<Tooltip content="Delete item">
|
|
189
|
+
<TrashCan style={{ cursor: 'pointer' }} />
|
|
190
|
+
</Tooltip>
|
|
191
|
+
<Tooltip content="More options">
|
|
192
|
+
<MoreHorizontal style={{ cursor: 'pointer' }} />
|
|
193
|
+
</Tooltip>
|
|
194
|
+
</div>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Controlled Tooltip
|
|
200
|
+
|
|
201
|
+
```tsx
|
|
202
|
+
import * as React from 'react';
|
|
203
|
+
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
204
|
+
import { Button } from '@xsolla/xui-button';
|
|
205
|
+
|
|
206
|
+
export default function ControlledTooltip() {
|
|
207
|
+
const [visible, setVisible] = React.useState(false);
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<div style={{ display: 'flex', gap: 16 }}>
|
|
211
|
+
<Tooltip content="I'm controlled!" controlledVisible={visible}>
|
|
212
|
+
<Button variant="secondary">Target</Button>
|
|
213
|
+
</Tooltip>
|
|
214
|
+
<Button onPress={() => setVisible(!visible)}>
|
|
215
|
+
{visible ? 'Hide' : 'Show'} Tooltip
|
|
216
|
+
</Button>
|
|
217
|
+
</div>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Disabled Button with Tooltip
|
|
223
|
+
|
|
224
|
+
```tsx
|
|
225
|
+
import * as React from 'react';
|
|
226
|
+
import { Tooltip } from '@xsolla/xui-tooltip';
|
|
227
|
+
import { Button } from '@xsolla/xui-button';
|
|
228
|
+
|
|
229
|
+
export default function DisabledButtonTooltip() {
|
|
230
|
+
return (
|
|
231
|
+
<Tooltip content="You need to complete the form first">
|
|
232
|
+
<span> {/* Wrapper needed for disabled elements */}
|
|
233
|
+
<Button disabled>Submit</Button>
|
|
234
|
+
</span>
|
|
235
|
+
</Tooltip>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## API Reference
|
|
25
241
|
|
|
26
242
|
### Tooltip
|
|
27
243
|
|
|
244
|
+
A tooltip component that shows on hover/focus.
|
|
245
|
+
|
|
246
|
+
**Tooltip Props:**
|
|
247
|
+
|
|
28
248
|
| Prop | Type | Default | Description |
|
|
29
|
-
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
-
|
|
|
249
|
+
| :--- | :--- | :------ | :---------- |
|
|
250
|
+
| content | `ReactNode` | - | **Required.** Tooltip content. |
|
|
251
|
+
| children | `ReactNode` | - | **Required.** Trigger element. |
|
|
252
|
+
| size | `"sm" \| "md" \| "lg" \| "xl"` | `"md"` | Size of the tooltip. |
|
|
253
|
+
| placement | `TooltipPlacement` | `"top"` | Position relative to trigger. |
|
|
254
|
+
| offset | `number` | `12` | Distance from trigger in pixels. |
|
|
255
|
+
| delayEnter | `number` | - | Delay before showing (ms). |
|
|
256
|
+
| delayLeave | `number` | - | Delay before hiding (ms). |
|
|
257
|
+
| controlledVisible | `boolean` | - | Control visibility externally. |
|
|
258
|
+
| style | `CSSProperties` | - | Custom styles. |
|
|
259
|
+
| className | `string` | - | Custom class name. |
|
|
260
|
+
| data-testid | `string` | - | Test identifier. |
|
|
261
|
+
|
|
262
|
+
**TooltipPlacement Options:**
|
|
263
|
+
|
|
264
|
+
| Placement | Description |
|
|
265
|
+
| :-------- | :---------- |
|
|
266
|
+
| `top` | Centered above trigger |
|
|
267
|
+
| `top-left` | Above, aligned to left edge |
|
|
268
|
+
| `top-right` | Above, aligned to right edge |
|
|
269
|
+
| `bottom` | Centered below trigger |
|
|
270
|
+
| `bottom-left` | Below, aligned to left edge |
|
|
271
|
+
| `bottom-right` | Below, aligned to right edge |
|
|
272
|
+
| `left` | Centered to the left |
|
|
273
|
+
| `right` | Centered to the right |
|
|
274
|
+
|
|
275
|
+
**Size Typography:**
|
|
276
|
+
|
|
277
|
+
| Size | Font Size | Line Height |
|
|
278
|
+
| :--- | :-------- | :---------- |
|
|
279
|
+
| sm | 14px | 16px |
|
|
280
|
+
| md | 16px | 18px |
|
|
281
|
+
| lg | 18px | 20px |
|
|
282
|
+
| xl | 20px | 22px |
|
|
283
|
+
|
|
284
|
+
## Theming
|
|
285
|
+
|
|
286
|
+
Tooltip uses the design system theme for colors:
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
// Colors accessed via theme
|
|
290
|
+
theme.colors.background.inverse // Tooltip background
|
|
291
|
+
theme.colors.content.inverse // Tooltip text
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## Accessibility
|
|
295
|
+
|
|
296
|
+
- Tooltip appears on focus for keyboard users
|
|
297
|
+
- Press Escape to dismiss tooltip
|
|
298
|
+
- Arrow indicator points to trigger element
|
|
299
|
+
- Content is accessible to screen readers
|
|
300
|
+
- Follows WCAG tooltip guidelines
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsolla/xui-tooltip",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.100.0",
|
|
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.100.0",
|
|
17
|
+
"@xsolla/xui-core": "0.100.0",
|
|
18
|
+
"@xsolla/xui-primitives-core": "0.100.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": ">=16.8.0",
|