Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

style(toasts): re-style toast components and add fading border to indicate toast freshness (#1533)

Aidan Holloway-Bidwell18841ac4a541
diff --git a/js/app/packages/core/component/Toast/Toast.tsx b/js/app/packages/core/component/Toast/Toast.tsx
index d232117203..e88ce41052 100644
--- a/js/app/packages/core/component/Toast/Toast.tsx
+++ b/js/app/packages/core/component/Toast/Toast.tsx
@@ -1,10 +1,17 @@
-import CheckCircle from '@icon/regular/check-circle.svg';
+import CheckIcon from '@icon/regular/check.svg';
+import ExclamationIcon from '@icon/regular/exclamation-mark.svg';
import Spinner from '@icon/regular/spinner.svg';
-import Warning from '@icon/regular/warning.svg';
-import WarningCircle from '@icon/regular/warning-circle.svg';
import XIcon from '@icon/regular/x.svg';
import { Toast, toaster } from '@kobalte/core/toast';
import type { Component } from 'solid-js';
+import {
+ Show,
+ createSignal,
+ onMount,
+ onCleanup,
+ createEffect,
+ on,
+} from 'solid-js';
import { Dynamic } from 'solid-js/web';
export enum ToastType {
@@ -16,61 +23,82 @@ export enum ToastType {
interface ToastStyle {
background: string;
- border: string;
- text: string;
- icon: Component;
+ /** Accent color for icon and icon background */
+ accent: string;
+ /** Border color class for animated border (Tailwind class, e.g. 'border-success') */
+ borderColor: string;
+ /** Text color for title */
+ titleText: string;
+ /** Text color for subtext/description */
+ subtitleText: string;
+ /** Icon component */
+ icon: Component<{ class?: string }>;
+ /** Action button styles */
button: {
background: string;
hover: string;
text: string;
};
+ /** Close button hover text color */
+ closeButtonHover: string;
}
const TOAST_STYLES: Record<ToastType, ToastStyle> = {
[ToastType.SUCCESS]: {
- background: 'floating-success-bg',
- border: 'border-success/30',
- text: 'text-success-ink',
- icon: CheckCircle,
+ background: 'bg-success/10',
+ accent: 'bg-success',
+ borderColor: 'border-success',
+ titleText: 'text-success-ink',
+ subtitleText: 'text-success-ink/70',
+ icon: CheckIcon,
button: {
- background: 'bg-success/15',
- hover: 'hover:bg-success/30',
+ background: 'bg-success',
+ hover: 'hover:bg-success/80',
text: 'text-success-ink',
},
+ closeButtonHover: 'hover:text-success-ink hover:bg-success/10',
},
[ToastType.FAILURE]: {
- background: 'floating-failure-bg',
- border: 'border-failure/30',
- text: 'text-failure-ink',
- icon: WarningCircle,
+ background: 'bg-failure/10',
+ accent: 'bg-failure',
+ borderColor: 'border-failure',
+ titleText: 'text-failure-ink',
+ subtitleText: 'text-failure-ink/70',
+ icon: ExclamationIcon,
button: {
- background: 'bg-failure/15',
- hover: 'hover:bg-failure/30',
+ background: 'bg-failure',
+ hover: 'hover:bg-failure/80',
text: 'text-failure-ink',
},
+ closeButtonHover: 'hover:text-failure-ink hover:bg-failure/10',
},
[ToastType.ALERT]: {
- background: 'floating-alert-bg',
- border: 'border-alert/30',
- text: 'text-alert-ink',
- icon: Warning,
+ background: 'bg-alert/10',
+ accent: 'bg-alert',
+ borderColor: 'border-alert',
+ titleText: 'text-alert-ink',
+ subtitleText: 'text-alert-ink/70',
+ icon: ExclamationIcon,
button: {
- background: 'bg-alert/15',
- hover: 'hover:bg-alert/30',
+ background: 'bg-alert',
+ hover: 'hover:bg-alert/80',
text: 'text-alert-ink',
},
+ closeButtonHover: 'hover:text-alert-ink hover:bg-alert/10',
},
[ToastType.LOADING]: {
- // SCUFFED: how do we want to handle these color?
- background: 'bg-[oklch(0.623_0.214_259.815)/0.15]',
- border: 'border-[color:oklch(0.882_0.059_254.128)]',
- text: 'text-[oklch(0.488_0.243_264.376)]',
+ background: 'bg-accent/10',
+ accent: 'bg-accent',
+ borderColor: 'border-accent',
+ titleText: 'text-ink',
+ subtitleText: 'text-ink-muted',
icon: Spinner,
button: {
- background: 'bg-[oklch(0.932_0.032_255.585)]',
- hover: 'hover:bg-[oklch(0.882_0.059_254.128)]',
- text: 'text-[oklch(0.488_0.243_264.376)]',
+ background: 'bg-accent',
+ hover: 'hover:bg-accent/80',
+ text: 'text-panel',
},
+ closeButtonHover: 'hover:text-accent hover:bg-accent/10',
},
};
@@ -142,58 +170,127 @@ function ToastContent(props: {
persistent?: boolean;
duration?: number;
}) {
+ const styles = () => TOAST_STYLES[props.toastType];
+
+ // Track progress until disappearance (1 = full duration remaining, 0 = time to disappear)
+ const [progress, setProgress] = createSignal(1);
+ const [isHovered, setIsHovered] = createSignal(false);
+
+ let elapsed = 0;
+
+ onMount(() => {
+ // Skip countdown for persistent toasts
+ if (props.persistent) return;
+
+ const duration = props.duration ?? 3000;
+ let lastTime: number | null = null;
+ let rafId: number;
+
+ const update = () => {
+ const currentTime = performance.now();
+
+ // Initialize lastTime on first frame
+ if (lastTime === null) {
+ lastTime = currentTime;
+ }
+
+ // Only accumulate time when not hovered
+ if (!isHovered()) {
+ elapsed += currentTime - lastTime;
+ }
+ lastTime = currentTime;
+
+ const remaining = Math.max(0, 1 - elapsed / duration);
+ setProgress(remaining);
+
+ if (remaining > 0) {
+ rafId = requestAnimationFrame(update);
+ } else {
+ // Dismiss the toast when countdown completes
+ toaster.dismiss(props.toastId);
+ }
+ };
+
+ rafId = requestAnimationFrame(update);
+
+ onCleanup(() => cancelAnimationFrame(rafId));
+ });
+
+ // Reset timer immediately when user starts hovering
+ createEffect(
+ on(isHovered, (hovered) => {
+ if (hovered && !props.persistent) {
+ // User started hovering - reset timer and progress immediately
+ elapsed = 0;
+ setProgress(1);
+ }
+ })
+ );
+
return (
<Toast
toastId={props.toastId}
- class={`flex flex-col items-center justify-between gap-2 border rounded-md p-3 pointer-events-auto
- ${TOAST_STYLES[props.toastType].background}
- ${TOAST_STYLES[props.toastType].border}
- ${TOAST_STYLES[props.toastType].text}
+ class={`relative overflow-visible rounded-xs pointer-events-auto
+ bg-panel
data-opened:animate-slide-in data-closed:animate-hide transition-transform data-[swipe=move]:translate-x-[var(--kb-toast-swipe-move-x)]
data-[swipe=cancel]:translate-x-0 data-[swipe=cancel]:ease-out data-[swipe=cancel]:duration-200 data-[swipe=end]:animate-swipe-out`}
- duration={props.duration}
- persistent={props.persistent}
+ persistent={true}
+ onMouseEnter={() => setIsHovered(true)}
+ onMouseLeave={() => setIsHovered(false)}
>
- <div class="flex flex-col gap-2 w-full">
- <div class="flex items-center w-full">
+ {/* Animated border that fades from opacity 1 to 0 */}
+ <Show when={!props.persistent}>
+ <div
+ class={`absolute inset-0 rounded-xs border-1 pointer-events-none ${styles().borderColor}`}
+ style={{ opacity: progress() }}
+ />
+ </Show>
+
+ <div class="flex">
+ {/* Left accent area with icon */}
+ <div
+ class={`flex items-center justify-center w-12 shrink-0 ${styles().accent}/20`}
+ >
<Dynamic
- component={TOAST_STYLES[props.toastType].icon as any}
- class={`h-7 shrink-0 ${TOAST_STYLES[props.toastType].text} mr-3 ${
- props.toastType === ToastType.LOADING ? 'animate-spin' : ''
- }`}
+ component={styles().icon}
+ class={`size-6 ${styles().titleText} ${props.toastType === ToastType.LOADING ? 'animate-spin' : ''}`}
/>
- <div>
- <Toast.Title
- class={`${props.subtext ? 'text-lg font-semibold' : 'text-normal font-medium'}`}
- >
- {props.message}
- </Toast.Title>
- {props.subtext && (
- <Toast.Description class="opacity-70 font-medium text-sm leading-[21px]">
- {props.subtext}
- </Toast.Description>
- )}
- </div>
- <Toast.CloseButton class="ml-auto">
- <XIcon
- class={`h-5 ml-4
- ${TOAST_STYLES[props.toastType].button.text}
+ </div>
+
+ {/* Content area */}
+ <div class="flex-1 pt-2 px-3 pb-3 pr-10">
+ <Toast.Title class={`font-semibold text-ink`}>
+ {props.message}
+ </Toast.Title>
+ <Show when={props.subtext}>
+ <Toast.Description class={`text-sm text-ink-extra-muted`}>
+ {props.subtext}
+ </Toast.Description>
+ </Show>
+
+ {/* Action button */}
+ <Show when={props.action}>
+ {(action) => (
+ <button
+ onClick={action().onClick}
+ class={`mt-2 w-full text-sm font-semibold py-1.5 px-3 rounded
+ ${styles().button.background}/20
+ ${styles().button.hover}
+ ${styles().button.text}
`}
- />
- </Toast.CloseButton>
+ >
+ {action().text}
+ </button>
+ )}
+ </Show>
</div>
- {props.action && (
- <button
- onClick={props.action.onClick}
- class={`w-full text-sm font-semibold py-1.5 px-3 rounded-md
- ${TOAST_STYLES[props.toastType].button.background}
- ${TOAST_STYLES[props.toastType].button.hover}
- ${TOAST_STYLES[props.toastType].button.text}
- `}
- >
- {props.action.text}
- </button>
- )}
+
+ {/* Close button */}
+ <Toast.CloseButton class="absolute top-2 right-2 p-1 rounded">
+ <XIcon
+ class={`size-4 text-ink-extra-muted transition-colors ${styles().closeButtonHover}`}
+ />
+ </Toast.CloseButton>
</div>
</Toast>
);
diff --git a/js/app/packages/core/component/Toast/ToastRegion.tsx b/js/app/packages/core/component/Toast/ToastRegion.tsx
index f9c43fa20b..10bc9dcfd7 100644
--- a/js/app/packages/core/component/Toast/ToastRegion.tsx
+++ b/js/app/packages/core/component/Toast/ToastRegion.tsx
@@ -5,7 +5,11 @@ export function ToastRegion() {
return (
<Portal>
<div class="fixed bottom-[40px] sm:bottom-12 right-0 w-[90%] sm:w-108 m-0 list-none outline-none pointer-events-none z-toast-region">
- <Toast.Region regionId="toast-region" duration={6000}>
+ <Toast.Region
+ regionId="toast-region"
+ duration={Infinity}
+ pauseOnInteraction={false}
+ >
<Toast.List class="absolute bottom-0 right-0 flex-col p-4 gap-2" />
</Toast.Region>
<Toast.Region regionId="stable-toast" duration={Infinity}>
diff --git a/js/app/packages/core/component/Toast/Toast.stories.tsx b/js/app/packages/ui/stories/Toast.stories.tsx
similarity index 60%
rename from js/app/packages/core/component/Toast/Toast.stories.tsx
rename to js/app/packages/ui/stories/Toast.stories.tsx
index e69da495d8..3fee546fc0 100644
--- a/js/app/packages/core/component/Toast/Toast.stories.tsx
+++ b/js/app/packages/ui/stories/Toast.stories.tsx
@@ -1,10 +1,9 @@
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
-import { DeprecatedTextButton } from '../DeprecatedTextButton';
-import { toast } from './Toast';
-import { ToastRegion } from './ToastRegion';
+import { toast } from '@core/component/Toast/Toast';
+import { ToastRegion } from '@core/component/Toast/ToastRegion';
const meta = {
- title: 'Toast',
+ title: 'Core/Toast',
parameters: {
docs: {
description: {
@@ -24,46 +23,50 @@ export const Default: Story = {
<>
<ToastRegion />
<div class="flex flex-col gap-2">
- <DeprecatedTextButton
- text="Show Success Toast"
- theme="base"
+ <button
+ class="px-4 py-2 bg-success/20 text-success-ink rounded hover:bg-success/30"
onClick={() =>
toast.success(
'Action completed successfully',
'Your changes have been saved'
)
}
- />
- <DeprecatedTextButton
- text="Show Failure Toast"
- theme="base"
+ >
+ Show Success Toast
+ </button>
+ <button
+ class="px-4 py-2 bg-failure/20 text-failure-ink rounded hover:bg-failure/30"
onClick={() =>
toast.failure(
'Action failed',
'An error occurred while saving your changes'
)
}
- />
- <DeprecatedTextButton
- text="Show Alert Toast"
- theme="base"
+ >
+ Show Failure Toast
+ </button>
+ <button
+ class="px-4 py-2 bg-alert/20 text-alert-ink rounded hover:bg-alert/30"
onClick={() =>
toast.alert(
'Please check your input',
'Some fields are missing or invalid'
)
}
- />
- <DeprecatedTextButton
- text="Show Success with Action"
- theme="base"
+ >
+ Show Alert Toast
+ </button>
+ <button
+ class="px-4 py-2 bg-success/20 text-success-ink rounded hover:bg-success/30"
onClick={() =>
toast.success('File deleted', 'The file has been removed', {
text: 'Undo',
onClick: () => console.log('Undo clicked'),
})
}
- />
+ >
+ Show Success with Action
+ </button>
</div>
</>
);