ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

极简界面的微交互:给删除操作增加“可后悔的 5 秒撤销条”

极简界面的微交互:给删除操作增加“可后悔的 5 秒撤销条” 极简界面的微交互给删除操作增加“可后悔的 5 秒撤销条”在人机交互设计HCI中关于“删除操作Deletion Action”的处理存在一个经典的体验两难方案 A弹窗二次确认Are you sure? Modal。每次用户想删一个待办都必须停下来在屏幕中央弹出一个冰冷的红色确认框点“确定”。这种设计极度打断心流让批量清理任务变得痛苦无比。方案 B直接秒删Instant Deletion。虽然顺畅但用户一旦手滑误删了重要便签数据瞬间灰飞烟灭产生强烈的挫败感。现代顶级交互范式如 Gmail、Telegram的最佳实践是“操作时 0 弹窗秒删 屏幕底部优雅滑出【可后悔的 5 秒撤销条5-Second Undo Toast】”。在「Tide UI」中我们结合手作和纸胶带美学设计了一个温润、支持倒计时进度条动画的纯 React 撤销条组件。-------------------------------------------------------------------- | 可后悔的 5 秒手绘撤销条微交互状态流 | -------------------------------------------------------------------- | [用户左滑撕下便签: 购买海盐咖啡豆] | | | | | ├── 1. 界面卡片 0.16s 丝滑坍缩滑出视口 (满足即时掌控感) | | └── 2. 数据进入本地暂存区 (Soft-deleted Store) | | | | [屏幕底部平滑浮现: 和纸胶带撤销条] | | ├── 左侧: 已撕下便签「购买海盐咖啡豆」 | | ├── 右侧: 带有水彩边框的【撤销】按钮 | | └── 底部: 5 秒平滑递减的水彩时间倒计时线 (100% - 0%) | | | | | ├── [若用户 5 秒内点击【撤销】]: 任务以弹簧动画原路恢复 | | └── [若 5 秒超时无操作]: 后台静默执行 IndexedDB 物理删除 | --------------------------------------------------------------------1. 撤销管理器状态机与 Hook 封装创建src/lib/useUndoableAction.tsimport { useState, useRef, useCallback } from react; export interface PendingActionT { id: string; data: T; description: string; timeoutId: NodeJS.Timeout; } export function useUndoableActionT(onPhysicalCommit: (data: T) void, timeoutSec 5) { const [pendingAction, setPendingAction] useStatePendingActionT | null(null); const activeActionRef useRefPendingActionT | null(null); // 触发软删除 const stageAction useCallback( (id: string, data: T, description: string) { // 若已有待处理动作先立即强制提交旧动作 if (activeActionRef.current) { clearTimeout(activeActionRef.current.timeoutId); onPhysicalCommit(activeActionRef.current.data); } const timeoutId setTimeout(() { onPhysicalCommit(data); setPendingAction(null); activeActionRef.current null; }, timeoutSec * 1000); const action { id, data, description, timeoutId }; activeActionRef.current action; setPendingAction(action); }, [onPhysicalCommit, timeoutSec] ); // 用户点击撤销 const cancelAction useCallback(() { if (activeActionRef.current) { clearTimeout(activeActionRef.current.timeoutId); const restoredData activeActionRef.current.data; setPendingAction(null); activeActionRef.current null; return restoredData; } return null; }, []); return { pendingAction, stageAction, cancelAction }; }2. 带有倒计时水彩线的手作撤销条 UIimport React from react; export const CozyUndoBar: React.FC{ description: string; onUndo: () void; durationSec?: number; } ({ description, onUndo, durationSec 5 }) { return ( div classNamefixed bottom-6 left-1/2 -translate-x-1/2 z-50 flex flex-col overflow-hidden bg-[#FAF7F0] border-2 border-[#2D2B2A] rounded-2xl shadow-[4px_5px_0px_#2D2B2A] max-w-sm w-full animate-bounce-in div classNameflex items-center justify-between px-4 py-3 span classNametext-xs font-bold text-[#2D2B2A] truncate pr-2 {description} /span button onClick{onUndo} classNamepx-3 py-1 bg-[#88AA99] text-white text-xs font-bold rounded-lg border border-[#2D2B2A] shadow-[1px_1px_0px_#2D2B2A] active:scale-95 transition-transform 撤销 ↩ /button /div {/* 底部 5 秒平滑递减倒计时线 */} div classNameh-1 bg-[#D36135] style{{ width: 100%, animation: shrink-line ${durationSec}s linear forwards, }} / /div ); };宽容是最高级的交互给用户的每一次误触留出 5 秒钟的温柔缓冲。不打扰、不审判、允许后悔正是手作工具给予使用者最温暖的陪伴与尊重。
返回列表