UNPKG

@td-design/react-native

Version:

react-native UI组件库

84 lines 2.51 kB
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import React, { forwardRef } from 'react'; import { StyleSheet, TextInput } from 'react-native'; import { useTheme } from '@shopify/restyle'; import Box from '../box'; import Brief from '../brief'; import Flex from '../flex'; import helpers from '../helpers'; import Label from '../label'; import Text from '../text'; import useTextArea from './useTextArea'; const { ONE_PIXEL, px } = helpers; const TextArea = /*#__PURE__*/forwardRef((_ref, ref) => { let { label, height = px(150), limit, value, border = true, onChange, style, brief, required, itemHeight, ...restProps } = _ref; const theme = useTheme(); const { inputValue, handleChange } = useTextArea({ value, onChange }); const styles = StyleSheet.create({ input: { height: '100%', padding: theme.spacing.x2, fontSize: px(14), lineHeight: px(20), color: theme.colors.text } }); return /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Label, { label, required, labelHeight: itemHeight }), /*#__PURE__*/React.createElement(Box, { borderWidth: border ? ONE_PIXEL : 0, borderColor: "border", style: [style, { height }] }, /*#__PURE__*/React.createElement(TextInput, _extends({ ref: ref, textAlignVertical: "top", autoCapitalize: "none", autoCorrect: false, autoComplete: "off" }, restProps, { style: styles.input, placeholderTextColor: theme.colors.gray300, selectionColor: theme.colors.primary200, value: inputValue, onChangeText: handleChange, multiline: true, underlineColorAndroid: "transparent", maxLength: limit })), !!limit && /*#__PURE__*/React.createElement(Flex, { flexDirection: "row-reverse", padding: "x1" }, /*#__PURE__*/React.createElement(Text, { variant: "p1", color: "text" }, (inputValue === null || inputValue === void 0 ? void 0 : inputValue.length) ?? 0, " / ", limit))), /*#__PURE__*/React.createElement(Brief, { brief })); }); TextArea.displayName = 'TextArea'; export default TextArea; //# sourceMappingURL=TextArea.js.map