UNPKG

@react-spectrum/s2

Version:
242 lines (229 loc) 11.9 kB
require("./TextField.css"); var $a0b996a550bb0891$exports = require("./Field.cjs"); var $bfa4962d90c8af48$exports = require("./Form.cjs"); var $ac757a4c2bd72aee$exports = require("../icons/useSpectrumContextProps.cjs"); var $tjrHw$reactjsxruntime = require("react/jsx-runtime"); var $tjrHw$reactariacomponents = require("react-aria-components"); var $tjrHw$react = require("react"); var $tjrHw$reactspectrumutils = require("@react-spectrum/utils"); var $tjrHw$reactariautils = require("@react-aria/utils"); function $parcel$export(e, n, v, s) { Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); } $parcel$export(module.exports, "TextFieldContext", () => $cce7e7de6810e1b5$export$2129e27b3ef0d483); $parcel$export(module.exports, "TextField", () => $cce7e7de6810e1b5$export$2c73285ae9390cec); $parcel$export(module.exports, "TextAreaContext", () => $cce7e7de6810e1b5$export$2dc6166a7e65358c); $parcel$export(module.exports, "TextArea", () => $cce7e7de6810e1b5$export$f5c9f3c2c4054eec); /* * Copyright 2024 Adobe. All rights reserved. * This file is licensed to you 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 REPRESENTATIONS * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ const $cce7e7de6810e1b5$export$2129e27b3ef0d483 = /*#__PURE__*/ (0, $tjrHw$react.createContext)(null); const $cce7e7de6810e1b5$export$2c73285ae9390cec = /*#__PURE__*/ (0, $tjrHw$react.forwardRef)(function TextField(props, ref) { [props, ref] = (0, $ac757a4c2bd72aee$exports.useSpectrumContextProps)(props, ref, $cce7e7de6810e1b5$export$2129e27b3ef0d483); return /*#__PURE__*/ (0, $tjrHw$reactjsxruntime.jsx)($cce7e7de6810e1b5$export$d22444a338b6e3c2, { ...props, ref: ref, children: /*#__PURE__*/ (0, $tjrHw$reactjsxruntime.jsx)((0, $a0b996a550bb0891$exports.Input), {}) }); }); const $cce7e7de6810e1b5$export$2dc6166a7e65358c = /*#__PURE__*/ (0, $tjrHw$react.createContext)(null); const $cce7e7de6810e1b5$export$f5c9f3c2c4054eec = /*#__PURE__*/ (0, $tjrHw$react.forwardRef)(function TextArea(props, ref) { [props, ref] = (0, $ac757a4c2bd72aee$exports.useSpectrumContextProps)(props, ref, $cce7e7de6810e1b5$export$2dc6166a7e65358c); return /*#__PURE__*/ (0, $tjrHw$reactjsxruntime.jsx)($cce7e7de6810e1b5$export$d22444a338b6e3c2, { ...props, ref: ref, fieldGroupCss: " ea91 Fd91", children: /*#__PURE__*/ (0, $tjrHw$reactjsxruntime.jsx)($cce7e7de6810e1b5$var$TextAreaInput, {}) }); }); const $cce7e7de6810e1b5$export$d22444a338b6e3c2 = /*#__PURE__*/ (0, $tjrHw$react.forwardRef)(function TextFieldBase(props, ref) { let inputRef = (0, $tjrHw$react.useRef)(null); let domRef = (0, $tjrHw$react.useRef)(null); let formContext = (0, $tjrHw$react.useContext)((0, $bfa4962d90c8af48$exports.FormContext)); props = (0, $bfa4962d90c8af48$exports.useFormProps)(props); let { label: label, description: description, errorMessage: errorMessage, necessityIndicator: necessityIndicator, labelPosition: labelPosition = 'top', labelAlign: labelAlign = 'start', fieldGroupCss: fieldGroupCss, UNSAFE_style: UNSAFE_style, UNSAFE_className: UNSAFE_className = '', ...textFieldProps } = props; // Expose imperative interface for ref (0, $tjrHw$react.useImperativeHandle)(ref, ()=>({ ...(0, $tjrHw$reactspectrumutils.createFocusableRef)(domRef, inputRef), select () { if (inputRef.current) inputRef.current.select(); }, getInputElement () { return inputRef.current; } })); return /*#__PURE__*/ (0, $tjrHw$reactjsxruntime.jsx)((0, $tjrHw$reactariacomponents.TextField), { ...textFieldProps, ref: domRef, style: UNSAFE_style, className: UNSAFE_className + function anonymous(props, overrides) { let rules = " "; let gridColumnStart = false; let gridColumnEnd = false; let matches = (overrides || '').matchAll(/(?:^|\s)(J|G|I|H|_u|_v|_s|__A|_d|_J|z|y|B|A|_P|_9|W|_l|_A|_z|Z|N|L)[^\s]+/g); for (let p of matches){ if (p[1] === "z") gridColumnStart = true; if (p[1] === "y") gridColumnEnd = true; rules += p[0]; } rules += ' se91'; if (props.isInForm) { if (!gridColumnStart) rules += ' z2mU91'; } if (props.isInForm) { if (props.labelPosition === "side") { if (!gridColumnEnd) rules += ' yvoofG91'; } } if (props.isInForm) rules += ' DLwlgod91'; else { if (props.labelPosition === "side") rules += ' DPlN5qb91'; else if (props.labelPosition === "top") rules += ' DM8Mfn91'; } if (props.labelPosition === "side") rules += ' EPlN5qb91'; else if (props.labelPosition === "top") rules += ' E4w1sLc91'; if (props.labelPosition === "side") rules += ' CbRM95c91'; else if (props.labelPosition === "top") rules += ' Cxaocre91'; if (props.size === "XL") { rules += ' vg91'; rules += ' vsj91'; } else if (props.size === "L") { rules += ' vp91'; rules += ' vsh91'; } else if (props.size === "S") { rules += ' vb91'; rules += ' vse91'; } else if (props.size === "XS") { rules += ' va91'; rules += ' vsc91'; } else { rules += ' vd91'; rules += ' vsf91'; } rules += ' ea91'; rules += ' _Fa91'; rules += ' _Ffb91'; if (props.size === "XL") rules += ' -BhX7R-Fz91'; else if (props.size === "L") rules += ' -BhX7R-Fv91'; else if (props.size === "S") rules += ' -BhX7R-Fp91'; else if (props.size === "XS") rules += ' -BhX7R-Fn91'; else rules += ' -BhX7R-Fx91'; rules += ' -AJjOLd-UVkF0Db91'; rules += ' qg91'; rules += ' __ca91'; return rules; }({ size: props.size, labelPosition: labelPosition, isInForm: !!formContext }, props.styles), children: (0, $tjrHw$reactariacomponents.composeRenderProps)(props.children, (children, { isDisabled: isDisabled, isInvalid: isInvalid })=>/*#__PURE__*/ (0, $tjrHw$reactjsxruntime.jsxs)((0, $tjrHw$reactjsxruntime.Fragment), { children: [ /*#__PURE__*/ (0, $tjrHw$reactjsxruntime.jsx)((0, $a0b996a550bb0891$exports.FieldLabel), { isDisabled: isDisabled, isRequired: props.isRequired, size: props.size, labelPosition: labelPosition, labelAlign: labelAlign, necessityIndicator: necessityIndicator, contextualHelp: props.contextualHelp, children: label }), /*#__PURE__*/ (0, $tjrHw$reactjsxruntime.jsxs)((0, $a0b996a550bb0891$exports.FieldGroup), { role: "presentation", isDisabled: isDisabled, isInvalid: isInvalid, size: props.size, styles: fieldGroupCss, children: [ /*#__PURE__*/ (0, $tjrHw$reactjsxruntime.jsx)((0, $tjrHw$reactariacomponents.InputContext).Consumer, { children: (ctx)=>/*#__PURE__*/ (0, $tjrHw$reactjsxruntime.jsx)((0, $tjrHw$reactariacomponents.InputContext).Provider, { value: { ...ctx, ref: (0, $tjrHw$reactariautils.mergeRefs)(ctx?.ref, inputRef) }, children: children }) }), isInvalid && /*#__PURE__*/ (0, $tjrHw$reactjsxruntime.jsx)((0, $a0b996a550bb0891$exports.FieldErrorIcon), { isDisabled: isDisabled }) ] }), /*#__PURE__*/ (0, $tjrHw$reactjsxruntime.jsx)((0, $a0b996a550bb0891$exports.HelpText), { size: props.size, isDisabled: isDisabled, isInvalid: isInvalid, description: description, children: errorMessage }) ] })) }); }); function $cce7e7de6810e1b5$var$TextAreaInput() { // Force re-render when value changes so we update the height. (0, $tjrHw$reactariacomponents.useSlottedContext)((0, $tjrHw$reactariacomponents.TextAreaContext)); let onHeightChange = (input)=>{ // TODO: only do this if an explicit height is not given? if (input) { let prevAlignment = input.style.alignSelf; let prevOverflow = input.style.overflow; // Firefox scroll position is lost when overflow: 'hidden' is applied so we skip applying it. // The measure/applied height is also incorrect/reset if we turn on and off // overflow: hidden in Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1787062 let isFirefox = 'MozAppearance' in input.style; if (!isFirefox) input.style.overflow = 'hidden'; input.style.alignSelf = 'start'; input.style.height = 'auto'; // offsetHeight - clientHeight accounts for the border/padding. input.style.height = `${input.scrollHeight + (input.offsetHeight - input.clientHeight)}px`; input.style.overflow = prevOverflow; input.style.alignSelf = prevAlignment; } }; return /*#__PURE__*/ (0, $tjrHw$reactjsxruntime.jsx)((0, $tjrHw$reactariacomponents.TextArea), { ref: onHeightChange, // Workaround for baseline alignment bug in Safari. // https://bugs.webkit.org/show_bug.cgi?id=142968 placeholder: " ", className: function anonymous(props) { let rules = " "; rules += ' Sd91'; rules += ' Rd91'; rules += ' Tu7Fubd91'; rules += ' Qu7Fubd91'; rules += ' MAyFGYc91'; rules += ' _oa91'; rules += ' g991'; rules += ' p40ub4c91'; rules += ' u40ub4c91'; rules += ' v40ub4c91'; rules += ' w40ub4c91'; rules += ' x40ub4c91'; rules += ' _xa91'; rules += ' _F40ub4c91'; rules += ' _ub91'; rules += ' Na91'; rules += ' _Le91'; rules += ' _je91'; rules += ' _Qc91'; rules += ' _Nc91'; if (props.size === "XL") rules += ' -M_-Mk91'; else if (props.size === "L") rules += ' -M_-Mh91'; else if (props.size === "S") rules += ' -M_-Mg91'; else if (props.size === "XS") rules += ' -M_-Mf91'; else rules += ' -M_-Mi91'; return rules; } }); } //# sourceMappingURL=TextField.cjs.map