Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Migrate FormGroup to TypeScript #999

Merged
merged 4 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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