UNPKG

aws-northstar

Version:
101 lines (97 loc) 4.59 kB
"use strict"; /** ******************************************************************************************************************* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. * ******************************************************************************************************************** */ var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.mapTextareaProps = void 0; const react_1 = __importDefault(require("react")); const TextareaAutosize_1 = __importDefault(require("@material-ui/core/TextareaAutosize")); const styles_1 = require("@material-ui/core/styles"); const clsx_1 = __importDefault(require("clsx")); const useUniqueId_1 = __importDefault(require("../../hooks/useUniqueId")); const useStyles = (0, styles_1.makeStyles)((theme) => ({ textarea: { fontSize: theme.typography.fontSize, borderRadius: '2px', border: `1px solid ${theme.palette.grey[400]}`, width: '100%', padding: '4px 10px', '&:focus:not([class*="invalid"])': { outline: '2px dotted transparent', boxShadow: `0 0 0 1px ${theme.palette.info.dark}`, border: `1px solid ${theme.palette.info.dark}`, }, '&:hover:not([class*="invalid"]):not([disabled])': { border: `1px solid ${theme.palette.info.dark}`, }, }, invalid: { border: `1px solid ${theme.palette.error.dark}`, boxShadow: 'none', outline: 'none', '&:focus': { outline: '2px dotted transparent', boxShadow: `0 0 0 1px ${theme.palette.error.dark}`, border: `1px solid ${theme.palette.error.dark}`, }, }, })); const mapTextareaProps = (_a) => { var { rows = 3, controlId, invalid = false, disableBrowserAutocorrect = false } = _a, props = __rest(_a, ["rows", "controlId", "invalid", "disableBrowserAutocorrect"]); const autoCompleteString = disableBrowserAutocorrect ? 'off' : 'on'; return { id: controlId, rowsMin: rows, required: props.ariaRequired, value: props.value, placeholder: props.placeholder, name: props.name, disabled: props.disabled, readOnly: props.readonly, autoComplete: autoCompleteString, autoCapitalize: autoCompleteString, autoFocus: props.autofocus, 'aria-label': props.value || props.placeholder || controlId, 'aria-describedby': props.ariaDescribedby, 'aria-required': props.ariaRequired, onChange: props.onChange, onFocus: props.onFocus, onBlur: props.onBlur, onKeyDown: props.onKeyDown, onKeyUp: props.onKeyUp, }; }; exports.mapTextareaProps = mapTextareaProps; /** * A Textarea is a multi-line text input control. * */ const Textarea = (_a) => { var { invalid } = _a, props = __rest(_a, ["invalid"]); const classes = useStyles(); const controlId = (0, useUniqueId_1.default)(props.controlId); return (react_1.default.createElement(TextareaAutosize_1.default, Object.assign({}, mapTextareaProps(Object.assign(Object.assign({}, props), { controlId })), { "data-testid": props['data-testid'], className: (0, clsx_1.default)(classes.textarea, { [classes.invalid]: invalid }, props.className) }))); }; exports.default = Textarea;