UNPKG

@catho/quantum

Version:
97 lines (96 loc) 7.38 kB
"use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _propTypes = _interopRequireDefault(require("prop-types")); var _styledComponents = _interopRequireWildcard(require("styled-components")); var _theme = require("../../shared/theme"); var _shared = require("../../shared"); var _excluded = ["theme"]; function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } 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) { _defineProperty(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; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; } var defaultSkin = function defaultSkin(_ref) { var theme = _ref.theme, error = _ref.error, hasDefaultValue = _ref.hasDefaultValue; var _theme$colors = theme.colors, _theme$colors$primary = _theme$colors.primary, primary100 = _theme$colors$primary[100], primary700 = _theme$colors$primary[700], _theme$colors$error = _theme$colors.error, error100 = _theme$colors$error[100], error700 = _theme$colors$error[700], _theme$colors$neutral = _theme$colors.neutral, neutral0 = _theme$colors$neutral[0], neutral100 = _theme$colors$neutral[100], neutral500 = _theme$colors$neutral[500], neutral700 = _theme$colors$neutral[700]; var mainColor = error ? error700 : primary700; return (0, _styledComponents.css)(["background-color:", ";border:2px solid ", ";color:", ";", " ", " &:hover,&:focus{border-color:", ";", "}&[disabled]{background-color:", ";border-color:", ";color:", ";}:-webkit-autofill{box-shadow:0 0 0 1000px ", " inset;}"], neutral0, neutral500, neutral700, error ? "border-color: ".concat(mainColor, ";") : '', hasDefaultValue ? "background-color: ".concat(primary100, ";") : '', mainColor, (0, _shared.shadow)(2, mainColor)({ theme: theme }), neutral100, neutral500, neutral500, error100); }; var darkSkin = function darkSkin(_ref2) { var theme = _ref2.theme, error = _ref2.error; var _theme$colors2 = theme.colors, primary = _theme$colors2.primary, neutral = _theme$colors2.neutral; return (0, _styledComponents.css)(["background-color:", ";border:2px solid transparent;color:", ";&::placeholder{color:", ";}", " &:hover,&:focus{border-color:", ";}&[disabled]{color:", ";border-color:transparent;}"], (0, _shared.hexToRgba)(neutral[1000], 0.7), neutral[0], neutral[0], error ? (0, _styledComponents.css)(["border-color:", ";"], neutral[0]) : '', primary[500], (0, _shared.hexToRgba)(neutral[0], 0.5)); }; var textInputSkinVariations = { "default": defaultSkin, dark: darkSkin }; var TextInput = _styledComponents["default"].input.attrs(function (_ref3) { var theme = _ref3.theme, rest = _objectWithoutProperties(_ref3, _excluded); return _objectSpread({ theme: _objectSpread({ spacing: _theme.spacing, colors: _theme.colors }, theme), skin: 'default' }, rest); }).withConfig({ displayName: "TextInput", componentId: "sc-ado1el-0" })(["-webkit-appearance:none;border-radius:4px;box-sizing:border-box;box-sizing:border-box;font-size:initial;letter-spacing:0.2px;outline:none;transition:all 0.2s ease-in-out;width:100%;&::-webkit-inner-spin-button,&::-webkit-outer-spin-button{-webkit-appearance:none;margin:0;}&::-webkit-calendar-picker-indicator,&::-webkit-search-cancel-button{display:none;}&::-ms-clear{display:none;}", ""], function (_ref4) { var hasDefaultValue = _ref4.hasDefaultValue, hasLabel = _ref4.hasLabel, error = _ref4.error, hasRightIcon = _ref4.hasRightIcon, hasLeftIcon = _ref4.hasLeftIcon, theme = _ref4.theme, skin = _ref4.skin; var _theme$spacing = theme.spacing, xsmall = _theme$spacing.xsmall, medium = _theme$spacing.medium, large = _theme$spacing.large; var iconSize = large; var horizontalPadding = medium + iconSize + xsmall; return (0, _styledComponents.css)(["margin-top:", "px;padding:", "px ", "px;", " ", " ", " &[disabled]{box-shadow:none;cursor:not-allowed;}"], hasLabel ? xsmall : '0', xsmall, medium, hasRightIcon ? "padding-right: ".concat(horizontalPadding, "px;") : '', hasLeftIcon ? "padding-left: ".concat(horizontalPadding, "px;") : '', textInputSkinVariations[skin]({ theme: theme, error: error, hasDefaultValue: hasDefaultValue })); }); TextInput.displayName = 'TextInput'; TextInput.propTypes = { theme: _propTypes["default"].shape({ spacing: _propTypes["default"].object, colors: _propTypes["default"].object }), skin: _propTypes["default"].oneOf(['default', 'dark']) }; var _default = exports["default"] = TextInput;