UNPKG

chayns-components

Version:

A set of beautiful React components for developing chayns® applications.

209 lines (202 loc) 7.27 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.default = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _propTypes = _interopRequireDefault(require("prop-types")); var _react = _interopRequireWildcard(require("react")); var _PersonsContext = _interopRequireDefault(require("./data/persons/PersonsContext")); var _MultiplePersonFinder = _interopRequireDefault(require("./MultiplePersonFinder")); var _SimplePersonFinder = _interopRequireDefault(require("./SimplePersonFinder")); 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 {./docs.md} */ /** * An autocomplete search for persons that can be customized to work with * arbitrary data. */ class PersonFinder extends _react.Component { constructor() { super(...arguments); this.personFinder = /*#__PURE__*/_react.default.createRef(); this.clear = () => { if (this.personFinder.current) { this.personFinder.current.clear(); } }; } render() { const { multiple, showPersons, showSites } = this.props; const PersonFinderComponent = multiple ? _MultiplePersonFinder.default : _SimplePersonFinder.default; return /*#__PURE__*/_react.default.createElement(PersonFinderComponent, (0, _extends2.default)({ ref: this.personFinder }, this.props, { autoLoading: !showPersons || !showSites })); } } PersonFinder.propTypes = { /** * The placeholder to show when the input field is empty. */ placeholder: _propTypes.default.string, /** * Wether the `PersonFinder` should allow multiple persons or sites to be * put in. */ multiple: _propTypes.default.bool, /** * Wether the `PersonFinder` should show persons in its autocomplete window. */ showPersons: _propTypes.default.bool, /** * Wether the `PersonFinder` should show sites in its autocomplete window. */ showSites: _propTypes.default.bool, /** * Whether the `PersonFinder` should show uac groups of the current site */ showUacGroups: _propTypes.default.bool, /** * Whether the `PersonFinder` should show known users of the current site */ showKnownPersons: _propTypes.default.bool, /** * The id of a UAC group to search persons in. */ uacId: _propTypes.default.number, /** * A function to reduce the results. */ reducerFunction: _propTypes.default.func, /** * The context of the PersonFinder. Take a look at the * [Custom Finder](#custom-finder) paragraph. */ context: _propTypes.default.shape({ Provider: _propTypes.default.func, // eslint-disable-next-line react/forbid-prop-types Consumer: _propTypes.default.object }), /** * This callback is invoked when a person is selected, removed or the * `PersonFinder` is cleared. */ onChange: _propTypes.default.func, /** * Wether the display of friends with an empty input should be disabled. */ disableFriends: _propTypes.default.bool, /** * A classname string that will be applied to the wrapper `<div>`-element. */ className: _propTypes.default.string, /** * The default value of the input field. Can be a string or a * person/location specified with an object. */ defaultValue: _propTypes.default.oneOfType([_propTypes.default.shape({ name: _propTypes.default.string, firstName: _propTypes.default.string, lastName: _propTypes.default.string, siteId: _propTypes.default.string, personId: _propTypes.default.string }), _propTypes.default.string]), /** * The default values of the input field if `multiple` is `true`. Can be * strings or an array of persons/locations specified with an object. */ defaultValues: _propTypes.default.arrayOf(_propTypes.default.shape({ name: _propTypes.default.string, firstName: _propTypes.default.string, lastName: _propTypes.default.string, siteId: _propTypes.default.string, personId: _propTypes.default.string })), /** * A callback that is invoked when a person is added to the `PersonFinder`. * Only works when `multiple` is `true` */ onAdd: _propTypes.default.func, /** * A callback that is invoked when a person is removed from the * `PersonFinder`. Only works when `multiple` is `true` */ onRemove: _propTypes.default.func, /** * The `onInput`-callback for the `<input>` element of the `PersonFinder`. */ onInput: _propTypes.default.func, /** * Props for the context. */ contextProps: _propTypes.default.object, // eslint-disable-line react/forbid-prop-types /** * The maximum amount of people selected at once. Only has an effect when * `multiple` is `true`. */ max: _propTypes.default.number, /** * The currently selected values when `multiple` is `true`. */ values: _propTypes.default.array, // eslint-disable-line react/forbid-prop-types /** * The value for the */ value: _propTypes.default.string, /** * Adds a small chevron icon to show / hide the results */ hasOpenCloseIcon: _propTypes.default.bool, /** * Removes already selected entries from search results */ filterSelected: _propTypes.default.bool, /** * Hides the extra icon for verified accounts */ hideVerifiedIcon: _propTypes.default.bool, /** * Minimum number of letters before the result overlay is displayed */ minCharCount: _propTypes.default.number }; PersonFinder.defaultProps = { placeholder: '', multiple: false, showPersons: true, disableFriends: false, className: null, showSites: false, showUacGroups: false, showKnownPersons: false, uacId: null, reducerFunction: null, context: _PersonsContext.default, onChange: null, defaultValue: null, defaultValues: [], onAdd: null, onRemove: null, onInput: null, contextProps: null, max: null, values: null, value: null, hasOpenCloseIcon: false, filterSelected: false, hideVerifiedIcon: false, minCharCount: null }; PersonFinder.displayName = 'PersonFinder'; var _default = PersonFinder; exports.default = _default; //# sourceMappingURL=PersonFinder.js.map