Skip to content

Button

Buttons are used to trigger an action, such as submitting a form or opening a link.

Component Type

Type

html
<wd-button>Primary Button</wd-button>
<wd-button type="success">Success Button</wd-button>
<wd-button type="info">Info Button</wd-button>
<wd-button type="warning">Warning Button</wd-button>
<wd-button type="danger">Danger Button</wd-button>

Component State

Disabled

Set the disabled property.

html
<wd-button disabled>Default Button</wd-button>

Loading

Set the loading property to put the button in a loading state. Buttons in loading state are disabled from clicking.

html
<wd-button loading>Loading</wd-button>

Component Variant

Plain

Set variant="plain".

html
<wd-button variant="plain">Primary Button</wd-button>

Dashed

Set variant="dashed".

html
<wd-button variant="dashed">Primary Button</wd-button>

Text

Set variant="text".

html
<wd-button variant="text">Text Button</wd-button>

Component Style

Size

Set size, supports 'mini', 'small', 'medium', 'large', default is 'medium'.

html
<wd-button size="mini">Mini Button</wd-button>
<wd-button size="small">Small Button</wd-button>
<wd-button size="medium">Medium Button</wd-button>
<wd-button size="large">Large Button</wd-button>

Hairline and Round

Set hairline and round properties.

html
<wd-button variant="plain" hairline>Hairline</wd-button>
<wd-button variant="plain" round>Round Button</wd-button>

Special Style

custom-class Shadow

Customize button styles through custom-class and custom-style properties. Here we use custom-class to add Material Design 3 style box-shadow.

html
<view class="page-class">
  <wd-button custom-class="custom-shadow">Primary Button</wd-button>
  <wd-button type="success" custom-class="custom-shadow">Success Button</wd-button>
  <wd-button type="info" custom-class="custom-shadow">Info Button</wd-button>
  <wd-button type="warning" custom-class="custom-shadow">Warning Button</wd-button>
  <wd-button type="danger" custom-class="custom-shadow">Danger Button</wd-button>
</view>
scss
.page-class {
  :deep() {
    .custom-shadow {
      box-shadow: 0 3px 1px -2px rgb(0 0 0 / 20%), 0 2px 2px 0 rgb(0 0 0 / 14%), 0 1px 5px 0 rgb(0 0 0 / 12%);
    }
  }
}

Content Form

Icon Only Button

Set the icon property to display an icon button.

html
<wd-button icon="edit-outline"></wd-button>

Icon and Text Button

Combine icon with content to display an icon and text button; combine with classPrefix to use custom icons, see Icon Custom Icon.

html
<wd-button icon="download">Download</wd-button>
<wd-button classPrefix="fish" icon="kehuishouwu">Recyclable</wd-button>

Layout Capability

Block Button

Set the block property.

html
<wd-button block>Primary Button</wd-button>

Attributes

ParameterDescriptionTypeDefault Value
typeButton type, optional values are primary, success, info, warning, dangerstringprimary
variantButton variant, optional values are base, plain, dashed, textstringbase
sizeButton size, optional values are mini, small, medium, largestringmedium
roundRound buttonbooleanfalse
disabledDisabled buttonbooleanfalse
hairlineHairline borderbooleanfalse
blockBlock buttonbooleanfalse
loadingLoading buttonbooleanfalse
textButton textstring-
iconIcon class namestring-
classPrefix v0.1.27Icon class prefixstringwd-icon
loading-propsLoading configurationPartial<LoadingProps>-
open-typeOpen capability type, see ButtonOpenType belowstring-
hover-stop-propagationStop ancestor node click statebooleanfalse
hover-start-timeHow long after pressing to show click state (ms)number20
hover-stay-timeHow long after releasing to remove click state (ms)number70
langUser info language, optional values are zh_CN, zh_TW, enstring-
session-fromSession source (valid when open-type=contact)string-
send-message-titleConversation message card title (valid when open-type=contact)stringCurrent title
send-message-pathConversation message card path (valid when open-type=contact)stringCurrent share path
send-message-imgConversation message card image (valid when open-type=contact)stringScreenshot
app-parameterOpen APP parameter (valid when open-type=launchApp)string-
show-message-cardShow conversation message card (valid when open-type=contact)booleanfalse
button-id v1.3.6Button unique identifierstring-
scope v1.3.14Alipay authorization scope, optional values are phoneNumber, userInfo (valid when open-type=getAuthorize)string-
loading-colorLoading icon colorstring-
custom-classRoot node custom class namestring-
custom-styleRoot node custom stylestring-

