Skip to content
LIBRARYBase

Button ​

Alpha.8 adds loadingIndicator="none|dots|bars|ring" (default none) and the opt-in reorderHandle prop for a plain-text collection handle. See visual motion and collections for the Jolt RC.11 requirement and platform limits. These additions are included in alpha.8.

m-button · Actions with variants, sizes and interaction states.

Web preview
Open example ↗

Usage ​

vue
<m-button variant="primary" @click="save">Save</m-button>

Values and handlers in this snippet belong to your component. The full example below includes their setup.

API ​

PropTypeDefaultPurpose
variantprimary / secondary / ghostprimaryButton appearance.
sizesm / md / lgmdMinimum height, font and padding.
disabledbooleanfalsePrevents activation.
loadingbooleanfalsePrevents activation and shows loadingText.
loadingTextstringLoading…Text shown while loading.
textstring—Alternative to slot text.
typebutton / submit / resetbuttonWeb only: HTML button action.
name / value / formstringunsetWeb only: submitter name/value and owning form ID.
icon / trailingIconIconName—Lucide icon before or after the text, sized with the button. An icon-only button requires accessibilityLabel; otherwise rendering throws RangeError.
grow / shrinknumber0 / contextSpace distribution within the parent layout.

Icons render from the bundled Lucide font at 16, 20 or 24 points for sm, md and lg, inherit the label color and never join the accessible name. click has no payload and is not emitted while disabled or loading is active. The slot accepts plain or interpolated text. Pass accessibilityLabel when the accessible name differs from the visible text. NativeScript uses Jolt for press feedback; Web renders a keyboard-accessible button with visible focus.

HTML forms (Web) ​

Use type="submit" and handle the form's @submit.prevent to receive validated click and Enter submissions. name and value identify the submitter; form can target a form elsewhere in the document. Keep a single save handler on the form instead of also saving in the button's @click.

Disabled buttons cannot activate. Loading buttons retain keyboard focus, announce their busy state and cancel both submit and reset defaults. The default type="button" never submits a form. With type="reset", handle the form's @reset.prevent to reset controlled models; see the Input form example. NativeScript keeps its ordinary action behavior and ignores the HTML-only props.

Full example ​

This file also runs in the NativeScript catalog and the Web preview.

View source
vue
<script setup lang="ts">
import { useCatalogLocale } from '../locale'
import { ref, onBeforeUnmount } from 'vue'
import { useActionOutcome } from '@getcortexlabs/mavis-core/vue'

const { t } = useCatalogLocale()

const props = withDefaults(defineProps<{ lang?: 'en' | 'pt' }>(), { lang: 'pt' })
const clicks = ref(0)
const loading = ref(false)
const saved = ref(false)
const coupon = ref<'idle' | 'checking' | 'expired' | 'applied'>('idle')
const outcome = useActionOutcome()
const timers = new Set<ReturnType<typeof setTimeout>>()
function later(work: () => void, delay: number) {
  const timer = setTimeout(() => {
    timers.delete(timer)
    work()
  }, delay)
  timers.add(timer)
}
function save() {
  loading.value = true
  later(() => {
    loading.value = false
    saved.value = !saved.value
  }, 900)
}
// Demonstration only: the first attempt is refused, the next one is accepted.
function apply() {
  const refused = coupon.value !== 'expired'
  coupon.value = 'checking'
  later(() => {
    coupon.value = refused ? 'expired' : 'applied'
    if (refused) outcome.refuse()
    else outcome.confirm()
  }, 700)
}
const pt = () => props.lang === 'pt'
onBeforeUnmount(() => timers.forEach(clearTimeout))
</script>

