npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ophiuchus/checkbox

v1.0.1

Published

### 介绍

Readme

Checkbox 复选框

介绍

用于在选中和非选中状态之间进行切换。

引入

// 方式1(推荐)
import Vue from 'vue';
import Checkbox from '@ophiuchus/checkbox';

Vue.use(Checkbox);

// 方式2
import Vue from 'vue';
import { Checkbox, CheckboxGroup } from '@ophiuchus/checkbox';

Vue.component(Checkbox.name, Checkbox);
Vue.component(CheckboxGroup.name, CheckboxGroup);

代码演示

基础用法

通过 v-model 绑定复选框的勾选状态。

<sf-checkbox v-model="checked">复选框</sf-checkbox>
export default {
  data() {
    return {
      checked: true,
    };
  },
};

禁用状态

通过设置 disabled 属性可以禁用复选框。

<sf-checkbox v-model="checked" disabled>复选框</sf-checkbox>

自定义形状

shape 属性设置为 square,复选框的形状会变成方形。

<sf-checkbox v-model="checked" shape="square">复选框</sf-checkbox>

自定义颜色

通过 checked-color 属性设置选中状态的图标颜色。

<sf-checkbox v-model="checked" checked-color="#ee0a24">复选框</sf-checkbox>

自定义大小

通过 icon-size 属性可以自定义图标的大小。

<sf-checkbox v-model="checked" icon-size="24px">复选框</sf-checkbox>

自定义图标

通过 icon 插槽自定义图标,可以通过 slotProps 判断是否为选中状态.

<sf-checkbox v-model="checked">
  自定义图标
  <template #icon="props">
    <img class="img-icon" :src="props.checked ? activeIcon : inactiveIcon" />
  </template>
</sf-checkbox>

<style>
  .img-icon {
    height: 20px;
  }
</style>
export default {
  data() {
    return {
      checked: true,
      activeIcon: 'https://img3.tuhu.org/3rq0A7JtvChtaD5QMO3HgA_w98_h78.png',
      inactiveIcon: 'https://img3.tuhu.org/4rjx6O9PLzcq84oLWQeXww_w98_h78.png',
    };
  },
};

禁用文本点击

设置 label-disabled 属性后,点击图标以外的内容不会触发复选框切换。

<sf-checkbox v-model="checked" label-disabled>复选框</sf-checkbox>

复选框组

复选框可以与复选框组一起使用,复选框组通过 v-model 数组绑定复选框的勾选状态。

<sf-checkbox-group v-model="result">
  <sf-checkbox name="a">复选框 a</sf-checkbox>
  <sf-checkbox name="b">复选框 b</sf-checkbox>
</sf-checkbox-group>
export default {
  data() {
    return {
      result: ['a', 'b'],
    };
  },
};

水平排列

direction 属性设置为 horizontal 后,复选框组会变成水平排列。

<sf-checkbox-group v-model="result" direction="horizontal">
  <sf-checkbox name="a">复选框 a</sf-checkbox>
  <sf-checkbox name="b">复选框 b</sf-checkbox>
</sf-checkbox-group>
export default {
  data() {
    return {
      result: [],
    };
  },
};

限制最大可选数

通过 max 属性可以限制复选框组的最大可选数。

<sf-checkbox-group v-model="result" :max="2">
  <sf-checkbox name="a">复选框 a</sf-checkbox>
  <sf-checkbox name="b">复选框 b</sf-checkbox>
  <sf-checkbox name="c">复选框 c</sf-checkbox>
</sf-checkbox-group>

全选与反选

通过 CheckboxGroup 实例上的 toggleAll 方法可以实现全选与反选。

<sf-checkbox-group v-model="result" ref="checkboxGroup">
  <sf-checkbox name="a">复选框 a</sf-checkbox>
  <sf-checkbox name="b">复选框 b</sf-checkbox>
  <sf-checkbox name="c">复选框 c</sf-checkbox>
</sf-checkbox-group>

<sf-button type="primary" @click="checkAll">全选</sf-button>
<sf-button type="info" @click="toggleAll">反选</sf-button>
export default {
  data() {
    return {
      result: [],
    };
  },
  methods: {
    checkAll() {
      this.$refs.checkboxGroup.toggleAll(true);
    },
    toggleAll() {
      this.$refs.checkboxGroup.toggleAll();
    },
  },
};

