独家

Balance Sheet <mv-balance-sheet>

结构化的双栏决策权衡(利弊、自建还是购买、是否招人、供应商选择、搬家),以账本形式排列,让论点彼此相对。

文化出处

鲁滨逊漂流记,丹尼尔·笛福(1719 年,小说)。困在荒岛上的鲁滨逊把自己的处境“像借方和贷方那样”分两栏写下,每一件坏事都对应一件好事,以便冷静地评判自己的境况,而不是陷入绝望。UI 把这种做法变成了决策账本:论点分两栏权衡,每个论据都可以由同一行上的反论点作答并被部分抵消,没有得到回应的顾虑会作为真正的悬而未决的问题突显出来,同时一根天平横梁和一行直白的结论显示天平倒向哪一边。

工作原理

结构化的双栏决策权衡(利弊、自建还是购买、是否招人、供应商选择、搬家),以账本形式排列,让论点彼此相对。每个论点都是一行可编辑的短文本,带有 1-5 的权重,权重通过绘制成五个圆点的原生 range 设置(键盘、拖动或点击),还可以设置一个用于缩放权重的置信度(certain、likely、unsure)。任何论点都可以通过“Answer with…”菜单由另一栏的论点作答(选择一个未配对的论点或新写一个):这对论点会移到同一行,由一个跨越中缝、带字母编号的连接线相连,两个论点都会被部分抵消(由 offset 属性控制,默认为较小分值的 50%),这样已被回应的噪声会离开总分,而仍待解决的部分权重更真实。无人回应的顾虑会作为真正的悬而未决的问题高亮显示,归集在“Not yet answered”分隔线下,并计入一行直白的结论(“Leaning yes · 17.6 vs 11.9 · 3 unanswered concerns”),点击其中的计数会从一个未解决的顾虑跳到下一个。支点上的横梁会以弹簧效果向较重的一侧倾斜(在减少动态效果模式下为静态角度)。可以在多个标签页中权衡多个选项,每个选项一张表,每个标签页都显示其净值,另有一个 Compare 标签页在表格中对它们排名,配有发散式净值条和“Best balance”标记。通过可取消的 mv-export 导出 Markdown(剪贴板)和 JSON(下载),可以持久化到 localStorage,并且是表单关联的:JSON 值包含每个选项的结果,required 和 require-answers(每个顾虑都已被回应)决定有效性。mv-change 报告每次编辑,mv-verdict 在倾向翻转到另一侧时触发,mv-remove 和 mv-pair 可取消。

分类表单
类型Web Component(<mv-balance-sheet>)
状态稳定版
同时安装button
Keywordsexclusive, culture, decision, pros-and-cons, decision-matrix, trade-off, weighted, comparison, vendor-selection, build-vs-buy, risk, verdict, ledger, scale, balance, form, export, markdown, json, adr

When to use

  • A team must decide yes or no on a proposal (a 4-day week, a rewrite, a hire) and wants the reasoning written down and weighed
  • Several vendors, tools or offers must be compared on strengths and risks before one is picked
  • Every concern raised in a review should be explicitly answered or left visibly open before a decision is submitted
  • A decision record needs to be exported to a doc, ticket or ADR as Markdown or stored as structured JSON

Avoid when

  • The user is picking one of a few ready-made options (plans, shipping) and needs quick help, not a written argument → use Lifelines instead
  • Options should be compared on computed numbers from the same inputs (price, rate, term) rather than on arguments → use Fork instead
  • The goal is to find a product in a large catalog by answering questions → use Narrow Down instead

安装

node scripts/add.mjs balance-sheet --out ./src/marvelous

通过 Marvelous UI MCP 服务器使用 AI 智能体:install_components({ slugs: ["balance-sheet"], target_dir: "<absolute path>/src/marvelous", framework: "react" })。

复制的文件(含依赖):tokens/tokens.css, core/base.css, components/button/button.css, core/dismiss.js, core/dom.js, core/element.js, core/focus.js, core/form.js, core/motion.js, core/position.js, components/balance-sheet/balance-sheet.js, components/balance-sheet/balance-sheet.css。

