@uniflowed/ui 0.0.0-alpha.18 → 0.0.0-alpha.37

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/tooltip.js CHANGED
@@ -75,7 +75,7 @@ import { useStableCallback } from "@uniflowed/hooks/lifecycle";
75
75
 
76
76
  import type { Align, LogicalSide } from "./internal/anchor.js";
77
77
  import type { DelayGroup, HoverIntent } from "./internal/hover-intent.js";
78
- import type { Rest } from "./internal/merge-props.js";
78
+ import type { RenderProp, Rest } from "./internal/merge-props.js";
79
79
  import { composeRefs, withProps, withoutComposed } from "./internal/merge-props.js";
80
80
  import {
81
81
  DEFAULT_CLOSE_DELAY,
@@ -243,11 +243,7 @@ export component TooltipRoot(
243
243
  * `render` function that forgets to spread something still gets a working
244
244
  * tooltip; see the module header.
245
245
  */
246
- export component TooltipTrigger(
247
- children?: React.Node,
248
- render?: (props: Rest) => React.Node,
249
- ...rest: Rest
250
- ) {
246
+ export component TooltipTrigger(children?: React.Node, render?: RenderProp, ...rest: Rest) {
251
247
  const tooltip = useTooltip("Tooltip.Trigger");
252
248
  const { closeDelay, dismissed, intent, openDelay, setOpen, triggerRef } = tooltip;
253
249
  useFocusableTrigger(triggerRef, "Tooltip.Trigger");
@@ -301,25 +297,16 @@ export component TooltipTrigger(
301
297
  });
302
298
  // Only while it is there. `aria-describedby` pointing at an element that has
303
299
  // been removed is the dangling reference this package keeps coming back to.
304
- const ours = {
300
+ const props = withProps(withoutComposed(rest, ["ref"]), {
305
301
  "aria-describedby": tooltip.open ? `${tooltip.base}-body` : undefined,
302
+ children,
306
303
  ref: attach,
307
- };
304
+ });
308
305
 
309
306
  if (render != null) {
310
- return render(withProps(withoutComposed(rest, ["ref"]), ours));
307
+ return render(props);
311
308
  }
312
-
313
- return (
314
- <button
315
- {...withoutComposed(rest, ["ref"])}
316
- aria-describedby={ours["aria-describedby"]}
317
- ref={attach}
318
- type="button"
319
- >
320
- {children}
321
- </button>
322
- );
309
+ return <button {...props} type="button" />;
323
310
  }
324
311
 
325
312
  /**
@@ -337,6 +324,7 @@ export component TooltipBody(
337
324
  alignOffset?: number = 0,
338
325
  avoidCollisions?: boolean = true,
339
326
  collisionPadding?: number = 0,
327
+ render?: RenderProp,
340
328
  side?: LogicalSide = "top",
341
329
  sideOffset?: number = 0,
342
330
  ...rest: Rest
@@ -391,21 +379,22 @@ export component TooltipBody(
391
379
  return null;
392
380
  }
393
381
 
394
- return (
395
- <div
396
- {...withoutComposed(rest, ["ref"])}
397
- data-align={anchored.align}
398
- data-side={anchored.side}
399
- data-state="open"
400
- id={`${tooltip.base}-body`}
401
- ref={composeRefs(rest.ref, (element) => {
402
- bodyRef.current = element;
403
- })}
404
- role="tooltip"
405
- // No `tabIndex`. A tooltip the keyboard can land in is a stop the reader
406
- // did not ask for and cannot leave the way they expect.
407
- >
408
- {children}
409
- </div>
410
- );
382
+ const props = withProps(withoutComposed(rest, ["ref"]), {
383
+ children,
384
+ "data-align": anchored.align,
385
+ "data-side": anchored.side,
386
+ "data-state": "open",
387
+ id: `${tooltip.base}-body`,
388
+ ref: composeRefs(rest.ref, (element) => {
389
+ bodyRef.current = element;
390
+ }),
391
+ role: "tooltip",
392
+ // No `tabIndex`. A tooltip the keyboard can land in is a stop the reader
393
+ // did not ask for and cannot leave the way they expect.
394
+ });
395
+
396
+ if (render != null) {
397
+ return render(props);
398
+ }
399
+ return <div {...props} />;
411
400
  }