Skip to content

Commit

Permalink
feat(textarea): add textarea
Browse files Browse the repository at this point in the history
  • Loading branch information
estevanmaito committed Jun 25, 2020
1 parent f57b764 commit 6a7a333
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
17 changes: 17 additions & 0 deletions __tests__/Textarea.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import { mount } from 'enzyme'
import Textarea from '../src/Textarea'

describe('Textarea', () => {
it('should render without crashing', () => {
mount(<Textarea />)
})

it('should render with base styles', () => {
const expected =
'block w-full text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-textarea focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray'
const wrapper = mount(<Textarea />)

expect(wrapper.find('textarea').getDOMNode().getAttribute('class')).toContain(expected)
})
})
28 changes: 28 additions & 0 deletions src/Textarea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { useContext } from 'react'
import classNames from 'classnames'
import PropTypes from 'prop-types'
import { ThemeContext } from './context/ThemeContext'
import defaultTheme from './themes/default'

const Textarea = React.forwardRef(function Textarea(props, ref) {
const { className, children, ...other } = props

const { textarea } = useContext(ThemeContext) || defaultTheme

const baseStyle = textarea.base

const cls = classNames(baseStyle, className)

return (
<textarea className={cls} ref={ref} {...other}>
{children}
</textarea>
)
})

Textarea.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
}

export default Textarea
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export { default as HelperText } from './HelperText'
export { default as Input } from './Input'
export { default as Label } from './Label'
export { default as Select } from './Select'
export { default as Textarea } from './Textarea'
6 changes: 6 additions & 0 deletions src/themes/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export default {
// Textarea
textarea: {
base:
'block w-full text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-textarea focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray',
},
// Select
select: {
base:
'block w-full text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray',
Expand Down

0 comments on commit 6a7a333

Please sign in to comment.