@tanishqkancharla/maui 0.0.50 → 0.0.52
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/dist/components/Tooltip.d.ts +5 -2
- package/dist/components/Tooltip.js +12 -9
- package/dist/tokens/prose.js +4 -11
- package/package.json +1 -1
- package/src/components/Tooltip.tsx +20 -13
- package/src/tokens/prose.ts +4 -12
|
@@ -3,8 +3,11 @@ type TooltipPlacement = "top" | "bottom" | "left" | "right";
|
|
|
3
3
|
type TooltipProps = {
|
|
4
4
|
/** The content shown inside the tooltip. */
|
|
5
5
|
content: React.ReactNode;
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The trigger: one focusable element, such as a Button, that forwards its
|
|
8
|
+
* ref and passes event handlers and ARIA props to the DOM.
|
|
9
|
+
*/
|
|
10
|
+
children: React.ReactElement;
|
|
8
11
|
placement?: TooltipPlacement;
|
|
9
12
|
/** Warmup delay in ms before the tooltip shows on hover. */
|
|
10
13
|
delay?: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
3
3
|
import ReactDOM from "react-dom";
|
|
4
|
-
import { mergeProps, useOverlayPosition, useTooltip, useTooltipTrigger, } from "react-aria";
|
|
4
|
+
import { mergeProps, mergeRefs, useOverlayPosition, useTooltip, useTooltipTrigger, } from "react-aria";
|
|
5
5
|
import { useTooltipTriggerState } from "react-stately";
|
|
6
6
|
import { useReducedMotion } from "motion/react";
|
|
7
7
|
import { style, useStyles } from "purse-styles";
|
|
@@ -16,9 +16,17 @@ export function Tooltip(props) {
|
|
|
16
16
|
const state = useTooltipTriggerState({ delay, isDisabled });
|
|
17
17
|
const triggerRef = useRef(null);
|
|
18
18
|
const { triggerProps, tooltipProps } = useTooltipTrigger({ delay, isDisabled }, state, triggerRef);
|
|
19
|
-
const triggerClassName = useStyles(triggerClass);
|
|
20
19
|
const transition = useTooltipTransition(state.isOpen);
|
|
21
|
-
|
|
20
|
+
// The trigger props go on the focusable element itself, as react-aria's
|
|
21
|
+
// FocusableProvider does. On a wrapper, focus never opened the tooltip
|
|
22
|
+
// (react-aria ignores focus on descendants) and aria-describedby missed
|
|
23
|
+
// the focused element.
|
|
24
|
+
const child = React.Children.only(children);
|
|
25
|
+
const trigger = React.cloneElement(child, {
|
|
26
|
+
...mergeProps(child.props, triggerProps),
|
|
27
|
+
ref: mergeRefs(child.props.ref, triggerRef),
|
|
28
|
+
});
|
|
29
|
+
return (_jsxs(_Fragment, { children: [trigger, transition.render && (_jsx(TooltipPopup, { state: state, triggerRef: triggerRef, placement: placement, animateIn: transition.animateIn, phase: transition.phase, onExited: transition.onExited, ...tooltipProps, children: content }))] }));
|
|
22
30
|
}
|
|
23
31
|
/**
|
|
24
32
|
* Coordinates enter/exit transitions across every tooltip so the animation only
|
|
@@ -155,11 +163,6 @@ function TooltipPopup(props) {
|
|
|
155
163
|
}
|
|
156
164
|
}, children: children }), document.body);
|
|
157
165
|
}
|
|
158
|
-
// The wrapper makes the trigger hoverable/focusable as a unit without
|
|
159
|
-
// affecting layout of the child.
|
|
160
|
-
const triggerClass = style({
|
|
161
|
-
display: "inline-block",
|
|
162
|
-
});
|
|
163
166
|
const tooltipClass = style(text({ size: "xs", fontWeight: 400, color: "highContrast" }), radius.sm, spacing.padding({ x: 3, y: 2 }), border([], "outline"), background.element, {
|
|
164
167
|
zIndex: 1000,
|
|
165
168
|
maxWidth: "240px",
|
package/dist/tokens/prose.js
CHANGED
|
@@ -38,7 +38,6 @@ const metrics = {
|
|
|
38
38
|
},
|
|
39
39
|
listPadding: 22,
|
|
40
40
|
listItemGap: 4,
|
|
41
|
-
listNestedGap: 8,
|
|
42
41
|
},
|
|
43
42
|
md: {
|
|
44
43
|
blockGap: 20,
|
|
@@ -69,7 +68,6 @@ const metrics = {
|
|
|
69
68
|
},
|
|
70
69
|
listPadding: 26,
|
|
71
70
|
listItemGap: 8,
|
|
72
|
-
listNestedGap: 12,
|
|
73
71
|
},
|
|
74
72
|
lg: {
|
|
75
73
|
blockGap: 24,
|
|
@@ -100,7 +98,6 @@ const metrics = {
|
|
|
100
98
|
},
|
|
101
99
|
listPadding: 28,
|
|
102
100
|
listItemGap: 12,
|
|
103
|
-
listNestedGap: 16,
|
|
104
101
|
},
|
|
105
102
|
};
|
|
106
103
|
// Slightly tighter reading rhythm on the Large platform scale.
|
|
@@ -148,12 +145,10 @@ export const prose = memoize((size) => {
|
|
|
148
145
|
fontWeight: 400,
|
|
149
146
|
color: bodyColor,
|
|
150
147
|
paddingInlineStart: px(m.listPadding),
|
|
151
|
-
|
|
148
|
+
// One gap between items at any depth, including through wrappers.
|
|
149
|
+
"& li + li, & li ul, & li ol": {
|
|
152
150
|
marginTop: px(m.listItemGap),
|
|
153
151
|
},
|
|
154
|
-
"& li > ul, & li > ol": {
|
|
155
|
-
marginTop: px(m.listNestedGap),
|
|
156
|
-
},
|
|
157
152
|
}),
|
|
158
153
|
};
|
|
159
154
|
});
|
|
@@ -279,12 +274,10 @@ export const proseHtml = memoize((size) => {
|
|
|
279
274
|
paddingRight: "0.4em",
|
|
280
275
|
boxSizing: "border-box",
|
|
281
276
|
},
|
|
282
|
-
|
|
277
|
+
// One gap between items at any depth, including through editor node views.
|
|
278
|
+
"& li + li, & li ul, & li ol": {
|
|
283
279
|
marginTop: px(m.listItemGap),
|
|
284
280
|
},
|
|
285
|
-
"& li > ul, & li > ol": {
|
|
286
|
-
marginTop: px(m.listNestedGap),
|
|
287
|
-
},
|
|
288
281
|
"& strong": { fontWeight: 600 },
|
|
289
282
|
"& em": { fontStyle: "italic" },
|
|
290
283
|
"& code": {
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import React, { useEffect, useRef, useState } from "react"
|
|
|
2
2
|
import ReactDOM from "react-dom"
|
|
3
3
|
import {
|
|
4
4
|
mergeProps,
|
|
5
|
+
mergeRefs,
|
|
5
6
|
useOverlayPosition,
|
|
6
7
|
useTooltip,
|
|
7
8
|
useTooltipTrigger,
|
|
@@ -22,8 +23,11 @@ type TooltipPlacement = "top" | "bottom" | "left" | "right"
|
|
|
22
23
|
type TooltipProps = {
|
|
23
24
|
/** The content shown inside the tooltip. */
|
|
24
25
|
content: React.ReactNode
|
|
25
|
-
/**
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The trigger: one focusable element, such as a Button, that forwards its
|
|
28
|
+
* ref and passes event handlers and ARIA props to the DOM.
|
|
29
|
+
*/
|
|
30
|
+
children: React.ReactElement
|
|
27
31
|
placement?: TooltipPlacement
|
|
28
32
|
/** Warmup delay in ms before the tooltip shows on hover. */
|
|
29
33
|
delay?: number
|
|
@@ -40,21 +44,30 @@ export function Tooltip(props: TooltipProps) {
|
|
|
40
44
|
} = props
|
|
41
45
|
|
|
42
46
|
const state = useTooltipTriggerState({ delay, isDisabled })
|
|
43
|
-
const triggerRef = useRef<
|
|
47
|
+
const triggerRef = useRef<HTMLElement>(null)
|
|
44
48
|
const { triggerProps, tooltipProps } = useTooltipTrigger(
|
|
45
49
|
{ delay, isDisabled },
|
|
46
50
|
state,
|
|
47
51
|
triggerRef,
|
|
48
52
|
)
|
|
49
53
|
|
|
50
|
-
const triggerClassName = useStyles(triggerClass)
|
|
51
54
|
const transition = useTooltipTransition(state.isOpen)
|
|
52
55
|
|
|
56
|
+
// The trigger props go on the focusable element itself, as react-aria's
|
|
57
|
+
// FocusableProvider does. On a wrapper, focus never opened the tooltip
|
|
58
|
+
// (react-aria ignores focus on descendants) and aria-describedby missed
|
|
59
|
+
// the focused element.
|
|
60
|
+
const child = React.Children.only(children) as React.ReactElement<
|
|
61
|
+
Record<string, unknown> & { ref?: React.Ref<HTMLElement> }
|
|
62
|
+
>
|
|
63
|
+
const trigger = React.cloneElement(child, {
|
|
64
|
+
...mergeProps(child.props, triggerProps),
|
|
65
|
+
ref: mergeRefs(child.props.ref, triggerRef),
|
|
66
|
+
})
|
|
67
|
+
|
|
53
68
|
return (
|
|
54
69
|
<>
|
|
55
|
-
|
|
56
|
-
{children}
|
|
57
|
-
</span>
|
|
70
|
+
{trigger}
|
|
58
71
|
{transition.render && (
|
|
59
72
|
<TooltipPopup
|
|
60
73
|
state={state}
|
|
@@ -257,12 +270,6 @@ function TooltipPopup(props: TooltipPopupProps) {
|
|
|
257
270
|
)
|
|
258
271
|
}
|
|
259
272
|
|
|
260
|
-
// The wrapper makes the trigger hoverable/focusable as a unit without
|
|
261
|
-
// affecting layout of the child.
|
|
262
|
-
const triggerClass = style({
|
|
263
|
-
display: "inline-block",
|
|
264
|
-
})
|
|
265
|
-
|
|
266
273
|
const tooltipClass = style(
|
|
267
274
|
text({ size: "xs", fontWeight: 400, color: "highContrast" }),
|
|
268
275
|
radius.sm,
|
package/src/tokens/prose.ts
CHANGED
|
@@ -45,7 +45,6 @@ type ProseMetric = {
|
|
|
45
45
|
h4: HeadingMetric
|
|
46
46
|
listPadding: number
|
|
47
47
|
listItemGap: number
|
|
48
|
-
listNestedGap: number
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
/** A block size that steps up with the platform data scale. */
|
|
@@ -84,7 +83,6 @@ const metrics: Record<ProseSize, ProseMetric> = {
|
|
|
84
83
|
},
|
|
85
84
|
listPadding: 22,
|
|
86
85
|
listItemGap: 4,
|
|
87
|
-
listNestedGap: 8,
|
|
88
86
|
},
|
|
89
87
|
md: {
|
|
90
88
|
blockGap: 20,
|
|
@@ -115,7 +113,6 @@ const metrics: Record<ProseSize, ProseMetric> = {
|
|
|
115
113
|
},
|
|
116
114
|
listPadding: 26,
|
|
117
115
|
listItemGap: 8,
|
|
118
|
-
listNestedGap: 12,
|
|
119
116
|
},
|
|
120
117
|
lg: {
|
|
121
118
|
blockGap: 24,
|
|
@@ -146,7 +143,6 @@ const metrics: Record<ProseSize, ProseMetric> = {
|
|
|
146
143
|
},
|
|
147
144
|
listPadding: 28,
|
|
148
145
|
listItemGap: 12,
|
|
149
|
-
listNestedGap: 16,
|
|
150
146
|
},
|
|
151
147
|
}
|
|
152
148
|
|
|
@@ -200,12 +196,10 @@ export const prose = memoize((size: ProseSize) => {
|
|
|
200
196
|
fontWeight: 400,
|
|
201
197
|
color: bodyColor,
|
|
202
198
|
paddingInlineStart: px(m.listPadding),
|
|
203
|
-
|
|
199
|
+
// One gap between items at any depth, including through wrappers.
|
|
200
|
+
"& li + li, & li ul, & li ol": {
|
|
204
201
|
marginTop: px(m.listItemGap),
|
|
205
202
|
},
|
|
206
|
-
"& li > ul, & li > ol": {
|
|
207
|
-
marginTop: px(m.listNestedGap),
|
|
208
|
-
},
|
|
209
203
|
}),
|
|
210
204
|
}
|
|
211
205
|
})
|
|
@@ -336,12 +330,10 @@ export const proseHtml = memoize((size: ProseSize) => {
|
|
|
336
330
|
paddingRight: "0.4em",
|
|
337
331
|
boxSizing: "border-box",
|
|
338
332
|
},
|
|
339
|
-
|
|
333
|
+
// One gap between items at any depth, including through editor node views.
|
|
334
|
+
"& li + li, & li ul, & li ol": {
|
|
340
335
|
marginTop: px(m.listItemGap),
|
|
341
336
|
},
|
|
342
|
-
"& li > ul, & li > ol": {
|
|
343
|
-
marginTop: px(m.listNestedGap),
|
|
344
|
-
},
|
|
345
337
|
"& strong": { fontWeight: 600 },
|
|
346
338
|
"& em": { fontStyle: "italic" },
|
|
347
339
|
"& code": {
|