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

tingle-picker

v0.2.0

Published

tingle-picker component for tingle.

Downloads

3

Readme

Picker

tingle-picker 是 tingle-xxxpicker 的容器控件。提供一个搜索条和一个可以垂直滚动的列表容器。

效果图:

Simple Usage


constructor(props) {
    super(props);
    this.state = {
        city: city,
        filter: ''
    };
}

_renderGroupLists() {
    let t = this;
    let arr = []
    let groups = Object.keys(t.state.city);
    groups.forEach(function(group, i) {
        arr.push(<GroupList className={group} title={group} key={group}>
                    {city[group].map(function(city, i) {
                        return <div className="tLH44 tPL10" key={group + i} data-group={group} data-name={city.name} onClick={t._handleClick.bind(t)}>{city.name}</div>
                    })}
                </GroupList>)
    });
    return arr;
}

_handleClick(e) {
    let t = this;
    let target = e.currentTarget;
    let name = target.getAttribute('data-name');
    let group = target.getAttribute('data-group');
    let data = city[group].filter(function(ele) {return ele.name == name})[0];
    alert(data.name);
}

_handleSearch(value) {
    let t = this;
    t._filterList(value);
    t.setState({
        filter: value
    })
}

/**
 * 判断是否是汉字
 */

_isChinese(str) {
    return /^[\u4e00-\u9fa5]+$/.test(str);
}

_filterList(value) {
    let t = this;
    let groups = Object.keys(city);
    let newCity = {};
    if (t._isChinese(value)) {
        groups.forEach(function(group, i) {
            let groupCity = city[group].filter(function(ele) {
                return ele.name.indexOf(value) != -1
            })
            if (groupCity.length != 0) {
                newCity[group] = groupCity;
            }
        });
    }
    else {
        groups.forEach(function(group, i) {
            let groupCity = city[group].filter(function(ele) {
                return ele.abbr.indexOf(value) != -1 || ele.pinyin.indexOf(value) != -1
            })
            if (groupCity.length != 0) {
                newCity[group] = groupCity;
            }
        });
    }
    t.setState({
        city: newCity
    })
}

render() {
    let t = this;
    
    return (
        <Picker
        show={true} 
        showSearchBar={true}
        filter={t.state.filter}
        onSearch={t._handleSearch.bind(t)}>
            <Picker.List>
                {t._renderGroupLists()}
            </Picker.List>
        </Picker>
  
}

Options 可用配置

| 配置项 | 类型 | 必填 | 默认值 | 功能/备注 | |---|---|---|---|---| |filter|string|optional|-|开启搜索时的默认搜索值| |show|boolean|optional|false|是否显示| |offsetTop|number|optional|0|picker 的主体部分距离顶端的高度,用于在 picker 插入自定义的部分| |offsetBottom|number|optional|0|picker 的主体部分距离底端的高度,用于在 picker 插入自定义的部分| |searchPlaceholder|string|optional|中文/拼音/首字母| |showSearchBar|boolean|optional|false|是否显示搜索条| |onSearch|function|optional|-|搜索条中的值发生改变时触发,可以在此时通过更改 filter 来改变 searchbar 里的显示

Links 相关链接