@robert-stackflow/oneui 0.6.21 → 0.6.22

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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.6.22
2
+
3
+ - Add opt-in Popover arrow and offset. The pointer tracks the anchor after viewport clamping; the body scrolls without clipping the pointer. Vertical surfaces flip when the other side offers more space.
4
+ - Animate pointed popovers with a small scale and slide from the pointer, preserving interrupted transitions and reduced-motion preferences.
5
+ - Add IconButton disclosure with a spaced, animated chevron and an expanded state; keep ordinary icon buttons unchanged.
6
+
1
7
  # 0.6.21
2
8
 
3
9
  - Add Link with inherited typography, subtle content links, shared hover/focus states and disabled navigation. Export from the root and Link subpath.
package/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  React 组件、应用外壳和两套可互换的主题。无 Electron、React Router、账户 API 或持久化存储依赖。
4
4
 
5
+ ## 带指向箭头的浮层(0.6.22)
6
+
7
+ `Popover arrow offset={14}` 在浮层边缘显示指向 anchor 的小三角,并以该点为原点轻微缩放、位移和淡入淡出。`offset` 控制浮层边缘与触发区域的距离;默认值保持原有布局。箭头在窗口边缘钳制位置后仍对准触发区域,内容在内部滚动。动效继承主题时长和减少动态效果设置。
8
+
9
+ `IconButton disclosure aria-expanded={open}` 自动添加有间距的展开箭头、旋转动效和展开状态;调用方只传主要图标。组合按钮的尺寸与焦点继续由 OneUI 负责。
10
+
5
11
  ## 内容链接与阅读字号(0.6.21)
6
12
 
7
13
  `Link` 从根入口或 `@robert-stackflow/oneui/Link` 导入。默认使用主题链接色;`variant="subtle"` 继承周围标题或正文的颜色与字体,统一 hover、键盘焦点和 disabled 行为,保留原生链接与新标签打开语义。应用无需单独定义标题链接样式。
@@ -1,7 +1,9 @@
1
1
  import type { ComponentPropsWithRef } from "react";
