Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | 2x 31x 31x 31x 31x 31x 31x 2x 31x 31x 2x 13x 13x 13x 13x 13x 2x 13x 13x | import * as React from 'react';
import { Box as ReakitBox } from 'reakit';
import { Size } from '../types';
import { useClassName, createComponent, createElement, createHook, pickCSSProps, omitCSSProps } from '../utils';
import { Box, BoxProps } from '../Box';
import { FieldWrapper, FieldWrapperProps } from '../FieldWrapper';
import * as styles from './styles';
export type LocalTextareaProps = {
autoComplete?: string;
/** Automatically focus on the textarea */
autoFocus?: boolean;
/** Default value of the textarea */
defaultValue?: string | string[];
/** Disables the textarea */
disabled?: boolean;
/** Makes the textarea required and sets aria-invalid to true */
isRequired?: boolean;
/** Name of the textarea field */
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;
/** This prop indicates whether the user can enter more than one value. This attribute only applies when the type attribute is set to email or file. */
multiple?: boolean;
/** 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;
/** Works with the min and max attributes to limit the increments at which a numeric or date-time value can be set. */
step?: number | string;
/** State of the textarea. Can be any color in the palette. */
state?: string;
/** Specify the type of textarea. */
type?: string;
/** Value of the textarea */
value?: string | number | string[];
/** Function to invoke when focus is lost */
onBlur?: React.FocusEventHandler<HTMLTextAreaElement>;
/** Function to invoke when textarea has changed */
onChange?: React.FormEventHandler<HTMLTextAreaElement>;
/** Function to invoke when textarea is focused */
onFocus?: React.FocusEventHandler<HTMLTextAreaElement>;
};
export type TextareaProps = BoxProps & LocalTextareaProps;
const useProps = createHook<TextareaProps>(
(props, { themeKey, themeKeyOverride }) => {
const { isRequired, state, ...restProps } = props;
const wrapperClassName = useClassName({
style: styles.TextareaWrapper,
styleProps: props,
themeKey,
themeKeyOverride,
themeKeySuffix: 'Wrapper',
prevClassName: restProps.className
});
const boxProps = Box.useProps({
...omitCSSProps(restProps),
className: undefined,
wrapElement: children => (
<Box className={wrapperClassName} {...pickCSSProps(props)}>
{children}
</Box>
)
});
const className = useClassName({
style: styles.Textarea,
styleProps: props,
themeKey,
themeKeyOverride,
prevClassName: boxProps.className
});
return { ...boxProps, className, 'aria-invalid': state === 'danger', 'aria-required': isRequired };
},
{ defaultProps: { type: 'text' }, themeKey: 'Textarea' }
);
export const Textarea = createComponent<TextareaProps>(
props => {
const textareaProps = useProps(props);
return createElement({
children: props.children,
component: ReakitBox,
use: props.use,
htmlProps: { ...textareaProps, ...(props.mask ? { mask: props.mask } : {}) }
});
},
{
attach: {
useProps
},
defaultProps: {
use: 'textarea'
},
themeKey: 'Textarea'
}
);
////////////////////////////////////////////////////////////////
export type LocalTextareaFieldProps = {
/** Additional props for the Textarea component */
textareaProps?: TextareaProps;
};
export type TextareaFieldProps = BoxProps & FieldWrapperProps & TextareaProps & LocalTextareaFieldProps;
const useTextareaFieldProps = createHook<TextareaFieldProps>(
(props, { themeKey, themeKeyOverride }) => {
const {
children,
autoComplete,
autoFocus,
defaultValue,
description,
disabled,
hint,
textareaProps,
isOptional,
isRequired,
label,
name,
size,
mask,
maxLength,
minLength,
multiple,
pattern,
placeholder,
readOnly,
spellCheck,
step,
state,
tooltip,
tooltipTriggerComponent,
type,
value,
onBlur,
onChange,
onFocus,
overrides,
validationText,
...restProps
} = props;
const boxProps = Box.useProps(restProps);
const className = useClassName({
style: styles.TextareaField,
styleProps: props,
themeKey,
themeKeyOverride,
prevClassName: boxProps.className
});
return {
...boxProps,
className,
children: (
<FieldWrapper
description={description}
hint={hint}
isOptional={isOptional}
isRequired={isRequired}
label={label}
overrides={overrides}
state={state}
tooltip={tooltip}
tooltipTriggerComponent={tooltipTriggerComponent}
validationText={validationText}
>
{({ elementProps }) => (
<Textarea
autoComplete={autoComplete}
autoFocus={autoFocus}
defaultValue={defaultValue}
disabled={disabled}
isRequired={isRequired}
name={name}
size={size}
mask={mask}
maxLength={maxLength}
minLength={minLength}
multiple={multiple}
pattern={pattern}
placeholder={placeholder}
readOnly={readOnly}
spellCheck={spellCheck}
step={step}
state={state}
type={type}
value={value}
onBlur={onBlur}
onChange={onChange}
onFocus={onFocus}
overrides={overrides}
{...elementProps}
{...textareaProps}
/>
)}
</FieldWrapper>
)
};
},
{ themeKey: 'TextareaField' }
);
export const TextareaField = createComponent<TextareaFieldProps>(
props => {
const textareaFieldProps = useTextareaFieldProps(props);
return createElement({
children: props.children,
component: ReakitBox,
use: props.use,
htmlProps: textareaFieldProps
});
},
{
attach: {
useProps
},
themeKey: 'TextareaField'
}
);
|