UNPKG

@navinc/base-react-components

Version:
71 lines (70 loc) 4.32 kB
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; }; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { styled } from 'styled-components'; import { Copy } from './copy.js'; import { moz } from './helpers/target-vendor.js'; import { Chevron, Label, Input, Field, Errors, Err, FieldWrapper, Helper } from './form-elements/shared.js'; import { redactProps } from './redact/redact.js'; const StyledBg = styled(Input).attrs(() => ({ as: 'div' })).withConfig({ displayName: "brc-sc-StyledBg", componentId: "brc-sc-tdh75l" }) ` position: absolute; inset: 0; width: auto; `; const SelectField = styled(Input).attrs(() => ({ as: 'select' })).withConfig({ displayName: "brc-sc-SelectField", componentId: "brc-sc-11bksnw" }) ` width: 100%; appearance: none; color: inherit; cursor: pointer; font-size: 16px; padding-right: 3em; outline: 0; z-index: 1; background: transparent; border-color: transparent; ${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 (_jsxs(FieldWrapper, { className: className, children: [lede && (_jsx(Copy, { bold: true, className: "select-lede", children: lede })), _jsxs(Field, { isVisited: true, children: [_jsx(StyledBg, { isInvalid: isInvalid }), _jsx(Chevron, { isInvalid: isInvalid, className: "select-chevron" }), _jsxs(SelectField, Object.assign({ onChange: onChange, required: required, value: value, isInvalid: isInvalid }, (isPrivate && redactProps), props, { children: [placeholder && (_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 (_jsx("option", { value: value, disabled: disabled, hidden: !value, children: label }, `${label}:${value}`)); })] })), label && (_jsx(Label, { required: required, className: "select-label", children: label }))] }), helperText && _jsx(Helper, { helperText: helperText, className: "select-helper-text" }), _jsx(Errors, { hasSpaceForErrors: hasSpaceForErrors, hasHelperText: !!helperText, className: "select-errors", children: !!errors.length && errors.map((err, i) => (_jsx(Err, { className: "select-error-text", children: err }, `err-${i}`))) })] })); }; _Select.displayName = 'Select'; /** * @deprecated This component is deprecated and will be removed in a future release. Avoid using it in new code. */ export const Select = styled(_Select).withConfig({ displayName: "brc-sc-Select", componentId: "brc-sc-1qxmfbm" }) ``; //# sourceMappingURL=select.js.map