PagePathAutoComplete.jsx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import React from 'react';
  2. import { pathUtils } from '@growi/core/dist/utils';
  3. import PropTypes from 'prop-types';
  4. import SearchTypeahead from './SearchTypeahead';
  5. const PagePathAutoComplete = (props) => {
  6. const { addTrailingSlash, initializedPath } = props;
  7. function getKeywordOnInit(path) {
  8. if (path == null) {
  9. return;
  10. }
  11. return addTrailingSlash
  12. ? pathUtils.addTrailingSlash(path)
  13. : pathUtils.removeTrailingSlash(path);
  14. }
  15. return (
  16. <SearchTypeahead
  17. {...props}
  18. inputProps={{ name: 'new_path' }}
  19. placeholder="Input page path"
  20. keywordOnInit={getKeywordOnInit(initializedPath)}
  21. autoFocus={props.autoFocus}
  22. />
  23. );
  24. };
  25. PagePathAutoComplete.propTypes = {
  26. initializedPath: PropTypes.string,
  27. addTrailingSlash: PropTypes.bool,
  28. onChange: PropTypes.func,
  29. onSubmit: PropTypes.func,
  30. onInputChange: PropTypes.func,
  31. autoFocus: PropTypes.bool,
  32. };
  33. PagePathAutoComplete.defaultProps = {
  34. initializedPath: '/',
  35. autoFocus: false,
  36. };
  37. export default PagePathAutoComplete;