react-summary
Advanced tools
+2
-1
@@ -10,3 +10,4 @@ import React, { Component } from 'react'; | ||
| <Summary items={['hey', 'foo', 'bar', 'selam']} | ||
| max={2} | ||
| max={3} | ||
| preventSingleRemaining={false} | ||
| onShowOthers={this.showOthers} /> | ||
@@ -13,0 +14,0 @@ </div> |
+1
-1
| { | ||
| "name": "react-summary", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "React summaries", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
+5
-2
@@ -39,6 +39,9 @@ React-Summary | ||
| | text | Object. Explained on the following table. | Translations of visible texts | | ||
| | preventSingleRemain | false | Prints the last item instead of `and 1 more` text | | ||
| | onShowOthers | No-op function | Callback function for `show others` link | | ||
| | preventSingleRemaining | false | Prints the last item instead of `and 1 more` text | | ||
| | onShowOthers | No-op | Callback function for `show others` link | | ||
| | itemRenderer | Identity (returns given parameter) | A wrapper function for styling items | | ||
| To styling items, you can provide react components instead of using itemRenderer. | ||
| Translation strings: | ||
@@ -45,0 +48,0 @@ |
+10
-8
@@ -13,4 +13,5 @@ import React, { Component } from 'react'; | ||
| }, | ||
| onShowOthers() {}, | ||
| preventSingleRemain: false | ||
| onShowOthers: () => {}, | ||
| itemRenderer: (item) => item, | ||
| preventSingleRemaining: false | ||
| }; | ||
@@ -26,13 +27,14 @@ | ||
| let {items, text, max, | ||
| preventSingleRemain} = this.props; | ||
| itemRenderer, | ||
| preventSingleRemaining} = this.props; | ||
| switch (items.length) { | ||
| case 0: | ||
| return text.none; | ||
| return itemRenderer(text.none); | ||
| case 1: | ||
| return items[0]; | ||
| return itemRenderer(items[0]); | ||
| case 2: | ||
| case max: | ||
| case preventSingleRemain && max + 1: | ||
| case preventSingleRemaining && max + 1: | ||
@@ -45,3 +47,3 @@ return ( | ||
| {i > 0 ? ', ' : null} | ||
| {item} | ||
| {itemRenderer(item)} | ||
| </span> | ||
@@ -59,3 +61,3 @@ ) : null | ||
| {i > 0 && i < max ? ', ': null} | ||
| {i < max ? item : null} | ||
| {i < max ? itemRenderer(item) : null} | ||
| {i === max && ( | ||
@@ -62,0 +64,0 @@ <span> |
8021
4.75%131
2.34%59
5.36%