Skip to content
14:21
Button

Button

Introduction ​

Buttons are used to trigger an action, such as submitting a form. Supports types, sizes, plain, round, square, block, disabled and loading states.

Examples ​

Button Type ​

Five types are supported: default, primary, success, warning and danger. The default is default.

vue
<m-button type="primary">Primary</m-button>
<m-button type="success">Success</m-button>
<m-button type="danger">Danger</m-button>
<m-button type="warning">Warning</m-button>
<m-button type="default">Default</m-button>

Plain Button ​

Set a button as plain with the plain attribute: the text takes the button color and the background becomes white.

vue
<m-button type="primary" plain>Plain</m-button>

Hairline Border ​

Use the hairline attribute for a 0.5px border (implemented via scale(0.5)).

vue
<m-button type="primary" plain hairline>Hairline</m-button>

Disabled ​

Disable a button with the disabled attribute; disabled buttons cannot be clicked.

vue
<m-button type="primary" disabled>Disabled</m-button>

Loading ​

Set a button to the loading state with the loading attribute; loading buttons cannot be clicked. Use loading-text to customize the loading label. Use loading-type to switch the loading icon style (circular spinning ring / spinner spinning petals); the icon is powered by the Loading component.

vue
<m-button type="primary" loading />
<m-button type="primary" loading loading-text="Loading..." />
<m-button type="primary" loading loading-type="spinner" />

Press Feedback ​

The button's overall opacity drops to 0.8 while pressed and restores on release; no press feedback is shown in disabled or loading state (implemented via hover-class).

vue
<m-button type="primary">Press to see feedback</m-button>

Button Size ​

Four sizes are supported: large, normal, small and mini. The default is normal.

vue
<m-button type="primary" size="large">Large</m-button>
<m-button type="primary" size="normal">Normal</m-button>
<m-button type="primary" size="small">Small</m-button>
<m-button type="primary" size="mini">Mini</m-button>

Block Element ​

The block attribute makes the button fill its parent container's width.

vue
<m-button type="primary" block>Block</m-button>

Custom Color ​

Customize the button color with the color attribute; linear-gradient is supported.

vue
<m-button color="#7232dd">Solid</m-button>
<m-button color="linear-gradient(to right, #ff6034, #ee0a24)">Gradient</m-button>
<m-button color="#7232dd" plain>Plain Color</m-button>

API ​

Props ​

PropDescriptionTypeDefault
typeType, can be set to primary success warning dangerButtonTypedefault
sizeSize, can be set to large normal small miniButtonSizenormal
plainWhether to be a plain buttonbooleanfalse
roundWhether to be a round buttonbooleanfalse
squareWhether to be a square buttonbooleanfalse
disabledWhether to disable the buttonbooleanfalse
hairlineWhether to use a 0.5px borderbooleanfalse
blockWhether to be a block elementbooleanfalse
loadingWhether to show the loading statebooleanfalse
loading-textLoading state labelstring-
loading-typeLoading icon type, can be set to circular spinnerLoadingTypecircular
colorCustom button color, supports linear-gradientstring-
custom-classCustom root node class namestring.ClassString-
custom-styleCustom root node inline stylestring-

Events ​

EventDescriptionParameters
clickEmitted when the button is clicked (not emitted while loading or disabled)event: MouseEvent

Slots ​

NameDescription
defaultButton content

Theming ​

Button styles can be customized with the following SCSS variables (define them directly in the project root uni.scss to override the defaults):

VariableDescriptionDefault
$m-color-primaryPrimary color#1989fa
$m-color-successSuccess color#07c160
$m-color-warningWarning color#ff976a
$m-color-dangerDanger color#ee0a24
$m-button-normal-heightNormal button height44px
$m-button-large-heightLarge button height50px
$m-button-small-heightSmall button height32px
$m-button-mini-heightMini button height24px
$m-button-radiusButton border radius8px
$m-button-active-opacityOpacity while pressed0.8

See Theming for the full variable list and override instructions.

Released under the MIT License.