Hiệu năng
Cần chú ýTốc độ khung hình: trung bình 60 fps, p5 59.9 · Tác vụ dài: 0 tác vụ, tổng 0 ms, dài nhất 0 ms · Mã nguồn gzip 11 KB · Khi chạy 284 KB
Create menuMITNútBencho
Component React Nút của Lorenzo Cabra. Được thu thập nguyên vẹn từ Bencho theo giấy phép MIT và hiển thị trực tiếp tại đây.
Báo cáo chất lượng
Xếp loại và điểm số đến từ các kiểm tra tự động lúc dựng hoặc kiểm thử. Nếu một mục chưa chạy, nó được đánh dấu Chưa kiểm tra — không bao giờ bịa số liệu.
Tốc độ khung hình: trung bình 60 fps, p5 59.9 · Tác vụ dài: 0 tác vụ, tổng 0 ms, dài nhất 0 ms · Mã nguồn gzip 11 KB · Khi chạy 284 KB
Vấn đề 0 · Trình đọc màn hình: Cần chú ý
Không có chuyển động liên tục
Không tràn
Số liệu tốc độ khung hình và tác vụ dài được đo trong Chromium không giao diện với WebGL phần mềm. Chúng chỉ nên được so sánh giữa các thành phần trên trang này, và không đại diện cho thiết bị thật.
Không áp dụng: không có hoạt ảnh nào thấy được khi đứng yên. Hoạt ảnh kích hoạt khi di chuột chưa được kiểm tra.
Không có vi phạm axe-core.

