← All proposals

Card Sequence

A new component, CardSequence, in the loading indicators family.

Net-new componentOpen in Storybook

proposals/CardSequence/card-sequence.css292 lines · View on GitHub
/* Choreography, per card (--card-start is the card's start time): the card is
   in at 0 s, its text settles at 1.5 s, the line to the next card is drawn
   from 2.2 to 3 s and the next card is in at 3 s. The last card shimmers
   until the work is done. STEP_MS and TAIL_MS in the component carry the same
   timeline. */
@property --card-dim {
	inherits: false;
	initial-value: 0.58;
	syntax: '<number>';
}

.pds-card-sequence {
	--sequence-fade: 450ms;
	--sequence-sweep: var(--pds-animation-duration-ai-shimmer);
	--sequence-ease: var(--pds-animation-timing-function-default);

	align-items: center;
	display: flex;
	flex-direction: column;
	margin-inline: auto;
	max-width: 18.75rem;
	width: 100%;
}

.pds-card-sequence__step {
	align-items: center;
	display: flex;
	flex-direction: column;
	width: 100%;
}

/* Headline: the working text and the complete text share one cell. */
.pds-card-sequence__headline {
	display: grid;
	margin-block-end: var(--pds-spacing-xl);
	text-align: center;
}

.pds-card-sequence__working,
.pds-card-sequence__complete {
	color: var(--pds-color-foreground-default);
	font-family: var(--pds-typography-ff-compact);
	font-size: var(--pds-typography-size-xl);
	font-weight: var(--pds-typography-fw-medium);
	grid-area: 1 / 1;
	justify-self: center;
	line-height: var(--pds-typography-lh-xs);
	transition:
		filter var(--sequence-fade) ease,
		opacity var(--sequence-fade) ease,
		transform var(--sequence-fade) ease;
}

.pds-card-sequence__working {
	animation: sequence-headline-in 600ms var(--sequence-ease) backwards;
}

.pds-card-sequence__stop {
	color: var(--pds-color-brand-default);
}

.pds-card-sequence__complete {
	color: var(--pds-color-badge-brand-foreground);
	filter: blur(var(--pds-spacing-3xs));
	isolation: isolate;
	opacity: 0;
	position: relative;
	transform: translateY(var(--pds-spacing-3xs));
}

/* The marker bar wipes in behind the complete text. It is a pseudo-element, so
   it adds no height or width to the layout. */
.pds-card-sequence__complete::before {
	background: var(--pds-color-badge-brand-background);
	content: '';
	inset: -0.12em -0.5em -0.08em;
	position: absolute;
	transform: scaleX(0);
	transform-origin: left center;
	transition: transform 550ms var(--sequence-ease) 100ms;
	z-index: -1;
}

/* Cards */
.pds-card-sequence__card {
	align-items: center;
	animation: sequence-card-in 500ms var(--sequence-ease) var(--card-start, 0ms)
		both;
	background: var(--pds-color-card-background);
	border: var(--pds-border-width-default) solid var(--pds-color-border-default);
	border-radius: var(--pds-border-radius-card);
	box-shadow: var(--pds-elevation-raised);
	display: flex;
	gap: var(--pds-spacing-s);
	padding: var(--pds-spacing-s);
	width: 100%;
}

.pds-card-sequence__tile {
	align-items: center;
	background: var(--pds-color-surface-default-secondary);
	border: var(--pds-border-width-default) solid var(--pds-color-border-default);
	border-radius: var(--pds-border-radius-card);
	color: var(--pds-color-foreground-default);
	display: grid;
	flex: none;
	height: var(--pds-spacing-2xl);
	justify-items: center;
	width: var(--pds-spacing-2xl);
}

/* Shimmer: a highlight sweeps through whatever is in the card. The content
   keeps its own colors; a mask dims it to --card-dim and lets a bright band
   through, so any text, a title and subtitle or a slot, works the same. */
.pds-card-sequence__content {
	--dim: color-mix(
		in oklch,
		var(--pds-color-foreground-default) calc(var(--card-dim) * 100%),
		transparent
	);
	--peak: var(--pds-color-foreground-default);

	animation: sequence-sweep var(--sequence-sweep) linear infinite;
	flex: 1;
	mask-image: linear-gradient(
		90deg,
		var(--dim) 0%,
		var(--dim) 38%,
		var(--peak) 50%,
		var(--dim) 62%,
		var(--dim) 100%
	);
	mask-position: 100% 0;
	mask-size: 250% 100%;
	min-width: 0;
	transition: --card-dim var(--sequence-fade) ease;
}

