Skip to content

Commit b1342da

Browse files
authored
Merge pull request #60 from primer/primer-input
Creating TextInput Component
2 parents 8359ba2 + 7028f3d commit b1342da

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

examples/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
Dropdown,
2323
Flash,
2424
Heading,
25+
TextInput,
2526
Label,
2627
Link,
2728
Page,
@@ -309,6 +310,19 @@ const Index = props => (
309310
<Text tag='div' key={i} fontSize={fontSize}>fontSize {fontSize}</Text>
310311
))}
311312
</Example>
313+
<Example name='Form elements'>
314+
<Heading mb={2}>Input</Heading>
315+
<TextInput name='zipcode'/>
316+
<Heading mb={2}>Input Sizes</Heading>
317+
<Box>
318+
<TextInput name='zipcode' size='small' placeholder='Small input'/>
319+
</Box>
320+
<Box>
321+
<TextInput name='zipcode' size='large' placeholder='Large input'/>
322+
</Box>
323+
<Heading mb={2}>Block input</Heading>
324+
<TextInput block placeholder='Full width block input'/>
325+
</Example>
312326
<Example name='Heading'>
313327
<Heading mb={2}>Default Heading</Heading>
314328
<Detail>

src/TextInput.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import classnames from 'classnames'
4+
5+
const TextInput = ({
6+
autocomplete,
7+
autofocus,
8+
block,
9+
disabled,
10+
id,
11+
name,
12+
placeholder,
13+
required,
14+
size,
15+
value
16+
}) => (
17+
<input
18+
aria-label={placeholder}
19+
autocomplete={autocomplete}
20+
autofocus={autofocus}
21+
className={classnames(
22+
'form-control',
23+
{
24+
'input-block': block,
25+
'input-sm': size === 'small',
26+
'input-lg': size === 'large'
27+
}
28+
)}
29+
disabled={disabled}
30+
id={id}
31+
name={name}
32+
placeholder={placeholder}
33+
required={required}
34+
type='text'
35+
value={value}
36+
/>
37+
)
38+
39+
TextInput.propTypes = {
40+
autocomplete: PropTypes.string,
41+
autofocus: PropTypes.bool,
42+
block: PropTypes.bool,
43+
disabled: PropTypes.bool,
44+
id: PropTypes.string,
45+
name: PropTypes.string,
46+
placeholder: PropTypes.string,
47+
required: PropTypes.bool,
48+
size: PropTypes.oneOf(['small', 'large']),
49+
value: PropTypes.string
50+
}
51+
52+
export default TextInput

src/__tests__/TextInput.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react'
2+
import TextInput from '../TextInput'
3+
import {render} from '../utils/testing'
4+
5+
describe('TextInput', () => {
6+
it('renders', () => {
7+
expect(render(<TextInput name='zipcode' />))
8+
.toEqual(render(<input name='zipcode' type='text' className='form-control' />))
9+
})
10+
11+
it('renders small', () => {
12+
expect(render(<TextInput name='zipcode' size='small' />))
13+
.toEqual(render(<input name='zipcode' type='text' className='form-control input-sm' />))
14+
})
15+
16+
it('renders large', () => {
17+
expect(render(<TextInput name='zipcode' size='large' />))
18+
.toEqual(render(<input name='zipcode' type='text' className='form-control input-lg' />))
19+
})
20+
21+
it('renders block', () => {
22+
expect(render(<TextInput name='zipcode' block />))
23+
.toEqual(render(<input name='zipcode' type='text' className='form-control input-block' />))
24+
})
25+
})

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export { default as Dropdown } from './Dropdown'
2626
export { default as DonutChart} from './DonutChart'
2727
export { default as DonutSlice} from './DonutSlice'
2828

29+
export { default as TextInput} from './TextInput'
30+
2931
export { default as Heading } from './Heading'
3032
export { default as Label } from './Label'
3133
export { default as BranchName } from './BranchName'

0 commit comments

Comments
 (0)