@opencode/ui 0.0.0-dev-228 → 0.0.0-dev-232

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.
@@ -23,14 +23,16 @@ export interface LineCommentEditorProps extends Omit<ComponentProps<"div">, "chi
23
23
  onInput: (value: string) => void;
24
24
  onCancel: () => void;
25
25
  onSubmit: (value: string) => void;
26
- /** Optional context in the footer, e.g. the page or element being commented on. */
26
+ /** Optional context in the footer, or above the input in the compact variant. */
27
27
  selection?: JSX.Element;
28
+ /** Compact layout with a growing input and inline action. */
29
+ variant?: "default" | "compact";
28
30
  placeholder?: string;
29
31
  rows?: number;
30
32
  cancelLabel?: string;
31
33
  submitLabel?: string;
32
34
  autofocus?: boolean;
33
- /** Submit an empty value too, such as to clear a comment that exists (default: false). */
35
+ /** Submit an empty value too, such as to clear a comment that exists (default: false). Compact empty actions otherwise cancel. */
34
36
  allowEmpty?: boolean;
35
37
  mention?: LineCommentEditorMention;
36
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencode/ui",
3
- "version": "0.0.0-dev-228",
3
+ "version": "0.0.0-dev-232",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -23,6 +23,7 @@
23
23
  "!src/**/*.stories.ts",
24
24
  "!src/**/*.stories.tsx",
25
25
  "src/**/*.css",
26
+ "src/data-display/line-comment/*.svg",
26
27
  "src/theme/themes/*.json",
27
28
  "src/components/app-icons/sprite.svg",
28
29
  "src/components/provider-icons/sprite.svg",
@@ -287,7 +288,7 @@
287
288
  "dependencies": {
288
289
  "@kitlangton/solid-motion": "0.2.2",
289
290
  "@kobalte/core": "0.13.13",
290
- "@opencode/util": "0.0.0-dev-228",
291
+ "@opencode/util": "0.0.0-dev-232",
291
292
  "@pierre/diffs": "1.6.1",
292
293
  "@pierre/highlights": "0.2.0",
293
294
  "@solid-primitives/event-listener": "2.4.6",
@@ -125,6 +125,10 @@
125
125
  }
126
126
 
127
127
  /* --- Editor --- */
128
+ [data-component="line-comment-v2"] [data-slot="line-comment-v2-input"] {
129
+ display: contents;
130
+ }
131
+
128
132
  [data-component="line-comment-v2"][data-variant="editor"] [data-slot="line-comment-v2-shell"] {
129
133
  display: flex;
130
134
  flex-direction: column;
@@ -196,6 +200,93 @@
196
200
  margin-inline-start: auto;
197
201
  }
198
202
 
