Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.uncontrolledPropTypes = uncontrolledPropTypes;
  5. exports.isProp = isProp;
  6. exports.defaultKey = defaultKey;
  7. exports.canAcceptRef = canAcceptRef;
  8. var _invariant = _interopRequireDefault(require("invariant"));
  9. var noop = function noop() {};
  10. function readOnlyPropType(handler, name) {
  11. return function (props, propName) {
  12. if (props[propName] !== undefined) {
  13. if (!props[handler]) {
  14. return new Error("You have provided a `" + propName + "` prop to `" + name + "` " + ("without an `" + handler + "` handler prop. This will render a read-only field. ") + ("If the field should be mutable use `" + defaultKey(propName) + "`. ") + ("Otherwise, set `" + handler + "`."));
  15. }
  16. }
  17. };
  18. }
  19. function uncontrolledPropTypes(controlledValues, displayName) {
  20. var propTypes = {};
  21. Object.keys(controlledValues).forEach(function (prop) {
  22. // add default propTypes for folks that use runtime checks
  23. propTypes[defaultKey(prop)] = noop;
  24. if (process.env.NODE_ENV !== 'production') {
  25. var handler = controlledValues[prop];
  26. !(typeof handler === 'string' && handler.trim().length) ? process.env.NODE_ENV !== "production" ? (0, _invariant.default)(false, 'Uncontrollable - [%s]: the prop `%s` needs a valid handler key name in order to make it uncontrollable', displayName, prop) : invariant(false) : void 0;
  27. propTypes[prop] = readOnlyPropType(handler, displayName);
  28. }
  29. });
  30. return propTypes;
  31. }
  32. function isProp(props, prop) {
  33. return props[prop] !== undefined;
  34. }
  35. function defaultKey(key) {
  36. return 'default' + key.charAt(0).toUpperCase() + key.substr(1);
  37. }
  38. /**
  39. * Copyright (c) 2013-present, Facebook, Inc.
  40. * All rights reserved.
  41. *
  42. * This source code is licensed under the BSD-style license found in the
  43. * LICENSE file in the root directory of this source tree. An additional grant
  44. * of patent rights can be found in the PATENTS file in the same directory.
  45. */
  46. function canAcceptRef(component) {
  47. return !!component && (typeof component !== 'function' || component.prototype && component.prototype.isReactComponent);
  48. }