Add close buttons to toasts #2023
Mergednoxire-dev(GitHub profile, opens in a new tab)merged 17 commits into
main fromrefs/pull/2023/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/web/src/components/ui/toast.tsx line 317OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -302,3 +303,15 @@302303 dismissAfterVisibleMs={toast.data?.dismissAfterVisibleMs}303304 toastId={toast.id}304305 />306+ <button307+ aria-label="Dismiss notification"308+ className={cn(309+ buttonVariants({ size: "icon-xs", variant: "ghost" }),310+ "absolute top-2 right-2 z-10 size-5 rounded-sm p-0 text-muted-foreground hover:text-foreground",311+ )}312+ data-slot="toast-close"313+ onClick={() => toastManager.close(toast.id)}314+ type="button"315+ >316+ <XIcon className="size-3" />317+ </button>
kendalled(GitHub profile, opens in a new tab) requested changes
- apps/web/src/components/ui/toast.logic.ts line 58Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -28,2 +33,20 @@33+ items: VisibleToastLayoutItem<TToast & ToastWithLayoutProps>[];2834 } {29- let offsetY = 0;35+ // Ending toasts are excluded from live index/offset calculations so the36+ // remaining toasts can reflow in parallel with the dismiss animation37+ // (otherwise the second toast only starts moving forward after the top38+ // toast's exit animation completes, causing a visible "stop and bump").39+ let liveIndex = 0;40+ let liveOffsetY = 0;41+42+ const items: VisibleToastLayoutItem<TToast & ToastWithLayoutProps>[] = visibleToasts.map(43+ (toast) => {44+ if (toast.transitionStatus === "ending") {45+ // Keep ending toasts at their previous front position so their exit46+ // animation originates from the correct spot. The data-ending-style47+ // transform takes over their actual motion.48+ return {49+ toast,50+ visibleIndex: 0,51+ offsetY: 0,52+ };
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/web/src/components/WebSocketConnectionSurface.tsx line 296OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -264,16 +283,14 @@264- }283+ type: "warning",284+ })265285 : shouldShowExhaustedToast266- ? {286+ ? stackedThreadToast({267287 actionProps: {268288 children: "Retry",269289 onClick: triggerManualReconnect,270290 },271291 description: describeExhaustedToast(),272292 timeout: 0,273293 title: "Disconnected from T3 Server",274- type: "error" as const,275- data: {276- hideCopyButton: true,277- },278- }294+ type: "error",295+ })279296 : {apps/web/src/routes/dev.toast.tsx lines 37 to 40OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +20,21 @@20+ "This description is intentionally long so you can confirm wrapping, collapsed-stack peek height, and expanded hover behavior without leaving this page.";21+22+const MEGA_ERROR_BODY = [23+ "Typecheck failed across 38 packages after incremental rebuild. The compiler stopped after the first 200 diagnostics; full output is ~18k lines on disk.",24+ "",25+ "packages/web/src/components/ChatView.tsx(3084,11): error TS2322: Type 'DispatchCommandResult | undefined' is not assignable to type 'DispatchCommandResult'.",26+ "packages/web/src/components/GitActionsControl.tsx(639,22): error TS18048: 'progress' is possibly 'undefined'.",27+ "packages/contracts/src/orchestration.ts(112,3): error TS4104: The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'string[]'.",28+ "",29+ "Caused by: upstream @types/node@22.10.2 conflicting with workspace typescript@5.9.2 — see https://example.invalid/ts-triage for the internal runbook.",30+ "",31+ LONG_COPY,32+ LONG_COPY,33+ "Retry with T3_VERBOSE_TSC=1 and attach .t3/tsc-full.log when filing an issue.",34+].join("\n");35+36+function DevToastPlaygroundRoute() {37+ const anchoredTooltipAnchorRef = useRef<HTMLButtonElement>(null);38+ const anchoredPanelAnchorRef = useRef<HTMLButtonElement>(null);39+ const anchoredManager = Toast.useToastManager<ThreadToastData>();40+
- apps/web/src/components/WebSocketConnectionSurface.tsx line 302Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -263,16 +283,13 @@263- },264- }283+ type: "warning",284+ })265285 : shouldShowExhaustedToast266- ? {286+ ? stackedThreadToast({267287 actionProps: {268288 children: "Retry",269289 onClick: triggerManualReconnect,270290 },271291 description: describeExhaustedToast(),272292 timeout: 0,273293 title: "Disconnected from T3 Server",274- type: "error" as const,275- data: {276- hideCopyButton: true,277- },278- }294+ type: "error",295+ })@@ -0,0 +455,21 @@455+ Panel anchored456+ </Button>457+ <Button458+ size="xs"459+ variant="outline"460+ className={cn(anchoredManager.toasts.length === 0 && "opacity-50")}461+ disabled={anchoredManager.toasts.length === 0}462+ onClick={() => {463+ for (const t of anchoredManager.toasts) {464+ anchoredManager.close(t.id);465+ }466+ }}467+ >468+ Dismiss all anchored469+ </Button>470+ </div>471+ </CardContent>472+ </Card>473+ </div>474+ );475+}
- apps/web/src/components/WebSocketConnectionSurface.tsx line 279Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -253,3 +277,3 @@253277254278 if (shouldShowReconnectToast || shouldShowOfflineToast || shouldShowExhaustedToast) {255279 const toastPayload = shouldShowOfflineToast
- apps/web/src/components/ui/toastHelpers.ts line 33Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +11,21 @@11+ description?: ReactNode;12+ timeout?: number;13+ priority?: "low" | "high";14+ actionProps?: ComponentPropsWithoutRef<"button">;15+ /** Merged into `data` after `actionLayout: "stacked-end"`. */16+ actionVariant?: ThreadToastData["actionVariant"];17+ data?: ThreadToastData;18+};19+20+/**21+ * Thread toast using the stacked body + bottom action row (copy for errors, CTA on its own row).22+ */23+export function stackedThreadToast(24+ options: StackedThreadToastOptions,25+): ToastManagerAddOptions<ThreadToastData> {26+ const { type, title, description, timeout, priority, actionProps, actionVariant, data } = options;27+28+ const mergedData: ThreadToastData = {29+ actionLayout: "stacked-end",30+ ...(data !== undefined ? data : {}),31+ };
- apps/web/src/rpc/requestLatencyState.ts line 39OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -36,4 +36,4 @@3636 }37373838 function shouldTrackRpcAck(tag: string): boolean {39- return !tag.startsWith("subscribe");39+ return !tag.includes("subscribe");apps/web/src/components/GitActionsControl.tsx line 788OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -763,8 +779,10 @@763779 : `${result.branch} is already synchronized.`,764780 data: threadToastData,765781 }),766- error: (err) => ({767- title: "Pull failed",768- description: err instanceof Error ? err.message : "An error occurred.",769- data: threadToastData,770- }),782+ error: (err) =>783+ stackedThreadToast({784+ type: "error",785+ title: "Pull failed",786+ description: err instanceof Error ? err.message : "An error occurred.",787+ ...(threadToastData !== undefined ? { data: threadToastData } : {}),788+ }),
- apps/web/src/components/ui/toast.tsx line 588OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -360,4 +572,17 @@360- data-slot="toast-action"361- >362- {toast.actionProps.children}363- </Toast.Action>572+ {hasTrailingControls ? (573+ <div className="flex shrink-0 items-center gap-1.5">574+ {copyErrorText !== null ? <CopyErrorButton text={copyErrorText} /> : null}575+ {toast.actionProps ? (576+ <Toast.Action577+ className={cn(578+ buttonVariants({ size: "xs", variant: actionVariant }),579+ "shrink-0",580+ )}581+ data-slot="toast-action"582+ >583+ {toast.actionProps.children}584+ </Toast.Action>585+ ) : null}586+ </div>587+ ) : null}588+ </>
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged this3a1daa8
juliusmarminge closed this
Sign in to join this conversation.
@juliusmarminge @noxire-dev


thank you for the feedback, I tweak the styling is this verison better ? if so i can update the branch @juliusmarminge
more like this ? sorry this is my first time contributing to open source so if its a bit back and forward @juliusmarminge
what is your opinons about this style ? in order to stop accidently click on it
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
322f332c-aeb3-4ac2-9cd4-0e651e249c93You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share