react-count
===========
Real-time counter button [React](http://facebook.github.io/react/) component baked by [Firebase](https://www.firebase.com/).
See demo [here](http://react-count.hashobject.com/).
## Use cases
This component can we useful in the following cases:
- follow/unfollow button with the showing number of followers
- like/unlike button with the showing number of likes
- page views counter
- counter for the users currently online
- generic read-only counters hooked up to any numeric data from your Firebase
## Install
If you use webpack just install react-count module
```
npm install react-count
```
and require it anywhere in your react app:
```
var Count = require('react-count');
```
or you can use additional more specific components like:
```
var OnlineCount = require('react-count').OnlineCount;
var ViewCount = require('react-count').ViewCount;
```
## Demo
You can see online demo [here](http://react-count.hashobject.com/) or you can open `examples/index.html` in your browser locally.
See `examples\App.js` to understand how this component can be used in your React applications.
## Customization
`ViewCount` has 4 properties:
- firebaseHost - required property where you specify Firebase host. E.x. `https://counter-button.firebaseio.com/`
- firebaseResourceId - required property where unique counter id. E.x. `article-1-counter`
- className - CSS classname that will be assigned to the component. This way you'd be able to overwrite styles Optional.
- counterText - text that will be shown near the counter number
`OnlineCount` has 4 properties:
- firebaseHost - required property where you specify Firebase host. E.x. `https://counter-button.firebaseio.com/`
- firebaseResourceId - required property where unique counter id. E.x. `article-1-counter`
- className - CSS classname that will be assigned to the component. This way you'd be able to overwrite styles Optional.
- counterText - text that will be shown near the counter number
`Count` has following properties:
- firebaseHost - required property where you specify Firebase host. E.x. `https://counter-button.firebaseio.com/`
- firebaseResourceId - required property where unique counter id. E.x. `article-1-counter`
- className - CSS classname that will be assigned to the component. This way you'd be able to overwrite styles Optional.
- counterText - text that will be shown near the counter number.
- allowMultiple - boolean flag that enables increasing counter multiple times by the single user. Default is `false`.
- isViewCounter - boolean flag that tells component to increase automatically on each view. Default is `false`.
- isOnlineCounter - boolean flag that tells component to increase automatically on each user online. Default is `false`.
- isUndoable - boolean flag that enables user to undo his click (follow/unfollow). Default is `false`.
- isReadonly - boolean flag that disables increasing counter value. Default is `false`.
- isButtonLast - boolean flag that defines order of text and button. Default is `false`.
- actionDoText - text shown on button initially.
- actionUndoText - text shown on button if `isUndoable === true` and user already clicked the button.
- actionDoneText - text shown on button if `isUndoable === false` and user already clicked the button.
## Firebase security rules
Add following firebase security rules if you want to prevent users from arbitrary changing your counters.
We allow incremental vote submissions:
```
{
"rules": {
".read": true,
"$counter": {
".write": "!root.child($counter).exists() || ((newData.val() - data.val()) === 1) || ((newData.val() - data.val()) === -1)",
"presence": {
".write": true
}
}
}
}
```
## TODO
- [x] implement undo
- [x] online users counter
- [x] create subcomponents
- [ ] betters styles customization
- [ ] auth support
没有合适的资源?快使用搜索试试~ 我知道了~
react-count:实时计数器按钮React组件
共16个文件
js:8个
css:1个
gitignore:1个
需积分: 50 3 下载量 141 浏览量
2021-06-19
06:45:54
上传
评论
收藏 215KB ZIP 举报
温馨提示
React计数 烘焙的实时计数器按钮组件。 查看演示。 用例 这个组件可以在以下情况下有用: 关注/取消关注按钮,显示关注者数量 喜欢/不喜欢按钮,显示喜欢的数量 页面浏览量计数器 当前在线用户的计数器 连接到 Firebase 中任何数字数据的通用只读计数器 安装 如果你使用 webpack 只需安装 react-count 模块 npm install react-count 并在你的 React 应用程序中的任何地方要求它: var Count = require('react-count'); 或者您可以使用其他更具体的组件,例如: var OnlineCount = require('react-count').OnlineCount; var ViewCount = require('react-count').ViewCount; 演示 您可以查看在线
资源详情
资源评论
资源推荐
收起资源包目录
react-count-master.zip (16个子文件)
react-count-master
webpack.config.js 283B
lib
Count.js 6KB
styles.js 1KB
ViewCount.js 657B
OnlineCount.js 663B
index.js 135B
examples
button
index.html 1KB
robots.txt 14B
index.css 131KB
favicon.ico 2KB
App.js 7KB
bundle.js 741KB
LICENSE 1KB
README.md 4KB
.gitignore 587B
package.json 911B
共 16 条
- 1
在南极找不到南
- 粉丝: 29
- 资源: 4605
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0