ButtonOpenType Open Capabilities

PropertyDescription
feedbackOpen "Feedback" page
shareTrigger user forwarding
getUserInfoGet user info
contactOpen customer service conversation
getPhoneNumberGet phone number
getRealtimePhoneNumberGet real-time phone number (WeChat only)
launchAppOpen APP in mini program
openSettingOpen authorization settings page
chooseAvatarGet user avatar
getAuthorizeSupport Alipay authorization (with scope)
lifestyleFollow lifestyle account (Alipay)
contactShareShare to contacts (Alipay)
openGroupProfileOpen group profile card (WeChat)
openGuildProfileOpen channel profile card (WeChat)
openPublicProfileOpen official account profile card (WeChat)
shareMessageToFriendShare message to friend (WeChat)
addFriendAdd friend (WeChat)
addColorSignAdd color sign (WeChat)
addGroupAppAdd group app (WeChat)
addToFavoritesAdd to favorites (WeChat)
chooseAddressChoose shipping address (WeChat)
chooseInvoiceTitleChoose invoice title (WeChat)
loginAuthorized login (platform capability)
subscribeSubscribe (platform capability)
favoriteFavorite (platform capability)
watchLaterWatch later (platform capability)
openProfileOpen personal homepage (platform capability)
agreePrivacyAuthorizationUser agrees to privacy agreement

Events

Event NameDescriptionParameters
clickClick eventevent
getuserinfoGet user info callbackevent
contactCustomer service message callback (open-type=contact)event
getphonenumberGet phone number callback (open-type=getPhoneNumber)event
getrealtimephonenumber v1.13.0Get real-time phone number callback (open-type=getRealtimePhoneNumber)event
errorOpen capability error callback (open-type=launchApp)event
launchappOpen APP success callback (open-type=launchApp)event
opensettingOpen authorization settings page callback (open-type=openSetting)event
chooseavatarGet user avatar callback (open-type=chooseAvatar)event
agreeprivacyauthorizationAgree to privacy agreement callback (open-type=agreePrivacyAuthorization)event

Slots

