# uxcore-tag

> uxcore-tag component for uxcore.

Latest version **2.3.0** (published 2021-06-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install uxcore-tag
pnpm add uxcore-tag
yarn add uxcore-tag
bun add uxcore-tag
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2021-06-02 |
| First published | 2016-06-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 67.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | peijie.dpj |
| Maintainers | taoqili, eternalsky, ex90rts, damian1017 |
| Keywords | react, react-component, uxcore-tag, Tag |

## Links

- npm: https://www.npmjs.com/package/uxcore-tag
- Repository: https://github.com/uxcore/uxcore-tag
- Homepage: https://github.com/uxcore/uxcore-tag#readme
- Issues: http://github.com/uxcore/uxcore-tag/issues
- npm.io page: https://npm.io/package/uxcore-tag

## Dependencies (6)

- [classnames](https://npm.io/package/classnames.md) ^2.1.2
- [prop-types](https://npm.io/package/prop-types.md) 15.x
- [uxcore-icon](https://npm.io/package/uxcore-icon.md) ^0.1.22
- [object-assign](https://npm.io/package/object-assign.md) ^4.0.0
- [uxcore-popover](https://npm.io/package/uxcore-popover.md) ^0.6.2
- [react-lifecycles-compat](https://npm.io/package/react-lifecycles-compat.md) ^3.0.4

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.3.0 (latest) — 2021-06-02
- 2.2.3 — 2018-09-28
- 2.2.2 — 2018-09-28
- 2.2.1 — 2018-09-12
- 2.2.0 — 2018-06-26
- 2.1.2 — 2018-06-07
- 2.1.1 — 2017-10-20
- 2.1.0 — 2017-06-09
- 2.0.2 — 2017-04-18
- 2.0.1 — 2017-03-29
- 2.0.0 — 2017-03-29
- 1.1.0 — 2017-01-04
- 1.0.2 — 2016-07-05
- 1.0.1 — 2016-06-20

## README

---

## uxcore-tag [![Dependency Status](http://img.shields.io/david/uxcore/uxcore-tag.svg?style=flat-square)](https://david-dm.org/uxcore/uxcore-tag) [![devDependency Status](http://img.shields.io/david/dev/uxcore/uxcore-tag.svg?style=flat-square)](https://david-dm.org/uxcore/uxcore-tag#info=devDependencies) 

## TL;DR

uxcore-tag ui component for react

#### setup develop environment

```sh
$ git clone https://github.com/uxcore/uxcore-tag
$ cd uxcore-tag
$ npm install
$ gulp server
```

## Usage

```javascript
const data = [
  {
    tag: 'owner创建0',
    count: 0,
    canAddCount: true,
    createByOwner: true,
    canDelete: true
  },
  {
    tag: 'owner创建1',
    count: 1,
    canAddCount: true,
    createByOwner: true,
    canDelete: false
  }
]

class Demo extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      data: data
    }
  }

  onClickTag(tag) {

    console.log('点击标签: ', tag)
  }

  onAdd(tag) {
    let me = this,
      data = me.state.data;
    

    let item = {
      tag: tag,
      count: 0,
      canAddCount: false,
      createByOwner: false,
      canDelete: true
    }

    data.push(item);

    me.setState({
      data: data
    })

    console.log('添加标签: ' + tag);
  }

  onLike(tag) {
     let me = this,
      data = me.state.data;

      data = data.map(function (item) {
        if (item.tag == tag) {
          item.count = item.count + 1;
          item.canAddCount = false;
        }
        return item
      })

     me.setState({
      data: data
     }) 

    console.log('赞标签: ', tag);
  }
  
  onDelete(tag, cb) {
    let me = this,
      data = me.state.data;

      data = data.filter(function (item) {
        return item.tag != tag
      })

      cb && cb();
     me.setState({
      data: data
     }) 

    console.log('删除标签: ' + tag);
  }

  render() {
    let me = this;

    let props = {
      className: 'tag-classname',
      addTags: true,
      onAdd: me.onAdd.bind(me),
      locale: 'zh-cn'
      //locale: 'en-us'
    }

    return (
      <div className="demo">
        
        <Tag {...props}>
        {me.state.data.map(function (item, index) {
            return <Item 
                key={"uxcore-tag-item-" + index}
                className={item.createByOwner ? "create-by-owner" : ''}
                tag={item.tag}
                count={item.count}
                canAddCount={item.canAddCount}
                canDelete={item.canDelete}
                onClick={me.onClickTag.bind(me)}
                maxDisplayCount={99}
                onAddCount={me.onLike.bind(me)}
                onDelete={me.onDelete.bind(me)}
                confirmDeleteText="确定删除该标签吗?"
                locale="zh-cn"
                >
                {item.tag}
              </Item>
        })}
          
        </Tag>
      </div>
    );
  }
```


## uxcore-tag
![image](https://img.alicdn.com/tps/TB1BPtHKpXXXXcCXpXXXXXXXXXX-328-211.png)


## API

## Props

### Tag

|配置项|类型|必填|默认值|功能/备注|
|---|---|---|---|---|
|className|string|optional|''|额外的className|
|addTags|boolean|optional|true|是否可以新增tag|
|onAdd(tagName [, callback(keepOpen)])|function|optional|noop|新增tag的回调,tagName为新增的标签名；如果传入第二个参数，那么必须要执行callback，keepOpen表示是否保留输入框内容不收起输入框|
|locale|string|optional|'zh-cn'|语言，另可选'en-us', 'pl-pl'|
|placeholder|string|optional|'请输入标签'|添加标签输入框的placeholder自定义|


### TagItem

> 通过 Tag.Item 取得。

|配置项|类型|必填|默认值|功能/备注|
|---|---|---|---|---|
|className|string|optional|''|额外的className|
|tag|string|require|''|tag的值|
|type|string|optional| | 枚举值 `show`, `success`, `warning`, `info`, `danger` |
|count|number|optional|0|标签后面的数字|
|canAddCount|boolean|optional|false|是否可以增加数字|
|canDelete|boolean|optional|false|是否可以删除标签| 
|onClick(tagName)|function|optional|noop|点标签回调|
|maxDisplayCount|number|optional|99|最大显示数字|
|onAddCount(tagName)|function|optional|noop|点击增加数字的加号回调|
|onDelete(tagName, cb)|function|optional|noop|点击删除icon回调 注意手动调用cb，否则弹窗不会消失|
|confirmDeleteText|string|optional|''|确认删除文案，如果不填则直接触发onDelete回调|

---
_Source: https://npm.io/package/uxcore-tag · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
