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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ophiuchus/radio

v1.0.1

Published

### 介绍

Downloads

4

Readme

Radio 单选框

介绍

用于在多个选项中选择单个结果。

引入

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

Vue.use(Radio);

// 方式2
import Vue from 'vue';
import { Radio, RadioGroup } from '@ophiuchus/radio';

Vue.component(Radio.name, Radio);
Vue.component(RadioGroup.name, RadioGroup);

代码演示

基础用法

通过 v-model 绑定值当前选中项的 name。

<sf-radio-group v-model="radio">
  <sf-radio name="1">单选框 1</sf-radio>
  <sf-radio name="2">单选框 2</sf-radio>
</sf-radio-group>
export default {
  data() {
    return {
      radio: '1',
    };
  },
};

水平排列

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

<sf-radio-group v-model="radio" direction="horizontal">
  <sf-radio name="1">单选框 1</sf-radio>
  <sf-radio name="2">单选框 2</sf-radio>
</sf-radio-group>

禁用状态

通过 disabled 属性禁止选项切换,在 Radio 上设置 disabled 可以禁用单个选项。

<sf-radio-group v-model="radio" disabled>
  <sf-radio name="1">单选框 1</sf-radio>
  <sf-radio name="2">单选框 2</sf-radio>
</sf-radio-group>

自定义形状

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

<sf-radio-group v-model="radio">
  <sf-radio name="1" shape="square">单选框 1</sf-radio>
  <sf-radio name="2" shape="square">单选框 2</sf-radio>
</sf-radio-group>

自定义颜色

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

<sf-radio-group v-model="radio">
  <sf-radio name="1" checked-color="#ee0a24">单选框 1</sf-radio>
  <sf-radio name="2" checked-color="#ee0a24">单选框 2</sf-radio>
</sf-radio-group>

自定义大小

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

<sf-radio-group v-model="radio">
  <sf-radio name="1" icon-size="24px">单选框 1</sf-radio>
  <sf-radio name="2" icon-size="24px">单选框 2</sf-radio>
</sf-radio-group>

自定义图标

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

<sf-radio-group v-model="radio">
  <sf-radio name="1">
    单选框 1
    <template #icon="props">
      <img class="img-icon" :src="props.checked ? activeIcon : inactiveIcon" />
    </template>
  </sf-radio>
  <sf-radio name="2">
    单选框 2
    <template #icon="props">
      <img class="img-icon" :src="props.checked ? activeIcon : inactiveIcon" />
    </template>
  </sf-radio>
</sf-radio-group>

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

禁用文本点击

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

<sf-radio-group v-model="radio">
  <sf-radio name="1" label-disabled>单选框 1</sf-radio>
  <sf-radio name="2" label-disabled>单选框 2</sf-radio>
</sf-radio-group>

与 Cell 组件一起使用

此时你需要再引入 CellCellGroup 组件。

<sf-radio-group v-model="radio">
  <sf-cell-group>
    <sf-cell title="单选框 1" clickable @click="radio = '1'">
      <template #right-icon>
        <sf-radio name="1" />
      </template>
    </sf-cell>
    <sf-cell title="单选框 2" clickable @click="radio = '2'">
      <template #right-icon>
        <sf-radio name="2" />
      </template>
    </sf-cell>
  </sf-cell-group>
</sf-radio-group>

API

Radio Props

| 参数 | 说明 | 类型 | 默认值 | | -------------- | ------------------------- | ------------------ | --------- | | 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 |

RadioGroup Props

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

Radio Events

| 事件名 | 说明 | 回调参数 | | ------ | ---------------- | -------------- | | click | 点击单选框时触发 | event: Event |

RadioGroup Events

| 事件名 | 说明 | 回调参数 | | ------ | ------------------------ | -------------- | | change | 当绑定值变化时触发的事件 | name: string |

Radio Slots

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

样式变量

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

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