@opencode/ui 0.0.0-dev-414 → 0.0.0-dev-420
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Root } from "@kobalte/core/button";
|
|
1
|
+
import type { Root } from "@kobalte/core/button";
|
|
2
2
|
import { type ComponentProps } from "solid-js";
|
|
3
3
|
import { type IconProps } from "@opencode/ui/icon";
|
|
4
4
|
import "./button.css";
|
|
5
|
-
export interface ButtonProps extends ComponentProps<typeof Root>, Pick<ComponentProps<"button">, "class" | "classList" | "children"> {
|
|
5
|
+
export interface ButtonProps extends Omit<ComponentProps<typeof Root>, "type">, Pick<ComponentProps<"button">, "class" | "classList" | "children" | "type"> {
|
|
6
6
|
size?: "small" | "normal" | "large";
|
|
7
7
|
variant?: "neutral" | "danger" | "warning" | "outline" | "contrast" | "submit" | "ghost" | "ghost-muted" | "ghost-faint" | "ghost-danger" | "loading";
|
|
8
8
|
icon?: IconProps["name"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencode/ui",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-420",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -288,7 +288,7 @@
|
|
|
288
288
|
"dependencies": {
|
|
289
289
|
"@kitlangton/solid-motion": "0.2.2",
|
|
290
290
|
"@kobalte/core": "0.13.13",
|
|
291
|
-
"@opencode/util": "0.0.0-dev-
|
|
291
|
+
"@opencode/util": "0.0.0-dev-420",
|
|
292
292
|
"@pierre/diffs": "1.6.1",
|
|
293
293
|
"@pierre/highlights": "0.2.0",
|
|
294
294
|
"@solid-primitives/event-listener": "2.4.6",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Root } from "@kobalte/core/button"
|
|
1
|
+
import type { Root } from "@kobalte/core/button"
|
|
2
2
|
import { type ComponentProps, Show, splitProps } from "solid-js"
|
|
3
3
|
import { Icon, type IconProps } from "@opencode/ui/icon"
|
|
4
4
|
import "./button.css"
|
|
5
5
|
|
|
6
6
|
export interface ButtonProps
|
|
7
|
-
extends ComponentProps<typeof Root>,
|
|
8
|
-
Pick<ComponentProps<"button">, "class" | "classList" | "children"> {
|
|
7
|
+
extends Omit<ComponentProps<typeof Root>, "type">,
|
|
8
|
+
Pick<ComponentProps<"button">, "class" | "classList" | "children" | "type"> {
|
|
9
9
|
size?: "small" | "normal" | "large"
|
|
10
10
|
variant?:
|
|
11
11
|
| "neutral"
|
|
@@ -22,11 +22,16 @@ export interface ButtonProps
|
|
|
22
22
|
icon?: IconProps["name"]
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// A native button with the attributes Kobalte's Button sets on one, without its per-instance computations.
|
|
25
26
|
export function Button(props: ButtonProps) {
|
|
26
|
-
const [split, rest] = splitProps(props, ["variant", "size", "icon", "class", "classList"])
|
|
27
|
+
const [split, rest] = splitProps(props, ["variant", "size", "icon", "class", "classList", "disabled"])
|
|
27
28
|
|
|
28
29
|
return (
|
|
29
|
-
<
|
|
30
|
+
<button
|
|
31
|
+
// A type the caller passes in `rest` replaces this default.
|
|
32
|
+
type="button"
|
|
33
|
+
disabled={split.disabled}
|
|
34
|
+
data-disabled={split.disabled ? "" : undefined}
|
|
30
35
|
{...rest}
|
|
31
36
|
data-component="button-v2"
|
|
32
37
|
data-size={split.size || "normal"}
|
|
@@ -39,6 +44,6 @@ export function Button(props: ButtonProps) {
|
|
|
39
44
|
>
|
|
40
45
|
<Show when={split.icon}>{(icon) => <Icon name={icon()} />}</Show>
|
|
41
46
|
{props.children}
|
|
42
|
-
</
|
|
47
|
+
</button>
|
|
43
48
|
)
|
|
44
49
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Root } from "@kobalte/core/button"
|
|
1
|
+
import type { Root } from "@kobalte/core/button"
|
|
2
2
|
import { type ComponentProps, splitProps } from "solid-js"
|
|
3
3
|
import { JSX } from "solid-js"
|
|
4
4
|
import "./icon-button.css"
|
|
@@ -12,11 +12,24 @@ export interface IconButtonProps
|
|
|
12
12
|
state?: "rest" | "hover" | "pressed"
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
// A native button with the attributes Kobalte's Button sets on one, without its per-instance computations.
|
|
15
16
|
export function IconButton(props: ComponentProps<"button"> & IconButtonProps) {
|
|
16
|
-
const [local, rest] = splitProps(props, [
|
|
17
|
+
const [local, rest] = splitProps(props, [
|
|
18
|
+
"variant",
|
|
19
|
+
"size",
|
|
20
|
+
"icon",
|
|
21
|
+
"class",
|
|
22
|
+
"classList",
|
|
23
|
+
"state",
|
|
24
|
+
"type",
|
|
25
|
+
"disabled",
|
|
26
|
+
])
|
|
17
27
|
|
|
18
28
|
return (
|
|
19
|
-
<
|
|
29
|
+
<button
|
|
30
|
+
type={local.type ?? "button"}
|
|
31
|
+
disabled={local.disabled}
|
|
32
|
+
data-disabled={local.disabled ? "" : undefined}
|
|
20
33
|
{...rest}
|
|
21
34
|
data-component="icon-button-v2"
|
|
22
35
|
data-size={local.size || "normal"}
|
|
@@ -28,6 +41,6 @@ export function IconButton(props: ComponentProps<"button"> & IconButtonProps) {
|
|
|
28
41
|
}}
|
|
29
42
|
>
|
|
30
43
|
{local.icon}
|
|
31
|
-
</
|
|
44
|
+
</button>
|
|
32
45
|
)
|
|
33
46
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Content, Portal, Root, Trigger } from "@kobalte/core/tooltip"
|
|
2
|
-
import { createEffect, Match, onCleanup, splitProps, Switch, untrack, type JSX } from "solid-js"
|
|
2
|
+
import { createComputed, createEffect, Match, onCleanup, Show, splitProps, Switch, untrack, type JSX } from "solid-js"
|
|
3
3
|
import type { ComponentProps } from "solid-js"
|
|
4
4
|
import { createStore } from "solid-js/store"
|
|
5
|
+
import { spread } from "solid-js/web"
|
|
5
6
|
import "./tooltip.css"
|
|
6
7
|
|
|
7
8
|
export interface TooltipProps extends ComponentProps<typeof Root> {
|
|
@@ -15,13 +16,23 @@ export interface TooltipProps extends ComponentProps<typeof Root> {
|
|
|
15
16
|
triggerTabIndex?: number
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
type TriggerHandlers = {
|
|
20
|
+
onPointerEnter?: (event: PointerEvent) => void
|
|
21
|
+
onFocus?: (event: FocusEvent) => void
|
|
22
|
+
}
|
|
23
|
+
|
|
18
24
|
export function Tooltip(props: TooltipProps) {
|
|
19
25
|
let ref: HTMLDivElement | undefined
|
|
26
|
+
let handlers: TriggerHandlers | undefined
|
|
20
27
|
|
|
21
28
|
const [state, setState] = createStore({
|
|
22
29
|
open: false,
|
|
23
30
|
block: false,
|
|
24
31
|
expand: false,
|
|
32
|
+
// Kobalte's tooltip costs dozens of computations and listeners per trigger, and most triggers (an action on every
|
|
33
|
+
// timeline row, a copy button on every code block) are never hovered. It mounts on the first interaction that
|
|
34
|
+
// could open it, or as soon as a caller controls it with forceOpen.
|
|
35
|
+
mounted: false,
|
|
25
36
|
})
|
|
26
37
|
|
|
27
38
|
const [local, others] = splitProps(props, [
|
|
@@ -75,11 +86,6 @@ export function Tooltip(props: TooltipProps) {
|
|
|
75
86
|
drop(expand)
|
|
76
87
|
}
|
|
77
88
|
|
|
78
|
-
const arm = () => {
|
|
79
|
-
setState("block", true)
|
|
80
|
-
close()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
89
|
const leave = () => {
|
|
84
90
|
// Kobalte's own pointerleave handler runs after this one and only starts the
|
|
85
91
|
// skip-delay window for neighbouring tooltips if it still sees this one open.
|
|
@@ -89,8 +95,21 @@ export function Tooltip(props: TooltipProps) {
|
|
|
89
95
|
})
|
|
90
96
|
}
|
|
91
97
|
|
|
98
|
+
const mount = (event: PointerEvent | FocusEvent) => {
|
|
99
|
+
if (state.mounted) return
|
|
100
|
+
setState("mounted", true)
|
|
101
|
+
|
|
102
|
+
// Kobalte attached its listeners while this event was being dispatched, too late to receive it.
|
|
103
|
+
if (event instanceof PointerEvent) handlers?.onPointerEnter?.(event)
|
|
104
|
+
else handlers?.onFocus?.(event)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
createComputed(() => {
|
|
108
|
+
if (controlled()) setState("mounted", true)
|
|
109
|
+
})
|
|
110
|
+
|
|
92
111
|
createEffect(() => {
|
|
93
|
-
if (!ref) return
|
|
112
|
+
if (!ref || !state.mounted) return
|
|
94
113
|
untrack(sync)
|
|
95
114
|
const obs = new MutationObserver(sync)
|
|
96
115
|
obs.observe(ref, {
|
|
@@ -104,73 +123,92 @@ export function Tooltip(props: TooltipProps) {
|
|
|
104
123
|
|
|
105
124
|
let justClickedTrigger = false
|
|
106
125
|
|
|
126
|
+
// Kobalte's trigger takes over the element rendered below instead of rendering one, so mounting the tooltip leaves
|
|
127
|
+
// the trigger and its children in place, with their focus and hover.
|
|
128
|
+
const adopt = (triggerProps: TriggerHandlers) => {
|
|
129
|
+
handlers = triggerProps
|
|
130
|
+
|
|
131
|
+
if (!ref) return null
|
|
132
|
+
// Kobalte owns the open state attributes from here, and spread never removes an attribute it did not set, so a
|
|
133
|
+
// tooltip that mounts open would keep the closed marker.
|
|
134
|
+
ref.removeAttribute("data-closed")
|
|
135
|
+
spread(ref, triggerProps, false, true)
|
|
136
|
+
|
|
137
|
+
return null
|
|
138
|
+
}
|
|
139
|
+
|
|
107
140
|
return (
|
|
108
141
|
<Switch>
|
|
109
142
|
<Match when={local.inactive}>{local.children}</Match>
|
|
110
143
|
<Match when={true}>
|
|
111
|
-
<
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
closeDelay={0}
|
|
117
|
-
ignoreSafeArea={local.ignoreSafeArea ?? true}
|
|
118
|
-
open={controlled() ? local.forceOpen : state.open}
|
|
119
|
-
onOpenChange={(open) => {
|
|
120
|
-
if (controlled()) return
|
|
121
|
-
|
|
122
|
-
if (state.block && open) return
|
|
123
|
-
|
|
124
|
-
if (justClickedTrigger) {
|
|
125
|
-
justClickedTrigger = false
|
|
126
|
-
|
|
127
|
-
return
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
setState("open", open)
|
|
144
|
+
<div
|
|
145
|
+
ref={(el) => {
|
|
146
|
+
ref = el
|
|
147
|
+
// Kobalte's trigger sets this on the element it renders; it sets it again here once it mounts.
|
|
148
|
+
el.setAttribute("type", "button")
|
|
131
149
|
}}
|
|
150
|
+
data-closed=""
|
|
151
|
+
tabIndex={local.triggerTabIndex}
|
|
152
|
+
data-component="tooltip-v2-trigger"
|
|
153
|
+
class={local.class}
|
|
154
|
+
onPointerEnter={mount}
|
|
155
|
+
onFocus={mount}
|
|
156
|
+
onFocusOut={() => requestAnimationFrame(() => drop())}
|
|
132
157
|
>
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
158
|
+
{local.children}
|
|
159
|
+
</div>
|
|
160
|
+
<Show when={state.mounted}>
|
|
161
|
+
<Root
|
|
162
|
+
gutter={4}
|
|
163
|
+
openDelay={400}
|
|
164
|
+
skipDelayDuration={300}
|
|
165
|
+
{...others}
|
|
166
|
+
closeDelay={0}
|
|
167
|
+
ignoreSafeArea={local.ignoreSafeArea ?? true}
|
|
168
|
+
open={controlled() ? local.forceOpen : state.open}
|
|
169
|
+
onOpenChange={(open) => {
|
|
170
|
+
if (controlled()) return
|
|
171
|
+
|
|
172
|
+
if (state.block && open) return
|
|
173
|
+
|
|
174
|
+
if (justClickedTrigger) {
|
|
175
|
+
justClickedTrigger = false
|
|
176
|
+
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
setState("open", open)
|
|
143
181
|
}}
|
|
144
|
-
onPointerLeave={leave}
|
|
145
|
-
onFocusOut={() => requestAnimationFrame(() => drop())}
|
|
146
182
|
>
|
|
147
|
-
{
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
<
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
183
|
+
{/* Kobalte calls leave inside its own pointerleave listener. As a separate listener, its microtask would
|
|
184
|
+
close the tooltip before Kobalte's listener ran, which then skipped the skip-delay window. */}
|
|
185
|
+
<Trigger as={adopt} onPointerLeave={leave} />
|
|
186
|
+
<Portal>
|
|
187
|
+
<Content
|
|
188
|
+
ref={(el) => {
|
|
189
|
+
const theme = ref?.closest("[data-theme]")?.getAttribute("data-theme")
|
|
190
|
+
|
|
191
|
+
if (theme) el.setAttribute("data-theme", theme)
|
|
192
|
+
}}
|
|
193
|
+
data-component="tooltip-v2"
|
|
194
|
+
data-appearance={local.appearance ?? "compact"}
|
|
195
|
+
data-placement={props.placement}
|
|
196
|
+
data-force-open={local.forceOpen}
|
|
197
|
+
class={local.contentClass}
|
|
198
|
+
style={local.contentStyle}
|
|
199
|
+
onPointerDownOutside={(e) => {
|
|
200
|
+
if (ref === e.target || (e.target instanceof Node && ref?.contains(e.target))) {
|
|
201
|
+
justClickedTrigger = true
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
e.preventDefault()
|
|
205
|
+
}}
|
|
206
|
+
>
|
|
207
|
+
{local.value}
|
|
208
|
+
</Content>
|
|
209
|
+
</Portal>
|
|
210
|
+
</Root>
|
|
211
|
+
</Show>
|
|
174
212
|
</Match>
|
|
175
213
|
</Switch>
|
|
176
214
|
)
|