2
- export declare function IconButton({ label, loading, children, variant, size, ...props }: ComponentPropsWithRef<"button"> & {
2
+ export declare function IconButton({ label, loading, children, variant, size, disclosure, ...props }: ComponentPropsWithRef<"button"> & {
3
3
  label: string;
4
4
  loading?: boolean;
5
5
  variant?: "primary" | "secondary" | "ghost" | "danger";
6
6
  size?: "small" | "normal";
7
+ /** Add a spaced disclosure chevron, driven by aria-expanded. */
8
+ disclosure?: boolean;
7
9
  }): import("react").JSX.Element;
@@ -1,7 +1,8 @@
1
1
  "use client";
2
- import { jsx } from "react/jsx-runtime";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import { Spinner } from "./Spinner.js";
4
4
  import { Tooltip } from "./Tooltip.js";
5
+ import { DisclosureChevron } from "./DisclosureChevron.js";
5
6
  import s from "./IconButton.module.css";
6
7
  function IconButton({
7
8
  label,
@@ -9,6 +10,7 @@ function IconButton({
9
10
  children,
10
11
  variant = "ghost",
11
12
  size = "normal",
13
+ disclosure = false,
12
14
  ...props
13
15
  }) {
14
16
  return /* @__PURE__ */ jsx(Tooltip, { content: label, children: /* @__PURE__ */ jsx(
@@ -20,9 +22,18 @@ function IconButton({
20
22
  "aria-busy": loading || void 0,
21
23
  "data-variant": variant,
22
24
  "data-size": size,
25
+ "data-disclosure": disclosure || void 0,
23
26
  disabled: props.disabled || loading,
24
27
  className: `${s.iconButton} ${props.className || ""}`,
25
- children: /* @__PURE__ */ jsx("span", { className: s.icon, children: loading ? /* @__PURE__ */ jsx(Spinner, { decorative: true }) : children })
28
+ children: /* @__PURE__ */ jsxs("span", { className: s.icon, children: [
29
+ loading ? /* @__PURE__ */ jsx(Spinner, { decorative: true }) : children,
30
+ disclosure && /* @__PURE__ */ jsx(
31
+ DisclosureChevron,
32
+ {
33
+ expanded: props["aria-expanded"] === true || props["aria-expanded"] === "true"
34
+ }
35
+ )
36
+ ] })
26
37
  }
27
38
  ) });
28
39
  }
@@ -40,3 +40,16 @@
40
40
  color: var(--danger);
41
41
  background: var(--danger-soft);
42
42
  }
43
+ .iconButton[data-disclosure] {
44
+ width: auto;
45
+ padding-inline: 7px;
46
+ }
47
+ .iconButton[data-disclosure] .icon {
48
+ display: flex;
49
+ align-items: center;
50
+ gap: 3px;
51
+ }
52
+ .iconButton[data-disclosure][aria-expanded="true"] {
53
+ color: var(--accent-ink, var(--fg));
54
+ background: var(--hover);
55
+ }
@@ -1,6 +1,6 @@
1
1
  import { type ReactNode, type RefObject } from "react";
2
2
  import { type MenuSide } from "./motion";
3
- export declare function Popover({ open: requestedOpen, onClose, anchor, children, width, maxHeight, scrollable, side, align, label, role, id, onKeyDown, descriptionId, autoFocus, matchAnchorWidth, className, portalContainer, }: {
3
+ export declare function Popover({ open: requestedOpen, onClose, anchor, children, width, maxHeight, scrollable, side, align, label, role, id, onKeyDown, descriptionId, autoFocus, matchAnchorWidth, className, portalContainer, arrow, offset, }: {
4
4
  open: boolean;
5
5
  onClose(): void;
6
6
  anchor: RefObject<HTMLElement | null>;
@@ -21,4 +21,8 @@ export declare function Popover({ open: requestedOpen, onClose, anchor, children
21
21
  matchAnchorWidth?: boolean;
22
22
  className?: string;
23
23
  portalContainer?: HTMLElement | null;
24
+ /** Show a pointer toward the anchor, with motion originating at that point. */
25
+ arrow?: boolean;
26
+ /** Space between the anchor and surface edge, in CSS pixels. */
27
+ offset?: number;
24
28
  }): import("react").ReactPortal | null;
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { jsx } from "react/jsx-runtime";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
3
  import { usePortalRoot } from "./usePortalRoot.js";
4
4
  import { FieldContext } from "./field.js";
5
5
  import {
@@ -8,7 +8,11 @@ import {
8
8
  useEffect
9
9
  } from "react";
10
10
  import { createPortal } from "react-dom";
11
- import { menuSurfaceMotion, cancelMotion } from "./motion.js";
11
+ import {
12
+ menuSurfaceMotion,
13
+ popoverSurfaceMotion,
14
+ cancelMotion
15
+ } from "./motion.js";
12
16
  import s from "./Popover.module.css";
13
17
  import { useSurfacePortal } from "./surfacePortal.js";
14
18
  function Popover({
@@ -29,7 +33,9 @@ function Popover({
29
33
  autoFocus = true,
30
34
  matchAnchorWidth = false,
31
35
  className = "",
32
- portalContainer
36
+ portalContainer,
37
+ arrow = false,
38
+ offset
33
39
  }) {
34
40
  const root = usePortalRoot();
35
41
  const owner = useSurfacePortal(), portalHost = portalContainer || owner?.host || root, open = requestedOpen && owner?.active !== false;
@@ -37,6 +43,7 @@ function Popover({
37
43
  close.current = onClose;
38
44
  const opened = useRef(open);
39
45
  opened.current = open;
46
+ const animate = arrow ? popoverSurfaceMotion : menuSurfaceMotion;
40
47
  useEffect(() => {
41
48
  if (requestedOpen && owner?.active === false) close.current();
42
49
  }, [requestedOpen, owner?.active]);
@@ -52,14 +59,12 @@ function Popover({
52
59
  if (!surface.matches(":popover-open")) return;
53
60
  surface.inert = true;
54
61
  surface.setAttribute("aria-hidden", "true");
55
- void menuSurfaceMotion(
56
- surface,
57
- "exit",
58
- surface.dataset.side
59
- ).then((done) => {
60
- if (done && !opened.current && surface.matches(":popover-open"))
61
- surface.hidePopover();
62
- });
62
+ void animate(surface, "exit", surface.dataset.side).then(
63
+ (done) => {
64
+ if (done && !opened.current && surface.matches(":popover-open"))
65
+ surface.hidePopover();
66
+ }
67
+ );
63
68
  return;
64
69
  }
65
70
  if (!trigger) return;
@@ -80,40 +85,61 @@ function Popover({
80
85
  Math.min(maxHeight, viewportBottom - viewportTop - 24)
81
86
  );
82
87
  surface.style.maxHeight = available + "px";
88
+ surface.style.setProperty(
89
+ "--popover-body-height",
90
+ Math.max(0, available - 12) + "px"
91
+ );
83
92
  const actualWidth = Math.min(
84
93
  matchAnchorWidth ? rect.width : width,
85
94
  Math.max(0, viewportWidth - 24)
86
95
  );
87
96
  surface.style.width = actualWidth + "px";
88
- const height = Math.min(surface.scrollHeight + 2, available);
89
- const below = viewportBottom - rect.bottom - 10;
90
- let resolved = side === "auto" ? below >= height || rect.top - viewportTop < height ? "bottom" : "top" : side;
97
+ const height = Math.min(surface.offsetHeight, available);
98
+ const gap = Math.max(0, Number.isFinite(offset) ? offset : 6);
99
+ const horizontalGap = Math.max(0, Number.isFinite(offset) ? offset : 8);
100
+ const below = viewportBottom - rect.bottom - gap - 12;
101
+ const above = rect.top - viewportTop - gap - 12;
102
+ let resolved = side === "auto" ? below >= height || below >= above ? "bottom" : "top" : side;
103
+ if (resolved === "top" && above < height && below > above)
104
+ resolved = "bottom";
105
+ else if (resolved === "bottom" && below < height && above > below)
106
+ resolved = "top";
91
107
  if (resolved === "left" && rect.left - viewportLeft - 20 < actualWidth && viewportLeft + viewportWidth - rect.right - 20 >= actualWidth)
92
108
  resolved = "right";
93
109
  if (resolved === "right" && viewportLeft + viewportWidth - rect.right - 20 < actualWidth && rect.left - viewportLeft - 20 >= actualWidth)
94
110
  resolved = "left";
95
111
  const horizontal = resolved === "left" || resolved === "right";
96
- const left = horizontal ? resolved === "left" ? rect.left - actualWidth - 8 : rect.right + 8 : align === "end" ? rect.right - actualWidth : align === "center" ? rect.left + (rect.width - actualWidth) / 2 : rect.left;
97
- const top = horizontal ? align === "end" ? rect.bottom - height : align === "center" ? rect.top + (rect.height - height) / 2 : rect.top : resolved === "bottom" ? rect.bottom + 6 : rect.top - height - 6;
112
+ const left = horizontal ? resolved === "left" ? rect.left - actualWidth - horizontalGap : rect.right + horizontalGap : align === "end" ? rect.right - actualWidth : align === "center" ? rect.left + (rect.width - actualWidth) / 2 : rect.left;
113
+ const top = horizontal ? align === "end" ? rect.bottom - height : align === "center" ? rect.top + (rect.height - height) / 2 : rect.top : resolved === "bottom" ? rect.bottom + gap : rect.top - height - gap;
98
114
  surface.dataset.side = resolved;
99
- surface.style.left = Math.max(
115
+ const placedLeft = Math.max(
100
116
  viewportLeft + 12,
101
117
  Math.min(left, viewportLeft + viewportWidth - actualWidth - 12)
102
- ) + "px";
103
- surface.style.top = Math.max(
118
+ );
119
+ const placedTop = Math.max(
104
120
  viewportTop + 12,
105
121
  Math.min(top, viewportBottom - height - 12)
106
- ) + "px";
122
+ );
123
+ surface.style.left = placedLeft + "px";
124
+ surface.style.top = placedTop + "px";
125
+ const pointerX = Math.max(
126
+ 16,
127
+ Math.min(actualWidth - 16, rect.left + rect.width / 2 - placedLeft)
128
+ );
129
+ const pointerY = Math.max(
130
+ 16,
131
+ Math.min(height - 16, rect.top + rect.height / 2 - placedTop)
132
+ );
133
+ surface.style.setProperty("--popover-arrow-x", pointerX + "px");
134
+ surface.style.setProperty("--popover-arrow-y", pointerY + "px");
135
+ if (arrow)
136
+ surface.style.transformOrigin = horizontal ? `${resolved === "right" ? "0" : "100%"} ${pointerY}px` : `${pointerX}px ${resolved === "bottom" ? "0" : "100%"}`;
107
137
  };
108
138
  const entering = !surface.matches(":popover-open") || surface.dataset.motionPhase === "exit" || surface.dataset.motionPhase === "hidden";
109
139
  if (!surface.matches(":popover-open")) surface.showPopover();
110
140
  position();
111
141
  if (entering)
112
- void menuSurfaceMotion(
113
- surface,
114
- "enter",
115
- surface.dataset.side
116
- );
142
+ void animate(surface, "enter", surface.dataset.side);
117
143
  if (autoFocus && role !== "listbox")
118
144
  (surface.querySelector("[data-autofocus]") || surface.querySelector(
119
145
  'input:not([disabled]),button:not([disabled]),[tabindex="0"]'
@@ -164,7 +190,9 @@ function Popover({
164
190
  autoFocus,
165
191
  matchAnchorWidth,
166
192
  side,
167
- align
193
+ align,
194
+ arrow,
195
+ offset
168
196
  ]);
169
197
  if (!portalHost) return null;
170
198
  return createPortal(
@@ -178,8 +206,11 @@ function Popover({
178
206
  "aria-label": label,
179
207
  "aria-describedby": descriptionId,
180
208
  onKeyDown,
181
- className: `${s.popover} ${scrollable ? "" : s.contained} ${className}`,
182
- children: /* @__PURE__ */ jsx(FieldContext, { value: null, children })
209
+ className: `${s.popover} ${scrollable ? "" : s.contained} ${arrow ? s.withArrow : ""} ${className}`,
210
+ children: /* @__PURE__ */ jsx(FieldContext, { value: null, children: arrow ? /* @__PURE__ */ jsxs(Fragment, { children: [
211
+ /* @__PURE__ */ jsx("span", { className: s.arrow, "data-popover-arrow": true, "aria-hidden": "true" }),
212
+ /* @__PURE__ */ jsx("div", { className: `${s.body} ${scrollable ? "" : s.bodyContained}`, children })
213
+ ] }) : children })
183
214
  }
184
215
  ),
185
216
  portalHost
@@ -25,3 +25,55 @@
25
25
  .popover:not(:popover-open) {
26
26
  display: none;
27
27
  }
28
+ .popover.withArrow {
29
+ overflow: visible;
30
+ }
31
+ .body {
32
+ min-height: 0;
33
+ flex-shrink: 1;
34
+ max-height: var(--popover-body-height);
35
+ overflow-y: auto;
36
+ overscroll-behavior: contain;
37
+ border-radius: max(0px, calc(var(--popup-radius) - 5px));
38
+ }
39
+ .bodyContained {
40
+ display: flex;
41
+ flex-direction: column;
42
+ overflow: hidden;
43
+ }
44
+ .bodyContained > * {
45
+ flex-shrink: 0;
46
+ }
47
+ .arrow {
48
+ position: absolute;
49
+ width: 10px;
50
+ height: 10px;
51
+ background: var(--popup-background);
52
+ border: 0 solid var(--popup-border);
53
+ transform: rotate(45deg);
54
+ pointer-events: none;
55
+ }
56
+ .withArrow[data-side="bottom"] > .arrow {
57
+ top: -6px;
58
+ left: calc(var(--popover-arrow-x) - 5px);
59
+ border-top-width: 1px;
60
+ border-left-width: 1px;
61
+ }
62
+ .withArrow[data-side="top"] > .arrow {
63
+ bottom: -6px;
64
+ left: calc(var(--popover-arrow-x) - 5px);
65
+ border-bottom-width: 1px;
66
+ border-right-width: 1px;
67
+ }
68
+ .withArrow[data-side="right"] > .arrow {
69
+ left: -6px;
70
+ top: calc(var(--popover-arrow-y) - 5px);
71
+ border-bottom-width: 1px;
72
+ border-left-width: 1px;
73
+ }
74
+ .withArrow[data-side="left"] > .arrow {
75
+ right: -6px;
76
+ top: calc(var(--popover-arrow-y) - 5px);
77
+ border-top-width: 1px;
78
+ border-right-width: 1px;
79
+ }
@@ -6,5 +6,6 @@ export declare function cancelMotion(node: HTMLElement): void;
6
6
  export declare function surfaceMotion(node: HTMLElement, phase: Phase, offset?: string, token?: string): Promise<boolean>;
7
7
  export declare function toastMotion(node: HTMLElement, phase: Phase, position: string): Promise<boolean>;
8
8
  export type MenuSide = "top" | "bottom" | "left" | "right";
9
+ export declare function popoverSurfaceMotion(node: HTMLElement, phase: "enter" | "exit", side?: MenuSide): Promise<boolean>;
9
10
  export declare function menuSurfaceMotion(node: HTMLElement, phase: "enter" | "exit", side?: MenuSide): Promise<boolean>;
10
11
  export {};
@@ -24,13 +24,17 @@ function runMotion(node, phase, offset = "0 -4px", token, profile = "surface") {
24
24
  opacity: interrupted ? style.opacity : phase === "enter" ? "0" : phase === "update" ? ".78" : "1",
25
25
  translate: interrupted ? style.translate : phase === "enter" ? offset : phase === "update" ? profile === "toast" ? "0 0" : "0 2px" : "0 0"
26
26
  };
27
- const scale = profile === "toast" ? { scale: interrupted ? style.scale : phase === "enter" ? ".96" : "1" } : {};
27
+ const scale = profile !== "surface" ? {
28
+ scale: interrupted ? style.scale : phase === "enter" ? profile === "toast" ? ".96" : ".97" : "1"
29
+ } : {};
28
30
  Object.assign(from, scale);
29
31
  state.animation?.cancel();
30
32
  const to = {
31
33
  opacity: phase === "exit" ? "0" : "1",
32
34
  translate: phase === "exit" ? offset : "0 0",
33
- ...profile === "toast" ? { scale: phase === "exit" ? ".98" : "1" } : {}
35
+ ...profile !== "surface" ? {
36
+ scale: phase === "exit" ? profile === "toast" ? ".98" : ".985" : "1"
37
+ } : {}
34
38
  };
35
39
  node.dataset.motionPhase = phase;
36
40
  const finish = () => {
@@ -75,6 +79,15 @@ function toastMotion(node, phase, position) {
75
79
  const offset = position.endsWith("right") ? "14px 0" : position.endsWith("left") ? "-14px 0" : position.startsWith("top") ? "0 -12px" : "0 12px";
76
80
  return runMotion(node, phase, offset, `--toast-${phase}`, "toast");
77
81
  }
82
+ function popoverSurfaceMotion(node, phase, side = "bottom") {
83
+ const offset = {
84
+ top: "0 6px",
85
+ bottom: "0 -6px",
86
+ left: "6px 0",
87
+ right: "-6px 0"
88
+ }[side];
89
+ return runMotion(node, phase, offset, void 0, "popover");
90
+ }
78
91
  function menuSurfaceMotion(node, phase, side = "bottom") {
79
92
  const offset = {
80
93
  top: "0 4px",
@@ -88,6 +101,7 @@ export {
88
101
  cancelMotion,
89
102
  menuSurfaceMotion,
90
103
  motionDuration,
104
+ popoverSurfaceMotion,
91
105
  popupExitDuration,
92
106
  reducedMotion,
93
107
  surfaceMotion,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robert-stackflow/oneui",
3
- "version": "0.6.21",
3
+ "version": "0.6.22",
4
4
  "description": "OneUI React components, application shell and portable visual themes",
5
5
  "type": "module",
6
6
  "sideEffects": [