Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
💄 Mobile-friendly buttons and dialogs (#3546)
Luke Vella509dae406d9c
diff --git a/apps/web/src/features/poll/components/mobile-poll.tsx b/apps/web/src/features/poll/components/mobile-poll.tsxindex 84d459ad6..c89ef3055 100644--- a/apps/web/src/features/poll/components/mobile-poll.tsx+++ b/apps/web/src/features/poll/components/mobile-poll.tsx@@ -143,7 +143,7 @@ const MobilePoll: React.FunctionComponent = () => {</SelectContent></Select>) : (- <div className="flex h-9 grow items-center px-1">+ <div className="flex min-h-9 grow items-center px-1"><Participant><YouAvatar /><ParticipantName>diff --git a/apps/web/src/features/poll/components/new-participant-modal.tsx b/apps/web/src/features/poll/components/new-participant-modal.tsxindex 6b83e98b5..f842b6489 100644--- a/apps/web/src/features/poll/components/new-participant-modal.tsx+++ b/apps/web/src/features/poll/components/new-participant-modal.tsx@@ -253,7 +253,9 @@ export const NewParticipantForm = (props: NewParticipantModalProps) => {return (<>- <DialogHeader>+ {/* The vote that opened this dialog already says what it is for. The+ title stays in the DOM to name the dialog via aria-labelledby. */}+ <DialogHeader className="max-sm:hidden"><DialogTitle><Trans i18nKey="newParticipant" defaults="New participant" /></DialogTitle>@@ -432,7 +434,12 @@ export const NewParticipantForm = (props: NewParticipantModalProps) => {</form></Form><DialogFooter>- <Button type="button" variant="ghost" onClick={props.onCancel}>+ <Button+ type="button"+ variant="ghost"+ className="max-sm:hidden"+ onClick={props.onCancel}+ >{t("back")}</Button><Buttondiff --git a/apps/web/src/features/poll/components/voting-form.tsx b/apps/web/src/features/poll/components/voting-form.tsxindex 198d024e9..185a0cafc 100644--- a/apps/web/src/features/poll/components/voting-form.tsx+++ b/apps/web/src/features/poll/components/voting-form.tsx@@ -154,7 +154,7 @@ export const VotingForm = ({ children }: React.PropsWithChildren) => {open={isNewParticipantModalOpen}onOpenChange={setIsNewParticipantModalOpen}>- <DialogContent size="sm">+ <DialogContent size="sm" fullScreenOnMobile><NewParticipantFormvotes={normalizeVotes(optionIds, form.watch("votes"))}onSubmit={(newParticipant) => {diff --git a/apps/web/src/features/poll/vote/components/vote-form.tsx b/apps/web/src/features/poll/vote/components/vote-form.tsxindex ccd35826c..7aaa2bfdc 100644--- a/apps/web/src/features/poll/vote/components/vote-form.tsx+++ b/apps/web/src/features/poll/vote/components/vote-form.tsx@@ -286,7 +286,7 @@ export function VoteForm({open={isNewParticipantOpen}onOpenChange={setIsNewParticipantOpen}>- <DialogContent size="sm">+ <DialogContent size="sm" fullScreenOnMobile><NewParticipantFormpollId={pollId}requireParticipantEmail={requireParticipantEmail}diff --git a/packages/tailwind-config/shared-styles.css b/packages/tailwind-config/shared-styles.cssindex 6fa44daa4..39045421d 100644--- a/packages/tailwind-config/shared-styles.css+++ b/packages/tailwind-config/shared-styles.css@@ -2,8 +2,8 @@@custom-variant dark (&:where(.dark, .dark *));/* A dialog header or footer at the top level of the dialog's scroll area- * (directly, or inside a top-level form or wizard step), where it pins to- * the edge. */+ * (directly, or inside a top-level form or wizard step), where it spans the+ * dialog's edges. */@custom-variant dialog-edge (:is([data-slot="dialog-scroller"],[data-slot="dialog-scroller"] > form,diff --git a/packages/ui/src/button-variants.ts b/packages/ui/src/button-variants.tsindex ca472fe60..7ce4433d1 100644--- a/packages/ui/src/button-variants.ts+++ b/packages/ui/src/button-variants.ts@@ -22,13 +22,14 @@ export const buttonVariants = cva(link: "border-transparent text-primary underline-offset-4 hover:underline",},size: {+ // Below sm the default sizes grow to a 44px touch target.default:- "h-9 gap-1.5 px-4 text-sm has-data-[icon=inline-end]:pr-2.5 has-data-[icon=inline-start]:pl-2.5",+ "h-9 gap-1.5 px-4 text-sm has-data-[icon=inline-end]:pr-2.5 has-data-[icon=inline-start]:pl-2.5 max-sm:h-11 max-sm:gap-2 max-sm:px-5 max-sm:text-base max-sm:has-data-[icon=inline-end]:pr-3.5 max-sm:has-data-[icon=inline-start]:pl-3.5",xs: "h-6 gap-1 px-2.5 text-xs has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",sm: "h-7 gap-1.5 px-3 text-sm has-data-[icon=inline-end]:pr-1.75 has-data-[icon=inline-start]:pl-1.75 [&_svg:not([class*='size-'])]:size-3.5",lg: "h-10 gap-1.5 px-4.5 text-sm has-data-[icon=inline-end]:pr-3 has-data-[icon=inline-start]:pl-3",xl: "h-12 gap-2 px-5.5 text-base has-data-[icon=inline-end]:pr-3.75 has-data-[icon=inline-start]:pl-3.75 [&_svg:not([class*='size-'])]:size-4.5",- icon: "size-9",+ icon: "size-9 max-sm:size-11","icon-xs": "size-6 [&_svg:not([class*='size-'])]:size-3","icon-sm": "size-7","icon-lg": "size-10",diff --git a/packages/ui/src/dialog.tsx b/packages/ui/src/dialog.tsxindex ca652d9ca..86c8d251a 100644--- a/packages/ui/src/dialog.tsx+++ b/packages/ui/src/dialog.tsx@@ -5,6 +5,7 @@ import type { VariantProps } from "class-variance-authority";import { cva } from "class-variance-authority";import { XIcon } from "lucide-react";import React from "react";+import { buttonVariants } from "./button-variants";import { cn } from "./lib/utils";function Dialog({ ...props }: DialogPrimitive.Root.Props) {@@ -49,7 +50,7 @@ function DialogOverlay({const dialogVariants = cva(cn(- "data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 fixed top-[50%] left-[50%] z-50 flex max-h-[calc(100dvh-2rem)] w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] flex-col overflow-hidden rounded-2xl border border-popover-border bg-popover shadow-lg outline-none duration-200 data-closed:animate-out data-open:animate-in",+ "data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 relative my-auto flex w-full shrink-0 flex-col overflow-hidden rounded-2xl border border-popover-border bg-popover shadow-lg outline-none duration-200 data-closed:animate-out data-open:animate-in",),{variants: {@@ -74,33 +75,64 @@ function DialogContent({children,showCloseButton = true,size = "md",+ fullScreenOnMobile = false,...props}: DialogPrimitive.Popup.Props &VariantProps<typeof dialogVariants> & {showCloseButton?: boolean;+ /**+ * Below the `sm` breakpoint the dialog fills the viewport and a short+ * dialog's footer sits on the bottom edge. Use for form dialogs, not+ * confirmations.+ */+ fullScreenOnMobile?: boolean;}) {return (<DialogPortal data-slot="dialog-portal"><DialogOverlay />- <DialogPrimitive.Popup- data-slot="dialog-content"- className={cn(dialogVariants({ size }), className)}- data-close-button={showCloseButton ? "" : undefined}- {...props}+ {/* A dialog taller than the screen scrolls as one card inside the+ viewport rather than scrolling its own content. */}+ <DialogPrimitive.Viewport+ data-slot="dialog-viewport"+ className={cn(+ "fixed inset-0 z-50 flex flex-col items-center overflow-y-auto overscroll-contain p-4",+ fullScreenOnMobile && "max-sm:p-0",+ )}>- <div- data-slot="dialog-scroller"- className="grid min-h-0 grow gap-4 overflow-y-auto overscroll-contain p-4"+ <DialogPrimitive.Popup+ data-slot="dialog-content"+ className={cn(+ dialogVariants({ size }),+ fullScreenOnMobile &&+ "max-sm:my-0 max-sm:min-h-dvh max-sm:rounded-none max-sm:border-0",+ className,+ )}+ data-close-button={showCloseButton ? "" : undefined}+ {...props}>- {children}- </div>- {showCloseButton && (- <DialogClose className="absolute top-4 right-4 z-20 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0">- <XIcon />- <span className="sr-only">Close</span>- </DialogClose>- )}- </DialogPrimitive.Popup>+ <div+ data-slot="dialog-scroller"+ className={cn(+ "grid gap-4 p-4",+ fullScreenOnMobile &&+ "max-sm:flex max-sm:grow max-sm:flex-col max-sm:*:data-[slot=dialog-footer]:mt-auto! max-sm:*:data-[slot=dialog-footer]:pb-[max(0.75rem,env(safe-area-inset-bottom))]!",+ )}+ >+ {children}+ </div>+ {showCloseButton && (+ <DialogClose+ className={cn(+ buttonVariants({ variant: "ghost", size: "icon" }),+ "absolute top-2 right-2 z-20 max-sm:top-1 max-sm:right-1 max-sm:size-10",+ )}+ >+ <XIcon />+ <span className="sr-only">Close</span>+ </DialogClose>+ )}+ </DialogPrimitive.Popup>+ </DialogPrimitive.Viewport></DialogPortal>);}@@ -110,9 +142,9 @@ function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {<divdata-slot="dialog-header"className={cn(- "dialog-edge:sticky dialog-edge:-top-4 dialog-edge:z-10 dialog-edge:-mx-4 dialog-edge:-mt-4 dialog-edge:bg-popover dialog-edge:px-4 dialog-edge:pt-4 dialog-edge:pb-2",+ "dialog-edge:pb-2",// Only the first row sits beside the close button.- "dialog-edge:in-data-close-button:*:first:pr-8",+ "dialog-edge:in-data-close-button:*:first:pr-10",className,)}{...props}@@ -126,7 +158,7 @@ function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {data-slot="dialog-footer"className={cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",- "dialog-edge:sticky dialog-edge:-bottom-4 dialog-edge:z-10 dialog-edge:-mx-4 dialog-edge:mt-2 dialog-edge:-mb-4 dialog-edge:border-popover-border dialog-edge:border-t dialog-edge:bg-card dialog-edge:px-4 dialog-edge:py-3",+ "dialog-edge:-mx-4 dialog-edge:mt-2 dialog-edge:-mb-4 dialog-edge:border-popover-border dialog-edge:border-t dialog-edge:bg-card dialog-edge:px-4 dialog-edge:py-3",className,)}{...props}