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-tabbar

v0.0.12

Published

## 引入

Downloads

14

Readme

Tabbar 标签栏

引入

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

"usingComponents": {
  "wr-tabbar": "@retailwe/ui-tabbar/index",
  "wr-tabbar-item": "@retailwe/ui-tabbar/tabbar-item/index"
}

代码演示

基础用法

<wr-tabbar active="{{ active }}" bind:change="onChange">
  <wr-tabbar-item icon="home-o">标签</wr-tabbar-item>
  <wr-tabbar-item icon="search">标签</wr-tabbar-item>
  <wr-tabbar-item icon="friends-o">标签</wr-tabbar-item>
  <wr-tabbar-item icon="setting-o">标签</wr-tabbar-item>
</wr-tabbar>
Page({
  data: {
    active: 0,
  },
  onChange(event) {
    // event.detail 的值为当前选中项的索引
    this.setData({ active: event.detail });
  },
});

通过名称匹配

在标签未指定name属性的情况下,active的值为当前标签的索引 在标签指定name属性的情况下,active的值为当前标签的name

<wr-tabbar active="{{ active }}" bind:change="onChange">
  <wr-tabbar-item name="home" icon="home-o">标签</wr-tabbar-item>
  <wr-tabbar-item name="search" icon="search">标签</wr-tabbar-item>
  <wr-tabbar-item name="friends" icon="friends-o">标签</wr-tabbar-item>
  <wr-tabbar-item name="setting" icon="setting-o">标签</wr-tabbar-item>
</wr-tabbar>
Page({
  data: {
    active: 'home',
  },
  onChange(event) {
    this.setData({ active: event.detail });
  },
});

显示徽标

<wr-tabbar active="{{ active }}" bind:change="onChange">
  <wr-tabbar-item icon="home-o">标签</wr-tabbar-item>
  <wr-tabbar-item icon="search" dot>标签</wr-tabbar-item>
  <wr-tabbar-item icon="friends-o" info="5">标签</wr-tabbar-item>
  <wr-tabbar-item icon="setting-o" info="20">标签</wr-tabbar-item>
</wr-tabbar>

url图标

icon属性也支持传入图片url

<wr-tabbar
    active="{{ active4 }}"
    data-key="active4"
    wr-class="tabbar-position"
    safe-area-inset-bottom="{{ false }}"
    bind:change="onChange"
  >
    <wr-tabbar-item icon="{{active4 === 0 ? icon.active : icon.normal}}" info="3">
      url图标
    </wr-tabbar-item>
    <wr-tabbar-item icon="tabbar-fenlei">标签</wr-tabbar-item>
    <wr-tabbar-item icon="tabbar-gerenzhongxin">标签</wr-tabbar-item>
  </wr-tabbar>

自定义图标

可以通过 slot 自定义图标,其中 icon slot 代表未选中状态下的图标,icon-active slot 代表选中状态下的图标

<wr-tabbar
    active="{{ active5 }}"
    bind:change="onChange"
  >
    <wr-tabbar-item info="3">
      <image
        slot="icon"
        src="{{ icon.normal }}"
        mode="aspectFit"
        style="width: 30px; height: 18px;"
      />
      <image
        slot="icon-active"
        src="{{ icon.active }}"
        mode="aspectFit"
        style="width: 30px; height: 18px;"
      />
      <view style="color: {{active5 === 0 ? '#1989fa' : ''}}">自定义</view>
    </wr-tabbar-item>
    <wr-tabbar-item icon="tabbar-fenlei">标签</wr-tabbar-item>
    <wr-tabbar-item icon="tabbar-gerenzhongxin">标签</wr-tabbar-item>
  </wr-tabbar>
Page({
  data: {
    active: 0,
    icon: {
      normal: 'https://img.yzcdn.cn/wrt/user-inactive.png',
      active: 'https://img.yzcdn.cn/wrt/user-active.png',
    },
  },
  onChange(event) {
    this.setData({ active: event.detail });
  },
});

自定义颜色

<wr-tabbar
  active="{{ active }}"
  active-color="#07c160"
  inactive-color="#000"
  bind:change="onChange"
>
  <wr-tabbar-item icon="home-o">标签</wr-tabbar-item>
  <wr-tabbar-item icon="search">标签</wr-tabbar-item>
  <wr-tabbar-item icon="friends-o">标签</wr-tabbar-item>
  <wr-tabbar-item icon="setting-o">标签</wr-tabbar-item>
</wr-tabbar>
Page({
  data: {
    active: 0,
  },
  onChange(event) {
    this.setData({ active: event.detail });
  },
});

切换标签事件

<wr-tabbar active="{{ active }}" bind:change="onChange">
  <wr-tabbar-item icon="home-o">标签1</wr-tabbar-item>
  <wr-tabbar-item icon="search">标签2</wr-tabbar-item>
  <wr-tabbar-item icon="friends-o">标签3</wr-tabbar-item>
  <wr-tabbar-item icon="setting-o">标签4</wr-tabbar-item>
</wr-tabbar>
Page({
  data: {
    active: 0,
  },
  onChange(event) {
    wx.showToast({
      title: `点击标签 ${event.detail + 1}`,
      icon: 'none',
    });
  },
});

API

Tabbar Props

| 参数 | 说明 | 类型 | 默认值 | 版本 | | --- | --- | --- | --- | --- | | active | 当前选中标签的索引 | number | - | - | | fixed | 是否固定在底部 | boolean | true | - | | border | 是否展示外边框 | boolean | true | - | | z-index | 元素 z-index | number | 1 | - | | active-color | 选中标签的颜色 | string | #1989fa | - | | inactive-color | 未选中标签的颜色 | string | #7d7e80 | - | | safe-area-inset-bottom | 是否为 iPhoneX 留出底部安全距离 | boolean | true | - |

Tabbar Event

| 事件名 | 说明 | 参数 | | ----------- | -------------- | ---------------------------------------- | | bind:change | 切换标签时触发 | event.detail: 当前选中标签的名称或索引值 |

TabbarItem Props

| 参数 | 说明 | 类型 | 默认值 | 版本 | | --- | --- | --- | --- | --- | | name | 标签名称,作为匹配的标识符 | string | number | 当前标签的索引值 | - | | icon | 图标名称或图片链接 | string | - | - | | dot | 是否显示小红点 | boolean | - | - | | info | 图标右上角提示信息 | string | number | - | - |

TabbarItem Slot

| 名称 | 说明 | | ----------- | -------------- | | icon | 未选中时的图标 | | icon-active | 选中时的图标 |