index.tsx
44 lines
| 1 | import styles from './RowAction.module.scss'; |
| 2 | import cx from 'classnames'; |
| 3 | |
| 4 | export default function RowAction({ |
| 5 | onClick = null, |
| 6 | className = '', |
| 7 | actionId = null, |
| 8 | displayText, |
| 9 | hiddenText = '', |
| 10 | disabled = false, |
| 11 | highlight = false, |
| 12 | href = '', |
| 13 | ariaLabel = '', |
| 14 | }) { |
| 15 | if (href) { |
| 16 | return ( |
| 17 | <a |
| 18 | href={href} |
| 19 | className={cx(styles.action, {[styles.delete]: highlight}, className)} |
| 20 | aria-label={ariaLabel || displayText} |
| 21 | > |
| 22 | {displayText} {hiddenText && <span className="give-visually-hidden">{hiddenText}</span>} |
| 23 | </a> |
| 24 | ); |
| 25 | } |
| 26 | |
| 27 | if (!onClick) { |
| 28 | return null; |
| 29 | } |
| 30 | |
| 31 | return ( |
| 32 | <button |
| 33 | type="button" |
| 34 | onClick={onClick} |
| 35 | data-actionid={actionId} |
| 36 | className={cx(styles.action, {[styles.delete]: highlight}, className)} |
| 37 | disabled={disabled} |
| 38 | aria-label={ariaLabel || displayText} |
| 39 | > |
| 40 | {displayText} {hiddenText && <span className="give-visually-hidden">{hiddenText}</span>} |
| 41 | </button> |
| 42 | ); |
| 43 | } |
| 44 |