@roadlittledawn/docs-design-system-react 0.12.2 → 0.12.3

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/USAGE.md CHANGED
@@ -1035,7 +1035,15 @@ A hover/tap-activated floating panel for enriching inline documentation content.
1035
1035
 
1036
1036
  ### Mobile behavior
1037
1037
 
1038
- On screens ≤ 640px, the popover renders as a **bottom sheet** instead of a floating panel. Hover doesn't apply on touch devices; the popover toggles on tap.
1038
+ On screens ≤ 640px, the popover renders as a **bottom sheet** instead of a floating panel. Hover doesn't apply on touch devices; the popover opens on tap.
1039
+
1040
+ ### Closing the popover
1041
+
1042
+ The popover can be closed in three ways:
1043
+
1044
+ - **Close button** — the × button in the upper-right corner of the panel
1045
+ - **Click / tap outside** — native light-dismiss provided by `popover="auto"`
1046
+ - **Escape key** — handled automatically by the Popover API
1039
1047
 
1040
1048
  ### Content modes (choose one)
1041
1049
 
@@ -80,6 +80,14 @@ export function Popover(_a) {
80
80
  var popoverRef = useRef(null);
81
81
  var showTimerRef = useRef(null);
82
82
  var hideTimerRef = useRef(null);
83
+ // Tracks when the popover was last shown automatically (hover/focus).
84
+ // Used to prevent the click handler from immediately closing a popover that
85
+ // was just opened by the hover timer (fixes the first-tap flicker on touch).
86
+ // On touch devices the synthetic `click` arrives ~300 ms after touch-start;
87
+ // the guard window must exceed showDelay (200 ms default) + that browser
88
+ // delay, so 400 ms is a safe minimum.
89
+ var FLICKER_GUARD_MS = 400;
90
+ var lastAutoShowTimeRef = useRef(0);
83
91
  var clearTimers = useCallback(function () {
84
92
  if (showTimerRef.current)
85
93
  clearTimeout(showTimerRef.current);
@@ -131,6 +139,8 @@ export function Popover(_a) {
131
139
  }
132
140
  positionPopover();
133
141
  popover.style.visibility = "";
142
+ // Record the time so the click handler knows the popover was auto-shown
143
+ lastAutoShowTimeRef.current = Date.now();
134
144
  }, showDelay);
135
145
  }, [clearTimers, showDelay, positionPopover]);
136
146
  var hidePopover = useCallback(function () {
@@ -188,6 +198,15 @@ export function Popover(_a) {
188
198
  var popover = popoverRef.current;
189
199
  if (!popover)
190
200
  return;
201
+ var isOpen = popover.matches(":popover-open") ||
202
+ popover.style.display === "block";
203
+ // Flicker guard: if the popover was just shown automatically by the
204
+ // hover/focus timer within the last 400 ms, a tap's synthetic click
205
+ // would arrive and toggle it closed. Instead, keep it open so the
206
+ // first tap reliably shows the popover.
207
+ if (isOpen && Date.now() - lastAutoShowTimeRef.current < FLICKER_GUARD_MS) {
208
+ return;
209
+ }
191
210
  try {
192
211
  popover.togglePopover();
193
212
  if (popover.matches(":popover-open"))
@@ -199,5 +218,17 @@ export function Popover(_a) {
199
218
  if (!isVisible)
200
219
  positionPopover();
201
220
  }
202
- }, "aria-describedby": popoverId, tabIndex: 0, children: children }), _jsx("div", __assign({ ref: popoverRef, id: popoverId }, { popover: "auto" }, { className: popoverClasses, onMouseEnter: clearTimers, onMouseLeave: hidePopover, children: popoverContent }))] }));
221
+ }, "aria-describedby": popoverId, tabIndex: 0, children: children }), _jsxs("div", __assign({ ref: popoverRef, id: popoverId }, { popover: "auto" }, { className: popoverClasses, onMouseEnter: clearTimers, onMouseLeave: hidePopover, children: [_jsx("button", { className: "dds-popover-close", "aria-label": "Close", onClick: function (e) {
222
+ e.stopPropagation();
223
+ clearTimers();
224
+ var popover = popoverRef.current;
225
+ if (!popover)
226
+ return;
227
+ try {
228
+ popover.hidePopover();
229
+ }
230
+ catch (_a) {
231
+ popover.style.display = "none";
232
+ }
233
+ }, children: "\u00D7" }), popoverContent] }))] }));
203
234
  }
