效能
需注意幀率: 平均 60 fps,p5 59.5 · 長任務: 0 個,共 0 毫秒,最長 0 毫秒 · 原始碼 gzip 6.6 KB · 執行時 281 KB
LikeMIT按鈕Bencho
由 Lorenzo Cabra 製作的按鈕 React 元件。依據 MIT 授權從 Bencho 原樣收錄,此處為即時預覽。
品質報告
等級和分數來自建置或測試時跑過的自動檢查。沒跑過的項目會標成「未檢測」,不會填假資料。
幀率: 平均 60 fps,p5 59.5 · 長任務: 0 個,共 0 毫秒,最長 0 毫秒 · 原始碼 gzip 6.6 KB · 執行時 281 KB
問題 0 · 讀屏: 需注意
沒有持續動效
無溢出
幀率和長任務是在無介面的 Chromium 裡用軟體 WebGL 測的,只適合在本站元件之間比較,不代表實機表現。
不適用:靜止時沒有可見動畫;由懸停觸發的動畫沒有測試。
沒有 axe-core 違規。

檢測於 2026年11月15日 · 資料來自自動腳本,不是手工填寫。
以實際尺寸顯示。
複製內容以授權聲明開頭,使用程式碼時請保留。
<div id="root"></div>:root{--bg:#f6f4f0;--ink:#17181a;--background:40 20% 96%;--foreground:24 10% 8%;--card:0 0% 100%}html,body{min-height:100%;margin:0;background:var(--bg);color:var(--ink)}html,body{height:100%;overflow:hidden}body{display:grid;place-items:center}#root{display:grid;place-items:center;max-width:100%;max-height:100%;box-sizing:border-box;padding:16px;color:hsl(var(--foreground))}#root.full{width:100%;height:100%;padding:0}@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation-play-state:paused!important;transition-duration:0s!important}}
/*
MIT License
Copyright (c) 2026 Lorenzo Cabra
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
---
Not covered by this licence: the Bencho name and the goat mark, and the
photographs shown on bencho.dev (none are included here). Third-party
material keeps its own licence; see THIRD_PARTY.md.
Icon substitution (this copy only): lucide-react (ISC) was replaced with @tabler/icons-react (MIT).
Sample photographs were replaced with Incidental AI assets. The Bencho name and goat mark are not licensed for marketing use.
*/
/* ── Bencho tokens ─────────────────────────────────────────
The custom properties the free blocks read, at the values
bencho.dev draws them with. Light by default; dark under
[data-theme="dark"] on any ancestor, or automatically with
the system setting unless [data-theme="light"] says otherwise.
Map these to your own theme rather than keeping two: a block
only ever reads the names, never the values. */
:root {
--font-ui: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
--bg: #ffffff;
--board: #ffffff;
--card: #f7f7f6;
--surface: #f7f7f6;
--surface-2: #f1f1f0;
--surface-3: #ecebe7;
--ink: #17181a;
--ink-rgb: 23, 24, 26;
--ink-2: #3c3b37;
--ink-3: #5c5b56;
--ink-4: #6f6e68;
--ink-5: #85847e;
--on-ink: #ffffff;
--on-ink-rgb: 255, 255, 255;
--slab: #17181a;
--on-slab: #ffffff;
--slab-dark: #0e0f11;
--fill-slab: #ffffff;
--fill-on: #17181a;
--fill-on-rgb: 23, 24, 26;
--pane: var(--fill-slab);
--pane-edge: rgba(23, 24, 26, 0.08);
--pane-thumb: rgba(23, 24, 26, 0.07);
--inlay: rgba(255, 255, 255, 0.55);
--inlay-hi: rgba(23, 24, 26, 0.09);
--elev-rgb: 255, 255, 255;
--glass-rgb: 255, 255, 255;
--shadow-rgb: 23, 24, 26;
--wash: 0.06;
--pick: #0d99ff;
--signal: #2231dd;
--focus: #2231dd;
--ok: #15803d;
--ember: #b8431c;
color-scheme: light;
}
[data-theme="dark"] {
--bg: #000000;
--board: #1a1a1a;
--card: #0a0a0a;
--surface: #0f0f0f;
--surface-2: #181818;
--surface-3: #202020;
--ink: #ffffff;
--ink-rgb: 255, 255, 255;
--ink-2: #b4b4b4;
--ink-3: #9a9a9a;
--ink-4: #828282;
--ink-5: #6b6b6b;
--on-ink: #000000;
--on-ink-rgb: 0, 0, 0;
--slab: #1a1a1a;
--on-slab: #ffffff;
--slab-dark: #262626;
--fill-slab: #262626;
--fill-on: #ffffff;
--fill-on-rgb: 255, 255, 255;
--pane-edge: rgba(255, 255, 255, 0.08);
--pane-thumb: rgba(255, 255, 255, 0.07);
--inlay: rgba(255, 255, 255, 0.1);
--inlay-hi: rgba(255, 255, 255, 0.09);
--elev-rgb: 32, 32, 32;
--shadow-rgb: 0, 0, 0;
--wash: 0.09;
--pick: #3aa9ff;
--ok: #34d17a;
color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) {
--bg: #000000;
--board: #1a1a1a;
--card: #0a0a0a;
--surface: #0f0f0f;
--surface-2: #181818;
--surface-3: #202020;
--ink: #ffffff;
--ink-rgb: 255, 255, 255;
--ink-2: #b4b4b4;
--ink-3: #9a9a9a;
--ink-4: #828282;
--ink-5: #6b6b6b;
--on-ink: #000000;
--on-ink-rgb: 0, 0, 0;
--slab: #1a1a1a;
--on-slab: #ffffff;
--slab-dark: #262626;
--fill-slab: #262626;
--fill-on: #ffffff;
--fill-on-rgb: 255, 255, 255;
--pane-edge: rgba(255, 255, 255, 0.08);
--pane-thumb: rgba(255, 255, 255, 0.07);
--inlay: rgba(255, 255, 255, 0.1);
--inlay-hi: rgba(255, 255, 255, 0.09);
--elev-rgb: 32, 32, 32;
--shadow-rgb: 0, 0, 0;
--wash: 0.09;
--pick: #3aa9ff;
--ok: #34d17a;
color-scheme: dark;
}
}
/* Like.css */
/*
MIT License
Copyright (c) 2026 Lorenzo Cabra
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
---
Not covered by this licence: the Bencho name and the goat mark, and the
photographs shown on bencho.dev (none are included here). Third-party
material keeps its own licence; see THIRD_PARTY.md.
Icon substitution (this copy only): lucide-react (ISC) was replaced with @tabler/icons-react (MIT).
Sample photographs were replaced with Incidental AI assets. The Bencho name and goat mark are not licensed for marketing use.
*/
/* ══ Like ═════════════════════════════════════════════════ */
/* a fixed frame: the pill grows by a digit at 9,999 and the
block must not rescale on the wall when it does */
.lk-frame {
width: 240px;
height: 130px;
display: grid;
place-items: center;}
.lk {
display: flex;
align-items: center;
gap: 8px;
padding: 0 20px 0 16px;
border: 0;
border-radius: var(--r);
background: var(--fill-slab, var(--card));
color: var(--fill-on, var(--ink));
font: inherit;
font-family: var(--font-ui);
font-size: 16px;
font-weight: 500;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
transition: scale 220ms cubic-bezier(0.22, 1, 0.36, 1);
letter-spacing: -0.01em;}
[data-stroke="on"] .lk { box-shadow: inset 0 0 0 1px var(--pane-edge); }
.lk:active { scale: 0.96; }
.lk:focus-visible {
outline: none;
box-shadow: 0 0 0 2px var(--fill-slab, #fff), 0 0 0 4px var(--signal, #2231dd);}
.lk-heart {
position: relative;
display: grid;
place-items: center;
width: 20px;
height: 20px;}
.lk-glyph { position: relative; z-index: 1; display: grid; }
/* the heart is gone while the bloom happens, then springs in
from nothing, red, past its size and back */
.lk-glyph[data-on] {
color: var(--lk-on);
/* the default landing: squeeze, swell past its size, settle */
animation: lk-pop 520ms cubic-bezier(0.3, 1.5, 0.4, 1) both;}
.lk[data-fx="Bloom"] .lk-glyph[data-on] {
animation: lk-heart 760ms cubic-bezier(0.3, 1.6, 0.4, 1) both;}
.lk-burst {
position: absolute;
left: 50%;
top: 50%;
pointer-events: none;}
/* the bloom: a full disc that grows, then hollows out from the
middle into a ring and thins to nothing — a border as wide as
the radius is a disc, and a border going to 0 is the hole */
.lk-bloom {
position: absolute;
left: -17px;
top: -17px;
width: 34px;
height: 34px;
box-sizing: border-box;
border-radius: 50%;
border: 17px solid #cc8ef5;
animation: lk-bloom 560ms cubic-bezier(0.25, 0.8, 0.35, 1) both;}
.lk[data-color="Ink"] .lk-bloom { border-color: var(--lk-on); animation-name: lk-bloom-ink; }
/* seven spokes, each a pair of dots, thrown as the ring opens */
.lk-spoke {
position: absolute;
left: 0;
top: 0;
rotate: var(--a);}
.lk-spoke i {
position: absolute;
width: 5px;
height: 5px;
margin: -2.5px 0 0 -2.5px;
border-radius: 50%;
background: var(--c);
animation: lk-dot 620ms cubic-bezier(0.2, 0.8, 0.3, 1) 200ms both;}
/* the pair sits either side of the spoke, one a little behind */
.lk-spoke i:first-child { --side: -4px; --far: 0px; }
.lk-spoke i:last-child { --side: 4px; --far: -5px; width: 4px; height: 4px; margin: -2px 0 0 -2px; }
/* ── Firework: up and out, then they fall ────── */
.lk-fw {
position: absolute;
left: 0;
top: 0;
animation: lk-fw-x 1000ms cubic-bezier(0.2, 0.7, 0.4, 1) var(--d) both;}
.lk-fw i {
position: absolute;
left: -2px;
top: -2px;
width: 4px;
height: 4px;
border-radius: 50%;
animation: lk-fw-y 1000ms linear var(--d) both;}
/* the count: one wheel per digit, each its own window */
.lk-count {
display: flex;
font-variant-numeric: tabular-nums;
line-height: 1;}
.lk-wheel {
position: relative;
display: inline-block;
height: 1.25em;
overflow: hidden;}
.lk-digit {
display: block;
line-height: 1.25em;}
.lk-comma { line-height: 1.25em; }
@media (prefers-reduced-motion: reduce) {
.lk-glyph[data-on], .lk-bloom, .lk-spoke i, .lk-fw, .lk-fw i { animation: none; }
}
@media (prefers-reduced-motion: reduce) {
.lk-burst { display: none; }
}
@keyframes lk-pop {
0% { scale: 0.6; }
45% { scale: 1.28; }
100% { scale: 1; }}
@keyframes lk-heart {
0%, 28% { scale: 0; }
62% { scale: 1.25; }
100% { scale: 1; }}
@keyframes lk-bloom {
0% { scale: 0.15; border-width: 17px; border-color: #e5484d; }
40% { scale: 1; border-width: 17px; border-color: #cc8ef5; }
75% { border-width: 2px; opacity: 1; }
100% { scale: 1.12; border-width: 0; opacity: 0; border-color: #cc8ef5; }}
@keyframes lk-bloom-ink {
0% { scale: 0.15; border-width: 17px; }
40% { scale: 1; border-width: 17px; }
75% { border-width: 2px; opacity: 1; }
100% { scale: 1.12; border-width: 0; opacity: 0; }}
@keyframes lk-dot {
0% { translate: 12px var(--side); scale: 1; opacity: 0; }
12% { opacity: 1; }
100% { translate: calc(18px + var(--fly) * 14px + var(--far)) calc(var(--side) * 1.6); scale: 0; opacity: 1; }}
@keyframes lk-fw-x { from { translate: 0 0; } to { translate: var(--x) 0; } }
@keyframes lk-fw-y {
0% { translate: 0 0; opacity: 1; animation-timing-function: cubic-bezier(0.2, 0.7, 0.4, 1); }
45% { translate: 0 var(--y); opacity: 1; animation-timing-function: cubic-bezier(0.5, 0, 0.8, 0.5); }
100% { translate: 0 calc(var(--y) + 30px); opacity: 0; }}
// bencho source (MIT). npm i @tabler/icons-react motion react · Tailwind CSS v4
// ── blocks/like/Like.tsx (https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/like/Like.tsx)
/*
MIT License
Copyright (c) 2026 Lorenzo Cabra
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
---
Not covered by this licence: the Bencho name and the goat mark, and the
photographs shown on bencho.dev (none are included here). Third-party
material keeps its own licence; see THIRD_PARTY.md.
Icon substitution (this copy only): lucide-react (ISC) was replaced with @tabler/icons-react (MIT).
Sample photographs were replaced with Incidental AI assets. The Bencho name and goat mark are not licensed for marketing use.
*/
import { useState } from "react";
import { AnimatePresence, motion } from "motion/react";
import { IconHeart as Heart } from "@tabler/icons-react";
/* ══ Like ═════════════════════════════════════════════════
A heart and a count. Press it and the heart vanishes, a disc
blooms where it was and hollows out into a ring, seven pairs
of coloured dots burst off the ring, and the heart springs
back in red and past its size — while the count rolls up one.
Press again and it empties and the count rolls back down.
── ONLY THE DIGITS THAT CHANGE ROLL ────────────────────
An odometer, not a number being replaced: 1,284 to 1,285
turns the last wheel and leaves the rest where they are,
and 1,299 to 1,300 turns three, each a beat after the one
to its right, the way a carry travels. Every digit is keyed
by its place and its value, so a digit that did not change
is the same element and never moves.
── UP FOR MORE, DOWN FOR LESS ─────────────────────────
Liking rolls the new digit in from below and the old one out
the top; unliking runs the other way. Direction is the whole
difference between a count going up and a count being
replaced. */
const H = 44;
const RED = "#e5484d";
/* the confetti: a pair of dots per spoke, never the same colour
twice in a pair */
const CONFETTI = ["#f48ea7", "#cc8ef5", "#8ce8c3", "#91d2fa", "#f5a524", "#e5484d", "#9fc7fa"];
const clamp = (v: number, a: number, b: number) => Math.min(b, Math.max(a, v));
const fmt = (n: number) => n.toLocaleString("en-US");
function Roll({ value, up }: { value: number; up: boolean }) {
const chars = fmt(value).split("");
/* places counted from the right, so a new leading digit does
not shift the keys of the ones already there */
return (
<span className="lk-count" aria-hidden="true">
{chars.map((c, i) => {
const place = chars.length - 1 - i;
if (c === ",") return <span key={`c${place}`} className="lk-comma">,</span>;
return (
<span key={`p${place}`} className="lk-wheel">
<AnimatePresence initial={false} mode="popLayout">
<motion.span
key={c}
className="lk-digit"
initial={{ y: up ? "100%" : "-100%", opacity: 0 }}
animate={{ y: "0%", opacity: 1 }}
exit={{ y: up ? "-100%" : "100%", opacity: 0 }}
transition={{ duration: 0.42, ease: [0.22, 1, 0.36, 1], delay: place * 0.04 }}
>
{c}
</motion.span>
</AnimatePresence>
</span>
);
})}
</span>
);
}
/* ── the effects ───────────────────────────────────────────
Two ways for a like to land, one knob. Every one plays once
per press from a layer keyed by the press, and every number
in them is fixed rather than random: several copies share a
wall and a bench, and must all do the same thing. */
export const EFFECTS = ["Bloom", "Firework"] as const;
/* a spread of fixed "random" numbers, one per particle */
const jit = (k: number, seed: number) => {
const x = Math.sin(k * 12.9898 + seed * 78.233) * 43758.5453;
return x - Math.floor(x);
};
function Burst({ fx, fly, ink }: { fx: string; fly: number; ink: boolean }) {
const c = (k: number) => (ink ? "var(--lk-on)" : CONFETTI[k % CONFETTI.length]);
const style = (o: Record<string, string | number>) => o as React.CSSProperties;
if (fx === "Firework") {
/* thrown up and out, then they fall: the x is steady, the y
is its own element on a rise-then-drop curve */
return (
<>
{Array.from({ length: 12 }, (_, k) => {
const a = -Math.PI / 2 + (k / 11 - 0.5) * Math.PI * 1.25;
const v = 22 + fly * 22 + jit(k, 7) * 10;
return (
<span key={k} className="lk-fw" style={style({ "--x": `${Math.cos(a) * v}px`, "--d": `${jit(k, 8) * 60}ms` })}>
<i style={style({ "--y": `${Math.sin(a) * v}px`, background: c(k) })} />
</span>
);
})}
</>
);
}
/* Bloom: a disc that hollows into a ring, and pairs of confetti */
return (
<>
<span className="lk-bloom" />
{Array.from({ length: 7 }, (_, k) => (
<span key={k} className="lk-spoke" style={style({ "--a": `${k * (360 / 7) - 90}deg` })}>
<i style={style({ "--c": c(k) })} />
<i style={style({ "--c": c(k + 3) })} />
</span>
))}
</>
);
}
export function Like({
/* the count before you press */
start = 1300,
/* how the like lands */
effect = "Bloom",
/* how far the particles fly, 0..100 */
burst = 50,
color = "Red",
corner = H / 2,
}: {
start?: number;
effect?: string;
burst?: number;
color?: string;
corner?: number;
} = {}) {
const base = Math.max(0, Math.round(start));
const [liked, setLiked] = useState(false);
const [beat, setBeat] = useState(0);
const count = base + (liked ? 1 : 0);
const fly = clamp(burst, 0, 100) / 100;
const r = clamp(corner, 0, H / 2);
const ink = color === "Ink";
const fx = (EFFECTS as readonly string[]).includes(effect) ? effect : "Bloom";
const press = () => {
const next = !liked;
setLiked(next);
if (next) {
setBeat((b) => b + 1);
}
};
return (
<div className="lk-frame">
<button
type="button"
className="lk"
data-liked={liked || undefined}
data-color={color}
data-fx={fx}
aria-pressed={liked}
aria-label={`Like. ${fmt(count)} likes`}
style={{ height: H, "--r": `${r}px`, "--lk-on": ink ? "var(--fill-on, var(--ink))" : RED } as React.CSSProperties}
onClick={press}
>
<span className="lk-heart">
{/* keyed by the press, so every like plays once */}
<span key={liked ? `on${beat}` : "off"} className="lk-glyph" data-on={liked || undefined}>
<Heart size={20} strokeWidth={2} fill={liked ? "currentColor" : "none"} />
</span>
{liked && fly > 0 && (
<span key={beat} className="lk-burst" style={{ "--fly": fly } as React.CSSProperties} aria-hidden="true">
<Burst fx={fx} fly={fly} ink={ink} />
</span>
)}
</span>
<Roll value={count} up={liked} />
</button>
</div>
);
}控制項 · HTML · CSS · JS
直接改程式碼,再用控制項微調,預覽會隨輸入即時更新。

線上編輯每個元件,用控制項微調,下載完整原始碼,複製進階提示詞。
一次性 $49暫定價格
測試模式:不會真的扣款。
免費:預覽、複製按鈕和課程說明。
清楚的形狀、一種強色和短促的按壓反饋,讓它有實體感。
主要操作、行動號召和工具欄。
改圓角、內邊距和懸停過渡的時長。
把 Bencho (github.com/cabralorenzo/bencho)(MIT)中的「點讚」元件加入我的 React + Tailwind CSS 應用程式。原始檔:https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/like/Like.tsx。清楚的形狀、一種強色和短促的按壓反饋,讓它有實體感。 適用情境:主要操作、行動號召和工具欄。 可調參數:改圓角、內邊距和懸停過渡的時長。 支援淺色與深色主題,遵循 prefers-reduced-motion。保留 MIT 授權聲明。
更完整的提示詞,包含調參、無障礙和接入步驟。