2021-07-15 00:09:42 +02:00
|
|
|
import React from 'react';
|
|
|
|
// import { Arrow } from './Arrow';
|
|
|
|
import './NumberSelector.css'
|
2021-07-15 21:24:11 +02:00
|
|
|
import { PercentageOverlay } from './PercentageOverlay';
|
2021-07-15 00:09:42 +02:00
|
|
|
|
|
|
|
// setType: (txt: string) => void
|
|
|
|
// choices: { label: string, value: string }[]
|
|
|
|
// selected: string
|
|
|
|
export function NumberSelector({ setType, choices, selected }) {
|
2022-01-03 13:30:41 +01:00
|
|
|
const handleKeyPress = choice => event => {
|
|
|
|
if (event.code === 'Space' || event.code === 'Enter'){
|
|
|
|
setType(choice);
|
|
|
|
}
|
|
|
|
}
|
2021-07-15 00:09:42 +02:00
|
|
|
return (
|
|
|
|
<div className="numberSelector">
|
|
|
|
{choices.map(v=>(
|
2022-01-03 13:30:41 +01:00
|
|
|
<div key={v.value} className="choiceWrapper" tabIndex={0} onKeyPress={handleKeyPress(v.value)}>
|
2021-07-15 21:04:47 +02:00
|
|
|
<div className={`choice ${selected&&selected===v.value?'selected':''}`} onClick={() => setType(v.value)}>
|
2021-07-15 00:09:42 +02:00
|
|
|
{v.label}
|
2021-07-15 21:24:11 +02:00
|
|
|
<PercentageOverlay percentage={v.percentage} />
|
2021-07-15 00:09:42 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|