Like Button <mv-like>

Botão de curtir ou favoritar com um clique tátil: o glifo afunda sob o ponteiro e depois passa do tamanho cheio ao se preencher, enquanto um anel e uma coroa de faíscas se irradiam uma vez; os dígitos do contador que mudam rolam para cima ou para baixo em posições fixas, formatados com Intl.

CategoriaMicrointerações
TipoWeb Component (<mv-like>)
Statusestável
Keywordslike, heart, favorite, star, wishlist, upvote, toggle, burst, counter, social

When to use

  • Posts, comments or products need a like, favorite or upvote toggle with a live counter
  • A product grid or detail page needs a compact icon-only wishlist heart
  • A social feed wants expressive feedback when a user hearts or stars an item

Avoid when

  • Users should give a graded score rather than a binary like → use Rating instead
  • The toggle is a neutral setting such as bold or mute in a toolbar → use Toggle instead

Instalação

node scripts/add.mjs like-button --out ./src/marvelous

Agente de IA com o servidor MCP do Marvelous UI: install_components({ slugs: ["like-button"], target_dir: "<absolute path>/src/marvelous", framework: "react" }).

Arquivos copiados (dependências incluídas): tokens/tokens.css, core/base.css, core/element.js, core/motion.js, components/like-button/like-button.js, components/like-button/like-button.css.

Uso

Marcação de referência, para usar como ponto de partida e personalizar com atributos, data-* e variáveis CSS:

<div style="display:grid;gap:1.25rem;justify-items:center;width:100%;max-width:400px">
  <article style="width:100%;border:1px solid var(--mv-border);border-radius:var(--mv-radius-xl);background:var(--mv-surface);box-shadow:var(--mv-shadow-md);overflow:hidden">
    <div style="aspect-ratio:16/8;position:relative;background:linear-gradient(160deg,oklch(0.86 0.07 200),oklch(0.66 0.11 230) 50%,oklch(0.36 0.09 260))">
      <svg viewBox="0 0 400 200" preserveAspectRatio="none" style="position:absolute;inset:0;width:100%;height:100%" aria-hidden="true"><circle cx="92" cy="62" r="26" fill="oklch(0.97 0.04 90 / .9)"/><path d="M0 150 70 96l52 30 88-74 76 62 58-30 56 36v80H0z" fill="oklch(0.42 0.08 250 / .6)"/><path d="M0 176 96 128l74 26 92-50 138 58v38H0z" fill="oklch(0.26 0.06 255 / .75)"/></svg>
    </div>
    <div style="padding:.9rem 1rem .5rem;display:grid;gap:.3rem">
      <strong style="font-size:.95rem">First light over Lofoten</strong>
      <span style="font-size:.8rem;color:var(--mv-fg-muted)">Photo by Ingrid Nilsen · Reine, Norway</span>
    </div>
    <footer style="display:flex;align-items:center;gap:.25rem;padding:0 .5rem .6rem">
      <mv-like id="mv-like-demo-heart" count="2381"></mv-like>
      <mv-like icon="star" count="64" pressed></mv-like>
      <span style="flex:1"></span>
      <mv-like data-variant="outline" count="999" label="Upvote"></mv-like>
    </footer>
  </article>
  <div style="display:flex;align-items:center;gap:.75rem">
    <mv-like label="Save to favorites"></mv-like>
    <mv-like icon="star" label="Star this repository" data-variant="outline"></mv-like>
    <mv-like data-size="lg" data-variant="outline" count="12" label="Like this recipe" pressed></mv-like>
    <mv-like count="7" disabled></mv-like>
  </div>
</div>

API

Attributes

NameTipoDefaultDescription
pressedbooleanLiked (reflected as aria-pressed on the inner button).
countnumberDisplayed counter (omitted = icon-only button). Steps by one on each toggle and never goes below 0.
labelstringLike (star: Favorite)Accessible name; the formatted counter is appended: “Like (2,381)”.
iconheart | starheartGlyph.
localeBCP 47en-USNumber formatting of the counter (Intl.NumberFormat).
disabledbooleanDisables the button.
data-variantoutlineOutlined pill on a solid background.
data-sizelgLarger.

Properties

NameTipoDescription
stringsPartial<{ like, favorite }>Default accessible names for the heart and star when label is not set. English defaults.

Methods

NameDescription
toggle(force?)Toggles like a click: plays the feedback, steps the counter, emits mv-change. Setting pressed or count directly updates silently.

Events

NameDescription
mv-changeAfter a toggle; detail = { pressed, count } (count is null without a counter).

CSS classes

NameDescription
mv-like-buttonThe generated <button> (data-icon-only without a counter); hosts may resize or restyle it.
mv-like-icon / -glyph / -ring / -burst / -countGenerated parts (all aria-hidden).

CSS variables

NameDefaultDescription
--mv-like-colorrose (star: gold)Liked color: fill, ring, long sparks and pressed tint.
--mv-like-spark-coloramber (star: copper)Color of the short sparks.

Accessibility

A real toggle <button> with aria-pressed; its accessible name carries the formatted counter (Intl, en-US by default). The glyph, ring, sparks and visual counter are aria-hidden and ignore the pointer. Setting pressed or count programmatically updates the state without replaying the burst. Reduced motion: no press sink, pop, burst or digit roll, only the fill, color and number change. Forced colors: system colors (ButtonText, Highlight) draw the outline and the liked fill; the burst is hidden.

Esta página foi traduzida com IA. Informar um problema de tradução