203
+ [data-component="line-comment-v2"][data-layout="compact"] {
204
+ display: flex;
205
+ max-height: var(--line-comment-max-height, none);
206
+
207
+ [data-slot="line-comment-v2-shell"] {
208
+ flex: 1 1 auto;
209
+ min-width: 0;
210
+ max-height: inherit;
211
+ padding: 12px;
212
+ gap: 10px;
213
+ border-radius: 8px;
214
+ box-shadow: none;
215
+ }
216
+
217
+ [data-slot="line-comment-v2-preview"] {
218
+ width: 100%;
219
+ min-width: 0;
220
+ flex-shrink: 0;
221
+ border-inline-start: 2px solid var(--v2-background-bg-layer-03);
222
+ padding-inline-start: 12px;
223
+ color: var(--v2-text-text-muted);
224
+ font-size: 13px;
225
+ font-weight: 440;
226
+ line-height: var(--line-height-base);
227
+ letter-spacing: -0.04px;
228
+
229
+ > span {
230
+ display: -webkit-box;
231
+ overflow: hidden;
232
+ -webkit-box-orient: vertical;
233
+ -webkit-line-clamp: var(--line-comment-preview-lines, 2);
234
+ overflow-wrap: anywhere;
235
+ }
236
+ }
237
+
238
+ [data-slot="line-comment-v2-input"] {
239
+ display: flex;
240
+ align-items: flex-end;
241
+ gap: 12px;
242
+ width: 100%;
243
+ min-width: 0;
244
+ min-height: var(--line-height-base);
245
+ flex: 1 1 auto;
246
+ }
247
+
248
+ [data-slot="line-comment-v2-field"] {
249
+ flex: 1 1 auto;
250
+ width: auto;
251
+ min-height: 0;
252
+ align-self: stretch;
253
+ }
254
+
255
+ [data-slot="line-comment-v2-textarea"] {
256
+ field-sizing: content;
257
+ height: auto;
258
+ flex: 1 1 auto;
259
+ min-height: var(--line-height-base);
260
+ max-height: 160px;
261
+ overflow-y: auto;
262
+ scrollbar-gutter: stable;
263
+ line-height: var(--line-height-base);
264
+
265
+ &::placeholder {
266
+ color: var(--v2-text-text-faint);
267
+ }
268
+ }
269
+
270
+ [data-slot="line-comment-v2-submit"] {
271
+ position: relative;
272
+ flex-shrink: 0;
273
+
274
+ @media (hover: none) {
275
+ &::after {
276
+ content: "";
277
+ position: absolute;
278
+ inset: -12px;
279
+ }
280
+ }
281
+ }
282
+
283
+ [data-slot="line-comment-v2-submit-icon"] {
284
+ width: 16px;
285
+ height: 16px;
286
+ background: currentColor;
287
+ }
288
+ }
289
+
199
290
  [data-component="line-comment-v2"][data-variant="editor"] [data-slot="line-comment-v2-mention-list"] {
200
291
  display: flex;
201
292
  flex-direction: column;
@@ -1,8 +1,24 @@
1
- import { For, Show, createSignal, onMount, splitProps, type ComponentProps, type JSX } from "solid-js"
1
+ import {
2
+ For,
3
+ Show,
4
+ createEffect,
5
+ createSignal,
6
+ on,
7
+ onCleanup,
8
+ onMount,
9
+ splitProps,
10
+ type ComponentProps,
11
+ type JSX,
12
+ } from "solid-js"
2
13
  import { FileIcon } from "@opencode/ui/file-icon"
3
14
  import { useI18n } from "../../context/i18n"
4
15
  import { useFilteredList } from "../../hooks"
5
16
  import { Button } from "@opencode/ui/button"
17
+ import { Icon } from "@opencode/ui/icon"
18
+ import { IconButton } from "@opencode/ui/icon-button"
19
+ import { Keybind } from "@opencode/ui/keybind"
20
+ import { Tooltip } from "@opencode/ui/tooltip"
21
+ import check from "./quote-check.svg"
6
22
  import "./line-comment.css"
7
23
 
8
24
  /** Horizontal “more” glyph for the display-card overflow control (Figma outline-dots). */
@@ -72,14 +88,16 @@ export interface LineCommentEditorProps extends Omit<ComponentProps<"div">, "chi
72
88
  onInput: (value: string) => void
73
89
  onCancel: () => void
74
90
  onSubmit: (value: string) => void
75
- /** Optional context in the footer, e.g. the page or element being commented on. */
91
+ /** Optional context in the footer, or above the input in the compact variant. */
76
92
  selection?: JSX.Element
93
+ /** Compact layout with a growing input and inline action. */
94
+ variant?: "default" | "compact"
77
95
  placeholder?: string
78
96
  rows?: number
79
97
  cancelLabel?: string
80
98
  submitLabel?: string
81
99
  autofocus?: boolean
82
- /** Submit an empty value too, such as to clear a comment that exists (default: false). */
100
+ /** Submit an empty value too, such as to clear a comment that exists (default: false). Compact empty actions otherwise cancel. */
83
101
  allowEmpty?: boolean
84
102
  mention?: LineCommentEditorMention
85
103
  }
@@ -108,6 +126,7 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
108
126
  "onCancel",
109
127
  "onSubmit",
110
128
  "selection",
129
+ "variant",
111
130
  "placeholder",