用法

标准标记,可在此基础上通过属性、data-* 和 CSS 变量进行定制:

<div id="bs-demo" style="width:min(100%,74rem);margin-inline:auto">
  <style>
    #bs-demo { display:grid; gap:1.5rem; align-content:start }
    #bs-demo .bs-layout { display:grid; grid-template-columns:minmax(0,1fr) 15.5rem; gap:1.25rem; align-items:start }
    #bs-demo .bs-intro { display:flex; align-items:flex-end; justify-content:space-between; gap:.5rem 1rem; flex-wrap:wrap; margin-bottom:.75rem }
    #bs-demo .bs-intro h3 { margin:0; font-size:1rem; letter-spacing:-.01em }
    #bs-demo .bs-intro p { margin:.1875rem 0 0; color:var(--mv-fg-muted); font-size:.8125rem }
    #bs-demo .bs-side { position:sticky; top:1rem; display:grid; gap:.875rem; padding:1rem; border:1px solid var(--mv-border); border-radius:var(--mv-radius-xl); background:var(--mv-surface-raised); box-shadow:var(--mv-shadow-sm); font-size:.8125rem }
    #bs-demo .bs-side h4 { display:flex; align-items:center; justify-content:space-between; gap:.5rem; margin:0; font-size:.8125rem; font-weight:600 }
    #bs-demo .bs-side p { margin:0; color:var(--mv-fg-muted); font-size:.75rem; line-height:1.45 }
    #bs-demo .bs-side .mv-choice { font-size:.8125rem }
    #bs-demo .bs-sep { height:1px; background:var(--mv-border) }
    #bs-demo .bs-log { display:grid; gap:.3125rem; margin:0; padding:0; list-style:none; font:.6875rem/1.45 var(--mv-font-mono); color:var(--mv-fg-muted) }
    #bs-demo .bs-log li { overflow:hidden; text-overflow:ellipsis; white-space:nowrap }
    #bs-demo .bs-log b { color:var(--mv-fg); font-weight:500 }
    #bs-demo .bs-form { display:flex; align-items:center; justify-content:space-between; gap:.75rem; flex-wrap:wrap; margin-top:.75rem; color:var(--mv-fg-muted); font-size:.75rem }
    #bs-demo .bs-hint { margin:0; color:var(--mv-fg-muted); font-size:.75rem; text-align:center }
    @media (max-width:56rem) {
      #bs-demo .bs-layout { grid-template-columns:minmax(0,1fr) }
      #bs-demo .bs-side { position:static }
    }
  </style>

  <div class="bs-layout">
    <section aria-labelledby="bs-week-title">
      <div class="bs-intro">
        <div>
          <h3 id="bs-week-title">Leadership offsite · People &amp; Ops</h3>
          <p>Decision due Friday, October 16 · Product team of 14 across Lisbon, Toronto and Singapore</p>
        </div>
        <span class="mv-badge" data-variant="outline" id="bs-verdict-badge">Leaning yes</span>
      </div>

      <form id="bs-week-form">
        <mv-balance-sheet id="bs-week" name="four-day-week" confidence require-answers
          question="Move the product team to a 4-day week?">
          <ul>
            <li data-side="for" data-weight="5" data-id="retention">Two engineers cited burnout in exit interviews this year; replacing each costs about $48,000</li>
            <li data-side="for" data-weight="5" data-confidence="likely" data-id="pilot">Lisbon pilot (Q2): shipped output flat, sick days down 30%</li>
            <li data-side="for" data-weight="3" data-id="stagger">Staggered days off (Mon or Fri) keep five-day coverage</li>
            <li data-side="for" data-weight="4" data-confidence="likely" data-id="hiring">4-day roles draw roughly 3× more applicants in our markets</li>
            <li data-side="for" data-weight="4" data-id="meetings">Forces us to cut recurring meetings (11 h per person per week today)</li>
            <li data-side="for" data-weight="3" data-confidence="unsure" data-id="raise">Cheaper than the 8% raise the team asked for in the spring</li>
            <li data-side="against" data-weight="3" data-confidence="likely" data-pair="pilot" data-id="cadence">Release cadence could slip during the transition quarter</li>
            <li data-side="against" data-weight="4" data-pair="stagger" data-id="support">Customer support needs full coverage on Fridays</li>
            <li data-side="against" data-weight="4" data-id="sla">Two enterprise contracts promise a 5-business-day response SLA</li>
            <li data-side="against" data-weight="2" data-id="payroll">Payroll and time-off policies must be rewritten in 3 countries</li>
            <li data-side="against" data-weight="3" data-confidence="likely" data-id="reverse">Hard to walk back once it is announced</li>
          </ul>
        </mv-balance-sheet>
        <div class="bs-form">
          <span id="bs-form-status" role="status">Every concern must be answered before this can be submitted.</span>
          <button class="mv-button" data-size="sm" type="submit">Submit decision</button>
        </div>
      </form>
    </section>

    <aside class="bs-side" aria-label="Demo controls">
      <h4>Options</h4>
      <label class="mv-choice"><input type="checkbox" role="switch" class="mv-switch" id="bs-conf" checked> Confidence per point</label>
      <label class="mv-choice"><input type="checkbox" role="switch" class="mv-switch" id="bs-ro"> Read-only record</label>
      <div class="bs-sep"></div>
      <h4>Try it</h4>
      <p>Answer “Hard to walk back” with a new point, or drag a weight: the beam tilts and the verdict line follows.</p>
      <button class="mv-button" data-variant="outline" data-size="sm" type="button" id="bs-answer">Answer the SLA concern</button>
      <button class="mv-button" data-variant="secondary" data-size="sm" type="button" id="bs-reset">Reset the sheet</button>
      <div class="bs-sep"></div>
      <h4>Events</h4>
      <ol class="bs-log" id="bs-log"><li>-</li></ol>
    </aside>
  </div>

  <!-- Variant: several options in tabs, compared in a summary table -->
  <section aria-labelledby="bs-vendor-title">
    <div class="bs-intro">
      <div>
        <h3 id="bs-vendor-title">Vendor review · Platform team</h3>
        <p>Three candidates for error monitoring, weighed option by option. Budget: $1,800 / month.</p>
      </div>
    </div>
    <mv-balance-sheet id="bs-vendor" selected="compare" for-label="Strengths" against-label="Risks" for-verdict="in favor" against-verdict="against"
      question="Which error-monitoring vendor should we adopt?">
      <ul data-option="Halcyra Metrics" data-option-id="halcyra">
        <li data-side="for" data-weight="5" data-id="l1">Source maps and release tracking work out of the box</li>
        <li data-side="for" data-weight="4" data-id="l2">EU data residency (Frankfurt) covers our GDPR review</li>
        <li data-side="for" data-weight="3" data-id="l3">Annual plan at $1,450 / month for 20 seats</li>
        <li data-side="against" data-weight="3" data-pair="l3" data-id="l4">Event overage billed at $0.00028 per event</li>
        <li data-side="against" data-weight="2" data-id="l5">No on-prem option if a customer demands one</li>
      </ul>
      <ul data-option="Tessera Cloud" data-option-id="tessera">
        <li data-side="for" data-weight="4" data-id="t1">Already used by the mobile team; one contract</li>
        <li data-side="for" data-weight="3" data-id="t2">Best session replay of the three</li>
        <li data-side="against" data-weight="5" data-id="t3">US-only hosting blocks two EU customers</li>
        <li data-side="against" data-weight="4" data-pair="t1" data-id="t4">Seat price rises to $95 at renewal</li>
        <li data-side="against" data-weight="3" data-id="t5">SAML only on the Enterprise tier</li>
      </ul>
      <ul data-option="Self-hosted stack" data-option-id="self">
        <li data-side="for" data-weight="4" data-id="s1">No per-event cost, data never leaves our cloud</li>
        <li data-side="for" data-weight="2" data-id="s2">Full control over retention (400 days)</li>
        <li data-side="against" data-weight="5" data-pair="s1" data-id="s3">About 0.5 FTE of on-call and upgrades</li>
        <li data-side="against" data-weight="4" data-id="s4">Alerting and dashboards to build ourselves</li>
      </ul>
    </mv-balance-sheet>
  </section>
  <p class="bs-hint">Open a vendor tab to edit its sheet · the Compare tab ranks the options by net balance · Copy Markdown exports the whole review</p>

  <script type="module">
    await customElements.whenDefined("mv-balance-sheet");
    const $ = (id) => document.getElementById(id);
    const sheet = $("bs-week");
    const log = $("bs-log");
    const badge = $("bs-verdict-badge");
    const write = (html) => {
      if (log.firstElementChild?.textContent === "-") log.replaceChildren();
      const li = document.createElement("li");
      li.append(...html);
      log.prepend(li);
      while (log.children.length > 6) log.lastElementChild.remove();
    };
    const b = (t) => { const el = document.createElement("b"); el.textContent = t; return el; };
    const paintBadge = () => {
      const r = sheet.verdict;
      badge.textContent = r.verdict.split(" · ")[0];
      badge.dataset.variant = r.lean === "for" ? "success" : r.lean === "against" ? "danger" : "secondary";
    };
    paintBadge();

    sheet.addEventListener("mv-change", (e) => {
      const { reason, results } = e.detail;
      write([b("mv-change "), `${reason} · net ${results[0].net > 0 ? "+" : ""}${results[0].net}`]);
      paintBadge();
    });
    sheet.addEventListener("mv-verdict", (e) => {
      write([b("mv-verdict "), `${e.detail.previous} → ${e.detail.lean}`]);
      paintBadge();
    });
    sheet.addEventListener("mv-export", (e) => write([b("mv-export "), e.detail.format]));

    $("bs-conf").addEventListener("change", (e) => { sheet.confidence = e.target.checked; paintBadge(); });
    $("bs-ro").addEventListener("change", (e) => { sheet.readonly = e.target.checked; });
    $("bs-answer").addEventListener("click", () => {
      const id = sheet.addItem("for", "Keep a rotating Friday responder for enterprise tickets", { weight: 4, answers: "sla" });
      if (id) $("bs-answer").disabled = true;
    });
    const initial = sheet.value;
    $("bs-reset").addEventListener("click", () => { sheet.value = initial; $("bs-answer").disabled = false; paintBadge(); write([b("reset")]); });

    const form = $("bs-week-form");
    const status = $("bs-form-status");
    form.addEventListener("submit", (e) => {
      e.preventDefault();
      const data = JSON.parse(new FormData(form).get("four-day-week"));
      status.textContent = `Submitted: ${data.results[0].verdict}.`;
    });
    form.addEventListener("invalid", () => { status.textContent = sheet.validationMessage; }, true);

    $("bs-vendor").addEventListener("mv-verdict", (e) => write([b("mv-verdict "), `${e.detail.label}: ${e.detail.lean}`]));
  </script>
