@opencode/ui 0.0.0-dev-565 → 0.0.0-dev-569

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,13 @@
1
1
  import { Root } from "@kobalte/core/checkbox";
2
2
  import type { ComponentProps, JSX, ParentProps } from "solid-js";
3
+ import "./checkbox-compact.css";
3
4
  export interface CheckboxProps extends ParentProps<ComponentProps<typeof Root>> {
5
+ /** `compact` is the design system checkbox; `standard` keeps the legacy look. */
6
+ appearance?: "standard" | "compact";
7
+ /** Background of the compact control. */
8
+ surface?: "base" | "layer-1";
4
9
  hideLabel?: boolean;
5
- description?: string;
10
+ description?: JSX.Element;
6
11
  icon?: JSX.Element;
7
12
  }
8
13
  export declare function Checkbox(props: CheckboxProps): JSX.Element;
@@ -16,6 +16,10 @@ export type SelectProps<T> = Omit<ComponentProps<typeof Root<T, {
16
16
  onHighlight?: (value: T | undefined) => void | (() => void);
17
17
  invalid?: boolean;
18
18
  numeric?: boolean;
19
+ /** `inline` is the borderless settings trigger; `small`, `base` and `large` are 24px, 28px and 32px input fields. */
20
+ appearance?: "inline" | "small" | "base" | "large";
21
+ /** Background surface of an input field; invisible gains a fill on hover. */
22
+ surface?: "base" | "layer-1" | "invisible";
19
23
  children?: (item: T) => JSX.Element;
20
24
  valueClass?: string;
21
25
  contentClass?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencode/ui",
3
- "version": "0.0.0-dev-565",
3
+ "version": "0.0.0-dev-569",
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-565",
291
+ "@opencode/util": "0.0.0-dev-569",
292
292
  "@pierre/diffs": "1.6.1",
293
293
  "@pierre/highlights": "0.2.0",
294
294
  "@solid-primitives/event-listener": "2.4.6",
@@ -0,0 +1,169 @@
1
+ /* Vite can link this before the app entry CSS, so name every layer here or `components` ranks below Tailwind's base reset. */
2
+ @layer properties, theme, base, components, utilities;
3
+
4
+ @layer components {
5
+ [data-slot="checkbox-v2"] {
6
+ display: flex;
7
+ flex-direction: column;
8
+ gap: 6px;
9
+ cursor: default;
10
+
11
+ &:where([data-disabled]) {
12
+ cursor: not-allowed;
13
+ }
14
+
15
+ &:where([data-readonly]) {
16
+ pointer-events: none;
17
+ }
18
+ }
19
+
20
+ [data-slot="checkbox-v2-error"] {
21
+ color: var(--v2-state-fg-danger);
22
+ font-size: 12px;
23
+ font-weight: 440;
24
+ line-height: var(--line-height-compact);
25
+ }
26
+
27
+ [data-slot="checkbox-v2-error"]:empty {
28
+ display: none;
29
+ }
30
+
31
+ [data-slot="checkbox-v2-row"] {
32
+ position: relative;
33
+ display: flex;
34
+ flex-direction: row;
35
+ align-items: flex-start;
36
+ gap: 8px;
37
+ }
38
+
39
+ [data-slot="checkbox-v2-input"] {
40
+ position: absolute;
41
+ width: 1px;
42
+ height: 1px;
43
+ padding: 0;
44
+ margin: -1px;
45
+ overflow: hidden;
46
+ clip: rect(0, 0, 0, 0);
47
+ white-space: nowrap;
48
+ border-width: 0;
49
+ }
50
+
51
+ /* 20px tall so the 16px control centres on the first 20px line of the label. */
52
+ [data-slot="checkbox-v2-control-stack"] {
53
+ position: relative;
54
+ width: 16px;
55
+ height: 20px;
56
+ flex: none;
57
+ }
58
+
59
+ [data-slot="checkbox-v2-control"] {
60
+ box-sizing: border-box;
61
+ position: absolute;
62
+ top: 2px;
63
+ left: 0;
64
+ width: 16px;
65
+ height: 16px;
66
+ border-radius: 4px;
67
+ color: var(--v2-icon-icon-contrast);
68
+ background: var(--v2-background-bg-base);
69
+ box-shadow: inset 0 0 0 0.5px var(--v2-border-border-strong);
70
+ transition:
71
+ background 85ms ease-out,
72
+ box-shadow 85ms ease-out;
73
+ }
74
+
75
+ [data-slot="checkbox-v2"][data-surface="layer-1"] [data-slot="checkbox-v2-control"] {
76
+ background: var(--v2-background-bg-layer-01);
77
+ }
78
+
79
+ [data-slot="checkbox-v2-indicator"] {
80
+ position: absolute;
81
+ inset: 0;
82
+ pointer-events: none;
83
+ }
84
+
85
+ [data-slot="checkbox-v2-text"] {
86
+ display: flex;
87
+ flex-direction: column;
88
+ justify-content: center;
89
+ align-items: flex-start;
90
+ gap: 6px;
91
+ min-width: 0;
92
+ }
93
+
94
+ [data-slot="checkbox-v2-label"] {
95
+ user-select: none;
96
+ color: var(--v2-text-text-base);
97
+ font-size: 13px;
98
+ font-weight: 440;
99
+ line-height: var(--line-height-base);
100
+ letter-spacing: -0.04px;
101
+ font-variation-settings: "slnt" 0;
102
+ }
103
+
104
+ [data-slot="checkbox-v2-description"] {
105
+ color: var(--v2-text-text-muted);
106
+ font-size: 11px;
107
+ font-weight: 440;
108
+ line-height: var(--line-height-tight);
109
+ letter-spacing: 0.05px;
110
+ user-select: none;
111
+ }
112
+
113
+ [data-slot="checkbox-v2"]:where(:not([data-readonly]))
114
+ [data-slot="checkbox-v2-input"]:focus-visible
115
+ ~ [data-slot="checkbox-v2-control-stack"]
116
+ [data-slot="checkbox-v2-control"] {
117
+ outline: 2px solid var(--v2-border-border-focus);
118
+ outline-offset: 2px;
119
+ }
120
+
121
+ @media (hover: hover) {
122
+ [data-slot="checkbox-v2"]:where(:hover):where(:not([data-disabled], [data-readonly], [data-invalid])):where(
123
+ :not([data-checked], [data-indeterminate])
124
+ )
125
+ [data-slot="checkbox-v2-control"] {
126
+ box-shadow:
127
+ inset 0 0 0 0.5px var(--v2-border-border-strong),
128
+ inset 0 0 0 100vmax var(--v2-overlay-simple-overlay-hover);
129
+ }
130
+
131
+ [data-slot="checkbox-v2"]:where([data-checked], [data-indeterminate]):where(:hover):where(
132
+ :not([data-disabled], [data-readonly])
133
+ )
134
+ [data-slot="checkbox-v2-control"] {
135
+ box-shadow:
136
+ inset 0 0 0 0.5px var(--v2-border-border-strong),
137
+ inset 0 0 0 100vmax var(--v2-overlay-simple-overlay-contrast-hover);
138
+ }
139
+ }
140
+
141
+ /* The depth gradient is Figma's white-to-clear fill at 20% opacity over the accent. */
142
+ [data-slot="checkbox-v2"]:where([data-checked], [data-indeterminate]) [data-slot="checkbox-v2-control"] {
143
+ background:
144
+ linear-gradient(180deg, var(--v2-alpha-light-20) 0%, var(--v2-alpha-light-0) 100%), var(--v2-background-bg-accent);
145
+ }
146
+
147
+ [data-slot="checkbox-v2"]:where([data-invalid]):where(:not([data-checked], [data-indeterminate]))
148
+ [data-slot="checkbox-v2-control"] {
149
+ background: var(--v2-state-bg-danger);
150
+ box-shadow: inset 0 0 0 0.5px var(--v2-state-fg-danger);
151
+ }
152
+
153
+ [data-slot="checkbox-v2"] .checkbox-v2-icon {
154
+ position: absolute;
155
+ left: 50%;
156
+ top: 50%;
157
+ transform: translate(-50%, -50%);
158
+ display: none;
159
+ }
160
+
161
+ [data-slot="checkbox-v2"]:where([data-checked]):where(:not([data-indeterminate])) .checkbox-v2-icon--check,
162
+ [data-slot="checkbox-v2"]:where([data-indeterminate]) .checkbox-v2-icon--minus {
163
+ display: block;
164
+ }
165
+
166
+ [data-slot="checkbox-v2"]:where([data-disabled]) [data-slot="checkbox-v2-row"] {
167
+ opacity: 0.5;
168
+ }
169
+ }
@@ -1,44 +1,106 @@
1
1
  import { Control, Description, ErrorMessage, Indicator, Input, Label, Root } from "@kobalte/core/checkbox"
2
- import { Show, splitProps } from "solid-js"
2
+ import { Match, Show, Switch, splitProps } from "solid-js"
3
3
  import type { ComponentProps, JSX, ParentProps } from "solid-js"
4
+ import "./checkbox-compact.css"
4
5
 
5
6
  export interface CheckboxProps extends ParentProps<ComponentProps<typeof Root>> {
7
+ /** `compact` is the design system checkbox; `standard` keeps the legacy look. */
8
+ appearance?: "standard" | "compact"
9
+ /** Background of the compact control. */
10
+ surface?: "base" | "layer-1"
6
11
  hideLabel?: boolean
7
- description?: string
12
+ description?: JSX.Element
8
13
  icon?: JSX.Element
9
14
  }
10
15
 
11
16
  export function Checkbox(props: CheckboxProps) {
12
- const [local, others] = splitProps(props, ["children", "class", "label", "hideLabel", "description", "icon"])
17
+ const [local, others] = splitProps(props, [
18
+ "children",
19
+ "class",
20
+ "label",
21
+ "appearance",
22
+ "surface",
23
+ "hideLabel",
24
+ "description",
25
+ "icon",
26
+ ])
13
27
 
14
28
  return (
15
- <Root {...others} data-component="checkbox">
16
- <Input data-slot="checkbox-checkbox-input" />
17
- <Control data-slot="checkbox-checkbox-control">
18
- <Indicator data-slot="checkbox-checkbox-indicator">
19
- {local.icon || (
20
- <svg viewBox="0 0 12 12" fill="none" width="10" height="10" xmlns="http://www.w3.org/2000/svg">
21
- <path
22
- d="M3 7.17905L5.02703 8.85135L9 3.5"
23
- stroke="currentColor"
24
- stroke-width="1.5"
25
- stroke-linecap="square"
26
- />
27
- </svg>
28
- )}
29
- </Indicator>
30
- </Control>
31
- <div data-slot="checkbox-checkbox-content">
32
- <Show when={props.children}>
33
- <Label data-slot="checkbox-checkbox-label" classList={{ "sr-only": local.hideLabel }}>
34
- {props.children}
35
- </Label>
36
- </Show>
37
- <Show when={local.description}>
38
- <Description data-slot="checkbox-checkbox-description">{local.description}</Description>
39
- </Show>
40
- <ErrorMessage data-slot="checkbox-checkbox-error" />
41
- </div>
42
- </Root>
29
+ <Switch>
30
+ <Match when={local.appearance === "compact"}>
31
+ <Root {...others} class={local.class} data-slot="checkbox-v2" data-surface={local.surface ?? "base"}>
32
+ <div data-slot="checkbox-v2-row">
33
+ <Input data-slot="checkbox-v2-input" />
34
+ <div data-slot="checkbox-v2-control-stack">
35
+ <Control data-slot="checkbox-v2-control">
36
+ <Indicator data-slot="checkbox-v2-indicator">
37
+ <svg
38
+ class="checkbox-v2-icon checkbox-v2-icon--check"
39
+ width="16"
40
+ height="16"
41
+ viewBox="0 0 16 16"
42
+ fill="none"
43
+ aria-hidden="true"
44
+ >
45
+ <path d="M3.53564 8.17857L6.39279 11.75L12.4642 4.25" stroke="currentColor" stroke-width="1" />
46
+ </svg>
47
+ <svg
48
+ class="checkbox-v2-icon checkbox-v2-icon--minus"
49
+ width="16"
50
+ height="16"
51
+ viewBox="0 0 16 16"
52
+ fill="none"
53
+ aria-hidden="true"
54
+ >
55
+ <path d="M12.75 8H3.25" stroke="currentColor" stroke-linejoin="round" stroke-width="1" />
56
+ </svg>
57
+ </Indicator>
58
+ </Control>
59
+ </div>
60
+ <div data-slot="checkbox-v2-text">
61
+ <Show when={local.children}>
62
+ <Label data-slot="checkbox-v2-label" classList={{ "sr-only": local.hideLabel }}>
63
+ {local.children}
64
+ </Label>
65
+ </Show>
66
+ <Show when={local.description}>
67
+ <Description data-slot="checkbox-v2-description">{local.description}</Description>
68
+ </Show>
69
+ </div>
70
+ </div>
71
+ <ErrorMessage data-slot="checkbox-v2-error" />
72
+ </Root>
73
+ </Match>
74
+ <Match when={true}>
75
+ <Root {...others} class={local.class} data-component="checkbox">
76
+ <Input data-slot="checkbox-checkbox-input" />
77
+ <Control data-slot="checkbox-checkbox-control">
78
+ <Indicator data-slot="checkbox-checkbox-indicator">
79
+ {local.icon || (
80
+ <svg viewBox="0 0 12 12" fill="none" width="10" height="10" xmlns="http://www.w3.org/2000/svg">
81
+ <path
82
+ d="M3 7.17905L5.02703 8.85135L9 3.5"
83
+ stroke="currentColor"
84
+ stroke-width="1.5"
85
+ stroke-linecap="square"
86
+ />
87
+ </svg>
88
+ )}
89
+ </Indicator>
90
+ </Control>
91
+ <div data-slot="checkbox-checkbox-content">
92
+ <Show when={props.children}>
93
+ <Label data-slot="checkbox-checkbox-label" classList={{ "sr-only": local.hideLabel }}>
94
+ {props.children}
95
+ </Label>
96
+ </Show>
97
+ <Show when={local.description}>
98
+ <Description data-slot="checkbox-checkbox-description">{local.description}</Description>
99
+ </Show>
100
+ <ErrorMessage data-slot="checkbox-checkbox-error" />
101
+ </div>
102
+ </Root>
103
+ </Match>
104
+ </Switch>
43
105
  )
44
106
  }
@@ -32,10 +32,9 @@
32
32
  border: 0;
33
33
  border-radius: 6px;
34
34
  outline: 1px solid transparent;
35
- outline-offset: 0;
36
- background:
37
- linear-gradient(180deg, var(--v2-alpha-light-2) 0%, var(--v2-alpha-light-0) 100%), var(--v2-background-bg-base);
38
- box-shadow: var(--v2-elevation-button-neutral);
35
+ outline-offset: -1px;
36
+ background: var(--v2-background-bg-base);
37
+ box-shadow: var(--v2-elevation-input);
39
38
  flex: none;
40
39
  align-self: stretch;
41
40
  user-select: none;
@@ -45,21 +44,59 @@
45
44
  box-shadow 85ms ease-out;
46
45
  }
