@tanishqkancharla/maui 0.0.49 → 0.0.51

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.
@@ -7,7 +7,8 @@ import { text } from "../tokens/text";
7
7
  import { memoize } from "../utils/memoize";
8
8
  export function Avatar({ name, size = "sm", className }) {
9
9
  const avatarClassName = useStyles(avatarClass(name, size));
10
- return (_jsx("span", { className: joinClassNames(avatarClassName, className), "aria-hidden": "true", children: initials(name) }));
10
+ const initialsClassName = useStyles(initialsClass);
11
+ return (_jsx("span", { className: joinClassNames(avatarClassName, className), "aria-hidden": "true", children: _jsx("span", { className: initialsClassName, children: initials(name) }) }));
11
12
  }
12
13
  const avatarPalette = [
13
14
  { background: colors.accent[4], color: colors.accent[11] },
@@ -82,6 +83,13 @@ const avatarClass = memoize((seed, size) => {
82
83
  color: palette.color,
83
84
  });
84
85
  });
86
+ // The grid centers the line box, which includes the font's descent, so
87
+ // capitals rode high. Trimming to cap height centers the letters themselves.
88
+ // text-box applies to block containers, not to the grid itself.
89
+ const initialsClass = style({
90
+ display: "block",
91
+ textBox: "trim-both cap alphabetic",
92
+ });
85
93
  function joinClassNames(...classNames) {
86
94
  return classNames.filter(Boolean).join(" ");
87
95
  }
@@ -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
- /** The trigger element. Must contain something focusable (e.g. a button). */
7
- children: React.ReactNode;
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
- return (_jsxs(_Fragment, { children: [_jsx("span", { ref: triggerRef, className: triggerClassName, ...triggerProps, children: children }), transition.render && (_jsx(TooltipPopup, { state: state, triggerRef: triggerRef, placement: placement, animateIn: transition.animateIn, phase: transition.phase, onExited: transition.onExited, ...tooltipProps, children: content }))] }));
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanishqkancharla/maui",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "description": "Maui design system",
5
5
  "type": "module",
6
6
  "main": "./dist/maui.js",
@@ -13,13 +13,14 @@ type AvatarProps = {
13
13
 
14
14
  export function Avatar({ name, size = "sm", className }: AvatarProps) {
15
15
  const avatarClassName = useStyles(avatarClass(name, size))
16
+ const initialsClassName = useStyles(initialsClass)
16
17
 
17
18
  return (
18
19
  <span
19
20
  className={joinClassNames(avatarClassName, className)}
20
21
  aria-hidden="true"
21
22
  >
22
- {initials(name)}
23
+ <span className={initialsClassName}>{initials(name)}</span>
23
24
  </span>
24
25
  )
25
26
  }
@@ -102,6 +103,14 @@ const avatarClass = memoize((seed: string, size: TextSize) => {
102
103
  })
103
104
  })
104
105
 
106
+ // The grid centers the line box, which includes the font's descent, so
107
+ // capitals rode high. Trimming to cap height centers the letters themselves.
108
+ // text-box applies to block containers, not to the grid itself.
109
+ const initialsClass = style({
110
+ display: "block",
111
+ textBox: "trim-both cap alphabetic",
112
+ })
113
+
105
114
  function joinClassNames(...classNames: Array<string | undefined>) {
106
115
  return classNames.filter(Boolean).join(" ")
107
116
  }
@@ -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
- /** The trigger element. Must contain something focusable (e.g. a button). */
26
- children: React.ReactNode
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<HTMLSpanElement>(null)
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
- <span ref={triggerRef} className={triggerClassName} {...triggerProps}>
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,