</div>

API

Attributes

Name类型DefaultDescription
questionstringThe decision being weighed, shown as the sheet's heading and used for the export file name. Also stored in the value.
for-label / against-labelstringFor / AgainstColumn headings and pan labels (e.g. Pros / Cons, Strengths / Risks, Build / Buy).
for-verdict / against-verdictstringyes / noWords used in the verdict line: “Leaning {word}”, “Clearly {word}”.
confidencebooleanShows a confidence select on every point (Certain ×1, Likely ×0.75, Unsure ×0.5); a point's score is weight × confidence. Unsure pips are hatched, likely pips lighter.
offsetnumber (0..1)0.5Share of the smaller score that a pair removes from both of its points. 0 = pairing is purely a link; 1 = the smaller point is fully cancelled. Pairing alone never flips the lean; it sharpens the margin.
tiltnumber (deg)10Maximum beam angle, reached when one side outweighs the other by about 2 to 1.
multiplebooleanShows the option tabs and the Add option button even with a single option. Tabs appear on their own as soon as there are two options.
selectedoption id | "compare"Option shown on first render (or the Compare view). Changing the attribute switches tabs.
readonlybooleanDecision record mode: nothing can be edited, added, paired or removed; pairs and verdict stay visible and exports still work.
persiststringlocalStorage key suffix (mv-balance-sheet:{persist}). The sheet is saved on every change and restored on load before the markup (a value property set by the app wins). clearSaved() forgets it.
name / required / disabledformForm association: the submitted value is JSON ({ question, options, results }). required = at least one point.
require-answersbooleanThe field is invalid while any concern is unanswered (“Answer every concern before submitting (3 open).”), anchored on the first open concern's Answer button.
hide-exportbooleanHides the Copy Markdown / Export JSON buttons (the methods still work).
heading-level1..63aria-level of the question heading; column headings use the next level.
localeBCP 47en-USNumber formatting of totals and nets.
data-side / data-weight / data-confidence / data-id / data-pairmarkupInitial points as <li data-side="for|against"> inside a <ul> child (or directly as children), read once then replaced. data-pair (alias data-answers) names the id of the point it faces. Wrap each option's points in <ul data-option="Label" data-option-id="id">. A <script type="application/json"> child with a value is also accepted.
data-lean / data-readonlyset by the componentOn the host: for | against | even for the option on screen (empty in the Compare view), and data-readonly while editing is locked.

