UNPKG

cspace-ui

Version:
84 lines (82 loc) 3.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _reactIntl = require("react-intl"); var _cspaceInput = require("cspace-input"); var _withConfig = _interopRequireDefault(require("../../enhancers/withConfig")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } const { OptionPickerInput: BaseOptionPickerInput } = _cspaceInput.components; const messages = (0, _reactIntl.defineMessages)({ count: { "id": "optionPickerInput.count", "defaultMessage": "{count, plural, =0 {No matching options} one {# matching option} other {# matching options}} found" } }); const propTypes = { // eslint-disable-next-line react/forbid-foreign-prop-types ...BaseOptionPickerInput.propTypes, config: _propTypes.default.shape({ defaultDropdownFilter: _propTypes.default.string }), intl: _reactIntl.intlShape }; /** * A wrapper around OptionPickerInput from cspace-input that applies default props from config, and * supplies i18n. */ class OptionPickerInput extends _react.Component { constructor() { super(); this.formatOptionLabel = this.formatOptionLabel.bind(this); this.formatStatusMessage = this.formatStatusMessage.bind(this); } formatOptionLabel(option) { const { labelFormatter, message, value } = option; const { intl } = this.props; if (labelFormatter) { return labelFormatter(intl, option); } if (message) { return intl.formatMessage(message); } return value; } formatStatusMessage(count) { const { intl } = this.props; return intl.formatMessage(messages.count, { count }); } render() { const { config, intl, ...remainingProps } = this.props; return /*#__PURE__*/_react.default.createElement(BaseOptionPickerInput, _extends({ filter: config.defaultDropdownFilter, formatOptionLabel: this.formatOptionLabel, formatStatusMessage: this.formatStatusMessage }, remainingProps)); } } OptionPickerInput.propTypes = propTypes; const IntlAwareOptionPickerInput = (0, _reactIntl.injectIntl)((0, _withConfig.default)(OptionPickerInput)); IntlAwareOptionPickerInput.propTypes = OptionPickerInput.propTypes; var _default = exports.default = IntlAwareOptionPickerInput;