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-dropdown-menu

v0.0.26

Published

## 引入

Downloads

23

Readme

dropdown-menu 下拉菜单

引入

全局引入,在 miniprogram 根目录下的app.json中配置,局部引入,在需要引入的页面或组件的index.json中配置。

// app.json 或 index.json
"usingComponents": {
  "wr-dropdown-menu": "@retailwe/ui-dropdown-menu/index"
}

代码演示

基础用法

<wr-dropdown-menu>
  <wr-dropdown-item value="{{ value1 }}" options="{{ option1 }}" />
  <wr-dropdown-item value="{{ value2 }}" options="{{ option2 }}" />
</wr-dropdown-menu>
Page({
  data: {
    option1: [
      { text: '全部商品', value: 0 },
      { text: '新款商品', value: 1 },
      { text: '活动商品', value: 2 },
    ],
    option2: [
      { text: '默认排序', value: 'a' },
      { text: '好评排序', value: 'b' },
      { text: '销量排序', value: 'c' },
    ],
    value1: 0,
    value2: 'a',
  },
});

自定义菜单内容

<wr-dropdown-menu>
  <wr-dropdown-item value="{{ value1 }}" options="{{ option1 }}" />
  <wr-dropdown-item id="item" title="{{ itemTitle }}">
    <wr-cell title="{{ switchTitle1 }}">
      <wr-icon
        slot="right-icon"
        size="40rpx"
        color="{{switch1 ? '#1989fa' : '#969799'}}"
        name="{{switch1 ? 'selected' : 'selected-border'}}"
        bind:tap="onSwitch1Change"
      />
    </wr-cell>
    <wr-cell title="{{ switchTitle2 }}">
      <wr-icon
        slot="right-icon"
        size="40rpx"
        color="{{switch2 ? '#1989fa' : '#969799'}}"
        name="{{switch2 ? 'selected' : 'selected-border'}}"
        bind:tap="onSwitch2Change"
      />
    </wr-cell>
    <button type="primary" bind:tap="onConfirm">
      确定
    </button>
  </wr-dropdown-item>
</wr-dropdown-menu>
Page({
  data: {
    option1: [
      { text: '全部商品', value: 0 },
      { text: '新款商品', value: 1 },
      { text: '活动商品', value: 2 },
    ],
    option2: [
      { text: '默认排序', value: 'a' },
      { text: '好评排序', value: 'b' },
      { text: '销量排序', value: 'c' },
    ],
    value1: 0,
    value2: 'a',
    switchTitle1: '包邮',
    switchTitle2: '团购',
    itemTitle: '筛选',
    switch1: false,
    switch2: false,
  },

  onConfirm() {
    this.selectComponent('#item').toggle();
  },

  onSwitch1Change() {
    this.setData({ switch1: !this.data.switch1 });
  },

  onSwitch2Change() {
    this.setData({ switch2: !this.data.switch2 });
  },
});

自定义选中状态颜色

<wr-dropdown-menu active-color="#ee0a24">
  <wr-dropdown-item value="{{ value1 }}" options="{{ option1 }}" />
  <wr-dropdown-item value="{{ value2 }}" options="{{ option2 }}" />
</wr-dropdown-menu>

向上展开

<wr-dropdown-menu direction="up">
  <wr-dropdown-item value="{{ value1 }}" options="{{ option1 }}" />
  <wr-dropdown-item value="{{ value2 }}" options="{{ option2 }}" />
</wr-dropdown-menu>

禁用菜单

<wr-dropdown-menu>
  <wr-dropdown-item value="{{ value1 }}" disabled options="{{ option1 }}" />
  <wr-dropdown-item value="{{ value2 }}" disabled options="{{ option2 }}" />
</wr-dropdown-menu>

API

DropdownMenu Props

| Attribute | Description | Type | Default | Version | | ---------------------- | ------------------------------ | --------- | --------- | ------- | | active-color | 菜单标题和选项的选中态颜色 | string | #1989fa | - | | z-index | 菜单栏 z-index 层级 | number | 10 | - | | duration | 动画时长,单位毫秒 | number | 200 | - | | direction | 菜单展开方向,可选值为 up | string | down | - | | overlay | 是否显示遮罩层 | boolean | true | - | | close-on-click-overlay | 是否在点击遮罩层后关闭菜单 | boolean | true | - | | close-on-click-outside | 是否在点击外部 menu 后关闭菜单 | boolean | true | - |

DropdownItem Props

| Attribute | Description | Type | Default | Version | | ----------- | ---------------------- | ------------------ | ----------------------- | ------- | | value | 当前选中项对应的 value | string | number | - | - | | title | 菜单项标题 | string | Text of selected option | - | | options | 选项数组 | Option[] | [] | - | | disabled | 是否禁用菜单 | boolean | false | - | | title-class | 标题额外类名 | string | - | - |

DropdownItem Events

| Event | Description | Arguments | | ------ | ----------------------------- | --------- | | change | 点击选项导致 value 变化时触发 | value | | close | 关闭菜单栏时触发 | - |

DropdownItem Methods

通过 selectComponent(id) 可访问

| Name | Attribute | Return value | Description | | ------ | ------------- | ------------ | ---------------- | | toggle | show: boolean | - | 切换菜单是否展示 |

Data Structure of Option

| Key | Description | Type | | ----- | ------------------------------------------ | ------------------ | | text | 文字 | string | | value | 标识符 | string | number | | icon | 左侧图标名称或图片链接,可选值见 Icon 组件 | string |

DropdownMenu 外部样式类

| 类名 | 说明 | | -------- | ---------------- | | wr-class | 根节点外部样式类 |

DropdownItem 外部样式类

| 类名 | 说明 | | -------- | ---------------- | | wr-class | 根节点外部样式类 |