cspace-ui
Version:
CollectionSpace user interface for browsers
85 lines (83 loc) • 3.61 kB
JavaScript
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(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, 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;
;