refactor(motion): simplify to default and reduced

This commit is contained in:
2026-03-20 16:44:24 +08:00
parent 9009ce4853
commit 142f4a399a
8 changed files with 92 additions and 322 deletions
+10 -61
View File
@@ -18,50 +18,21 @@ export const themeDetails = {
}
} as const satisfies Record<ThemeName, { label: string; note: string }>;
export const motionPackNames = ["calm", "snappy", "spring"] as const;
export type MotionPackName = (typeof motionPackNames)[number];
export const motionModeNames = ["default", "reduced"] as const;
export type MotionModeName = (typeof motionModeNames)[number];
export const defaultMotionPack: MotionPackName = "calm";
export const defaultMotionMode: MotionModeName = "default";
export const motionPackDetails = {
calm: {
label: "Calm",
note: "Editorial default with restrained lift and steady transitions"
},
snappy: {
label: "Snappy",
note: "Shorter durations, tighter distances, and more direct response"
},
spring: {
label: "Spring",
note: "More elastic easing, wider movement, and livelier feedback"
}
} as const satisfies Record<MotionPackName, { label: string; note: string }>;
export const motionAccessibilityNames = ["system", "full", "reduced"] as const;
export type MotionAccessibilityName = (typeof motionAccessibilityNames)[number];
export const defaultMotionAccessibility: MotionAccessibilityName = "system";
export const motionAccessibilityDetails = {
system: {
label: "System",
note: "Follow the operating system reduced-motion preference"
},
full: {
label: "Full",
note: "Always show the selected motion pack, even if the OS prefers reduced motion"
export const motionModeDetails = {
default: {
label: "Default",
note: "Standard Cadence UI motion for hover, press, overlays, and hierarchy"
},
reduced: {
label: "Reduced",
note: "Always collapse durations, distances, and animated feedback"
note: "Collapse durations, distances, and animated feedback"
}
} as const satisfies Record<MotionAccessibilityName, { label: string; note: string }>;
export const motionModeNames = motionAccessibilityNames;
export type MotionModeName = MotionAccessibilityName;
export const defaultMotionMode: MotionModeName = defaultMotionAccessibility;
} as const satisfies Record<MotionModeName, { label: string; note: string }>;
export const motionScale = {
instant: "var(--dur-instant)",
@@ -190,16 +161,6 @@ function getTargetElement(root?: HTMLElement) {
return document.documentElement;
}
export function setMotionPack(pack: MotionPackName, root?: HTMLElement) {
const target = getTargetElement(root);
if (!target) {
return;
}
target.dataset.motionPack = pack;
}
export function setTheme(theme: ThemeName, root?: HTMLElement) {
const target = getTargetElement(root);
@@ -210,24 +171,12 @@ export function setTheme(theme: ThemeName, root?: HTMLElement) {
target.dataset.theme = theme;
}
export function setMotionAccessibility(
mode: MotionAccessibilityName,
root?: HTMLElement
) {
export function setMotionMode(mode: MotionModeName, root?: HTMLElement) {
const target = getTargetElement(root);
if (!target) {
return;
}
if (mode === "system") {
delete target.dataset.motion;
return;
}
target.dataset.motion = mode;
}
export function setMotionMode(mode: MotionModeName, root?: HTMLElement) {
setMotionAccessibility(mode, root);
}