nameDescription
defaultButton content

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-button-primary-bg$primary-6主类型背景色
--wot-button-primary-bg-active$primary-7主类型背景激活色
--wot-button-primary-color$primary-6主类型文本色
--wot-button-primary-color-active$primary-7主类型文本激活色
--wot-button-primary-plain-bg$filled-zero主类型 plain 背景色
--wot-button-primary-plain-bg-active$primary-1主类型 plain 背景激活色
--wot-button-primary-plain-border$primary-6主类型 plain 边框色
--wot-button-primary-plain-border-active$primary-7主类型 plain 边框激活色
--wot-button-success-bg$success-main成功类型背景色
--wot-button-success-bg-active$success-clicked成功类型背景激活色
--wot-button-success-color$success-main成功类型文本色
--wot-button-success-color-active$success-clicked成功类型文本激活色
--wot-button-success-plain-bg$filled-zero成功类型 plain 背景色
--wot-button-success-plain-bg-active$success-surface成功类型 plain 背景激活色
--wot-button-success-plain-border$success-main成功类型 plain 边框色
--wot-button-success-plain-border-active$success-clicked成功类型 plain 边框激活色
--wot-button-danger-bg$danger-main危险类型背景色
--wot-button-danger-bg-active$danger-clicked危险类型背景激活色
--wot-button-danger-color$danger-main危险类型文本色
--wot-button-danger-color-active$danger-clicked危险类型文本激活色
--wot-button-danger-plain-bg$filled-zero危险类型 plain 背景色
--wot-button-danger-plain-bg-active$danger-surface危险类型 plain 背景激活色
--wot-button-danger-plain-border$danger-main危险类型 plain 边框色
--wot-button-danger-plain-border-active$danger-clicked危险类型 plain 边框激活色
--wot-button-warning-bg$warning-main警告类型背景色
--wot-button-warning-bg-active$warning-clicked警告类型背景激活色
--wot-button-warning-color$warning-main警告类型文本色
--wot-button-warning-color-active$warning-clicked警告类型文本激活色
--wot-button-warning-plain-bg$filled-zero警告类型 plain 背景色
--wot-button-warning-plain-bg-active$warning-surface警告类型 plain 背景激活色
--wot-button-warning-plain-border$warning-main警告类型 plain 边框色
--wot-button-warning-plain-border-active$warning-clicked警告类型 plain 边框激活色
--wot-button-info-bg$filled-content信息类型背景色
--wot-button-info-bg-active$filled-strong信息类型背景激活色
--wot-button-info-color$text-main信息类型文本色
--wot-button-info-color-active$text-secondary信息类型文本激活色
--wot-button-info-plain-bg$filled-zero信息类型 plain 背景色
--wot-button-info-plain-bg-active$filled-bottom信息类型 plain 背景激活色
--wot-button-info-plain-border$border-main信息类型 plain 边框色
--wot-button-info-plain-border-active$border-strong信息类型 plain 边框激活色
--wot-button-main-color$text-white实心按钮默认文本色
--wot-button-size-icon-mini$n-14mini 尺寸图标字号
--wot-button-size-icon-small$n-16small 尺寸图标字号
--wot-button-size-icon-medium$n-20medium 尺寸图标字号
--wot-button-size-icon-large$n-22large 尺寸图标字号
--wot-button-loading-size$n-20加载图标尺寸
--wot-button-loading-spacing$spacing-extra-tight加载图标与文字间距
--wot-button-font-size-mini$typography-body-size-mainmini 尺寸文字字号
--wot-button-font-size-small$typography-body-size-mainsmall 尺寸文字字号
--wot-button-font-size-medium$typography-body-size-extra-largemedium 尺寸文字字号
--wot-button-font-size-large$typography-body-size-extra-largelarge 尺寸文字字号
--wot-button-line-height-mini$typography-body-line--height-size-mainmini 尺寸文字行高
--wot-button-line-height-small$typography-body-line--height-size-mainsmall 尺寸文字行高
--wot-button-line-height-medium$typography-body-line--height-size-extra-largemedium 尺寸文字行高
--wot-button-line-height-large$typography-body-line--height-size-extra-largelarge 尺寸文字行高
--wot-button-left-right-padding-mini$padding-loosemini 尺寸左右内边距
--wot-button-left-right-padding-small$padding-loosesmall 尺寸左右内边距
--wot-button-left-right-padding-medium$padding-extra-loosemedium 尺寸左右内边距
--wot-button-left-right-padding-large$padding-super-looselarge 尺寸左右内边距
--wot-button-up-down-padding-mini$padding-super-tightmini 尺寸上下内边距
--wot-button-up-down-padding-small$padding-extra-tightsmall 尺寸上下内边距
--wot-button-up-down-padding-medium$padding-tightmedium 尺寸上下内边距
--wot-button-up-down-padding-large$padding-mainlarge 尺寸上下内边距
--wot-button-only-icon-padding-mini$padding-super-tightmini 尺寸仅图标按钮内边距
--wot-button-only-icon-padding-small$padding-extra-tightsmall 尺寸仅图标按钮内边距
--wot-button-only-icon-padding-medium$padding-tightmedium 尺寸仅图标按钮内边距
--wot-button-only-icon-padding-large$padding-looselarge 尺寸仅图标按钮内边距
--wot-button-spacing-mini$spacing-super-tightmini 尺寸图标与文字间距
--wot-button-spacing-small$spacing-super-tightsmall 尺寸图标与文字间距
--wot-button-spacing-medium$spacing-extra-tightmedium 尺寸图标与文字间距
--wot-button-spacing-large$spacing-extra-tightlarge 尺寸图标与文字间距
--wot-button-spacing-block$spacing-tight块级按钮纵向间距
--wot-button-radius-main$radius-main默认圆角
--wot-button-radius-full$radius-radius-full圆形圆角
--wot-button-disabled$opacity-disabled禁用态透明度

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.