Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: add prop variant to the Textarea component #1786

Merged
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
1 change: 1 addition & 0 deletions src/components/Textarea/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface TextareaProps extends BaseProps {
onBlur?: (event: FocusEvent<HTMLTextAreaElement>) => void;
onPaste?: (event: ClipboardEvent<HTMLTextAreaElement>) => void;
id?: string;
variant?: 'default' | 'shaded';
}

declare const Textarea: ComponentType<TextareaProps>;
Expand Down
6 changes: 6 additions & 0 deletions src/components/Textarea/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class Textarea extends Component {
hideLabel,
name,
footer,
variant,
} = this.props;

return (
Expand All @@ -113,6 +114,7 @@ class Textarea extends Component {
error={error}
readOnly={readOnly}
disabled={disabled}
variant={variant}
>
<StyledTextarea
error={error}
Expand Down Expand Up @@ -193,6 +195,9 @@ Textarea.propTypes = {
className: PropTypes.string,
/** An object with custom style applied to the outer element. */
style: PropTypes.object,
/** The variant changes the appearance of the Textarea. Accepted variants include default,
* and shaded. This value defaults to default. */
variant: PropTypes.oneOf(['default', 'shaded']),
/** The id of the outer element. */
id: PropTypes.string,
/** It is what will be displayed at the bottom of the component. */
Expand Down Expand Up @@ -220,6 +225,7 @@ Textarea.defaultProps = {
onPaste: () => {},
className: undefined,
style: undefined,
variant: 'default',
id: undefined,
hideLabel: false,
footer: undefined,
Expand Down
20 changes: 20 additions & 0 deletions src/components/Textarea/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,23 @@ function TextareaExample(props) {

<TextareaExample maxLength={160} />
```
##### Textarea with variant shaded

```js
import React from 'react';
import { Textarea } from 'react-rainbow-components';

const containerStyles = {
maxWidth: 700,
};

<Textarea
id="example-textarea-1"
label="Textarea Label"
rows={4}
placeholder="Placeholder Text"
style={containerStyles}
variant="shaded"
className="rainbow-m-vertical_x-large rainbow-p-horizontal_medium rainbow-m_auto"
/>;
```
6 changes: 6 additions & 0 deletions src/components/Textarea/styled/textareaContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const StyledTextareaContainer = attachThemeAttrs(styled.div)`
border: solid 2px ${props => props.palette.brand.main};
box-shadow: ${props => props.shadows.brand};
}
${props =>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

props.variant === 'shaded' &&
`
box-shadow:${props.disabled || props.readOnly ? '' : props.shadows.shadow_10};
border: 1px solid transparent;
`}

${props =>
props.error &&
Expand Down