From 892a0ad4276d8508a0d53090d526abee6275345f Mon Sep 17 00:00:00 2001 From: RickCole21 Date: Fri, 21 Aug 2020 17:33:31 +0800 Subject: [PATCH] doc search style --- examples/components/App.tsx | 6 +- examples/components/DocSearch.jsx | 120 +++++++++++++++++++++++++----- examples/style.scss | 98 ++++++++++++++++++++---- 3 files changed, 187 insertions(+), 37 deletions(-) diff --git a/examples/components/App.tsx b/examples/components/App.tsx index 88e01e82..7a23128a 100644 --- a/examples/components/App.tsx +++ b/examples/components/App.tsx @@ -281,10 +281,10 @@ export class App extends React.PureComponent { }} /> + -
- -
+
+
{ this.docs = result.data.docs; }) @@ -32,12 +44,14 @@ export default class DocSearch extends React.Component { }); } - onSearch(query) { - query = query.trim().toLowerCase(); + onSearch() { + let query = this.state.query.trim().toLowerCase(); + if (query === '') { this.setState({searchResults: []}); return; } + let results = []; for (let doc of this.docs) { let index = doc.body.indexOf(query); @@ -67,28 +81,94 @@ export default class DocSearch extends React.Component { this.setState({searchResults: results}); } - onSearchCancel() { + onChange(e) { + this.setState( + { + query: e.currentTarget.value + }, + () => this.onSearch() + ); + } + + onOpen() { + this.setState({ + show: true + }); + } + onClose() { + this.setState({ + show: false + }); + } + + onEntered() { + this.ref.current.focus(); + } + + onExited() { this.setState({searchResults: []}); } + clearValue() { + this.setState( + { + query: '' + }, + () => { + this.setState({searchResults: []}); + } + ); + } + render() { const searchResults = this.state.searchResults; + const ns = this.props.theme.ns; return ( -
- - {searchResults.length > 0 ? ( -
- {searchResults.map(item => { - return ( - -
{item.title}
-

- - ); - })} + <> +

+ + +
+ + +
+ + + {this.state.query ? ( + + + + ) : null}
- ) : null} -
+ + {searchResults.length > 0 ? ( +
+ {searchResults.map(item => { + return ( + +

{item.title}

+

+ + ); + })} +

+ ) : null} + + ); } } diff --git a/examples/style.scss b/examples/style.scss index 872f642b..44fad71b 100644 --- a/examples/style.scss +++ b/examples/style.scss @@ -218,7 +218,13 @@ a { width: 120px; .Doc-search { - top: 15px; + margin-top: 15px; + border: 0; + + > .icon-search { + margin-right: 8px; + top: 3px; + } } &::before { @@ -712,20 +718,84 @@ a { } } -.search-result { - background-color: #fff; - top: 50px; - bottom: 0; - position: fixed; - overflow-y: scroll; - overflow-x: hidden; - box-shadow: 0px 2px 7px #888888; - a { - padding: 0 5px; - display: block; +.Doc-searchDrawer { + border: 0; + + .a-Drawer-content, + .cxd-Drawer-content, + .dark-Drawer-content { + border: 0; } - a:hover { - background-color: $gray200; + + .a-Drawer-close, + .cxd-Drawer-close, + .dark-Drawer-close { + display: none; + } + + .a-Drawer-overlay, + .cxd-Drawer-overlay, + .dark-Drawer-overlay { + background-color: rgba(25, 35, 60, 0.3); + } + + .search-bar { + padding: 22px 20px; + border: 0; + border-bottom: 1px solid #e8ebee; + border-radius: 0; + font-size: 16px; + font-weight: 500; + + > .icon-search { + margin-right: 10px; + top: 4px; + } + } + + .search-result { + // background-color: #fff; + top: 65px; + bottom: 0; + left: 0; + right: 0; + position: fixed; + overflow-y: scroll; + overflow-x: hidden; + // box-shadow: 0px 2px 7px #888888; + + h4, + p { + padding: 20px; + border-bottom: 1px solid #e8ebee; + margin: 0; + + &:hover { + background-color: #f5f7f9; + } + } + + h4 { + font-weight: 500; + position: relative; + color: #000; + + &::before { + content: ' '; + border-left: 2px solid #108cee; + margin-right: 10px; + } + } + + p { + color: #666; + + strong { + color: #19233c; + background-color: rgba(16, 140, 238, 0.3); + font-weight: 700; + } + } } }