使用用例

基本按钮类型 type

spreadshrink; spread时按钮只能是圆形,且不包含文字
<template>
  <div style="background: var(--font-dark-gray)">
    <div class="in-bk">
      <GButton class="w-50 mg-10" type="spread">无法包含文字</GButton>
      <GButton class="w-50 mg-10" type="spread" icon="fork"></GButton>
      <GButton class="w-50 mg-10" type="shrink" shape="round"></GButton>
      <GButton class="w-100 mg-10" type="shrink">确认</GButton>
    </div>
  </div>
</template>

使用 Icon 来定义按钮图标

图片形式传入icon, 如果想要定义样式,使用后代选择器
自定义icon
icon会置于左侧位置,且当按钮为圆形时展示在按钮中央。传入值种类如下: 1. 图片路径: 包含/,.,视作图片路径或base64。2. 可变色图标: 以$开头,激活时提高颜色亮度。 3. 黑色背景图标:自带黑色圆形背景。 2,3类图标会在移除$字首后,以decoration-${icon}的方式传入class中。通过:deep伪类和后代选择器创建自定义css图标,选择器见代码css部分。
<template>
  <div style="background: var(--font-dark-gray); color: var(--blank-white);">
    <div>
      <GButton class="w-150 mg-10" type="shrink" balance icon="round">round</GButton>
      <GButton class="w-150 mg-10" type="shrink" balance icon="fork">fork</GButton>
      <GButton class="w-150 mg-10" type="shrink" balance icon="del">del</GButton>
      <GButton class="w-150 mg-10" type="shrink" balance icon="loading">loading</GButton>
      <GButton class="w-50 mg-10" type="shrink" balance shape="round" icon="$menu"></GButton>
      <GButton class="w-50 mg-10" type="shrink" balance shape="round" icon="$sort"></GButton>
      <GButton class="w-50 mg-10" type="shrink" balance shape="round" icon="$filter"></GButton>
      <GButton class="w-50 mg-10" type="shrink" balance shape="round" icon="$back"></GButton>
      <GButton class="w-50 mg-10" type="shrink" balance shape="round" icon="$close"></GButton>
      <GButton class="w-50 mg-10" type="shrink" balance shape="round" icon="$add"></GButton>
      <GButton class="w-50 mg-10" type="shrink" balance shape="round" icon="$reduce"></GButton>
    </div>
    <div style="padding-left: 10px;font-size: 20px;">图片形式传入icon, 如果想要定义样式,使用后代选择器</div>
    <div>
      <GButton class="w-150 mg-10 customed-image" type="shrink" :icon="$withBase('/flower.webp')" balance>图片icon</GButton>
    </div>
    <div style="padding-left: 10px;font-size: 20px;">自定义icon</div>
    <div>
      <GButton class="w-150 mg-10" type="shrink" icon="custom" balance>自定义</GButton>
    </div>
  </div>
</template>
<style>
/** 非所有例子都有对应实例按钮 */
/** 举例一: 给按钮传入类名,通过后代选择器选中1类型的图片,类 */
.customed-image.button-wrap-button .button-wrap-special {
  transform: rotate(180deg);
}
/** 举例二: 使用可变色图标, $custom, 关键路径为.decoration-custom::before, 双类名提供优先级支持 */
.decoration-colord-image.decoration-custom::before {
  background-image: url(./assets/custom.png);
  background-size: 80%;
}

/** 举例三: 使用黑背图标, custom, 关键路径为.decoration-custom::before, 双类名提供优先级支持,通常操作伪元素来表现样式,可使用背景图替代 */
.decoration-black-bgi.decoration-custom::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: block;
  width: 0;
  height: 0;

  --b-width: 9px;
  border: calc(var(--b-width) * 2) solid rgb(251, 204, 62);
  border-top: none;
  border-left: var(--b-width) solid transparent;
  border-right: var(--b-width) solid transparent;
}
</style>

disable 和 sleep

使用disable禁用按钮,内置sleep方法实现按钮后禁用一段时间。
<template>
  <div style="background: var(--font-dark-gray)">
    <div class="in-bk">
      <GButton class="w-100 mg-10" type="shrink">确认</GButton>
      <GButton class="w-100 mg-10" type="shrink" disable>确认</GButton>
      <GButton class="w-300 mg-10" type="shrink" :sleep="1000">确认(后禁用)</GButton>
    </div>
  </div>
</template>

主题

主题分为lightdark,默认dark
<template>
  <div style="background: var(--blank-white)">
    <GButton class="w-150 mg-10" type="shrink" icon="fork" theme="dark" balance>确认</GButton>
  </div>
</template>

杂项

使用balance来控制文字表现。使用shape来快速定义按钮形状。提供一个有replay属性的对象,按钮会在点击时尝试执行函数。
<template>
  <div style="background: var(--font-dark-gray)">
    <div class="in-bk">
      <GButton class="w-150 mg-10" type="shrink" attention>attention</GButton>
    </div>
    <div class="in-bk">
      <GButton class="w-200 mg-10 bk" type="shrink" icon="round">确认</GButton>
      <GButton class="w-200 mg-10 bk" type="shrink" icon="round" balance>确认</GButton>
    </div>
    <div class="in-bk">
      <GButton class="w-50 mg-10 bk" type="shrink" shape="round"></GButton>
    </div>
  </div>
</template>

参数定义

参数说明类型是否可选默认值
type按钮类型'shrink' | 'spread'可选shrink
shape按钮形状'round'可选-
balance当按钮长度过小时,用于平衡视觉效果boolean可选-
icon按钮按钮图标string可选-
disable按钮是否禁用boolean可选-
attention红色感叹号boolean可选-
theme按钮主题'dark' | 'light'可选light
sleep点击后禁用时间number可选-
sound按钮声音{ replay: () => void }可选-
Last Updated:
Contributors: shi-zhong