UNPKG

2.4 kBJavaScriptView Raw
1import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
2import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
3import { css } from '@emotion/css';
4import { Box } from '@spark-web/box';
5import { useFieldContext } from '@spark-web/field';
6import { useInputStyles, InputContainer } from '@spark-web/text-input';
7import { forwardRef } from 'react';
8import { useTheme } from '@spark-web/theme';
9import { jsx } from 'react/jsx-runtime';
10
11function useTextAreaStyles(props) {
12 var theme = useTheme();
13 var _useInputStyles = useInputStyles(props),
14 _useInputStyles2 = _slicedToArray(_useInputStyles, 2),
15 boxProps = _useInputStyles2[0],
16 inputStyles = _useInputStyles2[1];
17 return [boxProps, _objectSpread(_objectSpread({}, inputStyles), {}, {
18 // Text inputs have a fixed height, so we need to override it back to `auto`
19 height: 'auto',
20 minHeight: theme.sizing.medium,
21 paddingTop: theme.spacing.small,
22 paddingBottom: theme.spacing.small,
23 resize: 'vertical'
24 })];
25}
26
27var TextArea = /*#__PURE__*/forwardRef(function (_ref, forwardedRef) {
28 var data = _ref.data,
29 defaultValue = _ref.defaultValue,
30 name = _ref.name,
31 onBlur = _ref.onBlur,
32 onChange = _ref.onChange,
33 placeholder = _ref.placeholder,
34 required = _ref.required,
35 value = _ref.value;
36 var _useFieldContext = useFieldContext(),
37 _useFieldContext2 = _slicedToArray(_useFieldContext, 2),
38 _useFieldContext2$ = _useFieldContext2[0],
39 disabled = _useFieldContext2$.disabled,
40 invalid = _useFieldContext2$.invalid,
41 a11yProps = _useFieldContext2[1];
42 var _useTextAreaStyles = useTextAreaStyles({
43 disabled: disabled,
44 invalid: invalid
45 }),
46 _useTextAreaStyles2 = _slicedToArray(_useTextAreaStyles, 2),
47 boxProps = _useTextAreaStyles2[0],
48 textAreaStyles = _useTextAreaStyles2[1];
49 return /*#__PURE__*/jsx(InputContainer, {
50 children: /*#__PURE__*/jsx(Box, _objectSpread(_objectSpread(_objectSpread({}, boxProps), a11yProps), {}, {
51 as: "textarea",
52 className: css(textAreaStyles),
53 data: data,
54 defaultValue: defaultValue,
55 disabled: disabled,
56 name: name,
57 onBlur: onBlur,
58 onChange: onChange,
59 placeholder: placeholder,
60 ref: forwardedRef,
61 required: required,
62 rows: 3,
63 value: value
64 }))
65 });
66});
67TextArea.displayName = 'TextArea';
68
69export { TextArea };