47
46
 
48
- [data-component="select-v2"]:where(:hover):not([data-disabled], [data-invalid]):not(:focus-within):not(
49
- [data-expanded]
50
- ) {
51
- background:
52
- linear-gradient(0deg, var(--v2-overlay-simple-overlay-hover), var(--v2-overlay-simple-overlay-hover)),
53
- linear-gradient(180deg, var(--v2-alpha-light-2) 0%, var(--v2-alpha-light-0) 100%), var(--v2-background-bg-base);
47
+ [data-component="select-v2"][data-appearance="small"] {
48
+ height: 24px;
54
49
  }
55
50
 
56
- [data-component="select-v2"]:where([data-expanded]):not([data-disabled], [data-invalid]) {
57
- background:
58
- linear-gradient(0deg, var(--v2-overlay-simple-overlay-hover), var(--v2-overlay-simple-overlay-hover)),
59
- linear-gradient(180deg, var(--v2-alpha-light-2) 0%, var(--v2-alpha-light-0) 100%), var(--v2-background-bg-base);
51
+ [data-component="select-v2"][data-appearance="large"] {
52
+ height: 32px;
53
+ padding-inline: 0 8px;
54
+ }
55
+
56
+ [data-component="select-v2"][data-surface="layer-1"] {
57
+ background: var(--v2-background-bg-layer-01);
58
+ }
59
+
60
+ [data-component="select-v2"][data-surface="invisible"] {
61
+ background: transparent;
62
+ box-shadow: none;
63
+ }
64
+
65
+ /* An inset overlay keeps the surface colour underneath, the same hover the text input uses. */
66
+ @media (hover: hover) {
67
+ [data-component="select-v2"]:where(:hover):not(
68
+ [data-disabled],
69
+ [data-invalid],
70
+ [data-expanded],
71
+ [data-appearance="inline"],
72
+ [data-surface="invisible"]
73
+ ):not(:focus-within) {
74
+ box-shadow:
75
+ inset 0 0 0 100vmax var(--v2-overlay-simple-overlay-hover),
76
+ var(--v2-elevation-input);
77
+ }
78
+
79
+ [data-component="select-v2"][data-surface="invisible"]:where(:hover):not(
80
+ [data-disabled],
81
+ [data-invalid],
82
+ [data-expanded]
83
+ ):not(:focus-within) {
84
+ background: var(--v2-overlay-simple-overlay-hover);
85
+ }
86
+ }
87
+
88
+ [data-component="select-v2"]:where([data-expanded]):not([data-disabled], [data-invalid], [data-appearance="inline"]) {
89
+ box-shadow:
90
+ inset 0 0 0 100vmax var(--v2-overlay-simple-overlay-hover),
91
+ var(--v2-elevation-input);
60
92
  outline-color: transparent;
61
93
  }
62
94
 
95
+ [data-component="select-v2"][data-surface="invisible"]:where([data-expanded]):not([data-disabled], [data-invalid]) {
96
+ background: var(--v2-overlay-simple-overlay-hover);
97
+ box-shadow: none;
98
+ }
99
+
63
100
  [data-component="select-v2"]:where(:focus-within):not([data-disabled], [data-invalid]):not([data-expanded]) {
64
101
  outline-color: var(--v2-border-border-focus);
65
102
  box-shadow: none;
@@ -70,11 +70,17 @@ export type SelectProps<T> = Omit<
70
70
  onHighlight?: (value: T | undefined) => void | (() => void)
71
71
  invalid?: boolean
72
72
  numeric?: boolean
73
+ /** `inline` is the borderless settings trigger; `small`, `base` and `large` are 24px, 28px and 32px input fields. */
74
+ appearance?: "inline" | "small" | "base" | "large"
75
+ /** Background surface of an input field; invisible gains a fill on hover. */
76
+ surface?: "base" | "layer-1" | "invisible"
73
77
  children?: (item: T) => JSX.Element
74
78
  valueClass?: string
75
79
  contentClass?: string
76
80
  }
77
81
 
82
+ type HighlightState = { key?: string; cleanup?: void | (() => void) }
83
+
78
84
  export function Select<T>(props: SelectProps<T>) {
79
85
  const [local, others] = splitProps(props, [
80
86
  "class",
@@ -91,6 +97,8 @@ export function Select<T>(props: SelectProps<T>) {
91
97
  "children",
92
98
  "invalid",
93
99
  "numeric",
100
+ "appearance",
101
+ "surface",
94
102
  "disabled",
95
103
  "valueClass",
96
104
  "contentClass",
@@ -102,7 +110,7 @@ export function Select<T>(props: SelectProps<T>) {
102
110
  "fitViewport",
103
111
  ])
104
112
 
105
- const state: { key?: string; cleanup?: void | (() => void) } = {}
113
+ const state: HighlightState = {}
106
114
 
107
115
  const stop = () => {
108
116
  state.cleanup?.()
@@ -110,7 +118,7 @@ export function Select<T>(props: SelectProps<T>) {
110
118
  state.key = undefined
111
119
  }
112
120
 
113
- const keyFor = (item: T) => (local.value ? local.value(item) : String(item as string))
121
+ const keyFor = (item: T) => (local.value ? local.value(item) : String(item))
114
122
 
115
123
  const move = (item: T | undefined) => {
116
124
  if (!local.onHighlight) return
@@ -148,8 +156,8 @@ export function Select<T>(props: SelectProps<T>) {
148
156
  fitViewport={local.fitViewport ?? false}
149
157
  value={local.current}
150
158
  options={grouped()}
151
- optionValue={(x) => (local.value ? local.value(x) : String(x as string))}
152
- optionTextValue={(x) => (local.label ? local.label(x) : String(x as string))}
159
+ optionValue={(x) => (local.value ? local.value(x) : String(x))}
160
+ optionTextValue={(x) => (local.label ? local.label(x) : String(x))}
153
161
  optionGroupChildren="options"
154
162
  placeholder={local.placeholder}
155
163
  sectionComponent={(sectionProps) => (
@@ -172,7 +180,7 @@ export function Select<T>(props: SelectProps<T>) {
172
180
  ? local.children(itemProps.item.rawValue)
173
181
  : local.label
174
182
  ? local.label(itemProps.item.rawValue)
175
- : String(itemProps.item.rawValue as string)}
183
+ : String(itemProps.item.rawValue)}
176
184
  </ItemLabel>
177
185
  <ItemIndicator data-slot="menu-v2-item-indicator" forceMount>
178
186
  <CheckSmall />
@@ -180,7 +188,7 @@ export function Select<T>(props: SelectProps<T>) {
180
188
  </Item>
181
189
  )}
182
190
  onChange={(next) => {
183
- const v = next == null ? null : Array.isArray(next) ? ((next[0] as T) ?? null) : (next as T)
191
+ const v = next == null ? null : Array.isArray(next) ? (next[0] ?? null) : next
184
192
  local.onSelect?.(v)
185
193
  stop()
186
194
  }}
@@ -195,7 +203,8 @@ export function Select<T>(props: SelectProps<T>) {
195
203
  aria-label={props["aria-label"]}
196
204
  aria-labelledby={props["aria-labelledby"]}
197
205
  data-component="select-v2"
198
- data-appearance="inline"
206
+ data-appearance={local.appearance ?? "inline"}
207
+ data-surface={local.appearance && local.appearance !== "inline" ? (local.surface ?? "base") : undefined}
199
208
  data-invalid={local.invalid ? "" : undefined}
200
209
  data-numeric={local.numeric ? "" : undefined}
201
210
  disabled={local.disabled}
@@ -212,7 +221,7 @@ export function Select<T>(props: SelectProps<T>) {
212
221
 
213
222
  if (local.label && selected != null) return local.label(selected)
214
223
 
215
- return selected != null ? (selected as string) : ""
224
+ return selected != null ? String(selected) : ""
216
225
  }}
217
226
  </Value>
218
227
  </div>