import React, { ReactNode } from 'react'; import styled from 'styled-components'; import { margin, MarginProps, space } from 'styled-system'; import { ThemeProps } from '@t3n/theme'; import Box from '../Box'; import Text from '../Text'; export interface FormGroupProps extends React.LabelHTMLAttributes, Pick { label: string; labelSecondary?: string; labelEndContent?: ReactNode; errorMessage?: string; children?: ReactNode; } const Label = styled.span` display: inline-block; ${({ theme }: ThemeProps) => space({ mr: 1, theme })}; `; const LabelEnd = styled.span` margin-left: auto; `; const StyledFormGroup = styled.label>` display: block; position: relative; ${margin} `; const SecondaryLabel = styled(Text)` line-height: normal; `; const FormGroup: React.FC = ({ label, labelSecondary, labelEndContent, errorMessage, children, my = 4, ...props }) => ( {labelSecondary && ( {labelSecondary} )} {labelEndContent && {labelEndContent}} {children} {errorMessage && ( {errorMessage} )} ); export default FormGroup;