Dashboard sipadu mbip
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

utils.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import invariant from 'invariant';
  2. var noop = function noop() {};
  3. function readOnlyPropType(handler, name) {
  4. return function (props, propName) {
  5. if (props[propName] !== undefined) {
  6. if (!props[handler]) {
  7. 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 + "`."));
  8. }
  9. }
  10. };
  11. }
  12. export function uncontrolledPropTypes(controlledValues, displayName) {
  13. var propTypes = {};
  14. Object.keys(controlledValues).forEach(function (prop) {
  15. // add default propTypes for folks that use runtime checks
  16. propTypes[defaultKey(prop)] = noop;
  17. if (process.env.NODE_ENV !== 'production') {
  18. var handler = controlledValues[prop];
  19. !(typeof handler === 'string' && handler.trim().length) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Uncontrollable - [%s]: the prop `%s` needs a valid handler key name in order to make it uncontrollable', displayName, prop) : invariant(false) : void 0;
  20. propTypes[prop] = readOnlyPropType(handler, displayName);
  21. }
  22. });
  23. return propTypes;
  24. }
  25. export function isProp(props, prop) {
  26. return props[prop] !== undefined;
  27. }
  28. export function defaultKey(key) {
  29. return 'default' + key.charAt(0).toUpperCase() + key.substr(1);
  30. }
  31. /**
  32. * Copyright (c) 2013-present, Facebook, Inc.
  33. * All rights reserved.
  34. *
  35. * This source code is licensed under the BSD-style license found in the
  36. * LICENSE file in the root directory of this source tree. An additional grant
  37. * of patent rights can be found in the PATENTS file in the same directory.
  38. */
  39. export function canAcceptRef(component) {
  40. return !!component && (typeof component !== 'function' || component.prototype && component.prototype.isReactComponent);
  41. }