1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

56 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-01-17 02:50:57 -07:00
import React from "react";
2020-01-20 00:37:04 -07:00
import { Flex, FormControl, FormLabel, FormErrorMessage, useColorMode } from "@chakra-ui/core";
2020-01-17 02:50:57 -07:00
2020-01-27 21:28:27 -07:00
export default ({
label,
name,
error,
hiddenLabels,
helpIcon,
targetInfo,
setTarget,
labelAddOn,
fieldAddOn,
children,
...props
}) => {
2020-01-17 02:50:57 -07:00
const { colorMode } = useColorMode();
2020-01-20 00:37:04 -07:00
const labelColor = { dark: "whiteAlpha.600", light: "blackAlpha.600" };
2020-01-17 02:50:57 -07:00
return (
<FormControl
as={Flex}
flexDirection="column"
2020-01-20 00:37:04 -07:00
flex={["1 0 100%", "1 0 100%", "1 0 33.33%", "1 0 33.33%"]}
2020-01-17 02:50:57 -07:00
w="100%"
maxW="100%"
mx={2}
2020-01-20 00:37:04 -07:00
my={[2, 2, 4, 4]}
2020-01-17 02:50:57 -07:00
isInvalid={error && error.message}
{...props}
>
2020-01-20 00:37:04 -07:00
<FormLabel
htmlFor={name}
color={labelColor[colorMode]}
pl={1}
opacity={hiddenLabels ? 0 : null}
2020-01-27 21:28:27 -07:00
display="flex"
alignItems="center"
justifyContent="space-between"
pr={0}
2020-01-20 00:37:04 -07:00
>
2020-01-17 02:50:57 -07:00
{label}
2020-01-27 21:28:27 -07:00
{labelAddOn || null}
2020-01-17 02:50:57 -07:00
</FormLabel>
{children}
2020-01-27 21:28:27 -07:00
{fieldAddOn && (
<Flex justifyContent="flex-end" pt={3}>
{fieldAddOn}
</Flex>
)}
2020-01-17 02:50:57 -07:00
<FormErrorMessage opacity={hiddenLabels ? 0 : null}>
{error && error.message}
</FormErrorMessage>
</FormControl>
);
};