Malevich

Elements / Interactive/

Button

5 variants (primary/secondary/ghost/danger/success), 3 sizes, tweak slots.

Button

A button is a form: pressed, it acts. The button is the most basic interactive element in Malevich.

When to use

Use a button when the action happens on the current page (submitting a form, opening a dialog, toggling a state). Use an anchor (<a>) when the action navigates to a new page or scrolls to a section.

Variants

Variant Class Use for
Primary .button.-primary Primary CTA, hero conversions
Secondary .button.-secondary Secondary actions, "Cancel"
Ghost .button.-ghost Tertiary actions, low emphasis
Danger .button.-danger Destructive actions
Success .button.-success Positive confirmation actions

v0.1.0 compatibility: .button.-accent and .button.-neutral are retained as aliases for .button.-primary and .button.-secondary respectively. They will be removed during the v0.2.0 codemod migration. New code should use the v1.0 names.

States

States are expressed via pseudo-classes and the disabled attribute. The component handles them automatically — no manual class management.

State Trigger
Default (initial render)
Hover :hover
Active :active or [data-active="true"]
Disabled disabled attribute
Focused :focus-visible

[data-active="true"] is set by the runtime while keyboard activation (Space/Enter) is held, giving keyboard users the same pressed visual as mouse users.

Sizes

Size Class Typography token Use for
Small .button.-s caption Inline tools, table actions
Medium (default) body-support Most cases
Large .button.-l body-regular Hero CTAs

Anatomy

The author writes:

<button class="button -accent">Save</button>

After initButton runs, the DOM is:

<button class="button -accent" data-malevich-ready="true">
  <span class="button__bg" data-tweak-layer="background" hidden></span>
  <span class="button__glow" data-tweak-layer="glow" hidden></span>
  <span class="button__content">
    <span class="button__label">Save</span>
  </span>
  <span class="button__fx" data-tweak-layer="effects" hidden></span>
</button>

Tweak layers are hidden by default and have zero paint cost. A tweak (e.g. t-glow-hover) unhides the layer it needs.

Tokens used

Tier 3 (component-specific):

Accessibility

Edge cases

Do

Don't

Related