Button renders one immediate action as a native button or one explicit navigation action as an
anchor. Vue and Vanilla templates produce the same significant DOM and consume the shared
cm-button CSS contract.
Vue applications load the npm token and component styles:
import '@codemonster-ru/ui-tokens/tokens.css';
import '@codemonster-ru/ui-css/styles.css';Vanilla applications load the shared styles in this order:
<link rel="stylesheet" href="/vendor/codemonster-ui/css/tokens/tokens.css" />
<link rel="stylesheet" href="/vendor/codemonster-ui/css/css/styles.css" />Keep the imported files beside each entry. AssetPublisher publishes the complete integrity-checked
graph.
| Prop | Values | Default | Behavior |
|---|---|---|---|
variant |
primary, secondary, success, info, warn, help, danger, contrast, ghost |
primary |
Visual action emphasis. |
size |
sm, md, lg |
md |
Shared control height and spacing. |
type |
button, submit, reset |
button |
Native button type; ignored in link mode. |
href |
non-empty string or null |
null |
A non-empty value selects native anchor mode. |
block |
boolean | false |
Fills the available inline width. |
disabled |
boolean | false |
Prevents button or link activation. |
loading |
boolean | false |
Shows busy state and prevents activation. |
Unknown safe attributes reach the semantic root. Consumer classes are appended after the stable
contract classes and deduplicated. Component-owned type, href, disabled, busy, and link ARIA
state cannot be overridden through the attribute bag.
The required default slot supplies the visible label and accessible name. Optional leading and
trailing slots render inside fixed icon regions. Loading suppresses leading, shows an
aria-hidden spinner in its place, and keeps the label unchanged. Consumers must apply
aria-hidden="true" to decorative authored icons.
<script setup lang="ts">
import { ref } from 'vue';
import { CmButton } from '@codemonster-ru/ui-vue';
const saving = ref(false);
</script>
<template>
<CmButton type="submit" variant="primary" :loading="saving" data-testid="save">
<template #leading><SaveIcon aria-hidden="true" /></template>
Save
</CmButton>
<CmButton href="/docs" variant="ghost">Documentation</CmButton>
</template>Vue forwards native listeners to enabled roots. Disabled native buttons rely on browser behavior;
disabled links omit href, expose role="link" and aria-disabled="true", and suppress the
consumer click handler.
Use the canonical HTML for button. Add cm-button--block
to fill the available width.
- The default
type="button"avoids accidental form submission; usesubmitexplicitly. name,value,form, and other valid native attributes are forwarded in button mode.- Loading uses native
disabledplusaria-busy="true"and does not create a live region. - Disabled links have no navigable
hrefand are removed from normal link keyboard activation. - Provide a non-empty visible label or a valid native accessible naming attribute.
- Focus indication and forced-color behavior come from the shared stylesheets.