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

56 lines
1.2 KiB
JavaScript
Raw Normal View History

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