Skip to content

Commit

Permalink
feat(TextArea): New TextArea Component
Browse files Browse the repository at this point in the history
New bootstrap form-control TextArea component - leverages Paragon asInput

Note* based on: https://github.com/edx/paragon/tree/master/src/InputText

Ticket: EDUCATOR-1824
  • Loading branch information
Farhanah Sheets authored Dec 4, 2017
1 parent 25fe397 commit 4bd0082
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .storybook/__snapshots__/Storyshots.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1961,3 +1961,87 @@ exports[`Storyshots Tabs basic usage 1`] = `
</div>
</div>
`;

exports[`Storyshots Textarea minimal usage 1`] = `
<div
className="form-group"
>
<label
htmlFor="asInput20"
>
First Name
</label>
<textarea
aria-describedby={undefined}
aria-invalid={false}
className="form-control"
disabled={false}
id="asInput20"
name="name"
onBlur={[Function]}
onChange={[Function]}
placeholder={undefined}
required={false}
type="text"
value="Foo Bar"
/>
</div>
`;

exports[`Storyshots Textarea scrollable 1`] = `
<div
className="form-group"
>
<label
htmlFor="asInput21"
>
Information
</label>
<textarea
aria-describedby={undefined}
aria-invalid={false}
className="form-control"
disabled={false}
id="asInput21"
name="name"
onBlur={[Function]}
onChange={[Function]}
placeholder={undefined}
required={false}
type="text"
value="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
/>
</div>
`;

exports[`Storyshots Textarea validation 1`] = `
<div
className="form-group"
>
<label
htmlFor="asInput22"
>
Username
</label>
<textarea
aria-describedby="undefined description-asInput22"
aria-invalid={false}
className="form-control"
disabled={false}
id="asInput22"
name="username"
onBlur={[Function]}
onChange={[Function]}
placeholder={undefined}
required={false}
type="text"
value=""
/>
<small
className="form-text"
id="description-asInput22"
>
The unique name that identifies you throughout the site.
</small>
</div>
`;
8 changes: 8 additions & 0 deletions src/TextArea/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# TextArea

Provides an input component called TextArea that gives users a reusable textarea field.

## API

### `inputProps` (view asInput component for details)
`inputProps` specifies all of the properties that are necessary from the included `asInput` component. Please see details for input requirements within that component.
48 changes: 48 additions & 0 deletions src/TextArea/TextArea.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable import/no-extraneous-dependencies */
import React from 'react';
import { storiesOf } from '@storybook/react';

import TextArea from './index';

storiesOf('Textarea', module)
.add('minimal usage', () => (
<TextArea
name="name"
label="First Name"
value="Foo Bar"
/>
))
.add('scrollable', () => (
<TextArea
name="name"
label="Information"
value="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum."
/>
))
.add('validation', () => (
<TextArea
name="username"
label="Username"
description="The unique name that identifies you throughout the site."
validator={(value) => {
let feedback = { isValid: true };
if (value.length < 3) {
feedback = {
isValid: false,
validationMessage: 'Username must be at least 3 characters in length.',
};
}
return feedback;
}}
/>
));
29 changes: 29 additions & 0 deletions src/TextArea/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import classNames from 'classnames';

import asInput, { inputProps } from '../asInput';

function Text(props) {
return (
<textarea
id={props.id}
className={classNames(props.className)}
type="text"
name={props.name}
value={props.value}
placeholder={props.placeholder}
aria-describedby={props.describedBy}
onChange={props.onChange}
onBlur={props.onBlur}
aria-invalid={!props.isValid}
disabled={props.disabled}
required={props.required}
/>
);
}

Text.propTypes = inputProps;

const TextArea = asInput(Text);

export default TextArea;

0 comments on commit 4bd0082

Please sign in to comment.