Properties

Name类型Description
value{ question, options: [{ id, label, items: [{ id, side, text, weight, confidence, pair }] }] }The whole sheet. Accepts the same shape, { items } for a single option, an array of options or a JSON string; pairs are made symmetric and one-to-one. Setting it emits no event.
resultsArray<{ id, label, for, against, net, ratio, lean, strength, pairs, unanswered: { for, against }, scores, count, verdict }>Weighed result of every option (read-only). lean: for | against | even; strength: clear | leaning | even | empty; pairs carry their letter and offset; scores are the effective score of each point.
verdictresultResult of the option on screen, with its verdict sentence (read-only).
selectedOptionstringId of the option on screen, or "compare" (read-only; use select()).
stringsPartial<Record<string, string>>Overrides for every visible text and announcement (forLabel, againstLabel, forVerdict, againstVerdict, addFor, addAgainst, answer, answerLabel, pairedLabel, unanswered, verdictLeaning, verdictClear, verdictEven, concernsOne, concernsOther, concernsNone, divider, menuTitle, menuNew, menuUnpair, compare, best, copyMarkdown, exportJSON, announceFlip, requireAnswers…). English defaults.
question / forLabel / againstLabel / confidence / offset / tilt / readonly / persist …reflectedMirror the attributes.

Methods

