From 5a47d7383a708a4e5bf8c465c8d35fc2a9a52c3a Mon Sep 17 00:00:00 2001 From: Wez Pyke Date: Tue, 20 Nov 2018 19:51:29 +0000 Subject: [PATCH] Added Textarea --- src/Textarea/Textarea.js | 138 ++++++++++++++++++++++++ src/Textarea/Textarea.mdx | 104 ++++++++++++++++++ src/Textarea/__tests__/Textarea.test.js | 47 ++++++++ src/Textarea/index.js | 2 + src/Textarea/styled.js | 118 ++++++++++++++++++++ src/index.js | 1 + 6 files changed, 410 insertions(+) create mode 100644 src/Textarea/Textarea.js create mode 100644 src/Textarea/Textarea.mdx create mode 100644 src/Textarea/__tests__/Textarea.test.js create mode 100644 src/Textarea/index.js create mode 100644 src/Textarea/styled.js diff --git a/src/Textarea/Textarea.js b/src/Textarea/Textarea.js new file mode 100644 index 000000000..aec22c098 --- /dev/null +++ b/src/Textarea/Textarea.js @@ -0,0 +1,138 @@ +import React, { type Node } from 'react'; + +import type { Size } from '../types'; +import _Textarea, { LoadingSpinner } from './styled'; +import { InlineBlock } from '../primitives'; + +export type Props = { + /** An accessible identifier for the textarea */ + a11yId?: string, + /** An accessible label for the textarea */ + a11yLabel?: string, + as?: any, + autoComplete?: string, + /** Automatically focus on the textarea */ + autoFocus?: boolean, + children: Node, + className?: string, + /** Default value of the textarea */ + defaultValue?: string, + /** Disables the textrea */ + disabled?: boolean, + /** Makes the textarea span full width */ + isFullWidth?: boolean, + /** Adds a cute loading indicator to the textarea */ + isLoading?: boolean, + /** Makes the texrea required and sets aria-invalid to true */ + isRequired?: boolean, + /** Name of the textarea */ + name?: string, + /** Alters the size of the textarea. Can be "small", "medium" or "large" */ + size?: Size, + /** If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the maximum number of characters (in UTF-16 code units) that the user can enter. For other control types, it is ignored. */ + maxLength?: number, + /** If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the minimum number of characters (in UTF-16 code points) that the user can enter. For other control types, it is ignored. */ + minLength?: number, + /** Regex pattern to apply to the textarea */ + pattern?: string, + /** Hint text to display */ + placeholder?: string, + /** This prop prevents the user from modifying the value of the textarea. It is ignored if the value of the type attribute is hidden, range, color, checkbox, radio, file, or a button type (such as button or submit). */ + readOnly?: boolean, + /** Setting the value of this attribute to true indicates that the element needs to have its spelling and grammar checked. The value default indicates that the element is to act according to a default behavior, possibly based on the parent element's own spellcheck value. The value false indicates that the element should not be checked. */ + spellCheck?: boolean, + /** State of the input. Can be any color in the palette. */ + state?: string, + /** Value of the input */ + value?: string, + /** Function to invoke when focus is lost */ + onBlur?: Function, + /** Function to invoke when input has changed */ + onChange?: Function, + /** Function to invoke when input is focused */ + onFocus?: Function +}; + +const Textarea = ({ + a11yId, + a11yLabel, + autoComplete, + autoFocus, + className, + defaultValue, + disabled, + isFullWidth, + isLoading, + isRequired, + maxLength, + minLength, + onBlur, + onChange, + onFocus, + name, + pattern, + placeholder, + readOnly, + size, + spellCheck, + state, + value, + ...props +}: Props) => ( + + <_Textarea + aria-invalid={state === 'danger'} + aria-label={a11yLabel} + aria-required={isRequired} + autoComplete={autoComplete} + autoFocus={autoFocus} + defaultValue={defaultValue} + disabled={disabled} + id={a11yId} + isFullWidth={isFullWidth} + maxLength={maxLength} + minLength={minLength} + onBlur={onBlur} + onChange={onChange} + onFocus={onFocus} + name={name} + readOnly={readOnly} + pattern={pattern} + placeholder={placeholder} + size={size} + spellCheck={spellCheck} + state={state} + value={value} + /> + {isLoading && } + +); + +Textarea.defaultProps = { + a11yId: undefined, + a11yLabel: undefined, + as: undefined, + autoComplete: undefined, + autoFocus: false, + className: undefined, + defaultValue: undefined, + disabled: false, + isFullWidth: false, + isLoading: false, + isRequired: false, + maxLength: undefined, + minLength: undefined, + name: undefined, + onBlur: undefined, + onChange: undefined, + onFocus: undefined, + pattern: undefined, + placeholder: undefined, + readOnly: undefined, + spellCheck: undefined, + size: 'default', + state: undefined, + value: undefined +}; + +export default Textarea; diff --git a/src/Textarea/Textarea.mdx b/src/Textarea/Textarea.mdx new file mode 100644 index 000000000..3b9e4cae5 --- /dev/null +++ b/src/Textarea/Textarea.mdx @@ -0,0 +1,104 @@ +--- +name: Textarea +route: /form/textarea +menu: Form +--- + +import { Playground, PropsTable } from 'docz'; +import { Box } from '../primitives/index'; +import Textarea from './index'; +import Component from '@reactions/component'; + +# Textarea + +## Import + +`import { Textarea } from 'fannypack'` + +## Basic usage + +