<template>
  <m-column gap="lg">
    <m-row gap="sm" wrap>
      <m-button @click="clicks++">{{ t('Primary') }}</m-button>
      <m-button variant="secondary" @click="clicks++">{{ t('Secondary') }}</m-button>
      <m-button variant="ghost" @click="clicks++">{{ t('Ghost') }}</m-button>
    </m-row>
    <m-text variant="caption" tone="muted"
      >{{ t(clicks) }}
      {{
        t(lang === 'pt' ? (clicks === 1 ? 'clique' : 'cliques') : clicks === 1 ? 'click' : 'clicks')
      }}</m-text
    >
    <m-row gap="sm" align="center" wrap>
      <m-button size="sm" variant="secondary">{{ t('Small') }}</m-button>
      <m-button size="md" variant="secondary">{{ t('Medium') }}</m-button>
      <m-button size="lg" variant="secondary">{{ t('Large') }}</m-button>
    </m-row>
    <m-row gap="sm" align="center" wrap>
      <m-button icon="plus">{{ t(lang === 'pt' ? 'Adicionar' : 'Add') }}</m-button>
      <m-button variant="secondary" trailingIcon="arrow-right">{{
        t(lang === 'pt' ? 'Avançar' : 'Next')
      }}</m-button>
      <m-button
        variant="ghost"
        icon="heart"
        :accessibilityLabel="t(lang === 'pt' ? 'Favoritar' : 'Favorite')"
      />
    </m-row>
    <m-row gap="sm" wrap>
      <m-button
        :loading="loading"
        loadingIndicator="dots"
        :loadingText="t(lang === 'pt' ? 'Salvando…' : 'Saving…')"
        @click="save"
      >
        {{ t(saved ? (lang === 'pt' ? 'Salvo' : 'Saved') : lang === 'pt' ? 'Salvar' : 'Save') }}
      </m-button>
      <m-button disabled variant="secondary">{{
        t(lang === 'pt' ? 'Indisponível' : 'Unavailable')
      }}</m-button>
    </m-row>
    <m-column gap="sm">
      <m-row gap="sm" align="center" wrap>
        <m-button
          variant="secondary"
          :motionSurface="outcome.surface"
          :loading="coupon === 'checking'"
          :loadingText="t(pt() ? 'Conferindo…' : 'Checking…')"
          :disabled="coupon === 'applied'"
          @click="apply"
        >
          {{ t(pt() ? 'Aplicar cupom' : 'Apply coupon') }}
        </m-button>
        <m-button v-if="coupon === 'applied'" variant="ghost" @click="coupon = 'idle'">{{
          t(pt() ? 'Recomeçar' : 'Start over')
        }}</m-button>
      </m-row>
      <m-text
        variant="caption"
        :tone="coupon === 'expired' ? 'danger' : coupon === 'applied' ? 'success' : 'muted'"
        >{{
          t(
            coupon === 'expired'
              ? pt()
                ? 'Cupom expirado. Tente de novo.'
                : 'Coupon expired. Try again.'
              : coupon === 'applied'
                ? pt()
                  ? 'Cupom aplicado: 10% de desconto.'
                  : 'Coupon applied: 10% off.'
                : pt()
                  ? 'A primeira tentativa recusa; a seguinte confirma.'
                  : 'The first attempt is refused; the next one confirms.',
          )
        }}</m-text
      >
    </m-column>
  </m-column>
</template>

In context ​

See the components in a complete vehicle controls screen.

See Layout and text for flexible sizing, large text and RTL direction.

Accessible names, focus and screen-reader checks.

Customization ​

The theme provides component defaults and Web CSS custom properties. See Typography and customization for tokens, supported overrides and precedence.

Alpha.4 adds experimental motionSurface on Button. Read the shared animation and lifecycle contract.

Motion and feedback ​

  • Pointer light (Web). Where a pointer can hover, a soft light follows the cursor across the button and the icon leans its own way: arrows travel where they point, plus and settings turn, other icons swell. Pressing carries the gesture further. The light lives on its own decorative layer, created on the first hover, so the button's markup, name and your own motionSurface are untouched. Forced colors hide it.
  • Touch (NativeScript). There is no hover, so composed buttons (slots, a loading indicator, or Android icons) move their icons on press. Plain iOS buttons keep the system's text rendering.
  • Loading hand-over (Web). When loading changes, the old label leaves while the new one arrives and the width eases to its new size, in both directions. Keyboard focus stays on the button.
  • Outcome. To show how an action went, give the button an outcome surface and play it when the work settles. A confirmation pops, a refusal shakes; both compose with press and add a light/medium haptic where the device supports it.
vue
<script setup lang="ts">
import { useActionOutcome } from '@getcortexlabs/mavis/vue' // Web: @getcortexlabs/mavis-web
const outcome = useActionOutcome()
async function apply() {
  try {
    await redeem()
    outcome.confirm()
  } catch {
    outcome.refuse()
  }
}
</script>

<template>
  <m-button :motionSurface="outcome.surface" @click="apply">Apply coupon</m-button>
</template>

confirm() and refuse() return false while the button is not presented. Use useActionOutcome({ haptic: false }) to stay silent. Reduced motion settles every transform immediately on both renderers.

Leading and trailing content ​

The leading and trailing slots accept decorative content such as a brand mark, icon or badge. A supplied slot takes precedence over its side's icon prop. The default slot remains the text label, with text taking precedence. Loading replaces only the label with loadingText; adornments stay mounted to avoid unexpected width changes.

vue
<m-button @click="continueWithStudio">
  Continue with Studio
  <template #leading><m-icon name="sparkles" /></template>
  <template #trailing><m-badge text="New" tone="accent" /></template>
</m-button>

Adornments are excluded from the accessible name and do not receive interaction. Put meaningful badge information in the label or accessibilityLabel. Do not nest controls, links, editors or interaction handlers; recognized controls are rejected. Custom components must also render decorative content only. Use Mavis primitives or platform-supported images; browser SVG/HTML does not automatically become native content.

NativeScript buttons with these slots use a layout surface with one accessible action and Jolt feedback. The label follows system text size. Content wraps onto another line when a narrow button or larger text cannot fit its adornments beside the label. Web retains its HTML button, form behavior and Enter/Space activation. Morrow demonstrates one brand mark composed from the same primitives on both platforms.

Set href to render a single Web anchor. navigate, target and rel follow the Link contract, including RouterLink/NuxtLink custom slots, modified clicks and native host routing. error reports rejected navigation. A linked card must not contain other controls.

Components for NativeScript and Web. Starting with Vue.