-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
341 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react' | ||
import Proptypes from 'prop-types' | ||
|
||
import { CSSTransition } from 'react-transition-group' | ||
|
||
import './confirm.styl' | ||
export default class Confrim extends React.Component { | ||
|
||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
showFlag: false | ||
} | ||
} | ||
|
||
static propTypes = { | ||
text: Proptypes.string, | ||
confirmBtnText: Proptypes.string, | ||
cancelBtnText: Proptypes.string | ||
} | ||
|
||
static defaultProps = { | ||
text: '', | ||
cancelBtnText: '取消', | ||
confirmBtnText: '确认' | ||
} | ||
|
||
show() { | ||
this.setState({ | ||
showFlag: true | ||
}) | ||
} | ||
|
||
hide() { | ||
this.setState({ | ||
showFlag: false | ||
}) | ||
} | ||
|
||
confirm() { | ||
this.hide() | ||
this.props.confirm() | ||
} | ||
|
||
cancel() { | ||
this.hide() | ||
} | ||
|
||
render() { | ||
return ( | ||
<CSSTransition | ||
timeout={200} | ||
classNames="confirm-fade" | ||
> | ||
<div className="confirm" style={{'display': this.state.showFlag ? 'block' : 'none'}}> | ||
<div className="confirm-wrapper"> | ||
<div className="confirm-content"> | ||
<p className="text">{this.props.text}</p> | ||
<div className="operate"> | ||
<div className="operate-btn left" onClick={() => this.cancel()}>{this.props.cancelBtnText}</div> | ||
<div className="operate-btn" onClick={() => this.confirm()}>{this.props.confirmBtnText}</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</CSSTransition> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
@import "~common/styl/variable.styl" | ||
|
||
.confirm | ||
position fixed | ||
left 0px | ||
right 0px | ||
top 0px | ||
bottom 0px | ||
z-index 990 | ||
background-color $color-background-d | ||
.confirm-wrapper | ||
position: absolute | ||
top: 50% | ||
left: 50% | ||
transform: translate(-50%, -50%) | ||
z-index: 999 | ||
.confirm-content | ||
width: 270px | ||
border-radius: 13px | ||
background: $color-highlight-background | ||
.text | ||
padding: 19px 15px | ||
line-height: 22px | ||
text-align: center | ||
font-size: $font-size-large | ||
color: $color-text-l | ||
.operate | ||
display: flex | ||
align-items: center | ||
text-align: center | ||
font-size: $font-size-large | ||
.operate-btn | ||
flex: 1 | ||
line-height: 22px | ||
padding: 10px 0 | ||
border-top: 1px solid $color-background-d | ||
color: $color-text-d | ||
&.left | ||
border-right: 1px solid $color-background-d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react' | ||
import './searchList.styl' | ||
import Proptypes from 'prop-types' | ||
|
||
import { CSSTransition, TransitionGroup } from 'react-transition-group' | ||
|
||
export default class SearchList extends React.Component{ | ||
constructor(props) { | ||
super(props) | ||
this.state = {} | ||
} | ||
|
||
static propTypes = { | ||
searches: Proptypes.array | ||
} | ||
|
||
static defaultProps = { | ||
searches: [] | ||
} | ||
|
||
deleteOne(v, e) { | ||
e.stopPropagation() | ||
this.props.deleteOne(v) | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="search-list"> | ||
<TransitionGroup> | ||
{ | ||
this.props.searches.map((v, i) => | ||
<CSSTransition | ||
key={v} | ||
timeout={300} | ||
classNames="list"> | ||
<li | ||
onClick={() => this.props.selectItem(v)} | ||
className="search-item"> | ||
<span className="text">{v}</span> | ||
<span className="icon" onClick={(e) => this.deleteOne(v, e)}> | ||
<i className="icon-delete"></i> | ||
</span> | ||
</li> | ||
</CSSTransition> | ||
) | ||
} | ||
</TransitionGroup> | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@import "~common/styl/variable" | ||
@import "~common/styl/mixin" | ||
.search-list | ||
.search-item | ||
display: flex | ||
align-items: center | ||
height: 40px | ||
overflow: hidden | ||
.text | ||
flex: 1 | ||
color: $color-text-l | ||
.icon | ||
extend-click() | ||
.icon-delete | ||
font-size: $font-size-small | ||
color: $color-text-d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import storage from 'good-storage' | ||
|
||
const SEARCH_KEY = '__search__' | ||
const SEARCH_MAX_LENGTH = 15 | ||
|
||
|
||
export function saveSearch(query) { | ||
let searches = storage.get(SEARCH_KEY, []) | ||
insertArr(searches, query, (item) => { | ||
return item === query | ||
}, SEARCH_MAX_LENGTH) | ||
storage.set(SEARCH_KEY, searches) | ||
return searches | ||
} | ||
|
||
export function loadSearch() { | ||
return storage.get(SEARCH_KEY, []) | ||
} | ||
|
||
export function deleteSearch(query) { | ||
let searches = storage.get(SEARCH_KEY, []) | ||
deleteFromArr(searches, (item) => { | ||
return item === query | ||
}) | ||
storage.set(SEARCH_KEY, searches) | ||
return searches | ||
} | ||
|
||
export function clearSearch() { | ||
storage.remove(SEARCH_KEY) | ||
return [] | ||
} | ||
|
||
|
||
function insertArr(arr, val, compare, maxLen) { | ||
const index = arr.findIndex(compare) | ||
if (index === 0) return | ||
if (index > 0) { | ||
arr.splice(index, 1) | ||
} | ||
arr.unshift(val) | ||
if (maxLen && arr.length > maxLen) { | ||
arr.pop() | ||
} | ||
} | ||
|
||
function deleteFromArr(arr, compare) { | ||
const index = arr.findIndex(compare) | ||
if (index > -1) { | ||
arr.splice(index, 1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.