movie-web/src2/components/NumberSelector.js

28 lines
990 B
JavaScript
Raw Normal View History

2021-07-15 00:09:42 +02:00
import React from 'react';
// import { Arrow } from './Arrow';
import './NumberSelector.css'
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 }) {
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=>(
<div key={v.value} className="choiceWrapper" tabIndex={0} onKeyPress={handleKeyPress(v.value)}>
<div className={`choice ${selected&&selected===v.value?'selected':''}`} onClick={() => setType(v.value)}>
2021-07-15 00:09:42 +02:00
{v.label}
<PercentageOverlay percentage={v.percentage} />
2021-07-15 00:09:42 +02:00
</div>
</div>
))}
</div>
)
}