NameDescription
addItem(side, text, { weight?, confidence?, answers?, option?, id? })Adds a point (weight 3 by default) and returns its id; answers pairs it with an existing point of the other side. Emits mv-change (reason "add").
removeItem(id, { option? })Removes a point (cancelable mv-remove). Returns false if refused.
pair(a, b, { option? }) / unpair(id, { option? })Pairs two points of opposite sides (replacing their previous pairs) or breaks a pair. Cancelable through mv-pair.
addOption(label?) / removeOption(id) / select(id | "compare")Manages option sheets and switches tabs. removeOption keeps at least one option and emits a cancelable mv-remove with kind "option".
toMarkdown() / toJSON()The decision as Markdown (question, verdict, both columns with weights, answers and unanswered concerns, compare table) or as { question, options, results }.
copyMarkdown() / downloadJSON()Same as the footer buttons: clipboard (file fallback) and .json download named after the question. Return Promise<boolean>.
clearSaved()Forgets the persisted copy.

Events

NameDescription
mv-changeAfter every edit. detail: { reason: "add" | "remove" | "edit" | "weight" | "confidence" | "pair" | "unpair" | "option-add" | "option-remove" | "option-rename", value, results (summaries), item, option }. Text edits are reported on commit (blur), not per keystroke.
mv-verdictThe lean of an option flipped side (for, against or even) after a user action. detail: { option, label, lean, previous, strength, for, against, net, unanswered, verdict }.
mv-removeCancelable, before a point or an option is removed. detail: { kind: "item" | "option", item?, option, label? }.
mv-pairCancelable, before two points are paired or unpaired. detail: { action: "pair" | "unpair", for, against, option }.
mv-exportCancelable, before Copy Markdown or Export JSON. detail: { format: "markdown" | "json", text, filename }. preventDefault() to send the text somewhere else (a ticket, an ADR, your API).