Kiểm tra ngày 15 thg 11, 2026 · Số liệu đến từ tập lệnh tự động, không phải mẫu viết tay.
Hiển thị đúng kích thước thật.
Bản sao bắt đầu bằng thông báo giấy phép. Hãy giữ lại khi dùng mã.
<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;
}
}
/* Create.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.
*/
/* the create menu has no ::before to hang it on — its shape
is a blob on a metaball layer — so its ring is a spread
shadow, which is the same mark by another means */
[data-stroke="on"] .crt-body {
box-shadow: 0 0 0 1px var(--pane-edge);}
/* ── 5 · create ──────────────────────────────────────────── */
/* ── back to 244 ────────────────────────────────────────────
The stage, the panel and the rows are the numbers this was
drawn at. They had been shrunk three times chasing a
request that was only ever about the PILL — and shrinking
the panel with it was wrong twice over: the open state is
sized by the four rows it has to hold, so taking it down
crushed the rows, and the stage is sized by the panel plus
the room the blobs need to travel, so taking THAT down left
the metaball nowhere to go.
One number is smaller than it was, and it is the one that
was asked about. */
.crt-stage {
position: relative;
width: 244px; height: 244px;
/* the two states, as two sets of numbers. One attribute
picks between them and everything else follows. */
/* The pill, and only the pill. Its WIDTH is set inline from
the measured label — see Liquid.tsx — so this is the
fallback for the frame before that measurement lands, and
the height is the part that lives here. 46 before. */
--pill-w: 120px;
--pill-h: 38px;
--panel-w: 212px;
--panel-h: 166px; /* four rows and the padding; no header any more */
--w: var(--pill-w);
--h: var(--pill-h);
--r: var(--crt-shut-r, 999px);}
.crt-stage[data-open="true"] {
--w: var(--panel-w);
--h: var(--panel-h);
/* 28 outside against a 10px inset leaves 18 for the rows to
nest in, and a 34px row rounds fully at 17 — so the two
curves are concentric rather than merely both round. The
Corner knob moves all three together; see Liquid.tsx. */
--r: var(--crt-r, 28px);}
/* No metaball filter on this one, and that is the point. The
other studies have two or more shapes that have to fuse;
this has exactly one, so a blur can only damage it — at the
radius the others use, a fifth of this shape's height, the
corners came back bulged and uneven instead of at the
radius they were given. The liquid here is entirely in the
timing. */
.crt-blobs {
position: absolute; inset: 0;
pointer-events: none;}
/* one shape, dead centre, in both states */
/* ── CENTRED BY AUTO MARGINS, and it has been three things ──
A negative margin first, which had to be animated alongside
the size — two axes on different clocks, and the box drifted
34px above centre halfway through the morph.
Then `left: 50%` with `translate(-50%, -50%)`, which fixed
that: a percentage translate is always half of whatever the
box is right now, so there is nothing to keep in step.
And now auto margins, which are self-correcting in the same
way and use NO TRANSFORM AT ALL. That is the whole reason
for the third version. This box is a motion.div whose width
and height Framer writes inline on every frame of the open,
and a CSS transform on a Framer-managed element is the trap
this codebase has hit before — CSS `translate` and `scale`
resolve BEFORE `transform`, and anything the library decides
to write into `transform` takes the centring with it.
Reported on iOS as the menu jumping to one side as it opens,
which is exactly what a lost -50% looks like.
`inset: 0` plus `margin: auto` centres an absolutely
positioned box against its containing block whatever size
the box currently is — no transform to lose, nothing to
animate, and the same answer every frame. */
.crt-body {
position: absolute;
inset: 0;
margin: auto;
width: var(--w); height: var(--h);
border-radius: var(--r);
background: var(--slab);
/* No shadow. It had four stacked ones, added when this
became a white panel on the argument that a white panel on
a white page has no edge — which was true, and was still
the wrong fix: it made the menu read as a card lifted off
the page rather than as the page opening up. Stroke is the
way to give it an edge now, and it is off by default. */
/* One move: width, height and the corner all run the same
curve for the same time. Staggering the axes made the
open read as two animations queued up rather than one
thing changing size.
And no overshoot. A spring past the target takes the
corner radius with it — the corners dipped under 28 and
came back, which is a wobble, not a bounce. This curve is
quick off the mark and lands without ever passing the
number it is going to. */
/* width, height and the corner are Framer's now; `scale` stays
here because the press beat is a discrete state, not a value
being interpolated from JS. */
transition: scale 420ms cubic-bezier(0.22, 1, 0.36, 1);}
/* The first beat: pressed down. A plain uniform shrink — the
button gets smaller, nothing squashes and nothing spreads.
In fast, because a press should be felt at once and not
eased into. */
.crt-stage[data-sink="true"] .crt-body,
.crt-stage[data-sink="true"] .crt-pill {
scale: 0.94;
/* 120 against a 95ms handoff: the spread starts while this
is still running, so there is never a frame where nothing
is moving */
transition: scale 160ms cubic-bezier(0.22, 1, 0.36, 1);}
/* and closing is the same single move, run down */
.crt-stage:not([data-open="true"]) .crt-body {
transition: scale 220ms cubic-bezier(0.22, 1, 0.36, 1);}
/* ── a panel, not a slab of ink ───────────────────────────
`--slab` is redefined for this component rather than
changed at the root, because exactly two things read it and
the other is the overlay's Copy button — a primary action
that should stay filled.
On the STAGE, not on the body. The shape and the type are
deliberately two layers here — opaque blobs on a filtered
one, text riding above on an unfiltered one — and they are
siblings, so tokens set on the body reach the fill and
none of the words. The stage is the first element that is
an ancestor of both.
`--board` and `--ink` both flip with the theme, so one
definition covers both: white with dark type in light,
#212429 with light type in dark — which is what dark
already had. Only the light theme changes. */
.crt-stage {
/* the fill layer first, and what this was before it as the
fallback — so Auto is genuinely unchanged rather than a
third value that happens to look similar */
--slab: var(--fill-slab, var(--board));
--on-slab: var(--fill-on, var(--ink));
--on-slab-rgb: var(--fill-on-rgb, var(--ink-rgb));}
.crt-ink { position: absolute; inset: 0; }
/* the pill. It does not move aside, it is simply not there
once the shape has spread. */
/* the same auto-margin centring as .crt-body above, and for
the second reason given there: three boxes stacked on one
stage, centred by two different mechanisms, can round a
sub-pixel apart. One mechanism, one answer. */
.crt-pill {
position: absolute;
inset: 0;
margin: auto;
width: var(--pill-w); height: var(--pill-h);
display: flex; align-items: center; justify-content: center; gap: 8px;
border: 0; background: none;
color: var(--on-slab);
font-family: var(--font-ui);
font-size: 13px;
cursor: pointer;
transition:
width 420ms cubic-bezier(0.22, 1, 0.36, 1),
opacity 160ms ease,
scale 420ms cubic-bezier(0.22, 1, 0.36, 1);
letter-spacing: 0em;}
.crt-stage[data-open="true"] .crt-pill {
opacity: 0;
pointer-events: none;
transition: opacity 160ms ease;}
/* held at full strength through the press: fading it during
the squash would hide the beat that the squash is for */
.crt-stage[data-sink="true"] .crt-pill { opacity: 1; }
.crt-glyph { display: grid; place-items: center; }
/* the pill takes the width of whatever it is saying, so the
label can change without it jumping */
.crt-say {
display: block;
overflow: hidden;
white-space: nowrap;
text-align: left;
transition: width 420ms cubic-bezier(0.22, 1, 0.36, 1);}
/* inline-block so it has an offsetWidth to be measured by */
.crt-say > span { display: inline-block; }
/* the window, in the same place */
.crt-panel {
position: absolute;
inset: 0;
margin: auto;
width: var(--panel-w); height: var(--panel-h);
padding: 12px 12px;
color: var(--on-slab);
pointer-events: none;}
.crt-stage[data-open="true"] .crt-panel { pointer-events: auto; }
.crt-menu {
margin: 0; padding: 0;
list-style: none;
display: grid; align-content: start; gap: 2px;}
.crt-item {
opacity: 0;
transform: translateY(6px);
/* the same curve as the shell, and no overshoot either: a
row that slides past its resting line and comes back is
the same wobble at a smaller size. Shortened with it —
320ms of travel on a box that lands in 180 left the rows
still moving after the shape had stopped. */
transition: opacity 160ms ease, transform 220ms cubic-bezier(0.22, 1, 0.36, 1);}
.crt-stage[data-open="true"] .crt-item { opacity: 1; transform: none; }
.crt-item button {
position: relative;
width: 100%;
display: flex; align-items: center; gap: 12px;
height: 34px; padding: 0 16px;
/* fully round, so a row nests inside the card's own corners
instead of squaring off against them */
border: 0; border-radius: var(--crt-row-r, 999px);
background: none;
/* 0.78, not the 0.72 this carried when the slab was dark.
The same fraction is not the same contrast once the ink
and the ground swap ends: light type at 0.72 on near
black measured comfortably, dark type at 0.72 on white
lands at 4.6:1 — over the line but only just, and this is
the menu's only body text. */
color: rgba(var(--on-slab-rgb), 0.78);
font-family: var(--font-ui);
font-size: 13px;
text-align: left;
cursor: pointer;
transition: color 220ms ease;
letter-spacing: 0em;}
.crt-item button:hover { color: var(--on-slab); }
/* ── the hover wash, one per row ───────────────────────────
It was one pill that travelled between rows and stretched
on the way. Each row now fades its own in and out; nothing
moves between them. */
.crt-item button::before {
content: "";
position: absolute;
inset: 0;
z-index: -1;
border-radius: inherit;
background: rgba(var(--on-slab-rgb), 0.08);
opacity: 0;
transition: opacity 220ms ease;
pointer-events: none;}
@media (hover: hover) {
.crt-item button:hover::before { opacity: 1; transition-duration: 160ms; }
}
.crt-item button:focus-visible::before { opacity: 1; }
/* the wash sits behind the label, inside its own row */
.crt-item button { isolation: isolate; }
@media (prefers-reduced-motion: reduce) {
.crt-body, .crt-pill, .crt-item, .crt-say { transition-duration: 160ms; }
}
@media (prefers-reduced-motion: reduce) {
.crt-stage[data-sink="true"] .crt-body,
.crt-stage[data-sink="true"] .crt-pill { scale: 1; }
}
// bencho source (MIT). npm i @tabler/icons-react motion react · Tailwind CSS v4
// ── blocks/liq-create/Create.tsx (https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/liq-create/Create.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, useLayoutEffect, useRef, useState } from "react";
import { motion } from "motion/react";
import { IconFileText as FileText, IconFolder as Folder, IconGrid4x4 as Grid2x2, IconPlus as Plus, IconTable as Table2 } from "@tabler/icons-react";
/* ══ Liquid ═══════════════════════════════════════════════
Three metaball studies: a toggle, a reorderable list, and
a create menu.
RECONSTRUCTED. The original file was destroyed; this is
rebuilt against the surviving stylesheet, which specifies
the geometry, the layering and the timing exactly. The
behaviour matches what index.css and the catalog demos
require. The original's internal reasoning is not
recoverable and is not reproduced here.
── the shared constraint ───────────────────────────────
Everything on a filtered layer must be OPAQUE. The goo
filter thresholds alpha, so a translucent fill under it
disappears. That is why each of these has two layers: an
opaque blob layer that carries the filter, and an unfiltered
layer above it carrying the text — antialiased type would
be eaten by the same threshold. */
/* ── inlined from lab/motionkit ──────────────────────── */
/* ══ liquid ═══════════════════════════════════════════════
Shared parts for the Framer Motion layer: one spring, one
goo filter, one velocity→skew binding.
── why the filter is a hook ────────────────────────────
The filter is embedded in each component's own return, but
its id CANNOT be a literal. Every block here renders twice
at once — once in the wall card, once in the detail overlay
— and duplicate SVG ids do not scope, they collide: the
second instance silently steals the first one's filter.
useId() gives each mount its own name.
── what the goo can and cannot do ──────────────────────
This is feGaussianBlur + feColorMatrix, not a shader. The
matrix multiplies alpha by `cut` and subtracts half of it,
so alpha below 0.5 lands on zero and everything above 0.536
is fully opaque. That hard edge is what fuses nearby shapes
into one blob — and it is also why this must never touch
text: glyph antialiasing lives entirely below 0.5, so type
under this filter loses its edges and then itself. */
/* the elastic, as specified: ζ = 14 / (2·√(220·0.5)) ≈ 0.67,
so it overshoots about 6% before it settles. A deliberate
bounce, not a wobble. */
const LIQUID = {
type: "spring" as const,
stiffness: 220,
damping: 14,
mass: 0.5,
};
/* Non-drag blocks reuse the same feel without the overshoot,
so a toggle does not bounce like a dragged card. */
/* ── the same liquid, without the overshoot ────────────────
For shapes whose corner radius is animating: a spring that
passes its target drags the radius past it too, and corners
that dip under and come back read as a wobble rather than
as a bounce.
NOT just LIQUID with more damping, which is what this was.
Raising damping alone to 30 against the same stiffness put
ζ at 1.43 — comfortably overdamped, so it stopped
overshooting by creeping: about 470ms to settle, against
LIQUID's 290ms. It read as slow because it was.
Stiffness comes up with the damping instead, which holds ζ
at 1.03 — no overshoot, and it lands in about 180ms. */
const LIQUID_STILL = { ...LIQUID, stiffness: 420, damping: 30 };
const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));
/* ══ 3 · Create ═══════════════════════════════════════════
One shape, and no filter on it — the other studies fuse two
or more shapes, this has exactly one, so a blur could only
damage it. The liquid here is entirely in the timing: the
press sinks, and the spread starts while the sink is still
running so there is never a still frame.
The pill's width is measured from its own label and written
back as --pill-w, so the label can change without the shape
jumping. */
const ITEMS = [
{ icon: FileText, label: "Document" },
{ icon: Table2, label: "Spreadsheet" },
{ icon: Grid2x2, label: "Board" },
{ icon: Folder, label: "Folder" },
];
/* ── the menu's corners, and there are three ───────────────
The panel is 28, the rows inside it are cut to 28 less the
10px inset — concentric, which is what makes a row look like
it belongs in the panel rather than merely sitting in one —
and the shut pill is a 38px button, so 19 is round for it.
One knob moves all three because they are one relationship:
turn it down and the panel, the pill and the rows square off
together. Each is capped at half its own height, past which
a bigger number draws the same shape. */
const CRT_CORNER = 20;
const CRT_MAX = 40;
export function Create({ corner = CRT_CORNER }: { corner?: number } = {}) {
const [open, setOpen] = useState(false);
const [sink, setSink] = useState(false);
const panel = useRef<HTMLDivElement | null>(null);
const say = useRef<HTMLSpanElement | null>(null);
const beat = useRef(0);
const [sayW, setSayW] = useState(96);
/* ── MEASURE TWICE: ONCE NOW, ONCE THE FONT IS REAL ────────
.crt-say clips whatever it cannot fit, so this width being
even slightly short takes the right edge off the last
letter — and it was short two different ways.
The rounding: offsetWidth is an integer and the label is
not. "Create" measures 42.46 and comes back 42. The +1 is
the fix; the error is always under a pixel so a pixel
always covers it, and the pill is centred on the label so
the spare costs nothing.
The race, which is the one that made it intermittent: a
layout effect runs before a webfont has swapped in, so on
a cold cache this measured "Create" in the FALLBACK face
and then froze that number for good. Warm cache measured
Inter and looked fine — same code, different result, which
is why it only cut the word sometimes. So measure again
when the fonts are actually ready. */
useLayoutEffect(() => {
const el = say.current;
if (!el) return;
let live = true;
const measure = () => { if (live) setSayW(el.offsetWidth + 1); };
measure();
document.fonts?.ready.then(measure).catch(() => {});
return () => { live = false; };
}, []);
useEffect(() => () => {
window.clearTimeout(beat.current);
}, []);
/* No close button and no title bar — anywhere but the menu
puts it away. Registered only while it is open, and in an
effect, so the very press that opened it cannot close it
on the same click. */
useEffect(() => {
if (!open) return;
const away = (e: PointerEvent) => {
/* ── a press by SOMEBODY, not by the page ─────────────
This listens on the document, so it hears every press
anywhere — including the ones other components'
demonstrations dispatch at themselves. One component
performing is harmless; several at once are not. On a
page showing six of them side by side this menu was
opened by its own demonstration and then slammed shut
a moment later by a neighbour's, and the rest of its
script went on clicking a row that was no longer
there.
"Anywhere but the menu puts it away" was always about
a person reaching past it. A scripted press on another
component is not somebody deciding to leave. */
if (!e.isTrusted) return;
/* ── ASK THE VISIBLE BOX, NOT THE RESERVED ONE ───────
This used to be panel.current.contains(target), and
`panel` is the STAGE — the square this block reserves
so that opening the menu does not resize the card
under it. The stage is 305x305; the menu it holds is
265x208. Everything in between is stage, so every
press in it counted as a press on the menu and did
nothing: measured at 48px of dead ground above the
panel and 49 below, which is why closing it meant
clicking well clear of the block rather than just off
the menu.
Hit-tested against the panel's own rectangle instead.
Geometry rather than containment, because the thing
that must be hit is smaller than the element the ref
points at and there is no node covering only it — the
liquid body is painted, not laid out.
The rect is read per press rather than kept, since it
is a different size on every frame of the open. */
const box = panel.current
?.querySelector(".crt-panel")
?.getBoundingClientRect();
const on =
!!box &&
e.clientX >= box.left && e.clientX <= box.right &&
e.clientY >= box.top && e.clientY <= box.bottom;
if (!on) {
setOpen(false);
}
};
document.addEventListener("pointerdown", away);
return () => document.removeEventListener("pointerdown", away);
}, [open]);
const press = () => {
setSink(true);
window.clearTimeout(beat.current);
/* 60ms handoff against a 120ms sink: the spread begins
while the press is still running. It was 95, which is
most of the sink — long enough to read as a pause before
anything opened. */
beat.current = window.setTimeout(() => {
setSink(false);
setOpen(true);
}, 60);
};
/* glyph + gap + label + the padding either side */
const pillW = 18 + 8 + sayW + 34;
/* the two the animation needs as NUMBERS — Framer writes
borderRadius inline, so it cannot read a css variable */
const panelR = clamp(corner, 0, CRT_MAX);
const shutR = Math.min(19, panelR * (19 / CRT_CORNER));
return (
<motion.div
className="crt-stage"
data-open={open || undefined}
data-sink={sink || undefined}
ref={panel}
style={{
"--pill-w": `${pillW}px`,
"--crt-r": `${clamp(corner, 0, CRT_MAX)}px`,
/* the shut pill is 38 tall, so 19 is as round as it goes */
"--crt-shut-r": `${Math.min(19, clamp(corner, 0, CRT_MAX) * (19 / CRT_CORNER)).toFixed(2)}px`,
/* concentric: the panel's corner less its 10px inset,
and no rounder than the 34px row's own half */
"--crt-row-r": `${Math.min(17, Math.max(0, clamp(corner, 0, CRT_MAX) - 10)).toFixed(2)}px`,
} as React.CSSProperties}
>
<div className="crt-blobs" aria-hidden="true">
{/* LIQUID_STILL, not LIQUID. A spring past the target
takes the corner radius with it — the corners dip
under 28 and come back, which is a wobble, not a
bounce. This is the one shape here that must not
overshoot. */}
<motion.div
className="crt-body"
animate={{
width: open ? 212 : pillW,
height: open ? 166 : 38,
/* ── from the knob, not from two literals ──────
Framer writes this inline every frame, so the
stylesheet's `var(--r)` on .crt-body never gets
a look in — the CSS variables set on the stage
reach the ROWS, and this shape has to be told
separately. Same two numbers the vars carry:
the panel's own corner, and a 38px pill's half
when it is shut. */
borderRadius: open ? panelR : shutR,
}}
transition={LIQUID_STILL}
/>
</div>
<button className="crt-pill" onClick={press} aria-expanded={open}>
<span className="crt-glyph" aria-hidden="true">
<Plus size={16} strokeWidth={2} />
</span>
<span className="crt-say" style={{ width: sayW || undefined }}>
<span ref={say}>Create</span>
</span>
</button>
<div className="crt-panel">
{/* each row lights its own wash — see .crt-item button::before;
nothing travels between them */}
<ul className="crt-menu">
{ITEMS.map((it, i) => (
<li
className="crt-item"
key={it.label}
/* tightened with the shell. The last row used to
start at 162ms — after a box that now finishes
in 180 — so the menu kept arriving for half a
second after it had opened. */
style={{ transitionDelay: open ? `${30 + i * 22}ms` : "0ms" }}
>
<button
onClick={() => { setOpen(false); }}
>
<it.icon size={16} strokeWidth={2} />
{it.label}
</button>
</li>
))}
</ul>
</div>
</motion.div>
);
}Điều khiển · HTML · CSS · JS
Sửa mã và tinh chỉnh bằng các nút điều khiển. Bản xem trước cập nhật khi bạn gõ.

