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

@retailwe/ui-radio

v0.0.21

Published

## 引入

Downloads

17

Readme

Radio 单选框

引入

app.jsonindex.json中引入组件,详细介绍见快速上手

"usingComponents": {
  "wr-radio": "@retailwe/ui-radio/index",
  "wr-radio-group": "@retailwe/ui-radio-group/index"
}

代码演示

基础用法

通过value绑定值当前选中项的 name

<wr-radio-group value="{{ radio }}" bind:change="onChange">
  <wr-radio name="1">单选框 1</wr-radio>
  <wr-radio name="2">单选框 2</wr-radio>
</wr-radio-group>
Page({
  data: {
    radio: '1'
  },
  onChange(event) {
    this.setData({
      radio: event.detail
    });
  }
});

禁用状态

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

<wr-radio-group value="{{ radio }}" bind:change="onChange" disabled>
  <wr-radio name="1">单选框 1</wr-radio>
  <wr-radio name="2">单选框 2</wr-radio>
</wr-radio-group>

禁用文本点击

通过设置label-disabled属性可以禁用单选框文本点击

<wr-radio-group value="{{ radio }}" bind:change="onChange">
  <wr-radio name="1" icon-disabled>单选框 1</wr-radio>
  <wr-radio name="2" icon-disabled>单选框 2</wr-radio>
</wr-radio-group>

自定义颜色

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

<wr-radio-group value="{{ radio }}" bind:change="onChange">
 <wr-radio name="1" checked-color="#07c160">单选框 1</wr-radio>
 <wr-radio name="2" checked-color="#07c160">单选框 2</wr-radio>
</wr-radio-group>

自定义大小

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

<wr-radio-group value="{{ radio }}" bind:change="onChange">
  <wr-radio name="1">单选框 1</wr-radio>
  <wr-radio name="2" icon-size="25px">单选框 2</wr-radio>
</wr-radio-group>

自定义图标

通过icon插槽自定义图标,需要设置use-icon-slot属性

<wr-radio-group value="{{ radio }}" bind:change="onChange">
  <wr-radio use-icon-slot value="{{ radio }}" name="1">
    自定义图标
    <image slot="icon" src="{{ radio === '1' ? icon.active : icon.normal }}" />
  </wr-radio>
  <wr-radio use-icon-slot value="{{ radio }}" name="2">
    自定义图标
    <image slot="icon" src="{{ radio === '2' ? icon.active : icon.normal }}" />
  </wr-radio>
</wr-radio-group>
Page({
  data: {
    radio: true,
    icon: {
      normal: '//img.yzcdn.cn/icon-normal.png',
      active: '//img.yzcdn.cn/icon-active.png'
    }
  },
  onChange(event) {
    this.setData({
      radio: event.detail
    });
  }
});

与 Cell 组件一起使用

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

<wr-radio-group value="{{ radio }}" bind:change="onChange">
  <wr-cell-group>
    <wr-cell
      title="单选框 1"
      clickable
      data-name="1"
      bind:click="onClick"
    >
      <wr-radio slot="right-icon" name="1" />
    </wr-cell>
    <wr-cell
      title="单选框 2"
      clickable
      data-name="2"
      bind:click="onClick"
    >
      <wr-radio slot="right-icon" name="2" />
    </wr-cell>
  </wr-cell-group>
</wr-radio-group>
Page({
  data: {
    radio: '1'
  },

  onChange(event) {
    this.setData({
      radio: event.detail
    });
  },

  onClick(event) {
    const { name } = event.currentTarget.dataset;
    this.setData({
      radio: name
    });
  }
});

API

RadioGroup Props

| 参数 | 说明 | 类型 | 默认值 | 版本 | |-----------|-----------|-----------|-------------|-------------| | name | 在表单内提交时的标识符 | string | - | - | | value | 当前选中项的标识符 | any | - | - | | disabled | 是否禁用所有单选框 | boolean | false | - |

Radio Props

| 参数 | 说明 | 类型 | 默认值 | 版本 | |-----------|-----------|-----------|-------------|-------------| | name | 标识符 | string | - | - | | shape | 形状,可选值为 square | string | round | - | | disabled | 是否为禁用状态 | boolean | false | - | | label-disabled | 是否禁用文本内容点击 | boolean | false | - | | label-position | 文本位置,可选值为 left | string | right | - | | icon-size | 图标大小,默认单位为px | string | number | 20px | - | | checked-color | 选中状态颜色 | string | #1989fa | - | | use-icon-slot | 是否使用 icon 插槽 | boolean | false | - |

Radio Event

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

Radio 外部样式类

| 类名 | 说明 | |-----------|-----------| | wr-class | 根节点样式类 | | wr-class-icon | 图标样式类 | | wr-class-label | 描述信息样式类 |

RadioGroup Event

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