UNPKG

@navinc/base-react-components

Version:
56 lines (55 loc) 3.46 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 isRebrand from './is-rebrand.js'; const SelectField = styled(Input).attrs(() => ({ as: 'select' })).withConfig({ displayName: "brc-sc-SelectField", componentId: "brc-sc-1akz4kx" }) ` width: 100%; appearance: none; color: inherit; cursor: pointer; font-size: 16px; padding-right: 3em; outline: 0; ${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 }) => (isRebrand(theme) ? theme.navNeutral500 : theme.neutral500)}; } &:-moz-focusring * { color: ${({ theme }) => (isRebrand(theme) ? theme.navNeutral500 : theme.neutral500)}; 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: '' }; const Select = (_a) => { var { className, label, hasSpaceForErrors, helperText, isInvalid, options = [], value = defaultValue, required, errors = [], lede = '', onChange = (event) => event.target.value } = _a, props = __rest(_a, ["className", "label", "hasSpaceForErrors", "helperText", "isInvalid", "options", "value", "required", "errors", "lede", "onChange"]); return (_jsxs(FieldWrapper, Object.assign({ className: className }, { children: [lede && _jsx(Copy, Object.assign({ bold: true }, { children: lede })), _jsxs(Field, Object.assign({ isInvalid: isInvalid, isVisited: true, required: required }, { children: [_jsx(Chevron, { isInvalid: isInvalid }), _jsx(SelectField, Object.assign({ onChange: onChange, required: required, value: value, isInvalid: isInvalid }, props, { children: [defaultValue, ...options].map((option) => { const { label = option.label || option, value = option.value || option } = option; return (_jsx("option", Object.assign({ value: value, hidden: !value }, { children: label }), `${label}:${value}`)); }) })), _jsx(Label, Object.assign({ required: required, value: value }, { children: label }))] })), helperText && _jsx(Helper, { hasSpaceForHelper: hasSpaceForErrors, helperText: helperText }), _jsx(Errors, Object.assign({ hasSpaceForErrors: hasSpaceForErrors }, { children: !!errors.length && errors.map((err, i) => _jsx(Err, { children: err }, `err-${i}`)) }))] }))); }; Select.displayName = 'Select'; export default styled(Select).withConfig({ componentId: "brc-sc-8epnvq" }) ``; //# sourceMappingURL=select.js.map