chayns-components
Version:
A set of beautiful React components for developing chayns® applications.
124 lines (120 loc) • 4.74 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireWildcard(require("react"));
var _isInIframeDialog = _interopRequireDefault(require("../utils/isInIframeDialog"));
var _DialogSelectComboBox = _interopRequireDefault(require("./DialogSelectComboBox"));
var _HTMLSelectComboBox = _interopRequireDefault(require("./HTMLSelectComboBox"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**
* @component
*/
/**
* A button with a dropdown that contains a scrollable list of distinct values
* from which people can choose.
*/
const ComboBox = _ref => {
let {
className,
label,
list,
disabled = false,
listValue,
listKey,
stopPropagation = false,
defaultValue,
parent,
onSelect,
style,
value
} = _ref;
const iframeDialogView = (0, _react.useMemo)(_isInIframeDialog.default, []);
return iframeDialogView ? /*#__PURE__*/_react.default.createElement(_HTMLSelectComboBox.default, {
className: className,
label: label,
list: list,
disabled: disabled,
listValue: listValue,
listKey: listKey,
stopPropagation: stopPropagation,
defaultValue: defaultValue,
value: value,
onSelect: onSelect
}) : /*#__PURE__*/_react.default.createElement(_DialogSelectComboBox.default, {
className: className,
label: label,
list: list,
disabled: disabled,
listValue: listValue,
listKey: listKey,
stopPropagation: stopPropagation,
defaultValue: defaultValue,
parent: parent,
onSelect: onSelect,
style: style,
value: value
});
};
var _default = ComboBox;
exports.default = _default;
ComboBox.propTypes = {
/**
* This callback is called when an item is selected.
*/
onSelect: _propTypes.default.func,
/**
* Disables any interactions and styles the combobox with a disabled style.
*/
disabled: _propTypes.default.bool,
/**
* A placeholder value shown inside the combobox.
*/
label: _propTypes.default.string,
/**
* An array of values to select from.
*/
list: _propTypes.default.array.isRequired,
// eslint-disable-line react/forbid-prop-types
/**
* The name of the property on the list objects that uniquely identifies an
* item.
*/
listKey: _propTypes.default.string.isRequired,
/**
* The name of the property on the list objects that is shown as its name.
*/
listValue: _propTypes.default.string.isRequired,
/**
* A classname string that will be applied to the Button component and the
* overlay.
*/
className: _propTypes.default.string,
/**
* The default value of the combobox. This does not work in combination with
* the `label` or `value` props.
*/
defaultValue: _propTypes.default.string,
/**
* Wether to stop the propagation of click events.
*/
stopPropagation: _propTypes.default.bool,
/**
* The parent component of the combobox overlay.
*/
parent: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node]),
/**
* A React style object that will be applied to the Button component and the
* overlay.
*/
style: _propTypes.default.objectOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])),
/**
* The value of the combobox. This does not work in combination with the `
* label`-prop.
*/
value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
};
ComboBox.displayName = 'ComboBox';
//# sourceMappingURL=ComboBox.js.map