|
1 |
| -import { Slot, component$ } from '@builder.io/qwik'; |
2 |
| -import { Dialog } from '@qwik-ui/headless'; |
| 1 | +import { Slot, component$, useComputed$, useSignal } from '@builder.io/qwik'; |
| 2 | +import { Dialog, DialogRef } from '@qwik-ui/headless'; |
3 | 3 |
|
4 | 4 | export const Root = component$((props: Dialog.RootProps) => {
|
| 5 | + const dialog = useSignal<DialogRef>(); |
| 6 | + |
| 7 | + const modalClass = useComputed$(() => { |
| 8 | + const clazz = dialog.value?.opened ? 'modal modal-open' : 'modal'; |
| 9 | + console.log('CHANGE', dialog.value?.opened, clazz); |
| 10 | + |
| 11 | + return clazz; |
| 12 | + }); |
| 13 | + |
5 | 14 | return (
|
6 |
| - <Dialog.Root class="bg-slate-900 rounded-md text-white" {...props}> |
| 15 | + <Dialog.Root class={modalClass.value} {...props} ref={dialog}> |
7 | 16 | <Slot />
|
8 | 17 | </Dialog.Root>
|
9 | 18 | );
|
10 | 19 | });
|
11 | 20 |
|
12 |
| -export const Trigger = Dialog.Trigger; |
13 | 21 | export const Close = Dialog.Close;
|
| 22 | +export const Trigger = Dialog.Trigger; |
| 23 | + |
| 24 | +export const Content = component$(() => { |
| 25 | + return ( |
| 26 | + <Dialog.Content> |
| 27 | + <div class="modal-box"> |
| 28 | + <Slot /> |
| 29 | + </div> |
| 30 | + </Dialog.Content> |
| 31 | + ); |
| 32 | +}); |
| 33 | +export const ContentTitle = component$(() => { |
| 34 | + return ( |
| 35 | + <Dialog.ContentTitle> |
| 36 | + <h3 class="font-bold text-lg"> |
| 37 | + <Slot /> |
| 38 | + </h3> |
| 39 | + </Dialog.ContentTitle> |
| 40 | + ); |
| 41 | +}); |
| 42 | +export const ContentText = component$(() => { |
| 43 | + return ( |
| 44 | + <Dialog.ContentText> |
| 45 | + <p class="py-4"> |
| 46 | + <Slot /> |
| 47 | + </p> |
| 48 | + </Dialog.ContentText> |
| 49 | + ); |
| 50 | +}); |
| 51 | + |
| 52 | +export const Actions = component$(() => { |
| 53 | + return ( |
| 54 | + <Dialog.Actions> |
| 55 | + <div class="modal-actions"> |
| 56 | + <Slot /> |
| 57 | + </div> |
| 58 | + </Dialog.Actions> |
| 59 | + ); |
| 60 | +}); |
| 61 | + |
| 62 | +/* |
| 63 | +
|
| 64 | +<!-- The button to open modal --> |
| 65 | +<label for="my-modal" class="btn">open modal</label> |
| 66 | +
|
| 67 | +<!-- Put this part before </body> tag --> |
| 68 | +<input type="checkbox" id="my-modal" class="modal-toggle" /> |
| 69 | +<div class="modal"> |
| 70 | + <div class="modal-box"> |
| 71 | + <h3 class="font-bold text-lg">Congratulations random Internet user!</h3> |
| 72 | + <p class="py-4">You've been selected for a chance to get one year of subscription to use Wikipedia for free!</p> |
| 73 | + <div class="modal-action"> |
| 74 | + <label for="my-modal" class="btn">Yay!</label> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | +</div> |
14 | 78 |
|
15 |
| -export const Content = Dialog.Content; |
16 |
| -export const ContentTitle = Dialog.ContentTitle; |
17 |
| -export const ContentText = Dialog.ContentText; |
| 79 | +*/ |
0 commit comments