Skip to content
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
272 changes: 12 additions & 260 deletions packages/react-core/src/components/TextArea/examples/TextArea.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,300 +9,52 @@ propComponents: ['TextArea']

### Basic

```js
import React from 'react';
import { TextArea } from '@patternfly/react-core';

class SimpleTextArea extends React.Component {
constructor(props) {
super(props);
this.state = {
value: ''
};

this.handleTextAreaChange = value => {
this.setState({ value });
};
}

render() {
const { value } = this.state;

return <TextArea value={value} onChange={this.handleTextAreaChange} aria-label="text area example" />;
}
}
```ts file="./TextAreaBasic.tsx"
```

### Invalid

```js
import React from 'react';
import { TextArea } from '@patternfly/react-core';

class InvalidTextArea extends React.Component {
constructor(props) {
super(props);
this.state = {
value: ''
};

this.handleInvalidTextAreaChange = value => {
this.setState({ value });
};
}

render() {
const { value } = this.state;

return (
<TextArea
value={value}
onChange={this.handleInvalidTextAreaChange}
isRequired
validated={'error'}
aria-label="invalid text area example"
/>
);
}
}
```ts file="./TextAreaInvalid.tsx"
```

### Validated

```js
import React from 'react';
import { Form, FormGroup, TextArea } from '@patternfly/react-core';

class InvalidTextArea extends React.Component {
constructor(props) {
super(props);
this.state = {
value: '',
invalidText: 'You must have something to say',
validated: 'default',
helperText: 'Share your thoughts.'
};

this.simulateNetworkCall = callback => {
setTimeout(callback, 2000);
};

this.handleTextAreaChange = value => {
this.setState(
{
value,
validated: 'default',
helperText: 'Validating...'
},
this.simulateNetworkCall(() => {
if (value && value.length > 0) {
if (value.length >= 10) {
this.setState({ validated: 'success', helperText: 'Thanks for your comments!' });
} else {
this.setState({
validated: 'error',
invalidText: 'Your being too brief, please enter at least 10 characters.'
});
}
} else {
this.setState({ validated: 'warning', helperText: 'You must have something to say' });
}
})
);
};
}

render() {
const { value, validated, helperText, invalidText } = this.state;

return (
<Form>
<FormGroup
label="Comments:"
type="string"
helperText={helperText}
helperTextInvalid={invalidText}
fieldId="selection"
validated={validated}
>
<TextArea
value={value}
onChange={this.handleTextAreaChange}
isRequired
validated={validated}
aria-label="invalid text area example"
/>
</FormGroup>
</Form>
);
}
}
```ts file="./TextAreaValidated.tsx"
```

### Vertically resizable text area

```js
import React from 'react';
import { TextArea } from '@patternfly/react-core';
### Vertically resizable

class VerticalResizeTextArea extends React.Component {
constructor(props) {
super(props);
this.state = {
value: ''
};

this.handleTextAreaChange = value => {
this.setState({ value });
};
}

render() {
const { value } = this.state;

return (
<TextArea
value={value}
onChange={this.handleTextAreaChange}
resizeOrientation="vertical"
aria-label="text vertical resize example"
/>
);
}
}
```ts file="./TextAreaVerticallyResizable.tsx"
```

### Horizontally resizable text area

```js
import React from 'react';
import { TextArea } from '@patternfly/react-core';

class HorizontalResizeTextArea extends React.Component {
constructor(props) {
super(props);
this.state = {
value: ''
};

this.handleTextAreaChange = value => {
this.setState({ value });
};
}

render() {
const { value } = this.state;
### Horizontally resizable

return (
<TextArea
value={value}
onChange={this.handleTextAreaChange}
resizeOrientation="horizontal"
aria-label="text horizontal resize example"
/>
);
}
}
```ts file="./TextAreaHorizontallyResizable.tsx"
```

### Uncontrolled

```js
import React from 'react';
import { TextArea } from '@patternfly/react-core';

<TextArea defaultValue="default value" aria-label="uncontrolled text area example" />;
```ts file="./TextAreaUncontrolled.tsx"
```

### Disabled