搭配单元格组件使用

此时你需要再引入 CellCellGroup 组件,并通过 Checkbox 实例上的 toggle 方法触发切换。

<sf-checkbox-group v-model="result">
  <sf-cell-group>
    <sf-cell
      v-for="(item, index) in list"
      clickable
      :key="item"
      :title="`复选框 ${item}`"
      @click="toggle(index)"
    >
      <template #right-icon>
        <sf-checkbox :name="item" ref="checkboxes" />
      </template>
    </sf-cell>
  </sf-cell-group>
</sf-checkbox-group>
export default {
  data() {
    return {
      list: ['a', 'b'],
      result: [],
    };
  },
  methods: {
    toggle(index) {
      this.$refs.checkboxes[index].toggle();
    },
  },
};

API

Checkbox Props

| 参数 | 说明 | 类型 | 默认值 | | --------------- | ------------------------- | ------------------ | --------- | | v-model (value) | 是否为选中状态 | boolean | false | | name | 标识符 | any | - | | shape | 形状,可选值为 square | string | round | | disabled | 是否禁用复选框 | boolean | false | | label-disabled | 是否禁用复选框文本点击 | boolean | false | | label-position | 文本位置,可选值为 left | string | right | | icon-size | 图标大小,默认单位为 px | number | string | 20px | | checked-color | 选中状态颜色 | string | #1989fa | | bind-group | 是否与复选框组绑定 | boolean | true |

CheckboxGroup Props

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model (value) | 所有选中项的标识符 | any[] | - | | disabled | 是否禁用所有复选框 | boolean | false | | max | 最大可选数,0为无限制 | number | string | 0 | | direction | 排列方向,可选值为 horizontal | string | vertical | | icon-size | 所有复选框的图标大小,默认单位为 px | number | string | 20px | | checked-color | 所有复选框的选中状态颜色 | string | #1989fa |

Checkbox Events

| 事件名 | 说明 | 回调参数 | | ------ | ------------------------ | ------------------ | | change | 当绑定值变化时触发的事件 | checked: boolean | | click | 点击复选框时触发 | event: Event |

CheckboxGroup Events

| 事件名 | 说明 | 回调参数 | | ------ | ------------------------ | -------------- | | change | 当绑定值变化时触发的事件 | names: any[] |

Checkbox Slots

| 名称 | 说明 | 参数 | | ------- | ---------- | ------------------ | | default | 自定义文本 | - | | icon | 自定义图标 | checked: boolean |

CheckboxGroup 方法

通过 ref 可以获取到 CheckboxGroup 实例并调用实例方法,详见组件实例方法

| 方法名 | 说明 | 参数 | 返回值 | | --- | --- | --- | --- | | toggleAll | 切换所有复选框,传 true 为选中,false 为取消选中,不传参为取反 | options?: boolean | object | - |

toggleAll 方法示例

const { checkboxGroup } = this.$refs;

// 全部反选
checkboxGroup.toggleAll();
// 全部选中
checkboxGroup.toggleAll(true);
// 全部取消
checkboxGroup.toggleAll(false);

// 全部反选,并跳过禁用的复选框
checkboxGroup.toggleAll({
  skipDisabled: true,
});
// 全部选中,并跳过禁用的复选框
checkboxGroup.toggleAll({
  checked: true,
  skipDisabled: true,
});

Checkbox 方法

通过 ref 可以获取到 Checkbox 实例并调用实例方法,详见组件实例方法

| 方法名 | 说明 | 参数 | 返回值 | | --- | --- | --- | --- | | toggle | 切换选中状态,传 true 为选中,false 为取消选中,不传参为取反 | checked?: boolean | - |

样式变量

组件提供了下列 Less 变量,可用于自定义样式,使用方法请参考主题定制

| 名称 | 默认值 | 描述 | | ----------------------------------- | -------------------------- | ---- | | @checkbox-size | 20px | - | | @checkbox-border-color | @gray-5 | - | | @checkbox-transition-duration | @animation-duration-fast | - | | @checkbox-label-margin | @padding-xs | - | | @checkbox-label-color | @text-color | - | | @checkbox-checked-icon-color | @blue | - | | @checkbox-disabled-icon-color | @gray-5 | - | | @checkbox-disabled-label-color | @gray-5 | - | | @checkbox-disabled-background-color | @border-color | - |