Skip to content

Commit 231b01a

Browse files
committed
feat(dialog:headless): allow overriding css classes
1 parent 15ca27c commit 231b01a

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Diff for: packages/headless/src/components/dialog/dialog.tsx

+15-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ import A11yDialog from 'a11y-dialog';
1919
import stylesDialogContainer from './dialog-container.css?inline';
2020
import stylesDialogContent from './dialog-content.css?inline';
2121

22+
interface DialogStyleProps {
23+
classNames?: { container: string; content: string };
24+
}
25+
26+
interface StyleProps {
27+
class?: string;
28+
}
29+
2230
interface DialogContextSignals {
2331
/** Indicates whether Dialog is open or not. */
2432
isOpenSignal: Signal<boolean>;
@@ -65,7 +73,7 @@ const Root = component$(() => {
6573
);
6674
});
6775

68-
const Trigger = component$(() => {
76+
const Trigger = component$((props: StyleProps) => {
6977
const dialogContext = useContext(dialogContextId);
7078
const a11yDialog = useSignal<NoSerialize<A11yDialog>>();
7179

@@ -95,16 +103,16 @@ const Trigger = component$(() => {
95103
);
96104

97105
return (
98-
<div role="button">
106+
<div role="button" class={props.class}>
99107
<Slot />
100108
</div>
101109
);
102110
});
103111

104-
// TODO: We need a way to add the template as nearest as possible to the <body>-Element
112+
// TODO: We need a way to add the template as nearest as possible to the </body>-Element
105113
// This ensures the dialog being displayed on top of all other elements
106114
// React has a built-in way to create portals. How to we handle this in Qwik-UI?
107-
const Portal = component$(() => {
115+
const Portal = component$((props: DialogStyleProps) => {
108116
useStylesScoped$(stylesDialogContainer);
109117

110118
const dialogContext = useContext(dialogContextId);
@@ -119,15 +127,15 @@ const Portal = component$(() => {
119127
ref={containerRefSignal}
120128
aria-labelledby="your-dialog-title-id"
121129
aria-hidden="true"
122-
class="dialog-container"
130+
// class={`dialog-container ${props.classNames?.container}`}
131+
class={`${props.classNames?.container || 'dialog-container'}`}
123132
>
124133
<div
125134
data-a11y-dialog-hide
126135
class="dialog-overlay"
127136
onClick$={() => (dialogContext.isOpenSignal.value = false)}
128137
></div>
129-
130-
<div role="document">
138+
<div role="document" class={props.classNames?.content}>
131139
<Slot />
132140
</div>
133141
</div>

0 commit comments

Comments
 (0)