@momoi-labs/kiso-react 0.12.0 → 0.13.0

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/README.md CHANGED
@@ -225,6 +225,36 @@ const log = useRef<LogViewHandle>(null);
225
225
  <Button onClick={() => log.current?.scrollToBottom()}>Jump to end</Button>
226
226
  ```
227
227
 
228
+ LogView mounts every line it gets. For a log that grows without bound, hand
229
+ the handle's `getScrollElement()` to a virtualizer and let LogView keep
230
+ following the tail. The
231
+ [LogView contract](../../kiso/docs/components/log-view.md#virtualization) has
232
+ the rules. With TanStack Virtual:
233
+
234
+ ```tsx
235
+ const log = useRef<LogViewHandle>(null);
236
+ const rows = useVirtualizer({
237
+ count: lines.length,
238
+ getScrollElement: () => log.current?.getScrollElement() ?? null,
239
+ estimateSize: () => 20,
240
+ });
241
+
242
+ <LogView ref={log}>
243
+ <div style={{ position: "relative", height: rows.getTotalSize() }}>
244
+ {rows.getVirtualItems().map((row) => (
245
+ <LogViewLine
246
+ key={row.key}
247
+ ref={rows.measureElement}
248
+ data-index={row.index}
249
+ style={{ position: "absolute", top: 0, insetInline: 0, transform: `translateY(${row.start}px)` }}
250
+ >
251
+ {lines[row.index]}
252
+ </LogViewLine>
253
+ ))}
254
+ </div>
255
+ </LogView>
256
+ ```
257
+
228
258
  Compose confirmations with AlertDialogTitle and AlertDialogDescription inside
229
259
  AlertDialogContent, plus AlertDialogCancel and AlertDialogAction. For asynchronous
230
260
  actions, control `open` and prevent the Action's default click behavior until the
@@ -1,4 +1,4 @@
1
- export declare const accents: readonly ["violet", "terracotta", "teal", "cobalt", "nocturne", "tangerine"];
1
+ export declare const accents: readonly ["violet", "terracotta", "teal", "cobalt", "nocturne", "tangerine", "red", "gold", "lime"];
2
2
  export type Accent = (typeof accents)[number];
3
3
  export declare function AccentSelector({ accent, onChange, options, preview, }: {
4
4
  accent: string;
@@ -7,6 +7,9 @@ export const accents = [
7
7
  "cobalt",
8
8
  "nocturne",
9
9
  "tangerine",
10
+ "red",
11
+ "gold",
12
+ "lime",
10
13
  ];
11
14
  const label = (accent) => `${accent[0].toUpperCase()}${accent.slice(1)}`;
12
15
  export function AccentSelector({ accent, onChange, options = accents, preview = true, }) {
@@ -2,6 +2,7 @@ import * as React from "react";
2
2
  import { type VariantProps } from "class-variance-authority";
3
3
  type LogViewHandle = {
4
4
  scrollToBottom: (behavior?: ScrollBehavior) => void;
5
+ getScrollElement: () => HTMLDivElement | null;
5
6
  };
6
7
  declare function LogView({ className, children, follow, onFollowChange, ref, ...props }: Omit<React.ComponentProps<"div">, "ref"> & {
7
8
  follow?: boolean;
package/dist/log-view.js CHANGED
@@ -8,6 +8,9 @@ import { useIsomorphicLayoutEffect } from "./use-isomorphic-layout-effect.js";
8
8
  /* Within this much of the end counts as "at the bottom". A log that is being
9
9
  written to rarely lands on an exact scroll position. */
10
10
  const BOTTOM_THRESHOLD = 8;
11
+ function isAtBottom(el) {
12
+ return el.scrollHeight - el.scrollTop - el.clientHeight <= BOTTOM_THRESHOLD;
13
+ }
11
14
  /* The frame is `.logview` and the scroller is `.log-scroll` inside it, so the
12
15
  component owns the scroller and with it follow-tail: new lines pin the view
13
16
  to the end until the reader scrolls away, and returning to the end resumes.
@@ -15,6 +18,8 @@ const BOTTOM_THRESHOLD = 8;
15
18
  "Follow" switch — and read `onFollowChange` to keep it in step. */
16
19
  function LogView({ className, children, follow, onFollowChange, ref, ...props }) {
17
20
  const scroller = React.useRef(null);
21
+ /* The scroll height at the last pin, or null while not following. */
22
+ const pinned = React.useRef(null);
18
23
  const [atBottom, setAtBottom] = React.useState(true);
19
24
  const following = follow ?? atBottom;
20
25
  React.useImperativeHandle(ref, () => ({
@@ -23,16 +28,27 @@ function LogView({ className, children, follow, onFollowChange, ref, ...props })
23
28
  if (el)
24
29
  el.scrollTo({ top: el.scrollHeight, behavior });
25
30
  },
31
+ getScrollElement() {
32
+ return scroller.current;
33
+ },
26
34
  }), []);
27
- /* Before paint, so a new line never shows up above the fold first. */
35
+ /* Before paint, so a new line never shows up above the fold first. Skip the
36
+ pin when the height is unchanged and the view is still at the bottom: a
37
+ virtualized body re-renders its rows on every scroll, and pinning then
38
+ pulls back a reader who leaves the end in small steps. */
28
39
  useIsomorphicLayoutEffect(() => {
29
40
  const el = scroller.current;
30
- if (el && following)
31
- el.scrollTop = el.scrollHeight;
41
+ if (!el || !following) {
42
+ pinned.current = null;
43
+ return;
44
+ }
45
+ if (el.scrollHeight === pinned.current && isAtBottom(el))
46
+ return;
47
+ el.scrollTop = el.scrollHeight;
48
+ pinned.current = el.scrollHeight;
32
49
  }, [children, following]);
33
50
  return (_jsx("div", { "data-slot": "log-view", "data-follow": following, className: cn("logview", className), ...props, children: _jsx("div", { ref: scroller, "data-slot": "log-view-scroll", className: "log-scroll", onScroll: (event) => {
34
- const el = event.currentTarget;
35
- const bottom = el.scrollHeight - el.scrollTop - el.clientHeight <= BOTTOM_THRESHOLD;
51
+ const bottom = isAtBottom(event.currentTarget);
36
52
  setAtBottom(bottom);
37
53
  if (bottom !== following)
38
54
  onFollowChange?.(bottom);
package/dist/styles.css CHANGED
@@ -104,6 +104,7 @@
104
104
  color: var(--color-foreground);
105
105
  font-weight: var(--type-weight-medium);
106
106
  }
107
+ .accent-pill:is([data-accent="gold"], [data-accent="lime"])[aria-pressed="true"] { border-color: var(--color-link); }
107
108
  .accent-dot { width: var(--spacing-md); height: var(--spacing-md); border-radius: var(--radius-full); background: var(--color-primary); }
108
109
 
109
110
  .accent-preview {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momoi-labs/kiso-react",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Kiso React components built with shadcn/ui and Radix",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,7 +32,7 @@
32
32
  "prepack": "npm run build"
33
33
  },
34
34
  "dependencies": {
35
- "@momoi-labs/kiso": "^0.16.0",
35
+ "@momoi-labs/kiso": "^0.17.0",
36
36
  "class-variance-authority": "0.7.1",
37
37
  "clsx": "2.1.1",
38
38
  "radix-ui": "1.6.7",