Thành phần này chạy từ bản đóng gói nên mã script chỉ xem được ở đây. Hãy sửa HTML và CSS; mã nguồn đầy đủ nằm trong thẻ Mã.
Sửa trực tiếp mọi thành phần, tinh chỉnh bằng nút điều khiển, tải mã nguồn đầy đủ và sao chép prompt nâng cao.
$49 một lầnGiá tạm thời
Chế độ thử: không thu tiền thật.
Miễn phí: xem trước, nút sao chép và ghi chú bài học.
Hình dạng rõ, một màu mạnh và phản hồi nhấn ngắn tạo cảm giác như vật thật.
Thao tác chính, lời kêu gọi hành động và thanh công cụ.
Đổi độ bo góc, khoảng đệm và thời gian chuyển khi rê chuột.
Thêm component "Create menu" từ Bencho (github.com/cabralorenzo/bencho) (MIT) vào ứng dụng React + Tailwind CSS của tôi. Tệp nguồn: https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/liq-create/Create.tsx. Hình dạng rõ, một màu mạnh và phản hồi nhấn ngắn tạo cảm giác như vật thật. Dùng cho: Thao tác chính, lời kêu gọi hành động và thanh công cụ. Các thiết lập cần chỉnh: Đổi độ bo góc, khoảng đệm và thời gian chuyển khi rê chuột. Hỗ trợ giao diện sáng và tối, tôn trọng prefers-reduced-motion. Giữ thông báo giấy phép MIT.
Prompt dài hơn, có các bước tinh chỉnh, trợ năng và tích hợp.