Skip to content

Commit 92c1b74

Browse files
committed
refactor: Show calendar as full-screen overlay instead of in dialog
- Replace in-dialog calendar with full-screen overlay - Dialog closes when transitioning to calendar view - Cleaner separation between form and calendar UI
1 parent bfcae63 commit 92c1b74

File tree

1 file changed

+90
-90
lines changed

1 file changed

+90
-90
lines changed

reflex_ui/blocks/demo_form.py

Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,6 @@ def go_back(self):
292292
def go_back_from_calendar(self):
293293
"""Go back from calendar to step 3."""
294294
self.show_calendar = False
295-
# Clear the initialized flag so calendar can be reinitialized
296-
return rx.call_script("""
297-
var containers = document.querySelectorAll('.cal-embed-container');
298-
containers.forEach(function(el) {
299-
el.dataset.calInitialized = 'false';
300-
el.innerHTML = '';
301-
});
302-
""")
303295

304296
@rx.event
305297
def init_cal_embed(self):
@@ -310,8 +302,7 @@ def init_cal_embed(self):
310302
init_script = f"""
311303
(function initCal() {{
312304
var ns = "{unique_ns}";
313-
var el = document.querySelector('[role="dialog"] .cal-embed-container')
314-
|| document.querySelector('.cal-embed-container');
305+
var el = document.querySelector('.cal-embed-container');
315306
316307
if (!el || el.dataset.calInit === 'true') return;
317308
el.dataset.calInit = 'true';
@@ -343,12 +334,12 @@ def init_cal_embed(self):
343334
calLink: "team/reflex/reflex-intro-call?{self.cal_prefill_query}"
344335
}});
345336
346-
// Close dialog on booking success
337+
// Close overlay on booking success
347338
Cal.ns[ns]("on", {{
348339
action: "bookingSuccessful",
349340
callback: function() {{
350341
setTimeout(function() {{
351-
var btn = document.querySelector('[role="dialog"] button[aria-label="Close"]');
342+
var btn = document.querySelector('.cal-embed-container').closest('[class*="fixed"]').querySelector('button[aria-label="Close"]');
352343
if (btn) btn.click();
353344
}}, 1500);
354345
}}
@@ -724,28 +715,46 @@ def thank_you_screen() -> rx.Component:
724715
)
725716

726717

727-
def calendar_embed() -> rx.Component:
728-
"""Calendar embed component showing the Cal.com inline calendar."""
729-
return rx.el.div(
730-
# Calendar container - Cal.com inline embed will render here
718+
def calendar_overlay() -> rx.Component:
719+
"""Full-screen calendar overlay that replaces the dialog."""
720+
return rx.cond(
721+
DemoFormState.show_calendar,
731722
rx.el.div(
732-
class_name="w-full min-h-[600px] overflow-auto cal-embed-container relative",
733-
style={
734-
"zIndex": "99999",
735-
"position": "relative",
736-
"width": "100%",
737-
},
738-
),
739-
# Back button
740-
ui.button(
741-
"Back",
742-
variant="outline",
743-
on_click=DemoFormState.go_back_from_calendar,
744-
class_name="w-full mt-4",
723+
# Backdrop
724+
rx.el.div(
725+
class_name="fixed inset-0 bg-black/50 backdrop-blur-sm",
726+
on_click=DemoFormState.go_back_from_calendar,
727+
),
728+
# Calendar container
729+
rx.el.div(
730+
rx.el.div(
731+
rx.el.h1(
732+
"Book a Demo",
733+
class_name="text-xl font-bold text-secondary-12",
734+
),
735+
rx.el.p(
736+
"Select a time that works for you.",
737+
class_name="text-sm text-secondary-11",
738+
),
739+
ui.button(
740+
ui.hi("Cancel01Icon"),
741+
variant="ghost",
742+
size="icon-sm",
743+
on_click=DemoFormState.go_back_from_calendar,
744+
class_name="text-secondary-11 absolute top-4 right-4",
745+
aria_label="Close",
746+
),
747+
class_name="flex flex-col gap-0.5 px-6 pt-4 pb-2 relative",
748+
),
749+
rx.el.div(
750+
class_name="w-full min-h-[600px] overflow-auto cal-embed-container px-4 pb-4",
751+
),
752+
class_name="relative bg-secondary-1 rounded-xl shadow-2xl w-full max-w-4xl max-h-[90vh] overflow-auto",
753+
on_mount=DemoFormState.init_cal_embed,
754+
),
755+
class_name="fixed inset-0 z-[100000] flex items-center justify-center p-4",
745756
),
746-
class_name="flex flex-col relative w-full",
747-
style={"zIndex": "99999", "position": "relative", "width": "100%"},
748-
on_mount=DemoFormState.init_cal_embed,
757+
rx.fragment(),
749758
)
750759

751760

@@ -766,31 +775,22 @@ def demo_form(**props) -> rx.Component:
766775
DemoFormState.sent_to_unify,
767776
# Show thank you screen when sent to Unify
768777
thank_you_screen(),
769-
rx.cond(
770-
DemoFormState.show_calendar,
771-
# Show embedded calendar after form completion
772-
calendar_embed(),
773-
# Show regular multi-step form
774-
rx.fragment(
775-
step_indicator(),
776-
step_header(),
778+
# Show regular multi-step form
779+
rx.fragment(
780+
step_indicator(),
781+
step_header(),
782+
rx.cond(
783+
DemoFormState.current_step == 1,
784+
step_1_form(),
777785
rx.cond(
778-
DemoFormState.current_step == 1,
779-
step_1_form(),
780-
rx.cond(
781-
DemoFormState.current_step == 2,
782-
step_2_form(),
783-
step_3_form(),
784-
),
786+
DemoFormState.current_step == 2,
787+
step_2_form(),
788+
step_3_form(),
785789
),
786790
),
787791
),
788792
),
789-
class_name=rx.cond(
790-
DemoFormState.show_calendar,
791-
"flex flex-col p-2",
792-
"flex flex-col p-4 sm:p-6",
793-
),
793+
class_name="flex flex-col p-4 sm:p-6",
794794
**props,
795795
)
796796

@@ -812,49 +812,49 @@ def demo_form_dialog(trigger: rx.Component | None, **props) -> rx.Component:
812812

813813
demo_form_open_cs = ClientStateVar.create("demo_form_dialog_open", False)
814814

815-
return ui.dialog.root(
816-
ui.dialog.trigger(render_=trigger),
817-
ui.dialog.portal(
818-
ui.dialog.backdrop(),
819-
ui.dialog.popup(
820-
rx.el.div(
815+
return rx.fragment(
816+
ui.dialog.root(
817+
ui.dialog.trigger(render_=trigger),
818+
ui.dialog.portal(
819+
ui.dialog.backdrop(),
820+
ui.dialog.popup(
821821
rx.el.div(
822-
rx.el.h1(
823-
"Book a Demo",
824-
class_name="text-xl font-bold text-secondary-12",
825-
),
826-
rx.el.p(
827-
"Hop on a call with the Reflex team.",
828-
class_name="text-sm text-secondary-11",
829-
),
830-
ui.dialog.close(
831-
render_=ui.button(
832-
ui.hi("Cancel01Icon"),
833-
variant="ghost",
834-
size="icon-sm",
835-
on_click=DemoFormState.reset_form,
836-
class_name="text-secondary-11 absolute top-4 right-4",
837-
aria_label="Close",
822+
rx.el.div(
823+
rx.el.h1(
824+
"Book a Demo",
825+
class_name="text-xl font-bold text-secondary-12",
838826
),
827+
rx.el.p(
828+
"Hop on a call with the Reflex team.",
829+
class_name="text-sm text-secondary-11",
830+
),
831+
ui.dialog.close(
832+
render_=ui.button(
833+
ui.hi("Cancel01Icon"),
834+
variant="ghost",
835+
size="icon-sm",
836+
on_click=DemoFormState.reset_form,
837+
class_name="text-secondary-11 absolute top-4 right-4",
838+
aria_label="Close",
839+
),
840+
),
841+
class_name="flex flex-col gap-0.5 px-6 pt-4 pb-2 relative",
839842
),
840-
class_name="flex flex-col gap-0.5 px-6 pt-4 pb-2 relative",
843+
demo_form(class_name="w-full"),
844+
class_name="relative isolate overflow-hidden -m-px w-full max-w-md",
841845
),
842-
demo_form(class_name="w-full"),
843-
class_name=rx.cond(
844-
DemoFormState.show_calendar,
845-
"relative isolate overflow-hidden -m-px w-full max-w-4xl",
846-
"relative isolate overflow-hidden -m-px w-full max-w-md",
847-
),
848-
),
849-
class_name=rx.cond(
850-
DemoFormState.show_calendar,
851-
"h-fit mt-1 overflow-hidden w-full max-w-4xl transition-all duration-300",
852-
"h-fit mt-1 overflow-hidden w-full max-w-md transition-all duration-300",
846+
class_name="h-fit mt-1 overflow-hidden w-full max-w-md",
853847
),
854848
),
849+
open=rx.cond(
850+
DemoFormState.show_calendar,
851+
False,
852+
demo_form_open_cs.value,
853+
),
854+
on_open_change=demo_form_open_cs.set_value,
855+
class_name=class_name,
856+
**props,
855857
),
856-
open=demo_form_open_cs.value,
857-
on_open_change=demo_form_open_cs.set_value,
858-
class_name=class_name,
859-
**props,
858+
# Calendar overlay (shows when form is complete)
859+
calendar_overlay(),
860860
)

0 commit comments

Comments
 (0)