UNPKG

@primer/components

Version:
103 lines (87 loc) 5.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _classnames = _interopRequireDefault(require("classnames")); var _react = _interopRequireDefault(require("react")); var _styledComponents = _interopRequireWildcard(require("styled-components")); var _styledSystem = require("styled-system"); var _constants = require("./constants"); var _sx = _interopRequireDefault(require("./sx")); var _UnstyledTextInput = _interopRequireDefault(require("./_UnstyledTextInput")); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _extends() { _extends = Object.assign || 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); } const sizeVariants = (0, _styledSystem.variant)({ variants: { small: { minHeight: '28px', px: 2, py: '3px', fontSize: 0, lineHeight: '20px' }, large: { px: 2, py: '10px', fontSize: 3 } } }); const Wrapper = _styledComponents.default.span.withConfig({ displayName: "TextInput__Wrapper", componentId: "sc-1apmpmt-0" })(["display:inline-flex;align-items:stretch;min-height:34px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";", " .TextInput-icon{align-self:center;color:", ";margin:0 ", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", ";"], (0, _constants.get)('fontSizes.1'), (0, _constants.get)('colors.fg.default'), (0, _constants.get)('colors.border.default'), (0, _constants.get)('radii.2'), (0, _constants.get)('shadows.primer.shadow.inset'), props => { if (props.hasIcon) { return (0, _styledComponents.css)(["padding:0;"]); } else { return (0, _styledComponents.css)(["padding:6px 12px;"]); } }, (0, _constants.get)('colors.fg.muted'), (0, _constants.get)('space.2'), (0, _constants.get)('colors.accent.emphasis'), (0, _constants.get)('shadows.primer.shadow.focus'), props => props.contrast && (0, _styledComponents.css)(["background-color:", ";"], (0, _constants.get)('colors.canvas.inset')), props => props.disabled && (0, _styledComponents.css)(["color:", ";background-color:", ";border-color:", ";"], (0, _constants.get)('colors.fg.muted'), (0, _constants.get)('colors.input.disabledBg'), (0, _constants.get)('colors.border.default')), props => props.block && (0, _styledComponents.css)(["display:block;width:100%;"]), (0, _constants.get)('breakpoints.1'), (0, _constants.get)('fontSizes.1'), _styledSystem.width, _styledSystem.minWidth, _styledSystem.maxWidth, sizeVariants, _sx.default); // using forwardRef is important so that other components (ex. SelectMenu) can autofocus the input const TextInput = /*#__PURE__*/_react.default.forwardRef(({ inputComponent: InputComponent, icon: IconComponent, block, className, contrast, disabled, sx: sxProp, theme, width: widthProp, minWidth: minWidthProp, maxWidth: maxWidthProp, variant: variantProp, wrapperRef, ...inputProps }, ref) => { // this class is necessary to style FilterSearch, plz no touchy! const wrapperClasses = (0, _classnames.default)(className, 'TextInput-wrapper'); return /*#__PURE__*/_react.default.createElement(Wrapper, { block: block, className: wrapperClasses, contrast: contrast, disabled: disabled, hasIcon: !!IconComponent, sx: sxProp, theme: theme, width: widthProp, minWidth: minWidthProp, maxWidth: maxWidthProp, variant: variantProp, ref: wrapperRef }, IconComponent && /*#__PURE__*/_react.default.createElement(IconComponent, { className: "TextInput-icon" }), /*#__PURE__*/_react.default.createElement(_UnstyledTextInput.default, _extends({ ref: ref, disabled: disabled }, inputProps))); }); TextInput.defaultProps = { type: 'text' }; TextInput.displayName = 'TextInput'; var _default = TextInput; exports.default = _default;