UNPKG

@atlaskit/textfield

Version:

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

168 lines (164 loc) 6.51 kB
/* text-field.tsx generated by @compiled/babel-plugin v3.0.2 */ import _extends from "@babel/runtime/helpers/extends"; import "./text-field.compiled.css"; import { ax, ix } from "@compiled/react/runtime"; import React, { forwardRef, useCallback, useRef } from 'react'; import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next/usePlatformLeafEventHandler'; import { fg } from '@atlaskit/platform-feature-flags/fg'; const containerMedia = { invalid: "_msj6gir2", disabled: "_6up518qt" }; const inputMediaDisabled = null; const analyticsParams = { componentName: 'textField', packageName: "@atlaskit/textfield", packageVersion: "10.2.3" }; const disabledStyle = { standard: "_1h6d187o _bfhk187o _syaz1gmx _80om13gf", subtle: "_1h6d1j28 _bfhk1j28 _syaz1gmx _80om13gf", none: "_1h6d1j28 _bfhk1j28 _syaz1gmx _80om13gf" }; const invalidStyle = null; const focusWithinStyle = { standard: "_1p9x1v1w _qao9r01l _q433vyy1", subtle: "_1p9x1v1w _qao9r01l _q433vyy1", none: "_1p9x1j28 _qao91j28 _q4333sij" }; const hoverStyle = { standard: "_4cvxrsbi _irr3l4ek", subtle: "_4cvxrsbi _irr3l4ek", none: "_4cvx1j28 _irr31j28" }; const getContainerTextBgAndBorderColor = { standard: "_1h6drsbi _1dqonqa1 _syazi7uo _80om1kdv _bfhk1j9a _msj6gir2", subtle: "_1h6d1j28 _1dqonqa1 _syazi7uo _80om1kdv _16hg1j28 _msj6gir2", none: "_1h6d1j28 _1dqoglyw _syazi7uo _80om1kdv _16hg1j28 _msj6gir2" }; const widthMap = { xsmall: 80, small: 160, medium: 240, large: 320, xlarge: 480 }; const getMaxWidth = width => !width ? `100%` : width in widthMap ? `${widthMap[width]}px` : `${+width}px`; const containerStyleAppearance = { standard: "_1dqonqa1 _1q51e4h9 _85i5e4h9 _bozgidpf _y4tiidpf", subtle: "_1dqonqa1 _1q51e4h9 _85i5e4h9 _bozgidpf _y4tiidpf", none: "_1dqoglyw" }; const containerStyles = null; const inputDisabledStyle = null; const inputCompactStyle = null; const 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 const inputStyle = null; const 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) */ const Textfield = /*#__PURE__*/forwardRef((props, ref) => { const { appearance = 'standard', className, elemAfterInput, elemBeforeInput, isCompact = false, isDisabled = false, isInvalid = false, isMonospaced = false, isReadOnly = false, isRequired = false, name, onBlur, onChange, onFocus, onMouseDown, placeholder, testId, width, ...spreadProps } = props; const inputRef = useRef(null); const handleOnFocus = usePlatformLeafEventHandler({ fn: event => { onFocus && onFocus(event); }, action: 'focused', ...analyticsParams }); const handleOnBlur = usePlatformLeafEventHandler({ fn: event => { onBlur && onBlur(event); }, action: 'blurred', ...analyticsParams }); const handleOnMouseDown = useCallback(event => { // Running e.preventDefault() on the INPUT prevents double click behaviour // Sadly we needed this cast as the target type is being correctly set const 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]); const setInputRef = useCallback(inputElement => { inputRef.current = inputElement; if (!ref) { return; } if (typeof ref === 'object') { ref.current = inputElement; } if (typeof ref === 'function') { ref(inputElement); } }, [ref]); return /*#__PURE__*/React.createElement("div", { role: "presentation", "data-disabled": isDisabled ? isDisabled : undefined, "data-invalid": isInvalid ? isInvalid : undefined, "data-ds--text-field--container": true, "data-testid": testId && `${testId}-container`, onMouseDown: handleOnMouseDown, style: { maxWidth: `${getMaxWidth(width)}` }, // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766 className: 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.createElement("input", _extends({}, 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: 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", fg('platform-dst-tokens-finesse') && "_1idrazsu", isMonospaced && "_ect4zzfg _14mdzzfg", isCompact && "_11zpv77o _1l02v77o _daj712x7 _141f12x7 _1srd1b66 _oi9h1b66 _1e3012x7 _1txv12x7", isDisabled && "_syaz1gmx _1idr1gmx", isDisabled && "_1fnx18qt"]) })), elemAfterInput); }); export default Textfield;