Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

5.6 KB
Raw Blame
"use client";

import { cn } from "@rallly/ui";
import * as m from "motion/react-m";
import * as React from "react";
import { DemoScreen } from "../hero-demo/demo-frame";
import { ACCENT } from "./accent";
import type { CursorStop } from "./demo-cursor";
import { DemoCursor } from "./demo-cursor";
import type { Playback } from "./motion";
import { EXIT } from "./motion";
import { PressButton } from "./press-button";

// A textless mock of the poll creation form: title field and a month
// calendar with a weekly cadence of selected days. Bars stand in for copy so
// it doesn't compete with the section text. Sized to fit the 4:3 artboard on
// the how it works section.
//
// On play the cursor hops through the dates, each one lighting as it is
// clicked, then carries on to the submit button and presses it.
const WEEKS = 4;
const START_OFFSET = 2;

// Scattered rather than a single column: a weekly cadence reads as a
// recurring event, where the point here is someone picking whichever days
// happen to suit. Indices are cells in the WEEKS x 7 grid, listed in the
// order they get picked, which is deliberately not left to right.
const SELECTED = [10, 4, 17, 23, 12, 27];

// The cells light on the cursor's cadence rather than a fast burst: it
// reaches the first date half a second in, hops between dates from there,
// then travels down to the submit button.
const PICK_START = 0.5;
const PICK_STEP = 0.16;
const pickAt = (index: number) => PICK_START + index * PICK_STEP;
const SUBMIT_DELAY = pickAt(SELECTED.length - 1) + 0.35;

export const CreateStepDemo = ({ playback }: { playback: Playback }) => {
  const on = playback !== "idle";
  const instant = playback === "done";
  const cellRefs = React.useRef(
    SELECTED.map(() => React.createRef<HTMLDivElement>()),
  ).current;
  const submitRef = React.useRef<HTMLDivElement>(null);
  const stops = React.useMemo<CursorStop[]>(
    () => [
      ...SELECTED.map((_, index) => ({
        ref: cellRefs[index],
        at: pickAt(index),
        click: true,
      })),
      { ref: submitRef, at: SUBMIT_DELAY, click: true },
    ],
    [cellRefs],
  );
  return (
    <>
      <DemoScreen className="space-y-2 p-4">
        <div className="space-y-1.5">
          <div className="h-1.5 w-8 rounded-full bg-gray-300" />
          <div className="flex h-6 items-center rounded-md border border-gray-200 px-2">
            <div className="h-1.5 w-24 rounded-full bg-gray-300" />
          </div>
        </div>
        <div className="space-y-1.5">
          <div className="flex items-center justify-between">
            <div className="h-1.5 w-14 rounded-full bg-gray-300" />
            <div className="h-1.5 w-10 rounded-full bg-gray-200" />
          </div>
          <div className="grid grid-cols-7 gap-1">
            {Array.from({ length: 7 }, (_, index) => (
              <div
                // biome-ignore lint/suspicious/noArrayIndexKey: weekday header cells are positional
                key={index}
                className="flex justify-center py-0.5"
              >
                <div className="h-1 w-2 rounded-full bg-gray-200" />
              </div>
            ))}
            {Array.from({ length: WEEKS * 7 }, (_, index) => {
              if (index < START_OFFSET) {
                return (
                  <div
                    // biome-ignore lint/suspicious/noArrayIndexKey: calendar cells are positional
                    key={index}
                  />
                );
              }
              const pickedAt = SELECTED.indexOf(index);
              if (pickedAt === -1) {
                return (
                  <div
                    // biome-ignore lint/suspicious/noArrayIndexKey: calendar cells are positional
                    key={index}
                    className="h-3.5 rounded bg-gray-100"
                  />
                );
              }
              return (
                <m.div
                  // biome-ignore lint/suspicious/noArrayIndexKey: calendar cells are positional
                  key={index}
                  ref={cellRefs[pickedAt]}
                  // Color is a CSS transition so it follows the theme's gray
                  // tokens, which motion cannot interpolate.
                  className={cn(
                    "h-3.5 rounded transition-colors ease-[cubic-bezier(0.23,1,0.32,1)]",
                    on
                      ? "bg-gray-300 duration-220"
                      : "bg-gray-100 duration-180",
                    instant && "duration-0",
                  )}
                  style={{
                    transitionDelay:
                      on && !instant ? `${pickAt(pickedAt)}s` : undefined,
                  }}
                  initial={false}
                  animate={{ scale: on && !instant ? [0.88, 1] : 1 }}
                  transition={
                    instant
                      ? { duration: 0 }
                      : on
                        ? {
                            type: "spring",
                            duration: 0.44,
                            bounce: 0.42,
                            delay: pickAt(pickedAt),
                          }
                        : EXIT
                  }
                />
              );
            })}
          </div>
        </div>
        <div className="flex justify-end border-gray-200/60 border-t pt-2">
          <div ref={submitRef}>
            <PressButton
              playback={playback}
              delay={SUBMIT_DELAY}
              className={cn("h-7 w-14 rounded-md", ACCENT)}
            />
          </div>
        </div>
      </DemoScreen>
      <DemoCursor playback={playback} stops={stops} />
    </>
  );
};