|
8 | 8 | Header, |
9 | 9 | Icon, |
10 | 10 | Item, |
| 11 | + Popup, |
11 | 12 | Segment |
12 | 13 | } from 'semantic-ui-react'; |
13 | 14 | import _ from 'underscore'; |
@@ -267,17 +268,7 @@ class ItemsClass extends Component<Props, {}> { |
267 | 268 | extra |
268 | 269 | textAlign='center' |
269 | 270 | > |
270 | | - { _.map(actions, (action, actionIndex) => ( |
271 | | - <Button |
272 | | - aria-label={action.name} |
273 | | - basic |
274 | | - color={action.resolveColor ? action.resolveColor(item) : action.color} |
275 | | - icon={action.resolveIcon ? action.resolveIcon(item) : action.icon} |
276 | | - key={actionIndex} |
277 | | - onClick={action.onClick.bind(this, item)} |
278 | | - size={action.size} |
279 | | - /> |
280 | | - ))} |
| 271 | + { _.map(actions, this.renderCardAction.bind(this, item)) } |
281 | 272 | { this.isSelectable() && ( |
282 | 273 | <Button |
283 | 274 | aria-label='Select' |
@@ -309,6 +300,49 @@ class ItemsClass extends Component<Props, {}> { |
309 | 300 | return card; |
310 | 301 | } |
311 | 302 |
|
| 303 | + /** |
| 304 | + * Renders the action button for the passed item. |
| 305 | + * |
| 306 | + * @param action |
| 307 | + * @param index |
| 308 | + * @param item |
| 309 | + * |
| 310 | + * @returns {JSX.Element} |
| 311 | + */ |
| 312 | + renderCardAction(item, action, index) { |
| 313 | + const actionButton = ( |
| 314 | + <Button |
| 315 | + as={action.as} |
| 316 | + {...((action.asProps && action.asProps(item)) || {})} |
| 317 | + aria-label={action.name} |
| 318 | + basic |
| 319 | + color={action.resolveColor ? action.resolveColor(item) : action.color} |
| 320 | + icon={action.resolveIcon ? action.resolveIcon(item) : action.icon} |
| 321 | + key={index} |
| 322 | + onClick={action.onClick && action.onClick.bind(this, item)} |
| 323 | + size={action.size} |
| 324 | + /> |
| 325 | + ); |
| 326 | + |
| 327 | + // Wrap the button in a popup if the action specifies a popup attribute |
| 328 | + if (action.popup) { |
| 329 | + const { content, title } = action.popup; |
| 330 | + |
| 331 | + return ( |
| 332 | + <Popup |
| 333 | + content={content} |
| 334 | + header={title} |
| 335 | + hideOnScroll |
| 336 | + mouseEnterDelay={500} |
| 337 | + position='top right' |
| 338 | + trigger={actionButton} |
| 339 | + /> |
| 340 | + ); |
| 341 | + } |
| 342 | + |
| 343 | + return actionButton; |
| 344 | + } |
| 345 | + |
312 | 346 | /** |
313 | 347 | * Renders the empty list. |
314 | 348 | * |
@@ -405,12 +439,14 @@ class ItemsClass extends Component<Props, {}> { |
405 | 439 | )} |
406 | 440 | { _.map(this.getActions(item), (action, actionIndex) => ( |
407 | 441 | <Button |
| 442 | + as={action.as} |
| 443 | + {...((action.asProps && action.asProps(item)) || {})} |
408 | 444 | basic={action.basic} |
409 | 445 | color={action.resolveColor ? action.resolveColor(item) : action.color} |
410 | 446 | content={action.resolveName ? action.resolveName(item) : action.label} |
411 | 447 | key={actionIndex} |
412 | 448 | icon={action.resolveIcon ? action.resolveIcon(item) : action.icon} |
413 | | - onClick={action.onClick.bind(this, item)} |
| 449 | + onClick={action.onClick && action.onClick.bind(this, item)} |
414 | 450 | size={action.size} |
415 | 451 | /> |
416 | 452 | ))} |
|
0 commit comments