| 15 | const MANAGERS = Object.keys(COMMANDS) as Manager[]; |
| 16 | |
| 17 | function InstallCommand() { |
| 18 | const [manager, setManager] = React.useState<Manager>("npm"); |
| 19 | const [copied, copy] = useCopied(); |
| 20 | |
| 21 | return ( |
| 22 | <div className="install"> |
| 23 | <div className="install-tabs"> |
| 24 | {MANAGERS.map((key) => ( |
| 25 | <button |
| 26 | key={key} |
| 27 | type="button" |
| 28 | aria-pressed={key === manager} |
| 29 | className={`install-tab${key === manager ? " is-active" : ""}`} |
| 30 | onClick={() => setManager(key)} |
| 31 | > |
| 32 | {key} |
| 33 | </button> |
| 34 | ))} |
| 35 | </div> |
| 36 | |
| 37 | <div className="install-command"> |
| 38 | {/* Every command shares one grid cell, so the widest fixes the box |
| 39 | width and switching tabs does not resize it. */} |
| 40 | <code> |
| 41 | {MANAGERS.map((key) => ( |
| 42 | <span key={key} aria-hidden={key !== manager}> |
| 43 | <span className="install-prompt">$</span> {COMMANDS[key]} |
| 44 | </span> |
| 45 | ))} |
| 46 | </code> |
| 47 | |
| 48 | <button |
| 49 | type="button" |
| 50 | className={`icon-button${copied ? " is-copied" : ""}`} |
| 51 | onClick={() => copy(COMMANDS[manager])} |
| 52 | aria-label="Copy install command" |
| 53 | > |
| 54 | {copied ? <CheckIcon /> : <CopyIcon />} |
| 55 | </button> |
| 56 | </div> |
| 57 | </div> |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | export default InstallCommand; |