PagePathAutoComplete.jsx 1.1 KB

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