Content structure

NameDescription
(content)Initial data only (<ul>/<li data-side> or a JSON <script>); it is read once and replaced by the sheet.

CSS classes

NameDescription
mv-balance-sheet-head / -question / -scale / -verdictHead: question heading, the decorative scale (-beam, -arm, -hang[data-side], -cord, -pan, -pan-total, -fulcrum, -pivot, --_tilt) and the verdict line (-lean[data-lean][data-strength], -score, -open).
mv-balance-sheet-grid / -col / -list / -gutter / -link / -dividerLedger: three columns sharing rows through subgrid; -link (with -link-badge and -link-offset) joins each pair across the gutter; -divider heads the unanswered rows. Stacks under 38rem of container width.
mv-balance-sheet-itemA point: data-side, data-paired or data-open, data-hot (hovered or focused with its partner), data-confidence. Parts: -text (textarea), -remove, -weight (-pips, -range), -conf, -tag, -pair (data-letter).
mv-balance-sheet-add / -answeringAdd field under each column and the “Answering …” chip shown while a new point is written as an answer.
mv-balance-sheet-tabs / -tab / -tab-net / -compare / -tableOption tabs with their net badge, and the Compare view table (-net-bar, -best, -mini-beam).
mv-balance-sheet-menuThe “Answer with…” menu (Popover API, role="menu").
mv-balance-sheet-foot / -note / -exportFooter with the scoring note and export buttons.

CSS variables

NameDefaultDescription
--mv-balance-sheet-forvar(--mv-success)Color of the first column, its pan and pips.
--mv-balance-sheet-againstvar(--mv-danger)Color of the second column, its pan and pips.
--mv-balance-sheet-openvar(--mv-warning)Unanswered concerns: edge, tag and verdict count.
--mv-balance-sheet-linkvar(--mv-accent)Pair connectors, letters and the answering chip.
--mv-balance-sheet-gutter3.5remWidth of the gutter where pairs meet.

Accessibility

Each column is a real list (role="list") labelled by its heading (role="heading" with a configurable aria-level, one level below the question), and the heading reads its weighted total (“For, weighted total 17.6”). Every point is made of native controls: a textarea named “Point, For” (Enter moves to the next point, Backspace on an empty point removes it), a Remove button naming the point, a native range labelled “Weight” with aria-valuetext (“4 of 5, major”) driven by arrow keys, Home and End, and a native select for confidence. Pairing never needs dragging: the “Answer” button (aria-haspopup="menu", aria-expanded) names what it answers and opens a menu of the other column's unpaired points plus “Write a new point” and “Unpair”; arrow keys, Home and End move inside it, Escape or Tab closes it and returns focus to the button. A paired button reads “Answered by “…”, pair B”. Writing a new answer shows a visible “Answering …” chip and renames the add field accordingly; Escape cancels it. The beam, pans, gutter connectors and divider are aria-hidden: everything they show is also in text (column totals, the pair letter on both points, the “Unanswered” tag, the verdict line). The verdict line is plain text, and its concern count is a button that moves focus to the next unanswered concern. A polite live region announces additions, removals and pairings; an assertive one announces only when the verdict flips side (“Verdict changed. Leaning no · 12 vs 14.5 · 2 unanswered concerns.”). Tabs follow the tabs pattern (roving tabindex, arrow keys, automatic activation, tabpanel labelled by its tab, each tab named with its verdict); the Compare view is a real table with a caption, column and row headers. Hover or focus on a point highlights its partner. Colors always come with signs and words (+ / −, “Unanswered”, letters, numbers). Reduced motion (OS or data-motion="reduce"): the beam sits at its angle without a spring, rows do not glide when pairs form, the focus pulse becomes a static outline. Forced colors: pips, beam and connectors use CanvasText, unanswered concerns get a dashed border.

本页面由 AI 翻译。报告翻译问题