UNPKG

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