Skip to content

Commit

Permalink
Merge pull request #999 from primer/cb/ts-form-group
Browse files Browse the repository at this point in the history
Migrate FormGroup to TypeScript
  • Loading branch information
colebemis authored Feb 4, 2021
2 parents ee72194 + 2565a8e commit f81201d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 43 deletions.
41 changes: 0 additions & 41 deletions src/FormGroup.js

This file was deleted.

47 changes: 47 additions & 0 deletions src/FormGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import PropTypes from 'prop-types'
import styled from 'styled-components'
import {COMMON, get, TYPOGRAPHY, SystemCommonProps, SystemTypographyProps} from './constants'
import theme from './theme'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'

const FormGroup = styled.div<SystemCommonProps & SxProp>`
margin: ${get('space.3')} 0;
font-weight: ${get('fontWeights.normal')};
${COMMON};
${sx};
`

FormGroup.defaultProps = {theme}

FormGroup.propTypes = {
children: PropTypes.node,
...COMMON.propTypes,
...sx.propTypes
}

const FormGroupLabel = styled.label<SystemTypographyProps & SystemCommonProps & SxProp>`
display: block;
margin: 0 0 ${get('space.2')};
font-size: ${get('fontSizes.1')};
font-weight: ${get('fontWeights.bold')};
${TYPOGRAPHY};
${COMMON};
${sx};
`

FormGroupLabel.displayName = 'FormGroup.Label'

FormGroupLabel.defaultProps = {
theme
}

FormGroupLabel.propTypes = {
...TYPOGRAPHY.propTypes,
...COMMON.propTypes,
...sx.propTypes
}

export type FormGroupProps = ComponentProps<typeof FormGroup>
export type FormGroupLabelProps = ComponentProps<typeof FormGroupLabel>
export default Object.assign(FormGroup, {Label: FormGroupLabel})
4 changes: 2 additions & 2 deletions src/__tests__/FormGroup.js → src/__tests__/FormGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import {FormGroup, TextInput} from '..'
import {FormGroup} from '..'
import {COMMON, TYPOGRAPHY} from '../constants'
import {behavesAsComponent, checkExports} from '../utils/testing'
import {render as HTMLRender, cleanup} from '@testing-library/react'
Expand All @@ -18,7 +18,7 @@ describe('FormGroup', () => {
const {container} = HTMLRender(
<FormGroup>
<FormGroup.Label htmlFor="example-text">Example text</FormGroup.Label>
<TextInput id="example-text" value="Example Value" />
<input id="example-text" value="Example Value" />
</FormGroup>
)
const results = await axe(container)
Expand Down

0 comments on commit f81201d

Please sign in to comment.