UNPKG

@atlaskit/textfield

Version:

A text field is an input that allows a user to write or edit text.

188 lines (183 loc) 9.87 kB
/* text-field.tsx generated by @compiled/babel-plugin v3.0.2 */ "use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof3 = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; require("./text-field.compiled.css"); var _runtime = require("@compiled/react/runtime"); var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _react = _interopRequireWildcard(require("react")); var _usePlatformLeafEventHandler = require("@atlaskit/analytics-next/usePlatformLeafEventHandler"); var _fg = require("@atlaskit/platform-feature-flags/fg"); var _excluded = ["appearance", "className", "elemAfterInput", "elemBeforeInput", "isCompact", "isDisabled", "isInvalid", "isMonospaced", "isReadOnly", "isRequired", "name", "onBlur", "onChange", "onFocus", "onMouseDown", "placeholder", "testId", "width"]; function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var containerMedia = { invalid: "_msj6gir2", disabled: "_6up518qt" }; var inputMediaDisabled = null; var analyticsParams = { componentName: 'textField', packageName: "@atlaskit/textfield", packageVersion: "10.2.3" }; var disabledStyle = { standard: "_1h6d187o _bfhk187o _syaz1gmx _80om13gf", subtle: "_1h6d1j28 _bfhk1j28 _syaz1gmx _80om13gf", none: "_1h6d1j28 _bfhk1j28 _syaz1gmx _80om13gf" }; var invalidStyle = null; var focusWithinStyle = { standard: "_1p9x1v1w _qao9r01l _q433vyy1", subtle: "_1p9x1v1w _qao9r01l _q433vyy1", none: "_1p9x1j28 _qao91j28 _q4333sij" }; var hoverStyle = { standard: "_4cvxrsbi _irr3l4ek", subtle: "_4cvxrsbi _irr3l4ek", none: "_4cvx1j28 _irr31j28" }; var getContainerTextBgAndBorderColor = { standard: "_1h6drsbi _1dqonqa1 _syazi7uo _80om1kdv _bfhk1j9a _msj6gir2", subtle: "_1h6d1j28 _1dqonqa1 _syazi7uo _80om1kdv _16hg1j28 _msj6gir2", none: "_1h6d1j28 _1dqoglyw _syazi7uo _80om1kdv _16hg1j28 _msj6gir2" }; var widthMap = { xsmall: 80, small: 160, medium: 240, large: 320, xlarge: 480 }; var getMaxWidth = function getMaxWidth(width) { return !width ? "100%" : width in widthMap ? "".concat(widthMap[width], "px") : "".concat(+width, "px"); }; var containerStyleAppearance = { standard: "_1dqonqa1 _1q51e4h9 _85i5e4h9 _bozgidpf _y4tiidpf", subtle: "_1dqonqa1 _1q51e4h9 _85i5e4h9 _bozgidpf _y4tiidpf", none: "_1dqoglyw" }; var containerStyles = null; var inputDisabledStyle = null; var inputCompactStyle = null; var inputMonospacedStyle = null; // iOS Safari automatically zooms into form inputs on focus when the font size is less than 16px. // To prevent this zoom behaviour on mobile devices, the textfield uses font.body.large (16px) by default, // then switches to the smaller font.body on screens wider than 30rem (desktop). // @see: https://medium.com/@rares.popescu/2-ways-to-avoid-the-automatic-zoom-in-on-input-fields-8a71479e542e var inputStyle = null; var finessePlaceholderStyle = null; /** * __Textfield__ * * A text field is an input that allows a user to write or edit text. * * - [Examples](https://atlassian.design/components/textfield/examples) * - [Code](https://atlassian.design/components/textfield/code) * - [Usage](https://atlassian.design/components/textfield/usage) */ var Textfield = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) { var _props$appearance = props.appearance, appearance = _props$appearance === void 0 ? 'standard' : _props$appearance, className = props.className, elemAfterInput = props.elemAfterInput, elemBeforeInput = props.elemBeforeInput, _props$isCompact = props.isCompact, isCompact = _props$isCompact === void 0 ? false : _props$isCompact, _props$isDisabled = props.isDisabled, isDisabled = _props$isDisabled === void 0 ? false : _props$isDisabled, _props$isInvalid = props.isInvalid, isInvalid = _props$isInvalid === void 0 ? false : _props$isInvalid, _props$isMonospaced = props.isMonospaced, isMonospaced = _props$isMonospaced === void 0 ? false : _props$isMonospaced, _props$isReadOnly = props.isReadOnly, isReadOnly = _props$isReadOnly === void 0 ? false : _props$isReadOnly, _props$isRequired = props.isRequired, isRequired = _props$isRequired === void 0 ? false : _props$isRequired, name = props.name, onBlur = props.onBlur, onChange = props.onChange, onFocus = props.onFocus, onMouseDown = props.onMouseDown, placeholder = props.placeholder, testId = props.testId, width = props.width, spreadProps = (0, _objectWithoutProperties2.default)(props, _excluded); var inputRef = (0, _react.useRef)(null); var handleOnFocus = (0, _usePlatformLeafEventHandler.usePlatformLeafEventHandler)(_objectSpread({ fn: function fn(event) { onFocus && onFocus(event); }, action: 'focused' }, analyticsParams)); var handleOnBlur = (0, _usePlatformLeafEventHandler.usePlatformLeafEventHandler)(_objectSpread({ fn: function fn(event) { onBlur && onBlur(event); }, action: 'blurred' }, analyticsParams)); var handleOnMouseDown = (0, _react.useCallback)(function (event) { // Running e.preventDefault() on the INPUT prevents double click behaviour // Sadly we needed this cast as the target type is being correctly set var target = event.target; if (target.tagName !== 'INPUT') { event.preventDefault(); } if (inputRef && inputRef.current && !isDisabled && document.activeElement !== inputRef.current) { inputRef.current.focus(); } onMouseDown && onMouseDown(event); }, [onMouseDown, isDisabled]); var setInputRef = (0, _react.useCallback)(function (inputElement) { inputRef.current = inputElement; if (!ref) { return; } if ((0, _typeof2.default)(ref) === 'object') { ref.current = inputElement; } if (typeof ref === 'function') { ref(inputElement); } }, [ref]); return /*#__PURE__*/_react.default.createElement("div", { role: "presentation", "data-disabled": isDisabled ? isDisabled : undefined, "data-invalid": isInvalid ? isInvalid : undefined, "data-ds--text-field--container": true, "data-testid": testId && "".concat(testId, "-container"), onMouseDown: handleOnMouseDown, style: { maxWidth: "".concat(getMaxWidth(width)) }, // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766 className: (0, _runtime.ax)(["_16jlkb7n _1o9zkb7n _i0dl1osq _11c8fhey _1reo15vq _18m915vq _v564r5cv _189ee4h9 _1e0c1txw _vchhusvi _4cvr1h6o _1bah1yb4 _lcxv1wug _s7n4jp4b _slp31hna _1tnq1qi0", getContainerTextBgAndBorderColor[appearance], containerStyleAppearance[appearance], !isDisabled && focusWithinStyle[appearance], !isDisabled && hoverStyle[appearance], isDisabled && containerMedia.disabled, isDisabled && disabledStyle[appearance], isInvalid && containerMedia.invalid, isInvalid && "_1h6d1bqt _4cvx1bqt _16qsizbr _1dbzizbr _uk1sr01l", className]) }, elemBeforeInput, /*#__PURE__*/_react.default.createElement("input", (0, _extends2.default)({}, spreadProps, { "aria-invalid": isInvalid ? isInvalid : undefined // TODO: When removing legacy theming fix this. , "data-compact": isCompact ? isCompact : undefined, "data-ds--text-field--input": true, "data-monospaced": isMonospaced ? isMonospaced : undefined, "data-testid": testId, disabled: isDisabled, name: name, onBlur: handleOnBlur, onChange: onChange, onFocus: handleOnFocus, placeholder: placeholder, readOnly: isReadOnly, ref: setInputRef, required: isRequired, className: (0, _runtime.ax)(["_19itidpf _11c81d4k _12ji1r31 _1qu2glyw _12y31o36 _vchhusvi _1bsb1osq _1ul9idpf _bfhk1j28 _syaz1kw7 _80om1kw7 _14ji12x7 _olc612x7 _1kod12x7 _7ba012x7 _1goxglyw _13xeglyw _1n7e1l2s _1idr1rpy _1tn2fhey _l9oiu2gc _549yu2gc _1h5w12x7 _124212x7", (0, _fg.fg)('platform-dst-tokens-finesse') && "_1idrazsu", isMonospaced && "_ect4zzfg _14mdzzfg", isCompact && "_11zpv77o _1l02v77o _daj712x7 _141f12x7 _1srd1b66 _oi9h1b66 _1e3012x7 _1txv12x7", isDisabled && "_syaz1gmx _1idr1gmx", isDisabled && "_1fnx18qt"]) })), elemAfterInput); }); var _default = exports.default = Textfield;