cspace-ui
Version:
CollectionSpace user interface for browsers
102 lines (78 loc) • 4.7 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 _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _extends() { _extends = Object.assign || 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); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
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 = _objectSpread({}, BaseOptionPickerInput.propTypes, {
config: _propTypes.default.object,
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 {
message,
value
} = option;
const {
intl
} = this.props;
return message ? intl.formatMessage(message) : value;
}
formatStatusMessage(count) {
const {
intl
} = this.props;
return intl.formatMessage(messages.count, {
count
});
}
render() {
const _this$props = this.props,
{
config,
/* eslint-disable no-unused-vars */
intl
} = _this$props,
remainingProps = _objectWithoutProperties(_this$props, ["config", "intl"]);
return _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 = IntlAwareOptionPickerInput;
exports.default = _default;