@atlaskit/select
Version:
Select allows users to make a single selection or multiple selections from a list of options.
77 lines (71 loc) • 2.44 kB
JavaScript
/* country-select.tsx generated by @compiled/babel-plugin v3.0.2 */
import _extends from "@babel/runtime/helpers/extends";
import "./country-select.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { groupedCountries } from './data/countries';
import Select from './select';
// custom option renderer
var labelStyles = null;
var flagStyles = null;
var Opt = function Opt(_ref) {
var children = _ref.children,
icon = _ref.icon;
return /*#__PURE__*/React.createElement("div", {
className: ax(["_1e0c1txw _4cvr1h6o _vwz4cjiy"])
}, /*#__PURE__*/React.createElement("span", {
"aria-hidden": "true",
className: ax(["_1wyb1cby _12l2u2gc"])
}, icon), children);
};
// return the country name; used for searching
var getOptionLabel = function getOptionLabel(_ref2) {
var abbr = _ref2.abbr,
code = _ref2.code,
name = _ref2.name;
return "".concat(name, " (").concat(abbr.toUpperCase(), ") +").concat(code);
};
// set the country's abbreviation for the option value, (also searchable)
var getOptionValue = function getOptionValue(opt) {
return opt.abbr;
};
// the text node of the control
var controlLabel = function controlLabel(opt) {
return /*#__PURE__*/React.createElement(Opt, {
icon: opt.icon
}, opt.abbr.toUpperCase());
};
// the text node for an option
var optionLabel = function optionLabel(_ref3) {
var abbr = _ref3.abbr,
code = _ref3.code,
icon = _ref3.icon,
name = _ref3.name;
return /*#__PURE__*/React.createElement(Opt, {
icon: icon
}, getOptionLabel({
abbr: abbr,
code: code,
name: name
}));
};
// switch formatters based on render context (menu | value)
var formatOptionLabel = function formatOptionLabel(opt, _ref4) {
var context = _ref4.context;
return context === 'value' ? controlLabel(opt) : optionLabel(opt);
};
// put it all together
export var CountrySelect = function CountrySelect(props) {
var options = props.options;
var countryOptions = options || groupedCountries;
return /*#__PURE__*/React.createElement(Select, _extends({
isClearable: false,
formatOptionLabel: formatOptionLabel,
getOptionLabel: getOptionLabel,
getOptionValue: getOptionValue,
isMulti: false,
options: countryOptions
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
}, props));
};
// eslint-disable-next-line @repo/internal/react/require-jsdoc