@opencode/ui 0.0.0-dev-20083 → 0.0.0-dev-20086

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.
@@ -8,6 +8,9 @@ type Active = {
8
8
  onClose?: () => void;
9
9
  setClosing: (closing: boolean) => void;
10
10
  };
11
+ export declare function useDialogLayer(): {
12
+ setBackdropDismiss: (value: boolean) => void;
13
+ } | undefined;
11
14
  export declare function DialogProvider(props: ParentProps): JSX.Element;
12
15
  export declare function useDialog(): {
13
16
  readonly active: Active | undefined;
@@ -1,3 +1,4 @@
1
+ import { Content } from "@kobalte/core/dialog";
1
2
  import { type ComponentProps, type JSXElement, type ParentProps } from "solid-js";
2
3
  import "./dialog.css";
3
4
  export interface DialogProps extends ParentProps {
@@ -7,6 +8,8 @@ export interface DialogProps extends ParentProps {
7
8
  containerClass?: ComponentProps<"div">["class"];
8
9
  classList?: ComponentProps<"div">["classList"];
9
10
  fit?: boolean;
11
+ onCloseAutoFocus?: ComponentProps<typeof Content>["onCloseAutoFocus"];
12
+ preventBackdropDismiss?: boolean;
10
13
  }
11
14
  export interface DialogHeaderProps extends ParentProps {
12
15
  closeLabel?: string;
@@ -14,7 +17,7 @@ export interface DialogHeaderProps extends ParentProps {
14
17
  }
15
18
  export interface DialogTitleGroupProps {
16
19
  title?: JSXElement;
17
- description: JSXElement;
20
+ description?: JSXElement;
18
21
  }
19
22
  export declare function DialogFooter(props: ParentProps): import("solid-js").JSX.Element;
20
23
  export declare function DialogBody(props: ParentProps & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencode/ui",
3
- "version": "0.0.0-dev-20083",
3
+ "version": "0.0.0-dev-20086",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -28,6 +28,12 @@ type Active = {
28
28
  }
29
29
 
30
30
  const Context = createContext<ReturnType<typeof init>>()
31
+ // Lets the dialog rendered in a layer opt out of closing on a backdrop click.
32
+ const LayerContext = createContext<{ setBackdropDismiss: (value: boolean) => void }>()
33
+
34
+ export function useDialogLayer() {
35
+ return useContext(LayerContext)
36
+ }
31
37
 
32
38
  function init() {
33
39
  const [stack, setStack] = createSignal<Active[]>([])
@@ -86,6 +92,7 @@ function init() {
86
92
  createRoot((d: () => void) => {
87
93
  dispose = d
88
94
  const [closing, setClosingSignal] = createSignal(false)
95
+ const [backdropDismiss, setBackdropDismiss] = createSignal(true)
89
96
  setClosing = setClosingSignal
90
97
  return (
91
98
  <Kobalte
@@ -100,7 +107,9 @@ function init() {
100
107
  <Kobalte.Overlay
101
108
  data-component="dialog-overlay"
102
109
  style={{ "z-index": String(zIndex) }}
103
- onClick={() => close(id)}
110
+ onClick={() => {
111
+ if (backdropDismiss()) close(id)
112
+ }}
104
113
  />
105
114
  <div
106
115
  data-dialog-layer={layer}
@@ -114,7 +123,7 @@ function init() {
114
123
  "pointer-events": "none",
115
124
  }}
116
125
  >
117
- {element()}
126
+ <LayerContext.Provider value={{ setBackdropDismiss }}>{element()}</LayerContext.Provider>
118
127
  </div>
119
128
  </Kobalte.Portal>
120
129
  </Kobalte>
@@ -1,5 +1,6 @@
1
1
  import { CloseButton, Content, Description, Title } from "@kobalte/core/dialog"
2
- import { type ComponentProps, type JSXElement, type ParentProps, Show, children, splitProps } from "solid-js"
2
+ import { type ComponentProps, type JSXElement, type ParentProps, Show, children, createEffect, splitProps } from "solid-js"
3
+ import { useDialogLayer } from "../../context/dialog"
3
4
  import { useI18n } from "../../context/i18n"
4
5
  import "./dialog.css"
5
6
 
@@ -10,6 +11,8 @@ export interface DialogProps extends ParentProps {
10
11
  containerClass?: ComponentProps<"div">["class"]
11
12
  classList?: ComponentProps<"div">["classList"]
12
13
  fit?: boolean
14
+ onCloseAutoFocus?: ComponentProps<typeof Content>["onCloseAutoFocus"]
15
+ preventBackdropDismiss?: boolean
13
16
  }
14
17
 
15
18
  export interface DialogHeaderProps extends ParentProps {
@@ -19,7 +22,7 @@ export interface DialogHeaderProps extends ParentProps {
19
22
 
20
23
  export interface DialogTitleGroupProps {
21
24
  title?: JSXElement
22
- description: JSXElement
25
+ description?: JSXElement
23
26
  }
24
27
 
25
28
  export function DialogFooter(props: ParentProps) {
@@ -46,7 +49,7 @@ export function DialogTitleGroup(props: DialogTitleGroupProps) {
46
49
  return (
47
50
  <div data-slot="dialog-title-group">
48
51
  <Show when={title()}>{(t) => <Title data-slot="dialog-title">{t()}</Title>}</Show>
49
- <Description data-slot="dialog-description">{description()}</Description>
52
+ <Show when={description()}>{(value) => <Description data-slot="dialog-description">{value()}</Description>}</Show>
50
53
  </div>
51
54
  )
52
55
  }
@@ -82,7 +85,19 @@ export function DialogHeader(props: DialogHeaderProps) {
82
85
  }
83
86
 
84
87
  export function Dialog(props: DialogProps) {
85
- const [local] = splitProps(props, ["size", "variant", "class", "containerClass", "classList", "fit", "children"])
88
+ const [local] = splitProps(props, [
89
+ "size",
90
+ "variant",
91
+ "class",
92
+ "containerClass",
93
+ "classList",
94
+ "fit",
95
+ "children",
96
+ "onCloseAutoFocus",
97
+ "preventBackdropDismiss",
98
+ ])
99
+ const layer = useDialogLayer()
100
+ createEffect(() => layer?.setBackdropDismiss(!local.preventBackdropDismiss))
86
101
 
87
102
  return (
88
103
  <div
@@ -94,6 +109,10 @@ export function Dialog(props: DialogProps) {
94
109
  <div data-slot="dialog-container" class={local.containerClass}>
95
110
  <Content
96
111
  data-slot="dialog-content"
112
+ onCloseAutoFocus={local.onCloseAutoFocus}
113
+ onPointerDownOutside={(event) => {
114
+ if (local.preventBackdropDismiss) event.preventDefault()
115
+ }}
97
116
  classList={{
98
117
  ...local.classList,
99
118
  [local.class ?? ""]: !!local.class,