mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-10 19:32:25 +00:00
change search UI (#7331)
This commit is contained in:
parent
a372b7fc84
commit
39328ea23f
@ -1,15 +1,19 @@
|
|||||||
import React, { Component, Fragment } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import isHotkey from 'is-hotkey';
|
||||||
import { gettext } from '../../utils/constants';
|
import { gettext } from '../../utils/constants';
|
||||||
|
import { Utils } from '../../utils/utils';
|
||||||
import SearchFileDialog from '../dialog/search-file-dialog';
|
import SearchFileDialog from '../dialog/search-file-dialog';
|
||||||
|
|
||||||
import '../../css/top-search-by-name.css';
|
import '../../css/search-by-name.css';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
repoID: PropTypes.string.isRequired,
|
repoID: PropTypes.string.isRequired,
|
||||||
repoName: PropTypes.string.isRequired
|
repoName: PropTypes.string.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const controlKey = Utils.isMac() ? '⌘' : 'Ctrl';
|
||||||
|
|
||||||
class SearchByName extends Component {
|
class SearchByName extends Component {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -19,6 +23,20 @@ class SearchByName extends Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
document.addEventListener('keydown', this.onDocumentKeydown);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
document.removeEventListener('keydown', this.onDocumentKeydown);
|
||||||
|
}
|
||||||
|
|
||||||
|
onDocumentKeydown = (e) => {
|
||||||
|
if (isHotkey('mod+k')(e)) {
|
||||||
|
this.toggleDialog();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
toggleDialog = () => {
|
toggleDialog = () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
isDialogOpen: !this.state.isDialogOpen
|
isDialogOpen: !this.state.isDialogOpen
|
||||||
@ -28,13 +46,20 @@ class SearchByName extends Component {
|
|||||||
render() {
|
render() {
|
||||||
const { repoID, repoName } = this.props;
|
const { repoID, repoName } = this.props;
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<>
|
||||||
<i
|
<div className="search-by-name">
|
||||||
className="sf3-font sf3-font-search top-search-file-icon"
|
<i className="input-icon-addon sf3-font sf3-font-search"></i>
|
||||||
onClick={this.toggleDialog}
|
<div
|
||||||
title={gettext('Search files in this library')}
|
type="text"
|
||||||
>
|
className="form-control search-input"
|
||||||
</i>
|
name="query"
|
||||||
|
onClick={this.toggleDialog}
|
||||||
|
role="button"
|
||||||
|
title={gettext('Search files in this library')}
|
||||||
|
>
|
||||||
|
{gettext('Search files') + ` (${controlKey} + k)`}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{this.state.isDialogOpen &&
|
{this.state.isDialogOpen &&
|
||||||
<SearchFileDialog
|
<SearchFileDialog
|
||||||
repoID={repoID}
|
repoID={repoID}
|
||||||
@ -42,7 +67,7 @@ class SearchByName extends Component {
|
|||||||
toggleDialog={this.toggleDialog}
|
toggleDialog={this.toggleDialog}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
</Fragment>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
frontend/src/css/search-by-name.css
Normal file
10
frontend/src/css/search-by-name.css
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
.search-by-name {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-by-name .search-input {
|
||||||
|
color: #adb5bd;
|
||||||
|
padding: 0 12px 0 40px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
.top-search-file-icon {
|
|
||||||
color: #999;
|
|
||||||
font-size: 20px;
|
|
||||||
align-self: center;
|
|
||||||
font-weight: 800;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user