@@ -64,7 +64,7 @@ var meta = {
64
64
  layout: "centered",
65
65
  docs: {
66
66
  description: {
67
- component: "\nA hover/tap-activated popover for enriching inline content in documentation.\nBuilt on the native [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API) for reliable top-layer rendering \u2014 no z-index wars, no overflow clipping.\n\nCommon use cases include glossary term definitions and Wikipedia-style content previews.\n\n## Content modes\n\nThe `Popover` supports three mutually exclusive content modes, checked in this order:\n\n1. **`content`** \u2014 arbitrary `ReactNode`; you control everything\n2. **`glossary`** \u2014 structured `{ term, title, definition }` template\n3. **`preview`** \u2014 structured `{ title, excerpt, imageUrl, href }` template\n\n## When to Use\n\n- Inline term definitions that would interrupt reading flow if expanded in-place\n- Link previews that let users get context without navigating away\n- Any contextual content that benefits from being on-demand rather than always visible\n\n## When Not to Use\n\n- For critical information users must read \u2014 use a `Callout` instead\n- As a primary navigation mechanism\n- For content that needs persistent visibility\n\n## Mobile behavior\n\nOn screens \u2264 640 px the popover renders as a bottom sheet instead of a floating panel.\nHover events don't apply; the popover toggles on tap.\n\n## Accessibility\n\n- Trigger has `tabIndex={0}` and shows the popover on focus (keyboard accessible)\n- Popover panel has `role=\"tooltip\"` and is linked via `aria-describedby`\n- The native Popover API handles Escape-key dismissal automatically\n- Light-dismiss (click outside) is provided by `popover=\"auto\"`\n ",
67
+ component: "\nA hover/tap-activated popover for enriching inline content in documentation.\nBuilt on the native [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API) for reliable top-layer rendering \u2014 no z-index wars, no overflow clipping.\n\nCommon use cases include glossary term definitions and Wikipedia-style content previews.\n\n## Content modes\n\nThe `Popover` supports three mutually exclusive content modes, checked in this order:\n\n1. **`content`** \u2014 arbitrary `ReactNode`; you control everything\n2. **`glossary`** \u2014 structured `{ term, title, definition }` template\n3. **`preview`** \u2014 structured `{ title, excerpt, imageUrl, href }` template\n\n## When to Use\n\n- Inline term definitions that would interrupt reading flow if expanded in-place\n- Link previews that let users get context without navigating away\n- Any contextual content that benefits from being on-demand rather than always visible\n\n## When Not to Use\n\n- For critical information users must read \u2014 use a `Callout` instead\n- As a primary navigation mechanism\n- For content that needs persistent visibility\n\n## Mobile behavior\n\nOn screens \u2264 640 px the popover renders as a bottom sheet instead of a floating panel.\nHover events don't apply; the popover opens on tap.\n\n## Closing the popover\n\nThe popover can be closed in three ways:\n- **Close button** \u2014 the \u00D7 button in the upper-right corner of the panel\n- **Click / tap outside** \u2014 native light-dismiss provided by `popover=\"auto\"`\n- **Escape key** \u2014 handled automatically by the Popover API\n\n## Accessibility\n\n- Trigger has `tabIndex={0}` and shows the popover on focus (keyboard accessible)\n- Popover panel has `role=\"tooltip\"` and is linked via `aria-describedby`\n- The native Popover API handles Escape-key dismissal automatically\n- Light-dismiss (click outside) is provided by `popover=\"auto\"`\n ",
68
68
  },
69
69
  },
70
70
  },
package/dist/styles.css CHANGED
@@ -1844,7 +1844,7 @@ a.no-text-decoration {
1844
1844
  /* Trigger */
1845
1845
  .dds-popover-trigger {
1846
1846
  display: inline;
1847
- cursor: default;
1847
+ cursor: help;
1848
1848
  text-decoration-line: underline;
1849
1849
  text-decoration-style: dotted;
1850
1850
  text-decoration-color: currentColor;
@@ -1940,6 +1940,38 @@ a.no-text-decoration {
1940
1940
  .dds-popover-lg {
1941
1941
  width: var(--dds-popover-width-lg);
1942
1942
  }
1943
+ /* ==========================================================================
1944
+ Close button — sits in the upper-right corner of the popover panel
1945
+ ========================================================================== */
1946
+ .dds-popover-close {
1947
+ position: absolute;
1948
+ top: 0.5rem;
1949
+ right: 0.5rem;
1950
+ display: flex;
1951
+ align-items: center;
1952
+ justify-content: center;
1953
+ width: 1.5rem;
1954
+ height: 1.5rem;
1955
+ padding: 0;
1956
+ background: transparent;
1957
+ border: none;
1958
+ border-radius: 0.25rem;
1959
+ cursor: pointer;
1960
+ color: var(--dds-popover-eyebrow-color);
1961
+ font-size: 1.125rem;
1962
+ line-height: 1;
1963
+ transition:
1964
+ background 120ms,
1965
+ color 120ms;
1966
+ }
1967
+ .dds-popover-close:hover {
1968
+ background: var(--dds-popover-border);
1969
+ color: var(--dds-popover-text);
1970
+ }
1971
+ .dds-popover-close:focus-visible {
1972
+ outline: 2px solid var(--dds-link-color);
1973
+ outline-offset: 2px;
1974
+ }
1943
1975
  /* ==========================================================================
1944
1976
  Shared inner elements
1945
1977
  ========================================================================== */
@@ -1951,6 +1983,7 @@ a.no-text-decoration {
1951
1983
  text-transform: uppercase;
1952
1984
  color: var(--dds-popover-eyebrow-color);
1953
1985
  margin-bottom: 0.25rem;
1986
+ padding-right: 1.75rem; /* leave room for the close button */
1954
1987
  }
1955
1988
  .dds-popover-title {
1956
1989
  margin: 0 0 0.5rem;
@@ -1958,6 +1991,7 @@ a.no-text-decoration {
1958
1991
  font-weight: var(--dds-font-semibold);
1959
1992
  color: var(--dds-popover-title-color);
1960
1993
  line-height: var(--dds-line-height-tight);
1994
+ padding-right: 1.75rem; /* leave room for the close button */
1961
1995
  }
1962
1996
  .dds-popover-title dfn {
1963
1997
  font-style: normal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roadlittledawn/docs-design-system-react",
3
- "version": "0.12.2",
3
+ "version": "0.12.3",
4
4
  "license": "MIT",
5
5
  "description": "React components for documentation design system",
6
6
  "repository": {