/* A card that is not the last settles on its own, 1.5 s after it appears. */
.pds-card-sequence__card:not(.pds-card-sequence__card--last)
	.pds-card-sequence__content {
	animation:
		sequence-sweep var(--sequence-sweep) linear infinite,
		sequence-settle 300ms linear calc(var(--card-start) + 1500ms) both;
}

/* Title and subtitle */
.pds-card-sequence__text {
	display: grid;
	gap: var(--pds-spacing-5xs);
}

.pds-card-sequence__title {
	color: var(--pds-color-foreground-default);
	font-family: var(--pds-typography-ff-compact);
	font-size: var(--pds-typography-size-m);
	font-weight: var(--pds-typography-fw-medium);
	line-height: var(--pds-typography-lh-xs);
}

.pds-card-sequence__subtitle {
	color: var(--pds-color-foreground-default-secondary);
}

/* Line and its end dots, from one card to the next */
.pds-card-sequence__link {
	display: block;
	height: var(--pds-spacing-4xl);
	margin-block: var(--pds-spacing-5xs);
	overflow: visible;
	width: var(--pds-spacing-s);
}

.pds-card-sequence__line {
	animation: sequence-draw 800ms cubic-bezier(0.4, 0, 0.2, 1)
		calc(var(--card-start) + 2200ms) both;
	fill: none;
	stroke: var(--pds-color-foreground-default);
	stroke-dasharray: 1;
	stroke-linecap: round;
	stroke-width: 1.5;
}

.pds-card-sequence__dot {
	animation: sequence-appear 150ms linear both;
	fill: var(--pds-color-foreground-default);
}

.pds-card-sequence__dot--start {
	animation-delay: calc(var(--card-start) + 2050ms);
}

.pds-card-sequence__dot--end {
	animation-delay: calc(var(--card-start) + 2900ms);
}

/* Landed: the last card settles, the headline changes and the bar wipes in. */
.pds-card-sequence--landed
	.pds-card-sequence__card--last
	.pds-card-sequence__content {
	--card-dim: 1;
}

.pds-card-sequence--landed .pds-card-sequence__working {
	filter: blur(var(--pds-spacing-3xs));
	opacity: 0;
	transform: translateY(calc(-1 * var(--pds-spacing-3xs)));
}

.pds-card-sequence--landed .pds-card-sequence__complete {
	filter: none;
	opacity: 1;
	transform: none;
}

.pds-card-sequence--landed .pds-card-sequence__complete::before {
	transform: scaleX(1);
}

@keyframes sequence-headline-in {
	from {
		filter: blur(var(--pds-spacing-3xs));
		opacity: 0;
		transform: translateY(var(--pds-spacing-3xs));
	}
}

@keyframes sequence-card-in {
	from {
		filter: blur(var(--pds-spacing-3xs));
		opacity: 0;
		transform: translateY(var(--pds-spacing-2xs));
	}
}

@keyframes sequence-sweep {
	0% {
		mask-position: 100% 0;
	}
	100% {
		mask-position: 0% 0;
	}
}

@keyframes sequence-settle {
	to {
		--card-dim: 1;
	}
}

@keyframes sequence-draw {
	from {
		stroke-dashoffset: 1;
	}
	to {
		stroke-dashoffset: 0;
	}
}

@keyframes sequence-appear {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

/* Reduced motion: the final layout, no movement, no shimmer. */
@media (prefers-reduced-motion: reduce) {
	.pds-card-sequence__working,
	.pds-card-sequence__complete,
	.pds-card-sequence__complete::before,
	.pds-card-sequence__card,
	.pds-card-sequence__line,
	.pds-card-sequence__dot,
	.pds-card-sequence__content,
	.pds-card-sequence__card:not(.pds-card-sequence__card--last)
		.pds-card-sequence__content {
		animation: none !important;
		transition: none;
	}

	.pds-card-sequence__line {
		stroke-dashoffset: 0;
	}

	.pds-card-sequence__content {
		mask-image: none;
	}
}