2020-04-06 21:47:06 -04:00
|
|
|
import React from "react";
|
2020-04-06 22:05:30 -04:00
|
|
|
import { Box, Flex, IconButton, Text } from "theme-ui";
|
2020-04-06 21:47:06 -04:00
|
|
|
|
2020-04-12 10:24:03 -04:00
|
|
|
function NumberInput({ value, onChange, title, min, max }) {
|
2020-04-06 21:47:06 -04:00
|
|
|
return (
|
|
|
|
<Box>
|
2020-04-08 21:30:48 -04:00
|
|
|
<Text sx={{ textAlign: "center" }} variant="heading" as="h1">
|
2020-04-12 10:24:03 -04:00
|
|
|
{title}
|
2020-04-06 21:47:06 -04:00
|
|
|
</Text>
|
|
|
|
<Flex sx={{ alignItems: "center", justifyContent: "center" }}>
|
|
|
|
<IconButton
|
2020-04-12 10:24:03 -04:00
|
|
|
aria-label={`Decrease ${title}`}
|
|
|
|
title={`Decrease ${title}`}
|
|
|
|
onClick={() => value > min && onChange(value - 1)}
|
2020-04-06 21:47:06 -04:00
|
|
|
>
|
|
|
|
<svg
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
height="24"
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
width="24"
|
|
|
|
fill="currentcolor"
|
|
|
|
>
|
|
|
|
<path d="M0 0h24v24H0V0z" fill="none" />
|
|
|
|
<path d="M18 13H6c-.55 0-1-.45-1-1s.45-1 1-1h12c.55 0 1 .45 1 1s-.45 1-1 1z" />
|
|
|
|
</svg>
|
|
|
|
</IconButton>
|
2020-04-12 10:24:03 -04:00
|
|
|
<Text as="p" aria-label={`Current ${title}`}>
|
2020-04-08 21:30:48 -04:00
|
|
|
{value}
|
|
|
|
</Text>
|
2020-04-06 21:47:06 -04:00
|
|
|
<IconButton
|
2020-04-12 10:24:03 -04:00
|
|
|
aria-label={`Increase ${title}`}
|
|
|
|
title={`Increase ${title}`}
|
|
|
|
onClick={() => value < max && onChange(value + 1)}
|
2020-04-06 21:47:06 -04:00
|
|
|
>
|
|
|
|
<svg
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
height="24"
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
width="24"
|
|
|
|
fill="currentcolor"
|
|
|
|
>
|
|
|
|
<path d="M0 0h24v24H0V0z" fill="none" />
|
|
|
|
<path d="M18 13h-5v5c0 .55-.45 1-1 1s-1-.45-1-1v-5H6c-.55 0-1-.45-1-1s.45-1 1-1h5V6c0-.55.45-1 1-1s1 .45 1 1v5h5c.55 0 1 .45 1 1s-.45 1-1 1z" />
|
|
|
|
</svg>
|
|
|
|
</IconButton>
|
|
|
|
</Flex>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-12 10:24:03 -04:00
|
|
|
NumberInput.defaultProps = {
|
2020-04-06 21:47:06 -04:00
|
|
|
value: 1,
|
|
|
|
onChange: () => {},
|
2020-04-12 10:24:03 -04:00
|
|
|
title: "Number",
|
|
|
|
min: 0,
|
|
|
|
max: 10,
|
2020-04-06 21:47:06 -04:00
|
|
|
};
|
|
|
|
|
2020-04-12 10:24:03 -04:00
|
|
|
export default NumberInput;
|