1 | import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
|
2 | import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
|
3 | import { css } from '@emotion/css';
|
4 | import { Box } from '@spark-web/box';
|
5 | import { useFieldContext } from '@spark-web/field';
|
6 | import { useInputStyles, InputContainer } from '@spark-web/text-input';
|
7 | import { forwardRef } from 'react';
|
8 | import { useTheme } from '@spark-web/theme';
|
9 | import { jsx } from 'react/jsx-runtime';
|
10 |
|
11 | function 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 |
|
19 | height: 'auto',
|
20 | minHeight: theme.sizing.medium,
|
21 | paddingTop: theme.spacing.small,
|
22 | paddingBottom: theme.spacing.small,
|
23 | resize: 'vertical'
|
24 | })];
|
25 | }
|
26 |
|
27 | var TextArea = 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 jsx(InputContainer, {
|
50 | children: 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 | });
|
67 | TextArea.displayName = 'TextArea';
|
68 |
|
69 | export { TextArea };
|