Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): add ShareViewToggle and stage morph styles

Richie McIlroyc1ba6943bf7a
diff --git a/apps/web/app/globals.css b/apps/web/app/globals.css
index 8f0b2defe..3a1ea67b9 100644
--- a/apps/web/app/globals.css
+++ b/apps/web/app/globals.css
@@ -983,6 +983,19 @@ footer a {
margin-bottom: 0;
}
+/*
+ * While the share-page stage is morphing between the player and timeline
+ * views, its layout animation scales the whole card. Overlay chrome that is
+ * positioned against the video (controls, comment stamps) skews visibly during
+ * that scale, so it is faded out for the duration of the morph.
+ */
+[data-morphing] [data-media-player-controls],
+[data-morphing] [data-comment-stamp] {
+ opacity: 0;
+ pointer-events: none;
+ transition: opacity 120ms linear;
+}
+
@supports (view-transition-name: none) {
::view-transition-old(root),
::view-transition-new(root) {
diff --git a/apps/web/app/s/[videoId]/_components/ShareViewToggle.tsx b/apps/web/app/s/[videoId]/_components/ShareViewToggle.tsx
new file mode 100644
index 000000000..79003a936
--- /dev/null
+++ b/apps/web/app/s/[videoId]/_components/ShareViewToggle.tsx
@@ -0,0 +1,70 @@
+"use client";
+
+import { classNames } from "@cap/utils";
+import { motion, useReducedMotion } from "motion/react";
+
+export type ShareView = "classic" | "timeline";
+
+const OPTIONS: { value: ShareView; label: string }[] = [
+ { value: "classic", label: "Player" },
+ { value: "timeline", label: "Timeline" },
+];
+
+interface ShareViewToggleProps {
+ view: ShareView;
+ onChange: (view: ShareView) => void;
+ disabled?: boolean;
+ /** Warms the lazily-loaded timeline chunk before the user commits. */
+ prefetch?: () => void;
+}
+
+export function ShareViewToggle({
+ view,
+ onChange,
+ disabled = false,
+ prefetch,
+}: ShareViewToggleProps) {
+ const reduceMotion = useReducedMotion() ?? false;
+
+ return (
+ <div className="inline-flex items-center gap-0.5 p-0.5 rounded-full border border-gray-5 bg-gray-3">
+ {OPTIONS.map((option) => {
+ const active = option.value === view;
+ return (
+ <button
+ key={option.value}
+ type="button"
+ disabled={disabled}
+ aria-pressed={active}
+ title={`${option.label} (T)`}
+ onClick={() => {
+ if (active) return;
+ onChange(option.value);
+ }}
+ onPointerEnter={prefetch}
+ onFocus={prefetch}
+ className={classNames(
+ "relative px-3 py-1 rounded-full text-xs font-medium transition-colors duration-150",
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-9",
+ disabled ? "opacity-50 cursor-not-allowed" : "cursor-pointer",
+ active ? "text-gray-12" : "text-gray-11 hover:text-gray-12",
+ )}
+ >
+ {active && (
+ <motion.span
+ layoutId="share-view-thumb"
+ className="absolute inset-0 rounded-full border border-gray-5 bg-white shadow-sm"
+ transition={
+ reduceMotion
+ ? { duration: 0 }
+ : { type: "spring", stiffness: 500, damping: 30 }
+ }
+ />
+ )}
+ <span className="relative z-10">{option.label}</span>
+ </button>
+ );
+ })}
+ </div>
+ );
+}