112
131
  "rows",
113
132
  "cancelLabel",
@@ -120,6 +139,12 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
120
139
  ])
121
140
 
122
141
  const canSubmit = () => !!local.allowEmpty || local.value.trim().length > 0
142
+ const compactCancel = () => !canSubmit()
143
+
144
+ const compactLabel = () =>
145
+ compactCancel()
146
+ ? (local.cancelLabel ?? i18n.t("ui.lineComment.cancel"))
147
+ : (local.submitLabel ?? i18n.t("ui.lineComment.submit"))
123
148
 
124
149
  const closeMention = () => {
125
150
  setMentionOpen(false)
@@ -215,124 +240,203 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
215
240
  requestAnimationFrame(() => textareaRef?.focus())
216
241
  })
217
242
 
243
+ onMount(() => {
244
+ if (CSS.supports("field-sizing", "content")) return
245
+
246
+ createEffect(() => {
247
+ const textarea = textareaRef
248
+
249
+ if (local.variant !== "compact" || !textarea) return
250
+
251
+ const resize = () => {
252
+ // Reset before measuring so the field can shrink as well as grow.
253
+ textarea.style.height = "0px"
254
+ textarea.style.height = `${textarea.scrollHeight}px`
255
+ }
256
+
257
+ createEffect(on(() => local.value, resize))
258
+
259
+ let width = 0
260
+
261
+ const observer = new ResizeObserver(([entry]) => {
262
+ if (!entry || entry.contentRect.width === width) return
263
+ width = entry.contentRect.width
264
+ resize()
265
+ })
266
+
267
+ observer.observe(textarea)
268
+ onCleanup(() => {
269
+ observer.disconnect()
270
+ textarea.style.removeProperty("height")
271
+ })
272
+ })
273
+ })
274
+
218
275
  return (
219
276
  <div
220
277
  {...rest}
221
278
  data-component="line-comment-v2"
222
279
  data-variant="editor"
280
+ data-layout={local.variant ?? "default"}
223
281
  classList={{
224
282
  ...local.classList,
225
283
  [local.class ?? ""]: !!local.class,
226
284
  }}
227
285
  >
228
286
  <div data-slot="line-comment-v2-shell">
229
- <div data-slot="line-comment-v2-field">
230
- <textarea
231
- ref={(el) => {
232
- textareaRef = el
233
- }}
234
- data-slot="line-comment-v2-textarea"
235
- aria-label={local.label ?? i18n.t("ui.lineComment.submit")}
236
- dir="auto"
237
- rows={local.rows ?? 4}
238
- placeholder={local.placeholder ?? i18n.t("ui.lineComment.contextPlaceholder")}
239
- value={local.value}
240
- style={{ "unicode-bidi": "plaintext", "text-align": "start" }}
241
- onInput={(e) => {
242
- local.onInput(e.currentTarget.value)
243
- syncMention()
244
- }}
245
- onClick={() => syncMention()}
246
- onSelect={() => syncMention()}
247
- onKeyDown={(e) => {
248
- e.stopPropagation()
249
-
250
- if (e.isComposing || e.keyCode === 229) return
251
-
252
- if (mentionOpen()) {
253
- if (e.key === "Escape") {
254
- e.preventDefault()
255
- closeMention()
256
-
257
- return
287
+ <Show when={local.variant === "compact" && local.selection}>
288
+ {(selection) => <div data-slot="line-comment-v2-preview">{selection()}</div>}
289
+ </Show>
290
+ <div data-slot="line-comment-v2-input">
291
+ <div data-slot="line-comment-v2-field">
292
+ <textarea
293
+ ref={(el) => {
294
+ textareaRef = el
295
+ }}
296
+ data-slot="line-comment-v2-textarea"
297
+ data-scrollable
298
+ aria-label={local.label ?? i18n.t("ui.lineComment.submit")}
299
+ dir="auto"
300
+ rows={local.rows ?? (local.variant === "compact" ? 1 : 4)}
301
+ placeholder={local.placeholder ?? i18n.t("ui.lineComment.contextPlaceholder")}
302
+ value={local.value}
303
+ style={{ "unicode-bidi": "plaintext", "text-align": "start" }}
304
+ onInput={(e) => {
305
+ local.onInput(e.currentTarget.value)
306
+ syncMention()
307
+ }}
308
+ onClick={() => syncMention()}
309
+ onSelect={() => syncMention()}
310
+ onKeyDown={(e) => {
311
+ e.stopPropagation()
312
+
313
+ if (e.isComposing || e.keyCode === 229) return
314
+
315
+ if (mentionOpen()) {
316
+ if (e.key === "Escape") {
317
+ e.preventDefault()
318
+ closeMention()
319
+
320
+ return
321
+ }
322
+
323
+ if (e.key === "Tab") {
324
+ if (mention.flat().length === 0) return
325
+ e.preventDefault()
326
+ selectActiveMention()
327
+
328
+ return
329
+ }
330
+
331
+ const nav = e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "Enter"
332
+
333
+ const ctrlNav =
334
+ e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey && (e.key === "n" || e.key === "p")
335
+
336
+ if ((nav || ctrlNav) && mention.flat().length > 0) {
337
+ mention.onKeyDown(e)
338
+ e.preventDefault()
339
+
340
+ return
341
+ }
258
342
  }
259
343
 
260
- if (e.key === "Tab") {
261
- if (mention.flat().length === 0) return
344
+ if (e.key === "Escape") {
262
345
  e.preventDefault()
263
- selectActiveMention()
346
+ e.currentTarget.blur()
347
+ local.onCancel()
264
348
 
265
349
  return
266
350
  }
267
351
 
268
- const nav = e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "Enter"
269
- const ctrlNav = e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey && (e.key === "n" || e.key === "p")
270
-
271
- if ((nav || ctrlNav) && mention.flat().length > 0) {
272
- mention.onKeyDown(e)
352
+ if (e.key === "Enter" && !e.shiftKey) {
273
353
  e.preventDefault()
274
-
275
- return
354
+ submit()
276
355
  }
356
+ }}
357
+ />
358
+ <Show when={mentionOpen() && mention.flat().length > 0}>
359
+ <div data-slot="line-comment-v2-mention-list">
360
+ <For each={mention.flat().slice(0, 10)}>
361
+ {(item) => {
362
+ const directory = item.path.endsWith("/") ? item.path : pathDirectory(item.path)
363
+ const name = item.path.endsWith("/") ? "" : pathFilename(item.path)
364
+
365
+ return (
366
+ <button
367
+ type="button"
368
+ data-slot="line-comment-v2-mention-item"
369
+ data-active={mention.active() === item.path ? "" : undefined}
370
+ onMouseDown={(event) => event.preventDefault()}
371
+ onMouseEnter={() => mention.setActive(item.path)}
372
+ onClick={() => selectMention(item)}
373
+ >
374
+ <FileIcon node={{ path: item.path, type: "file" }} class="shrink-0 size-4" />
375
+ <div data-slot="line-comment-v2-mention-path">
376
+ <span data-slot="line-comment-v2-mention-dir">{directory}</span>
377
+ <Show when={name}>
378
+ <span data-slot="line-comment-v2-mention-file">{name}</span>
379
+ </Show>
380
+ </div>
381
+ </button>
382
+ )
383
+ }}
384
+ </For>
385
+ </div>
386
+ </Show>
387
+ </div>
388
+ <Show when={local.variant === "compact"}>
389
+ <Tooltip
390
+ value={
391
+ <>
392
+ {compactLabel()} <Keybind keys={[compactCancel() ? "Esc" : "⏎"]} variant="neutral" />
393
+ </>
277
394
  }
278
-
279
- if (e.key === "Escape") {
280
- e.preventDefault()
281
- e.currentTarget.blur()
282
- local.onCancel()
283
-
284
- return
285
- }
286
-
287
- if (e.key === "Enter" && !e.shiftKey) {
288
- e.preventDefault()
289
- submit()
290
- }
291
- }}
292
- />
293
- <Show when={mentionOpen() && mention.flat().length > 0}>
294
- <div data-slot="line-comment-v2-mention-list">
295
- <For each={mention.flat().slice(0, 10)}>
296
- {(item) => {
297
- const directory = item.path.endsWith("/") ? item.path : pathDirectory(item.path)
298
- const name = item.path.endsWith("/") ? "" : pathFilename(item.path)
299
-
300
- return (
301
- <button
302
- type="button"
303
- data-slot="line-comment-v2-mention-item"
304
- data-active={mention.active() === item.path ? "" : undefined}
305
- onMouseDown={(event) => event.preventDefault()}
306
- onMouseEnter={() => mention.setActive(item.path)}
307
- onClick={() => selectMention(item)}
308
- >
309
- <FileIcon node={{ path: item.path, type: "file" }} class="shrink-0 size-4" />
310
- <div data-slot="line-comment-v2-mention-path">
311
- <span data-slot="line-comment-v2-mention-dir">{directory}</span>
312
- <Show when={name}>
313
- <span data-slot="line-comment-v2-mention-file">{name}</span>
314
- </Show>
315
- </div>
316
- </button>
395
+ placement="top"
396
+ >
397
+ <IconButton
398
+ data-slot="line-comment-v2-submit"
399
+ type="button"
400
+ size="small"
401
+ variant={local.value.trim() ? "neutral" : "ghost-muted"}
402
+ icon={
403
+ compactCancel() ? (
404
+ <Icon name="close" />
405
+ ) : (
406
+ <span
407
+ aria-hidden="true"
408
+ data-slot="line-comment-v2-submit-icon"
409
+ style={{ mask: `url("${check}") center / contain no-repeat` }}
410
+ />
317
411
  )
412
+ }
413
+ aria-label={compactLabel()}
414
+ onClick={() => (compactCancel() ? local.onCancel() : submit())}
415
+ onKeyDown={(event) => {
416
+ if (event.key !== "Escape" || event.isComposing) return
417
+ event.preventDefault()
418
+ event.stopPropagation()
419
+ local.onCancel()
318
420
  }}
319
- </For>
320
- </div>
421
+ />
422
+ </Tooltip>
321
423
  </Show>
322
424
  </div>
323
- <div data-slot="line-comment-v2-footer">
324
- <Show when={local.selection}>
325
- {(selection) => <div data-slot="line-comment-v2-footer-meta">{selection()}</div>}
326
- </Show>
327
- <div data-slot="line-comment-v2-footer-actions">
328
- <Button type="button" size="small" variant="ghost" onClick={() => local.onCancel()}>
329
- {local.cancelLabel ?? i18n.t("ui.lineComment.cancel")}
330
- </Button>
331
- <Button type="button" size="small" variant="contrast" disabled={!canSubmit()} onClick={submit}>
332
- {local.submitLabel ?? i18n.t("ui.lineComment.submit")}
333
- </Button>
425
+ <Show when={local.variant !== "compact"}>
426
+ <div data-slot="line-comment-v2-footer">
427
+ <Show when={local.selection}>
428
+ {(selection) => <div data-slot="line-comment-v2-footer-meta">{selection()}</div>}
429
+ </Show>
430
+ <div data-slot="line-comment-v2-footer-actions">
431
+ <Button type="button" size="small" variant="ghost" onClick={() => local.onCancel()}>
432
+ {local.cancelLabel ?? i18n.t("ui.lineComment.cancel")}
433
+ </Button>
434
+ <Button type="button" size="small" variant="contrast" disabled={!canSubmit()} onClick={submit}>
435
+ {local.submitLabel ?? i18n.t("ui.lineComment.submit")}
436
+ </Button>
437
+ </div>
334
438
  </div>
335
- </div>
439
+ </Show>
336
440
  </div>
337
441
  </div>
338
442
  )
@@ -0,0 +1,3 @@
1
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M2.44444 8.22222L6 12.6667L13.5556 3.33333" stroke-linecap="square" stroke="currentColor"/>
3
+ </svg>