性能
需注意帧率: 平均 60 fps,p5 59.5 · 长任务: 0 个,共 0 毫秒,最长 0 毫秒 · 源码 gzip 11 KB · 运行时 289 KB
Asset swapMIT卡片Bencho
由 Lorenzo Cabra 制作的卡片 React 组件。依据 MIT 许可从 Bencho 原样收录,此处为实时预览。
质量报告
等级和分数来自构建或测试时跑过的自动检查。没跑过的项目会标成「未检测」,不会填假数据。
帧率: 平均 60 fps,p5 59.5 · 长任务: 0 个,共 0 毫秒,最长 0 毫秒 · 源码 gzip 11 KB · 运行时 289 KB
问题 2 · 读屏: 需注意
没有持续动效
无溢出
帧率和长任务是在无界面的 Chromium 里用软件 WebGL 测的,只适合在本站组件之间比较,不代表真机表现。
不适用:静止时没有可见动画;由悬停触发的动画没有测试。

检测于 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;
}
}
/* Swap.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.
*/
/* ══ Asset swap ════════════════════════════════════════════ */
.swp {
position: relative;
font-family: var(--font-ui);
color: var(--fill-on, var(--ink));
overflow: hidden;
border-radius: var(--swp-r);}
.swp-card {
position: absolute;
left: 0;
right: 0;
height: 116px;
z-index: 1;
overflow: hidden;
border-radius: var(--swp-r);
background: var(--fill-slab, var(--card));}
/* the slab that is open, or still shrinking home, is above the
other slab and the arrow */
.swp-card[data-lifted] { z-index: 3; }
/* what a slab shows, at the slab's resting height whatever the
slab is doing: amount and fiat low on the left, the label and
the coin pinned to the corners */
.swp-face {
position: absolute;
left: 0;
right: 0;
height: 116px;
display: flex;
flex-direction: column;
justify-content: flex-end;
padding: 0 20px 16px;}
[data-stroke="on"] .swp-card { box-shadow: inset 0 0 0 1px var(--pane-edge); }
.swp-label {
position: absolute;
top: 16px;
left: 18px;
font-size: 12px;
font-weight: 400;
color: color-mix(in srgb, var(--fill-on, #17181a) 32%, var(--fill-slab, #ffffff));
letter-spacing: 0em;}
.swp-amount {
font-size: 20px;
font-weight: 500;
letter-spacing: -0.02em;
line-height: 1.1;
margin-bottom: 4px;
font-variant-numeric: tabular-nums;
white-space: nowrap;}
.swp-fiat {
font-size: 12px;
color: color-mix(in srgb, var(--fill-on, #17181a) 52%, var(--fill-slab, #ffffff));
font-variant-numeric: tabular-nums;
letter-spacing: 0em;}
/* the coin sits in the slab's bottom-right corner */
.swp-coin {
position: absolute;
right: 14px;
bottom: 14px;
display: inline-flex;
align-items: center;
gap: 8px;
height: 30px;
padding: 0 12px 0 4px;
border-radius: 999px;
background: color-mix(in srgb, var(--fill-on, #17181a) 6%, transparent);
font-size: 13px;
font-weight: 500;
/* a button now: it opens the picker */
border: 0;
margin: 0;
color: inherit;
font-family: inherit;
cursor: pointer;
transition: background 160ms ease, scale 160ms ease;
-webkit-tap-highlight-color: transparent;
letter-spacing: 0em;}
.swp-coin:hover { background: color-mix(in srgb, var(--fill-on, #17181a) 12%, transparent); }
/* on the dark fill 6% of white barely separates from the slab, so
the pill takes more of it there */
[data-fill="dark"] .swp-coin { background: color-mix(in srgb, var(--fill-on, #17181a) 12%, transparent); }
[data-fill="dark"] .swp-coin:hover { background: color-mix(in srgb, var(--fill-on, #17181a) 12%, transparent); }
.swp-coin:active { scale: 0.96; }
.swp-coin:focus-visible { outline: 2px solid var(--pick); outline-offset: 2px; }
.swp-logo { display: block; flex: none; }
/* on the seam, floating over both slabs */
.swp-flip {
position: absolute;
z-index: 2;
left: 50%;
top: 117.5px; /* the middle of the gap */
width: 40px;
height: 40px;
margin: -20px 0 0 -20px;
display: grid;
place-items: center;
border: 0;
padding: 0;
cursor: pointer;
color: var(--fill-on, var(--ink));
/* no shadow: a step darker than the slabs is what sets it apart */
background: color-mix(in srgb, var(--fill-on, var(--ink)) 7%, var(--fill-slab, var(--card)));
-webkit-tap-highlight-color: transparent;}
[data-stroke="on"] .swp-flip { box-shadow: inset 0 0 0 1px var(--pane-edge); }
.swp-flip:focus-visible { outline: 2px solid var(--pick); outline-offset: 2px; }
.swp-pick-in {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
height: 100%;
gap: 2px;
padding: 8px 12px 12px;}
.swp-pick-head {
display: flex;
align-items: center;
justify-content: space-between;
height: 32px;
padding-left: 12px;
margin-bottom: 2px;
font-size: 12px;
font-weight: 400;
color: color-mix(in srgb, var(--fill-on, #17181a) 52%, var(--fill-slab, #ffffff));
letter-spacing: 0em;}
.swp-pick-x {
display: grid;
place-items: center;
width: 30px;
height: 30px;
border: 0;
padding: 0;
border-radius: 50%;
background: transparent;
/* a solid grey, mixed from the fill's own ink and slab, rather
than a translucent ink — nothing shows through it */
color: color-mix(in srgb, var(--fill-on, var(--ink)) 50%, var(--fill-slab, var(--card)));
cursor: pointer;}
.swp-pick-x:hover { background: color-mix(in srgb, var(--fill-on, #17181a) 6%, transparent); color: var(--fill-on, var(--ink)); }
.swp-pick-row {
display: flex;
align-items: center;
gap: 12px;
flex: 1;
min-height: 0;
padding: 0 12px;
border: 0;
border-radius: 10px;
background: transparent;
color: inherit;
font-family: inherit;
text-align: left;
cursor: pointer;
-webkit-tap-highlight-color: transparent;}
.swp-pick-row:hover { background: color-mix(in srgb, var(--fill-on, #17181a) 6%, transparent); }
.swp-pick-row:focus-visible { outline: 2px solid var(--pick); outline-offset: -2px; }
.swp-pick-sym { font-size: 14px; font-weight: 500; letter-spacing: -0.01em; }
.swp-pick-name { font-size: 13px; color: color-mix(in srgb, var(--fill-on, #17181a) 52%, var(--fill-slab, #ffffff)); letter-spacing: 0em; }
.swp-pick-on { margin-left: auto; }
// bencho source (MIT). npm i @tabler/icons-react motion react · Tailwind CSS v4
// ── blocks/asset-swap/Swap.tsx (https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/asset-swap/Swap.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 { type ReactNode, useEffect, useState } from "react";
import { AnimatePresence, motion } from "motion/react";
import { IconArrowDown as ArrowDown, IconCheck as Check, IconX as X } from "@tabler/icons-react";
/* ══ Asset swap ═══════════════════════════════════════════
Two rounded slabs, one over the other, each holding a coin and
an amount, and an arrow on the seam saying which way the swap
goes. Press the arrow and it turns to point the other way.
The slabs and the coins in them stay exactly where they are:
only the direction changes, and the labels with it — whichever
slab the arrow leaves is "You pay", the one it points at is
"You receive".
── THE ARROW KEEPS TURNING ONE WAY ──────────────────────
Half a turn every press, counted up rather than flipped
between 0 and 180, so the second press carries on round
instead of unwinding back the way it came.
── THE SLAB IS THE PICKER ───────────────────────────────
Press a coin and the slab it sits in grows — the same element,
its height animated — until it covers the whole block: the top
slab down over the bottom one, the bottom slab up over the top.
Its own face fades out and the list of coins loads inside it;
pick one and it shrinks back to a slab. Nothing is laid over
it and nothing replaces it. Picking
the coin already on the other slab swaps the two, which is
what every exchange does rather than allowing a coin for
itself. */
const W = 300;
const CARD = 116;
const GAP = 3;
const PITCH = CARD + GAP;
const H = CARD * 2 + GAP;
/* THE NUMBERS COME FROM THE COINS. The paying slab holds a round
amount of whatever it is — a lot that is ordinary for that coin,
0.05 BTC, 1.5 ETH, 100 HYPE — and the receiving slab is what that
buys at the two prices, less a 0.3% fee. Change either coin, or
reverse the arrow, and both sides are worked out again. */
const FEE = 0.003;
/* price in dollars, dp the decimals shown, lot the round amount it pays */
type Coin = { sym: string; name: string; price: number; dp: number; lot: number; logo: ReactNode };
/* Every mark is one flat shape on a 32 grid. BTC, ZEC and QNT wear
their own colours (BTC's ₿ and QNT's mark are the CC0 set's
paths); ETH and HYPE are drawn here in a deep shade of their
colour with the mark in a pale tint of it. In order of market
cap, largest first. */
const COINS: Coin[] = [
{
sym: "NTH", name: "North", price: 97700, dp: 5, lot: 0.05,
/* Bitcoin's own orange and white, and its own ₿ (the CC0 set's
path) — turned upright, since the official mark leans 14° */
logo: (
<>
<circle cx="16" cy="16" r="16" fill="#3D5A4A" />
<text x="16" y="20.5" textAnchor="middle" fontSize="9" fontWeight="700" fill="#F3F1EC" fontFamily="ui-sans-serif, system-ui, sans-serif">NTH</text>
</>
),
},
{
sym: "RVR", name: "River", price: 3368.64, dp: 4, lot: 1.5,
logo: (
<>
<circle cx="16" cy="16" r="16" fill="#1B3A4B" />
<text x="16" y="20.5" textAnchor="middle" fontSize="9" fontWeight="700" fill="#E8F1F5" fontFamily="ui-sans-serif, system-ui, sans-serif">RVR</text>
</>
),
},
{
sym: "CDR", name: "Cedar", price: 38.2, dp: 3, lot: 100,
logo: (
<>
<circle cx="16" cy="16" r="16" fill="#3A2E1B" />
<text x="16" y="20.5" textAnchor="middle" fontSize="9" fontWeight="700" fill="#F4EDE0" fontFamily="ui-sans-serif, system-ui, sans-serif">CDR</text>
</>
),
},
{
sym: "QRY", name: "Quarry", price: 52.4, dp: 3, lot: 40,
/* Zcash's own colours: its gold, with the mark in black */
logo: (
<>
<circle cx="16" cy="16" r="16" fill="#4A3A28" />
<text x="16" y="20.5" textAnchor="middle" fontSize="9" fontWeight="700" fill="#F6F0E6" fontFamily="ui-sans-serif, system-ui, sans-serif">QRY</text>
</>
),
},
{
sym: "MDW", name: "Meadow", price: 104.5, dp: 3, lot: 20,
/* Quant's own mark and colours, white on black, from the CC0 set */
logo: (
<>
<circle cx="16" cy="16" r="16" fill="#2C3B2E" />
<text x="16" y="20.5" textAnchor="middle" fontSize="9" fontWeight="700" fill="#EAF2EA" fontFamily="ui-sans-serif, system-ui, sans-serif">MDW</text>
</>
),
},
];
/* ── or money: the same picker over currencies ─────────────
A currency has no logo; what an exchange shows is its country's
flag in a circle, and these are those — the circle-flags set
(MIT, HatScripts). Each is drawn as an image rather than inlined,
because every one of them masks itself with an id of "a", and six
of those in one page would all resolve to the first. In order of
how much each is traded, USD first. */
const FLAG: Record<string, string> = {
USD: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1MTIiIGhlaWdodD0iNTEyIiB2aWV3Qm94PSIwIDAgNTEyIDUxMiI+PG1hc2sgaWQ9ImEiPjxjaXJjbGUgY3g9IjI1NiIgY3k9IjI1NiIgcj0iMjU2IiBmaWxsPSIjZmZmIi8+PC9tYXNrPjxnIG1hc2s9InVybCgjYSkiPjxwYXRoIGZpbGw9IiNlZWUiIGQ9Ik0yNTYgMGgyNTZ2NjRsLTMyIDMyIDMyIDMydjY0bC0zMiAzMiAzMiAzMnY2NGwtMzIgMzIgMzIgMzJ2NjRsLTI1NiAzMkwwIDQ0OHYtNjRsMzItMzItMzItMzJ2LTY0eiI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OEgwdjk2aDIwOHYyMDhoOTZWMzA0aDIwOHYtOTZIMzA0VjBoLTk2em0yNTkgMEwzMzYgMTMxdjQ1TDUxMiAwaC00NXpNMTc2IDMzNiAwIDUxMmg0NWwxMzEtMTMxdi00NXptMTYwIDAgMTc2IDE3NnYtNDVMMzgxIDMzNmgtNDV6Ii8+PC9nPjwvc3ZnPg==",
CAD: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1MTIiIGhlaWdodD0iNTEyIiB2aWV3Qm94PSIwIDAgNTEyIDUxMiI+PG1hc2sgaWQ9ImEiPjxjaXJjbGUgY3g9IjI1NiIgY3k9IjI1NiIgcj0iMjU2IiBmaWxsPSIjZmZmIi8+PC9tYXNrPjxnIG1hc2s9InVybCgjYSkiPjxwYXRoIGZpbGw9IiNkODAwMjciIGQ9Ik0wIDB2NTEyaDE0NGwxMTItNjQgMTEyIDY0aDE0NFYwSDM2OEwyNTYgNjQgMTQ0IDBaIi8+PHBhdGggZmlsbD0iI2VlZSIgZD0iTTE0NCAwaDIyNHY1MTJIMTQ0WiIvPjxwYXRoIGZpbGw9IiNkODAwMjciIGQ9Im0zMDEgMjg5IDQ0LTIyLTIyLTExdi0yMmwtNDUgMjIgMjMtNDRoLTIzbC0yMi0zNC0yMiAzM2gtMjNsMjMgNDUtNDUtMjJ2MjJsLTIyIDExIDQ1IDIyLTEyIDIzaDQ1djMzaDIydi0zM2g0NXoiLz48L2c+PC9zdmc+",
};
const flag = (sym: string) => <image href={FLAG[sym]} width="32" height="32" />;
const MONEY: Coin[] = [
{ sym: "USD", name: "US Dollar", price: 1, dp: 2, lot: 1000, logo: flag("USD") },
{ sym: "EUR", name: "Euro", price: 1.08, dp: 2, lot: 1000, logo: flag("EUR") },
{ sym: "JPY", name: "Japanese Yen", price: 0.0067, dp: 0, lot: 150000, logo: flag("JPY") },
{ sym: "GBP", name: "British Pound", price: 1.27, dp: 2, lot: 1000, logo: flag("GBP") },
{ sym: "CAD", name: "Canadian Dollar", price: 0.73, dp: 2, lot: 1000, logo: flag("CAD") },
];
/* each set, and the pair it opens on */
export const SETS: Record<string, { list: Coin[]; start: [string, string] }> = {
Crypto: { list: COINS, start: ["NTH", "CDR"] },
Currency: { list: MONEY, start: ["USD", "EUR"] },
};
const BY = Object.fromEntries([...COINS, ...MONEY].map((c) => [c.sym, c])) as Record<string, Coin>;
/* money always shows its cents; a coin only the decimals it needs */
const units = (n: number, c: Coin) =>
n.toLocaleString("en-US", { minimumFractionDigits: MONEY.includes(c) ? c.dp : 0, maximumFractionDigits: c.dp });
const usd = (n: number) => n.toLocaleString("en-US", { style: "currency", currency: "USD" });
/* a coin's mark on its own, by symbol: other blocks wear the same
marks (the prediction card's HYPE market) rather than a second copy */
export function CoinMark({ sym, size = 32, className }: { sym: string; size?: number; className?: string }) {
const coin = COINS.find((c) => c.sym === sym);
if (!coin) return null;
return (
<svg className={className} viewBox="0 0 32 32" width={size} height={size} aria-hidden="true">
{coin.logo}
</svg>
);
}
function Logo({ coin, size }: { coin: Coin; size: number }) {
return (
<svg className="swp-logo" viewBox="0 0 32 32" width={size} height={size} aria-hidden="true">
{coin.logo}
</svg>
);
}
export function Swap({
/* what is being swapped: crypto or currencies */
assets = "Crypto",
/* how much the arrow overshoots as it turns, 0..100 */
bounce = 30,
/* the slabs' corner, px */
corner = 20,
}: {
assets?: string;
bounce?: number;
corner?: number;
} = {}) {
/* the coin in each slab, top then bottom */
const set = SETS[assets] ?? SETS.Crypto;
const [coins, setCoins] = useState<[string, string]>(set.start);
/* a new set is a new start: its own pair, the picker shut */
useEffect(() => {
setCoins(set.start);
setPick(null);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [assets]);
/* how many presses so far: even, the arrow points down */
const [turns, setTurns] = useState(0);
/* which slab is open as the picker */
const [pick, setPick] = useState<number | null>(null);
/* which slab is drawn over everything: the open one, and it stays
on top until it has finished shrinking back, or it would slip
under its neighbour halfway home */
const [lifted, setLifted] = useState<number | null>(null);
const up = turns % 2 === 1;
const spring = { type: "spring" as const, duration: 0.6, bounce: (Math.min(100, Math.max(0, bounce)) / 100) * 0.5 };
/* the slab's growth: firm, with only a breath of overshoot */
const grow = { type: "spring" as const, duration: 0.6, bounce: 0.12 };
/* the button's corner follows the slabs', capped at a circle */
const r = Math.min(corner, 20);
const payer = up ? 1 : 0;
/* what each slab reads: the payer its coin's lot, the other what
that lot buys after the fee, each with its own dollar value */
const paid = BY[coins[payer]];
const value = paid.lot * paid.price;
const shown = (i: number) => {
const c = BY[coins[i]];
const v = i === payer ? value : value * (1 - FEE);
return { amount: units(i === payer ? c.lot : v / c.price, c), fiat: usd(v) };
};
const open = (slot: number) => {
setPick(slot);
setLifted(slot);
};
const choose = (sym: string) => {
if (pick === null) return;
const slot = pick, other = 1 - pick;
setCoins((c) => {
const next: [string, string] = [c[0], c[1]];
/* the coin already on the other slab trades places with this one */
if (c[other] === sym) next[other] = c[slot];
next[slot] = sym;
return next;
});
setPick(null);
};
/* Escape shuts the picker */
useEffect(() => {
if (pick === null) return;
const key = (e: KeyboardEvent) => { if (e.key === "Escape") setPick(null); };
window.addEventListener("keydown", key);
return () => window.removeEventListener("keydown", key);
}, [pick]);
return (
<div className="swp" style={{ width: W, height: H, ["--swp-r" as string]: `${corner}px` }}>
{coins.map((sym, i) => {
const coin = BY[sym];
const on = pick === i;
/* the OTHER slab, while this one's neighbour is open */
const squeezed = pick !== null && !on;
/* the slab's role, which the picker keeps as its heading — it
is the same slab, still saying what it is for */
const role = i === payer ? "You pay" : "You receive";
return (
<motion.div
key={i}
className="swp-card"
data-lifted={lifted === i || undefined}
initial={false}
/* THE SLAB IS THE PICKER: the same element, its height
grown to the whole block — down from the top slab, up
from the bottom one */
animate={{
top: on ? 0 : i * PITCH,
height: on ? H : CARD,
/* the neighbour is SQUEEZED: pressed toward its far edge
by the slab growing into it. Flattened on the same
curve that grows the open slab, so its near edge stays
just ahead of the growing one instead of being run
over — it visibly gives, then fades out before it is
flat */
scaleY: squeezed ? 0.02 : 1,
opacity: squeezed ? 0 : 1,
}}
style={{ transformOrigin: i === 0 ? "50% 0%" : "50% 100%" }}
transition={{
default: grow,
/* no overshoot here: past flat a scale turns inside out */
scaleY: { type: "spring", duration: 0.6, bounce: 0 },
opacity: squeezed ? { delay: 0.1, duration: 0.16 } : { delay: 0.06, duration: 0.22 },
}}
/* lowered only when a SHRINK lands: the open finishing can
report in after a close has already started */
onAnimationComplete={(d) => {
if ((d as { height?: number }).height === CARD && pick === null) setLifted((l) => (l === i ? null : l));
}}
role={on ? "dialog" : undefined}
aria-label={on ? `${role}: choose a coin` : undefined}
>
{/* what the slab shows: pinned to the edge the slab grows
away from, so it never moves; it fades as the list
arrives and comes back as the slab shuts */}
<motion.div
className="swp-face"
style={i === 0 ? { top: 0 } : { bottom: 0 }}
initial={false}
animate={{ opacity: on ? 0 : 1 }}
transition={on ? { duration: 0.16 } : { delay: 0.14, duration: 0.22 }}
aria-hidden={on || undefined}
>
<span className="swp-label">{role}</span>
<span className="swp-amount">{shown(i).amount}</span>
<span className="swp-fiat">{shown(i).fiat}</span>
<button
type="button"
className="swp-coin"
onClick={() => open(i)}
tabIndex={pick === null ? 0 : -1}
aria-label={`${coin.name}. Choose another coin`}
>
<Logo coin={coin} size={22} />
{coin.sym}
</button>
</motion.div>
{/* the list loads inside once the slab is mostly open,
and goes before it starts to shut */}
<AnimatePresence>
{on && (
<motion.div
className="swp-pick-in"
initial={{ opacity: 0 }}
animate={{ opacity: 1, transition: { delay: 0.1, duration: 0.22 } }}
exit={{ opacity: 0, transition: { duration: 0.16 } }}
>
<div className="swp-pick-head">
<span>{role}</span>
<button type="button" className="swp-pick-x" onClick={() => setPick(null)} aria-label="Close">
<X size={16} strokeWidth={2} />
</button>
</div>
{set.list.map((c) => (
<button key={c.sym} type="button" className="swp-pick-row" onClick={() => choose(c.sym)}>
<Logo coin={c} size={24} />
<span className="swp-pick-sym">{c.sym}</span>
<span className="swp-pick-name">{c.name}</span>
{coins[i] === c.sym && <Check className="swp-pick-on" size={16} strokeWidth={2} />}
</button>
))}
</motion.div>
)}
</AnimatePresence>
</motion.div>
);
})}
<motion.button
type="button"
className="swp-flip"
style={{ borderRadius: r }}
initial={false}
/* the arrow leaves as soon as a slab starts to open, and only
comes back once that slab is home — lifted clears when
the shrink lands, not when the close is asked for */
animate={{ rotate: turns * 180, scale: lifted === null ? 1 : 0.5, opacity: lifted === null ? 1 : 0 }}
transition={{
default: spring,
scale: lifted === null ? { type: "spring", duration: 0.42, bounce: 0.35 } : { duration: 0.16 },
opacity: { duration: lifted === null ? 0.18 : 0.1 },
}}
whileTap={{ scale: 0.9 }}
onClick={() => {
setTurns((n) => n + 1);
}}
tabIndex={pick === null ? 0 : -1}
aria-label={`Paying ${coins[payer]} for ${coins[1 - payer]}. Reverse`}
>
<ArrowDown size={18} strokeWidth={2} />
</motion.button>
</div>
);
}控件 · HTML · CSS · JS
直接改代码,再用控件微调,预览会随输入实时更新。

在线编辑每个组件,用控件微调,下载完整源码,复制进阶提示词。
一次性 $49占位价格
测试模式:不会真实扣款。
免费:预览、复制按钮和课程说明。
宽松的内边距、柔和的圆角和单一强调色,让内容站在前面。
功能列表、个人资料、商品卡和仪表盘。
调内边距、阴影深度和强调色。
把 Bencho (github.com/cabralorenzo/bencho)(MIT)中的「资产兑换」组件加入我的 React + Tailwind CSS 应用。源文件:https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/asset-swap/Swap.tsx。宽松的内边距、柔和的圆角和单一强调色,让内容站在前面。 适用场景:功能列表、个人资料、商品卡和仪表盘。 可调参数:调内边距、阴影深度和强调色。 支持浅色与深色主题,遵循 prefers-reduced-motion。保留 MIT 许可声明。
更完整的提示词,包含调参、无障碍和接入步骤。