性能
需注意帧率: 平均 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 许可声明。
更完整的提示词,包含调参、无障碍和接入步骤。