UNPKG

@navinc/base-react-components

Version:
73 lines (72 loc) 4.87 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 }); exports.Select = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const styled_components_1 = __importDefault(require("styled-components")); const copy_js_1 = require("./copy.js"); const target_vendor_js_1 = require("./helpers/target-vendor.js"); const shared_js_1 = require("./form-elements/shared.js"); const StyledBg = (0, styled_components_1.default)(shared_js_1.Input).attrs(() => ({ as: 'div' })).withConfig({ displayName: "brc-sc-StyledBg", componentId: "brc-sc-zg5871" }) ` position: absolute; inset: 0; width: auto; `; const SelectField = (0, styled_components_1.default)(shared_js_1.Input).attrs(() => ({ as: 'select' })).withConfig({ displayName: "brc-sc-SelectField", componentId: "brc-sc-1lum0x0" }) ` width: 100%; appearance: none; color: inherit; cursor: pointer; font-size: 16px; padding-right: 3em; outline: 0; z-index: 1; background: transparent; border-color: transparent; ${(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.navNeutral500}; } &:-moz-focusring * { color: ${({ theme }) => theme.navNeutral500}; text-shadow:none; } `} & > * { /** for firefox. also note that you cant style for safari **/ font-family: ${({ theme }) => theme.fontPrimary}; font-weight: normal; } `; const defaultValue = { label: '...', value: '', disabled: false }; const isOptionObject = (option) => typeof option === 'object'; const _Select = (_a) => { var { className, label, hasSpaceForErrors, helperText, isInvalid, options = [], value = defaultValue.value, required, errors = [], lede = '', onChange = (event) => event.target.value, placeholder, isPrivate } = _a, props = __rest(_a, ["className", "label", "hasSpaceForErrors", "helperText", "isInvalid", "options", "value", "required", "errors", "lede", "onChange", "placeholder", "isPrivate"]); return ((0, jsx_runtime_1.jsxs)(shared_js_1.FieldWrapper, { className: className, children: [lede && ((0, jsx_runtime_1.jsx)(copy_js_1.Copy, { bold: true, className: "select-lede", children: lede })), (0, jsx_runtime_1.jsxs)(shared_js_1.Field, { isVisited: true, children: [(0, jsx_runtime_1.jsx)(StyledBg, { isInvalid: isInvalid }), (0, jsx_runtime_1.jsx)(shared_js_1.Chevron, { isInvalid: isInvalid, className: "select-chevron" }), (0, jsx_runtime_1.jsxs)(SelectField, Object.assign({ onChange: onChange, required: required, value: value, isInvalid: isInvalid }, (isPrivate && { className: 'js-private', 'data-heap-redact-text': 'true' }), props, { children: [placeholder && ((0, jsx_runtime_1.jsx)("option", { value: "", disabled: true, selected: true, hidden: true, children: placeholder })), [defaultValue, ...options].map((option) => { const { label, value, disabled } = isOptionObject(option) ? option : { label: option, value: option, disabled: false }; return ((0, jsx_runtime_1.jsx)("option", { value: value, disabled: disabled, hidden: !value, children: label }, `${label}:${value}`)); })] })), label && ((0, jsx_runtime_1.jsx)(shared_js_1.Label, { required: required, className: "select-label", children: label }))] }), helperText && ((0, jsx_runtime_1.jsx)(shared_js_1.Helper, { hasSpaceForHelper: hasSpaceForErrors, helperText: helperText, className: "select-helper-text" })), (0, jsx_runtime_1.jsx)(shared_js_1.Errors, { hasSpaceForErrors: hasSpaceForErrors, className: "select-errors", children: !!errors.length && errors.map((err, i) => ((0, jsx_runtime_1.jsx)(shared_js_1.Err, { className: "select-error-text", children: err }, `err-${i}`))) })] })); }; _Select.displayName = 'Select'; exports.Select = (0, styled_components_1.default)(_Select).withConfig({ displayName: "brc-sc-Select", componentId: "brc-sc-1w0zmq3" }) ``; //# sourceMappingURL=select.js.map