UNPKG

@navinc/base-react-components

Version:
75 lines (71 loc) 4.21 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const styled_components_1 = __importDefault(require("styled-components")); const shared_js_1 = require("./form-elements/shared.js"); const target_vendor_js_1 = require("./helpers/target-vendor.js"); const copy_1 = __importDefault(require("./copy")); const StyledFieldWrapper = (0, styled_components_1.default)(shared_js_1.FieldWrapper) ` & > ${copy_1.default} { margin-left: 18px; } `; const SelectField = (0, styled_components_1.default)(shared_js_1.Input).attrs(() => ({ as: 'select' })) ` width: 100%; appearance: none; color: inherit; cursor: pointer; border-radius: 20px; font-size: 16px; padding: 8px 16px; outline: 0; background: ${({ isInvalid, theme }) => (isInvalid ? theme.sebastianRed100 : theme.transparentWhite)}; border: 2px solid ${({ isInvalid, theme }) => (isInvalid ? theme.sebastianRed200 : theme.bubbleBlue500)}; ${({ disabled, theme }) => disabled && ` color: ${theme.scuttleGray500}; border-color: ${theme.scuttleGray200}; background: ${theme.scuttleGray100}; cursor: not-allowed `}; &:focus { background: ${({ theme }) => theme.bubbleBlue100}; } ${(0, target_vendor_js_1.moz) ` // Selects in firefox have extra, unstylable, 3px of whitespace around the text. padding-left: 10px; // Focusable elements in firefox have a focus ring around sub-elements. &:-moz-focusring { color: transparent; text-shadow:0 0 0 ${({ theme }) => theme.neutral500}; } &:-moz-focusring * { color: ${({ theme }) => theme.neutral500}; text-shadow:none; } `} `; const defaultValue = { label: '...', value: '' }; const SelectPill = (_a) => { var { className, disabled, errors = [], hasSpaceForErrors, helperText, isInvalid, label, onChange, options = [], required, value = defaultValue } = _a, props = __rest(_a, ["className", "disabled", "errors", "hasSpaceForErrors", "helperText", "isInvalid", "label", "onChange", "options", "required", "value"]); return ((0, jsx_runtime_1.jsxs)(StyledFieldWrapper, Object.assign({ className: className }, { children: [label && ((0, jsx_runtime_1.jsx)(copy_1.default, Object.assign({ light: true, size: "sm" }, { children: label }), void 0)), (0, jsx_runtime_1.jsxs)(shared_js_1.Field, Object.assign({ isInvalid: isInvalid, required: required }, { children: [(0, jsx_runtime_1.jsx)(SelectField, Object.assign({ disabled: disabled, isInvalid: isInvalid, onChange: onChange, required: required, value: value }, props, { children: [defaultValue, ...options].map((option) => { const { label = option, value = option } = option; return ((0, jsx_runtime_1.jsx)("option", Object.assign({ value: value, hidden: !value }, { children: label }), `${label}:${value}`)); }) }), void 0), (0, jsx_runtime_1.jsx)(shared_js_1.Chevron, { name: "actions/carrot-down", disabled: disabled, isInvalid: isInvalid }, void 0)] }), void 0), helperText && (0, jsx_runtime_1.jsx)(shared_js_1.Helper, { hasSpaceForHelper: hasSpaceForErrors, helperText: helperText }, void 0), (0, jsx_runtime_1.jsx)(shared_js_1.Errors, Object.assign({ hasSpaceForErrors: hasSpaceForErrors }, { children: !!errors.length && errors.map((err, i) => (0, jsx_runtime_1.jsx)(shared_js_1.Err, { children: err }, `err-${i}`)) }), void 0)] }), void 0)); }; exports.default = (0, styled_components_1.default)(SelectPill) ``; //# sourceMappingURL=select-pill.js.map