useSearchConfig.js 883 B

1234567891011121314151617181920212223242526
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import _typeof from "@babel/runtime/helpers/esm/typeof";
  3. import warning from "rc-util/es/warning";
  4. import * as React from 'react';
  5. // Convert `showSearch` to unique config
  6. export default function useSearchConfig(showSearch) {
  7. return React.useMemo(function () {
  8. if (!showSearch) {
  9. return [false, {}];
  10. }
  11. var searchConfig = {
  12. matchInputWidth: true,
  13. limit: 50
  14. };
  15. if (showSearch && _typeof(showSearch) === 'object') {
  16. searchConfig = _objectSpread(_objectSpread({}, searchConfig), showSearch);
  17. }
  18. if (searchConfig.limit <= 0) {
  19. searchConfig.limit = false;
  20. if (process.env.NODE_ENV !== 'production') {
  21. warning(false, "'limit' of showSearch should be positive number or false.");
  22. }
  23. }
  24. return [true, searchConfig];
  25. }, [showSearch]);
  26. }