效能
需注意幀率: 平均 60 fps,p5 59.5 · 長任務: 0 個,共 0 毫秒,最長 0 毫秒 · 原始碼 gzip 6.8 KB · 執行時 158 KB
Label inputMIT輸入框Bencho
由 Lorenzo Cabra 製作的輸入框 React 元件。依據 MIT 授權從 Bencho 原樣收錄,此處為即時預覽。
品質報告
等級和分數來自建置或測試時跑過的自動檢查。沒跑過的項目會標成「未檢測」,不會填假資料。
幀率: 平均 60 fps,p5 59.5 · 長任務: 0 個,共 0 毫秒,最長 0 毫秒 · 原始碼 gzip 6.8 KB · 執行時 158 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;
}
}
/* LabelInput.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.
*/
/* ══ Label input ═══════════════════════════════════════════
lab/LabelInput.tsx. Positioned at the root for the canvas
halo — see the note on .gen. */
.lbi {
position: relative;
font-family: var(--font-ui);
display: grid;
place-items: center;
/* room above the field for the lifted label */
padding-top: 12px;}
/* no fill: the field is only its outline */
.lbi-box {
position: relative;
background: transparent;
cursor: text;}
/* ── the outline ────────────────────────────────────────────
Always whole. At rest a hairline of grey; focused, the ink
at a hair heavier; left filled, a grey a step darker than
rest. The gap across the top is the only part that moves. */
.lbi-ring {
position: absolute;
inset: 0;
overflow: visible;
pointer-events: none;}
.lbi-ring path {
fill: none;
stroke: color-mix(in srgb, var(--fill-on, #17181a) 32%, var(--fill-slab, #ffffff));
stroke-width: 1;
stroke-linecap: butt;
transition: stroke 220ms ease, stroke-width 220ms ease;}
.lbi[data-focus="true"] .lbi-ring path {
stroke: var(--ink);
stroke-width: 1.5;}
.lbi[data-filled="true"]:not([data-focus="true"]) .lbi-ring path {
stroke: color-mix(in srgb, var(--fill-on, #17181a) 32%, var(--fill-slab, #ffffff));}
/* the gap: whole at rest, parting from its middle when the
label lifts. The dash is longer than the path so offset 0
is the whole line and -1 is none of it. */
.lbi-gap {
stroke-dasharray: 1 2;
stroke-dashoffset: 0;
transition: stroke 220ms ease, stroke-width 220ms ease,
stroke-dashoffset 420ms cubic-bezier(0.22, 1, 0.36, 1);}
.lbi[data-up="true"] .lbi-gap { stroke-dashoffset: -1; }
/* ── the label ──────────────────────────────────────────────
Its placeholder self in the middle of the field, and its
lifted self centred on the top edge — the second is the
first moved up by half the field and scaled from its left. */
.lbi-label {
position: absolute;
left: var(--lbi-x);
top: 50%;
font-size: 16px;
line-height: 1;
letter-spacing: -0.01em;
white-space: pre;
color: var(--ink-4);
transform-origin: left center;
transform: translateY(-50%);
transition: transform 420ms cubic-bezier(0.22, 1, 0.36, 1), color 220ms ease;
cursor: text;
-webkit-user-select: none;
user-select: none;}
.lbi[data-up="true"] .lbi-label {
transform: translateY(-50%) translateY(-26px) scale(0.78);
color: var(--ink-3);}
.lbi[data-focus="true"] .lbi-label { color: var(--fill-on, var(--ink)); }
.lbi-label span { display: inline-block; }
/* the hop: each letter lifts a hair and settles, one after the
next, so the word ripples as it rises */
.lbi[data-focus="true"] .lbi-label span {
animation: lbi-hop 460ms cubic-bezier(0.3, 0.7, 0.3, 1) both;
animation-delay: calc(var(--i) * 24ms);}
.lbi-field {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
padding: 0 0 0 var(--lbi-x);
border: 0;
border-radius: inherit;
background: transparent;
font: inherit;
font-size: 16px;
letter-spacing: -0.01em;
color: var(--fill-on, var(--ink));
outline: none;}
/* the reveal: the text passes through a soft blur rather than
snapping between dots and letters. Two names so a second
press restarts it. */
.lbi-field[data-flip="1"] { animation: lbi-flip-a 260ms ease-out; }
.lbi-field[data-flip="0"] { animation: lbi-flip-b 260ms ease-out; }
.lbi-eye {
position: absolute;
right: 10px;
top: 50%;
width: 30px;
height: 30px;
margin-top: -15px;
display: grid;
place-items: center;
padding: 0;
border: 0;
border-radius: 999px;
background: transparent;
color: var(--ink-4);
cursor: pointer;
transition: color 160ms ease, scale 160ms cubic-bezier(0.22, 1, 0.36, 1);}
.lbi-eye:hover { color: var(--fill-on, var(--ink)); }
.lbi-eye:active { scale: 0.96; }
/* the two icons in one place, trading places */
.lbi-eye svg {
grid-area: 1 / 1;
transition: opacity 220ms ease, scale 220ms cubic-bezier(0.22, 1, 0.36, 1), filter 220ms ease;}
.lbi-eye svg:last-child { opacity: 0; scale: 0.7; filter: blur(2px); }
.lbi-eye[data-show="true"] svg:first-child { opacity: 0; scale: 0.7; filter: blur(2px); }
.lbi-eye[data-show="true"] svg:last-child { opacity: 1; scale: 1; filter: none; }
@media (prefers-reduced-motion: reduce) {
.lbi-ring path,
.lbi-gap,
.lbi-label { transition-duration: 160ms; }
}
@media (prefers-reduced-motion: reduce) {
.lbi[data-focus="true"] .lbi-label span,
.lbi-field { animation: none; }
}
@keyframes lbi-hop {
0% { transform: translateY(0); }
38% { transform: translateY(-3px); }
100% { transform: translateY(0); }}
@keyframes lbi-flip-a { from { filter: blur(3px); opacity: 0.5; } }
@keyframes lbi-flip-b { from { filter: blur(3px); opacity: 0.5; } }
// bencho source (MIT). npm i @tabler/icons-react motion react · Tailwind CSS v4
// ── blocks/label-input/LabelInput.tsx (https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/label-input/LabelInput.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 { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
import { IconEye as Eye, IconEyeOff as EyeOff } from "@tabler/icons-react";
/* ══ Label input ══════════════════════════════════════════
A field whose label is its placeholder until you are in it.
On focus the label lifts into the top edge with a small hop
running along its letters, the outline darkens in place, and
the top line parts under the label from its middle outward.
── ONE THING MOVES ─────────────────────────────────────
It used to DRAW its outline out of the notch, both ways
round the field — and that was the field performing, which
is too much for a thing you focus forty times a day. Now the
outline is always whole; focus only changes its ink and
opens the gap. The label is the event, and the line makes
room for it.
The gap is two short paths across the notch, each from the
middle to one side, retracted from the middle outward by a
negative dash offset. */
const clamp = (v: number, a: number, b: number) => Math.min(b, Math.max(a, v));
const W = 280;
const H = 52;
/* the lifted label's size, against its resting one */
const S = 0.78;
/* the stroke sits half a stroke inside the box so none of it
is clipped by the svg's own edge */
const IN = 0.75;
export function LabelInput({
field = "Email",
/* the field's corner, px — at half the height it is a pill */
corner = 20,
/* a showcase, not a form: on a touch screen, keep the device's
keyboard down. Off by default — a real field wants its
keyboard — and the bench turns it on for its feed */
showcase = false,
}: {
field?: string;
corner?: number;
showcase?: boolean;
} = {}) {
const r = clamp(corner, 0, H / 2);
const secret = field === "Password";
const label = secret ? "Password" : "Email";
const id = `lbi-${useId().replace(/:/g, "")}`;
const [focus, setFocus] = useState(false);
const [quiet] = useState(() => showcase && typeof window !== "undefined" && window.matchMedia("(pointer: coarse)").matches);
const [value, setValue] = useState("");
const [show, setShow] = useState(false);
const [flip, setFlip] = useState(0);
const input = useRef<HTMLInputElement | null>(null);
/* the notch is the label's own width, so it is measured */
const lab = useRef<HTMLLabelElement | null>(null);
const [lw, setLw] = useState(40);
useLayoutEffect(() => {
if (lab.current) setLw(lab.current.offsetWidth);
}, [label]);
/* a different kind of field starts empty — an email left in
a password box would be shown in the clear */
useEffect(() => {
setValue("");
setShow(false);
}, [field]);
const up = focus || value.length > 0;
/* ── where the label sits, and the gap it leaves ─────────
Never inside the corner's curve: the notch has to open on
the straight part of the top edge, so a rounder field
starts its label further in. */
const lx = Math.max(14, r + 4);
const x0 = Math.max(r * 0.6, lx - 5);
const x1 = lx + lw * S + 5;
const a = r - IN;
const R = W - IN;
const B = H - IN;
const mid = W / 2;
/* the gap, as two halves from its middle to each side */
const nm = (x0 + x1) / 2;
const gapL = `M${nm},${IN} L${x0},${IN}`;
const gapR = `M${nm},${IN} L${x1},${IN}`;
/* right: from the notch, clockwise, to the bottom middle */
const right = r > 0
? `M${x1},${IN} L${W - r},${IN} A${a},${a} 0 0 1 ${R},${r} L${R},${H - r} A${a},${a} 0 0 1 ${W - r},${B} L${mid},${B}`
: `M${x1},${IN} L${R},${IN} L${R},${B} L${mid},${B}`;
/* left: from the notch, the other way round, to the same point */
const left = r > 0
? `M${x0},${IN} L${r},${IN} A${a},${a} 0 0 0 ${IN},${r} L${IN},${H - r} A${a},${a} 0 0 0 ${r},${B} L${mid},${B}`
: `M${x0},${IN} L${IN},${IN} L${IN},${B} L${mid},${B}`;
const reveal = () => {
setShow((s) => !s);
setFlip((f) => f + 1);
};
return (
<div className="lbi" data-up={up} data-focus={focus} data-filled={value.length > 0}>
<div
className="lbi-box"
style={{ width: W, height: H, borderRadius: r, "--lbi-x": `${lx}px` } as React.CSSProperties}
>
<svg className="lbi-ring" width={W} height={H} viewBox={`0 0 ${W} ${H}`} aria-hidden="true">
<path d={right} />
<path d={left} />
<path className="lbi-gap" d={gapL} pathLength={1} />
<path className="lbi-gap" d={gapR} pathLength={1} />
</svg>
<label className="lbi-label" htmlFor={id} ref={lab}>
{[...label].map((ch, i) => (
<span key={i} style={{ "--i": i } as React.CSSProperties}>{ch}</span>
))}
</label>
<input
ref={input}
id={id}
className="lbi-field"
data-flip={flip % 2}
/* ── no autofill, when it is only being shown ───────
An email or password box is an invitation: the browser
drops its saved addresses under it, a password manager
pins its badge in it, the phone offers a contact. On
the bench it is a preview, not a form, so it is a plain
text field — a hidden password masked by the font
rather than by the type — named so Safari takes it for
a search, and marked off for the managers that read
their own attribute. A real use keeps the real types. */
type={showcase ? "text" : secret && !show ? "password" : secret ? "text" : "email"}
name={showcase ? "search-preview" : undefined}
data-1p-ignore={showcase || undefined}
data-lpignore={showcase ? "true" : undefined}
data-bwignore={showcase || undefined}
data-form-type={showcase ? "other" : undefined}
autoCorrect="off"
autoCapitalize="off"
value={value}
onChange={(e) => setValue(e.target.value)}
onFocus={() => setFocus(true)}
onBlur={() => setFocus(false)}
autoComplete="off"
spellCheck={false}
/* ── no keyboard, when it is only being shown ─────
In a feed you are scrolling on a phone, a tap that
lands on the field threw the keyboard up over the
page. inputMode "none" keeps everything the block is
about — the focus, the label lifting, the gap
opening — and only tells the device not to raise its
keyboard. A mouse and a hardware keyboard are
untouched, and so is any real use of this field. */
inputMode={quiet ? "none" : undefined}
style={{
paddingRight: secret ? 48 : lx,
...(showcase && secret && !show ? { WebkitTextSecurity: "disc" } : {}),
} as React.CSSProperties}
/>
{secret && (
<button
className="lbi-eye"
type="button"
data-show={show}
/* keep focus in the field: the eye is a toggle on
what you are typing, not somewhere to go */
onPointerDown={(e) => e.preventDefault()}
onClick={reveal}
aria-label={show ? "Hide password" : "Show password"}
>
<Eye size={16} strokeWidth={2} aria-hidden="true" />
<EyeOff size={16} strokeWidth={2} aria-hidden="true" />
</button>
)}
</div>
</div>
);
}控制項 · HTML · CSS · JS
直接改程式碼,再用控制項微調,預覽會隨輸入即時更新。

線上編輯每個元件,用控制項微調,下載完整原始碼,複製進階提示詞。
一次性 $49暫定價格
測試模式:不會真的扣款。
免費:預覽、複製按鈕和課程說明。
可見的標籤、安靜的邊框和清楚的焦點狀態引導輸入。
搜尋、登入和短文字欄位。
調高度、邊框顏色和焦點光暈。
把 Bencho (github.com/cabralorenzo/bencho)(MIT)中的「浮動標籤輸入」元件加入我的 React + Tailwind CSS 應用程式。原始檔:https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/label-input/LabelInput.tsx。可見的標籤、安靜的邊框和清楚的焦點狀態引導輸入。 適用情境:搜尋、登入和短文字欄位。 可調參數:調高度、邊框顏色和焦點光暈。 支援淺色與深色主題,遵循 prefers-reduced-motion。保留 MIT 授權聲明。
更完整的提示詞,包含調參、無障礙和接入步驟。