Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions packages/design-system/components/collapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@ import * as React from 'react';
import { cn } from '../utils';
import { Collapsible as CollapsiblePrimitive } from 'radix-ui';

const HasOpenedContext = React.createContext(false);

interface CollapsibleProps extends React.ComponentProps<typeof CollapsiblePrimitive.Root> {}

function Collapsible({ ...props }: CollapsibleProps) {
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />;
function Collapsible({ defaultOpen = false, ...props }: CollapsibleProps) {
const [hasOpened, setHasOpened] = React.useState(defaultOpen);
if (props.open && !hasOpened) setHasOpened(true);
return (
<HasOpenedContext value={hasOpened}>
<CollapsiblePrimitive.Root
data-slot="collapsible"
defaultOpen={defaultOpen}
{...props}
onOpenChange={isOpen => {
if (isOpen) setHasOpened(true);
props.onOpenChange?.(isOpen);
}}
/>
</HasOpenedContext>
);
}

interface CollapsibleTriggerProps extends React.ComponentProps<
Expand All @@ -20,16 +36,20 @@ interface CollapsibleContentProps extends React.ComponentProps<
typeof CollapsiblePrimitive.Content
> {}

function CollapsibleContent({ className, ...props }: CollapsibleContentProps) {
// Radix zeroes the transition of the content while measuring it, so the fold animates a grid inside.
function CollapsibleContent({ className, children, ...props }: CollapsibleContentProps) {
const hasOpened = React.use(HasOpenedContext);
return (
<CollapsiblePrimitive.Content
data-slot="collapsible-content"
className={cn(
'overflow-hidden ease-out-quint data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down',
className,
)}
forceMount
className={cn('group/collapsible-content', className)}
{...props}
/>
>
<div className="grid grid-rows-[1fr] transition-[grid-template-rows,visibility] duration-200 ease-out-quint group-data-[state=closed]/collapsible-content:invisible group-data-[state=closed]/collapsible-content:grid-rows-[0fr]">
<div className="min-h-0 overflow-hidden">{hasOpened && children}</div>
</div>
</CollapsiblePrimitive.Content>
);
}

Expand Down
10 changes: 8 additions & 2 deletions packages/design-system/components/command.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { Command as CommandPrimitive } from 'cmdk';
import { cn } from '../utils';
import { Spinner } from './spinner';
import { Dialog as DialogPrimitive } from 'radix-ui';

interface CommandDialogProps extends React.ComponentProps<typeof DialogPrimitive.Root> {
Expand Down Expand Up @@ -92,13 +93,18 @@ function CommandEmpty({ className, ...props }: CommandEmptyProps) {

interface CommandLoadingProps extends React.ComponentProps<typeof CommandPrimitive.Loading> {}

function CommandLoading({ className, ...props }: CommandLoadingProps) {
function CommandLoading({ className, children, ...props }: CommandLoadingProps) {
return (
<CommandPrimitive.Loading
data-slot="command-loading"
className={cn('px-2.5 py-2 text-body text-fg-muted', className)}
{...props}
/>
>
<span className="flex items-center gap-2">
<Spinner />
{children}
</span>
</CommandPrimitive.Loading>
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/design-system/components/dropdown-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function DropdownMenuContent({
align={align}
sideOffset={sideOffset}
className={cn(
'z-50 min-w-48 origin-(--radix-dropdown-menu-content-transform-origin) rounded-lg border border-line bg-raised p-1 text-body-sm text-fg shadow-popover ease-out-quint data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
'z-50 min-w-48 origin-(--radix-dropdown-menu-content-transform-origin) rounded-lg border border-line bg-raised p-1 text-body-sm text-fg shadow-popover ease-out-quint data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:duration-100 data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
className,
)}
{...props}
Expand Down
1 change: 1 addition & 0 deletions packages/design-system/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './page-states';
export * from './relative-time';
export * from './separator';
export * from './sliding-pill';
export * from './spinner';
4 changes: 2 additions & 2 deletions packages/design-system/components/page-states.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Loader } from 'lucide-react';
import type { ReactNode } from 'react';
import { Spinner } from './spinner';

export function LoadingState() {
return (
<p
role="status"
className="flex animate-in items-center justify-center gap-2 py-10 text-body text-fg-muted delay-150 duration-300 fill-mode-backwards fade-in"
>
<Loader aria-hidden="true" className="spin-in-place size-3.5" />
<Spinner />
Loading…
</p>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/design-system/components/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function PopoverContent({
align={align}
sideOffset={sideOffset}
className={cn(
'z-50 w-max max-w-80 origin-(--radix-popover-content-transform-origin) rounded-lg border border-line bg-raised px-3 py-2.5 text-body-sm text-fg shadow-popover ease-out-quint data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
'z-50 w-max max-w-80 origin-(--radix-popover-content-transform-origin) rounded-lg border border-line bg-raised px-3 py-2.5 text-body-sm text-fg shadow-popover ease-out-quint data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:duration-100 data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
className,
)}
{...props}
Expand Down
22 changes: 22 additions & 0 deletions packages/design-system/components/spinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { cn } from '../utils';

const BAR_XS = [1, 7, 13, 19];

interface SpinnerProps {
className?: string;
}

export function Spinner({ className }: SpinnerProps) {
return (
<svg
aria-hidden="true"
viewBox="0 9 24 6"
fill="currentColor"
className={cn('spinner-steps aspect-4/1 w-5 shrink-0', className)}
>
{BAR_XS.map(x => (
<rect key={x} x={x} y={9} width={4} height={6} rx={1.25} />
))}
</svg>
);
}
2 changes: 1 addition & 1 deletion packages/design-system/components/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function TooltipContent({ className, sideOffset = 0, children, ...props }: Toolt
data-slot="tooltip-content"
sideOffset={sideOffset}
className={cn(
'z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-lg border border-line bg-raised px-2.5 py-1.5 text-body-sm text-balance text-fg shadow-popover ease-out-quint fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=instant-open]:animate-none',
'z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-lg border border-line bg-raised px-2.5 py-1.5 text-body-sm text-balance text-fg shadow-popover ease-out-quint fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:duration-100 data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=instant-open]:animate-none',
className,
)}
{...props}
Expand Down
2 changes: 1 addition & 1 deletion packages/design-system/icons/brand-mark.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cn } from '../utils';

const SMOKE_PATH = 'M46.4 23.21A9 9 0 0 1 46.4 10.48L52.88 4L55.71 6.83A5 5 0 0 1 55.71 13.9Z';
const SMOKE_CLASS_NAME = 'origin-[47px_23px] animate-smoke-drift';
const SMOKE_CLASS_NAME = 'origin-[47px_23px] motion-safe:animate-smoke-drift';

interface BrandMarkProps {
className?: string;
Expand Down
63 changes: 60 additions & 3 deletions packages/design-system/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,25 @@
opacity: 0;
}
}

/* tw-animate's enter and exit also animate filter: blur(0), which Chrome will not composite. */
@keyframes enter {
from {
opacity: var(--tw-enter-opacity, 1);
transform: translate3d(var(--tw-enter-translate-x, 0), var(--tw-enter-translate-y, 0), 0)
scale3d(var(--tw-enter-scale, 1), var(--tw-enter-scale, 1), var(--tw-enter-scale, 1))
rotate(var(--tw-enter-rotate, 0));
}
}

@keyframes exit {
to {
opacity: var(--tw-exit-opacity, 1);
transform: translate3d(var(--tw-exit-translate-x, 0), var(--tw-exit-translate-y, 0), 0)
scale3d(var(--tw-exit-scale, 1), var(--tw-exit-scale, 1), var(--tw-exit-scale, 1))
rotate(var(--tw-exit-rotate, 0));
}
}
}

@layer base {
Expand Down Expand Up @@ -279,13 +298,22 @@
outline-offset: 2px;
}
}
/* Reduced motion keeps fades, colours and spinners; movement jumps and fires no transitionend. */
@media (prefers-reduced-motion: reduce) {
*,
::before,
::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
--tw-enter-translate-x: 0 !important;
--tw-enter-translate-y: 0 !important;
--tw-enter-scale: 1 !important;
--tw-enter-rotate: 0 !important;
--tw-exit-translate-x: 0 !important;
--tw-exit-translate-y: 0 !important;
--tw-exit-scale: 1 !important;
--tw-exit-rotate: 0 !important;
transition-property:
color, background-color, border-color, outline-color, text-decoration-color, fill, stroke,
opacity, filter !important;
scroll-behavior: auto !important;
}
}
Expand Down Expand Up @@ -366,6 +394,35 @@
}
}

@utility spinner-steps {
& > * {
animation: spinner-steps 1.6s linear infinite;
}
& > :nth-child(1) {
animation-delay: -1.6s;
}
& > :nth-child(2) {
animation-delay: -1.4s;
}
& > :nth-child(3) {
animation-delay: -1.2s;
}
& > :nth-child(4) {
animation-delay: -1s;
}
}

@keyframes spinner-steps {
0%,
55% {
opacity: 1;
}
60%,
100% {
opacity: 0.15;
}
}

@layer utilities {
.markdown.prose {
--tw-prose-body: var(--fg-prose);
Expand Down
4 changes: 4 additions & 0 deletions packages/design-system/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ export function useDebouncedValue<Value>(value: Value, delayMs: number): Value {
}, [value, delayMs]);
return debounced;
}

export function checkPrefersReducedMotion(): boolean {
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function DaemonStatusIndicator() {
{checkHasRunning(data) && (
<span
className={cn(
'absolute inline-flex size-full animate-ping rounded-full opacity-75',
'absolute inline-flex size-full rounded-full opacity-75 motion-safe:animate-ping',
appearance.dotClassName,
)}
/>
Expand Down
7 changes: 5 additions & 2 deletions packages/domains/routine/components/webhook-queue-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ListOrdered } from 'lucide-react';
import { useState } from 'react';
import { match } from 'ts-pattern';

import { Badge, Button, Popover } from 'design-system/components';
import { Badge, Button, Popover, Spinner } from 'design-system/components';
import { sameOriginApi } from 'utils/http';

import { WebhookQueueList } from '../../webhook/components/webhook-queue-list';
Expand Down Expand Up @@ -70,7 +70,10 @@ export function WebhookQueueButton({ routine, count, look = 'button' }: WebhookQ
</p>
)}
{data === undefined && error === null && (
<p className="px-3 py-2.5 text-fg-muted">Loading…</p>
<p className="flex items-center gap-2 px-3 py-2.5 text-fg-muted">
<Spinner />
Loading…
</p>
)}
<WebhookQueueList queue={data?.queue ?? []} />
</Popover.Content>
Expand Down
4 changes: 2 additions & 2 deletions packages/domains/run/components/run-status-badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ export function RunStatusBadge({ status }: RunStatusBadgeProps) {
key={status}
variant={appearance.variant}
size="medium"
className={cn(status !== initialStatus && 'animate-status-pop')}
className={cn(status !== initialStatus && 'motion-safe:animate-status-pop')}
>
<span className="relative flex size-1.5 shrink-0">
{appearance.isPulsing && (
<span
className={cn(
'absolute inline-flex size-full animate-ping rounded-full opacity-75',
'absolute inline-flex size-full rounded-full opacity-75 motion-safe:animate-ping',
appearance.dotClassName,
)}
/>
Expand Down
42 changes: 20 additions & 22 deletions packages/web-app/src/features/calendar/week-calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Ban, Check, ChevronLeft, ChevronRight, Clock, Ellipsis, Loader, X } fro
import { Link } from 'react-router';
import { match } from 'ts-pattern';
import { Button, DropdownMenu, ErrorState } from 'design-system/components';
import { cn } from 'design-system/utils';
import { checkPrefersReducedMotion, cn } from 'design-system/utils';
import type { CalendarEntryId } from 'domains/calendar/ids';
import { getCalendar } from 'domains/calendar/requests';
import type { CalendarEntry } from 'domains/calendar/types';
Expand Down Expand Up @@ -90,36 +90,29 @@ const blockIcons: Record<RunStatus, BlockIcon> = {

const outlinedBlockClassName = 'hover:border-fg-faint';
const tintedBlockClassName = 'pl-[7px] hover:brightness-125 focus-visible:shadow-focus';
// Not for the running block: its pulse is an animation too, and an element runs only one.
const blockEnterClassName = 'animate-in animation-duration-300 fade-in';

const blockStyles: Record<BlockVariant, BlockStyle> = {
planned: {
className: cn(blockSurfaceClassNames.planned, outlinedBlockClassName, blockEnterClassName),
className: cn(blockSurfaceClassNames.planned, outlinedBlockClassName),
icon: null,
},
plannedDefault: {
className: cn(
blockSurfaceClassNames.plannedDefault,
outlinedBlockClassName,
blockEnterClassName,
),
className: cn(blockSurfaceClassNames.plannedDefault, outlinedBlockClassName),
icon: null,
},
succeeded: {
className: cn(blockSurfaceClassNames.succeeded, tintedBlockClassName, blockEnterClassName),
className: cn(blockSurfaceClassNames.succeeded, tintedBlockClassName),
icon: blockIcons.succeeded,
},
failed: {
className: cn(blockSurfaceClassNames.failed, tintedBlockClassName, blockEnterClassName),
className: cn(blockSurfaceClassNames.failed, tintedBlockClassName),
icon: blockIcons.failed,
},
timed_out: {
className: cn(blockSurfaceClassNames.timed_out, tintedBlockClassName, blockEnterClassName),
className: cn(blockSurfaceClassNames.timed_out, tintedBlockClassName),
icon: blockIcons.timed_out,
},
aborted: {
className: cn(blockSurfaceClassNames.aborted, tintedBlockClassName, blockEnterClassName),
className: cn(blockSurfaceClassNames.aborted, tintedBlockClassName),
icon: blockIcons.aborted,
},
running: {
Expand Down Expand Up @@ -357,13 +350,18 @@ function DayColumn({ day, entries, now, isToday, routinesById }: DayColumnProps)
backgroundSize: '100% var(--hour-height)',
}}
>
{positioned.map(item => (
<CalendarBlock
key={item.entry.id}
positioned={item}
overlapLabel={routinesById && getCalendarEntryOverlapLabel(item.entry, routinesById)}
/>
))}
{/* One fade per day when its runs arrive, not hundreds of block fades at once. */}
{positioned.length > 0 && (
<div className="absolute inset-0 z-10 animate-in duration-150 ease-out-quint fade-in">
{positioned.map(item => (
<CalendarBlock
key={item.entry.id}
positioned={item}
overlapLabel={routinesById && getCalendarEntryOverlapLabel(item.entry, routinesById)}
/>
))}
</div>
)}
{isToday && <CurrentTimeLine now={now} dayStart={day} />}
</div>
);
Expand Down Expand Up @@ -471,7 +469,7 @@ function getWeekDays(weekStart: Date): Date[] {
}

function getScrollBehavior(): ScrollBehavior {
return window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'instant' : 'smooth';
return checkPrefersReducedMotion() ? 'instant' : 'smooth';
}

function getWheelDeltaX(event: WheelEvent, pageWidth: number): number {
Expand Down
Loading
Loading