```js
import React from 'react';
import { TextArea } from '@patternfly/react-core';

<TextArea aria-label="disabled text area example" isDisabled />;
```ts file="./TextAreaDisabled.tsx"
```

### Read only

```js
import React from 'react';
import { Checkbox, TextArea } from '@patternfly/react-core';

const ReadOnlyTextArea = () => {
const [isPlainChecked, setIsPlainChecked] = React.useState(false);

return (
<React.Fragment>
<div style={{ marginBottom: '12px' }}>
<Checkbox
id="isPlain"
key="isPlain"
label="Plain read only variant"
isChecked={isPlainChecked}
onChange={checked => setIsPlainChecked(checked)}
/>
</div>
<TextArea
aria-label="read only text area example"
value="read only text area example"
readOnlyVariant={isPlainChecked ? 'plain' : 'default'}
/>
</React.Fragment>
);
};
```ts file="./TextAreaReadOnly.tsx"
```

### Auto resizing

```js
import React from 'react';
import { TextArea } from '@patternfly/react-core';

<TextArea aria-label="auto resizing text area example" autoResize />;
```ts file="./TextAreaAutoResizing.tsx"
```

### Icon sprite variants

**Note:** The icons for the success, invalid, calendar, etc. variations in form control elements are applied as background images to the form element. By default, the image URLs for these icons are data URIs. However, there may be cases where data URIs are not ideal, such as in an application with a content security policy that disallows data URIs for security reasons. The `isIconSprite` variation changes the icon source to an external SVG file that serves as a sprite for all of the supported icons.

```js
import React from 'react';
import { TextArea } from '@patternfly/react-core';

IconSpriteTextArea = () => {
const [success, setSuccess] = React.useState('');
const [warning, setWarning] = React.useState('');
const [error, setError] = React.useState('');

return (
<>
<TextArea
validated={ValidatedOptions.success}
isIconSprite
type="text"
onChange={value => setSuccess(value)}
aria-label="success icon sprite text area example"
/>
<br />
<br />
<TextArea
validated={ValidatedOptions.warning}
isIconSprite
type="text"
onChange={value => setWarning(value)}
aria-label="warning icon sprite text input example"
/>
<br />
<br />
<TextArea
validated={ValidatedOptions.error}
isIconSprite
type="text"
onChange={value => setError(value)}
aria-label="error icon sprite text area example"
/>
</>
);
};
```ts isBeta file="./TextAreaIconSprite.tsx"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { TextArea } from '@patternfly/react-core';

export const TextAreaAutoResizing: React.FunctionComponent = () => {
const [value, setValue] = React.useState('');
return (
<TextArea
value={value}
onChange={value => setValue(value)}
aria-label="auto resizing text area example"
autoResize
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';
import { TextArea } from '@patternfly/react-core';

export const TextAreaBasic: React.FunctionComponent = () => {
const [value, setValue] = React.useState('');
return <TextArea value={value} onChange={value => setValue(value)} aria-label="text area example" />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import { TextArea } from '@patternfly/react-core';

export const TextAreaDisabled: React.FunctionComponent = () => (
<TextArea aria-label="disabled text area example" isDisabled />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { TextArea } from '@patternfly/react-core';

export const TextAreaHorizontallyResizable: React.FunctionComponent = () => {
const [value, setValue] = React.useState('');
return (
<TextArea
value={value}
onChange={value => setValue(value)}
resizeOrientation="horizontal"
aria-label="text area horizontal resize example"
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import { TextArea } from '@patternfly/react-core';

export const TextAreaIconSprite: React.FunctionComponent = () => {
const [success, setSuccess] = React.useState('');
const [warning, setWarning] = React.useState('');
const [error, setError] = React.useState('');

return (
<>
<TextArea
validated={'success'}
isIconSprite
type="text"
onChange={value => setSuccess(value)}
value={success}
aria-label="success icon sprite text area example"
/>
<br />
<br />
<TextArea
validated={'warning'}
isIconSprite
type="text"
onChange={value => setWarning(value)}
value={warning}
aria-label="warning icon sprite text area example"
/>
<br />
<br />
<TextArea
validated={'error'}
isIconSprite
type="text"
onChange={value => setError(value)}
value={error}
aria-label="error icon sprite text area example"
/>
</>
);
};
Loading