forked from naturalcrit/homebrewery
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into addDirectPrint-naturalcrit#2742
- Loading branch information
Showing
33 changed files
with
16,176 additions
and
29,212 deletions.
There are no files selected for viewing
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,129 @@ | ||
const React = require('react'); | ||
const createClass = require('create-react-class'); | ||
const _ = require('lodash'); | ||
const cx = require('classnames'); | ||
require('./combobox.less'); | ||
|
||
const Combobox = createClass({ | ||
displayName : 'Combobox', | ||
getDefaultProps : function() { | ||
return { | ||
className : '', | ||
trigger : 'hover', | ||
default : '', | ||
placeholder : '', | ||
autoSuggest : { | ||
clearAutoSuggestOnClick : true, | ||
suggestMethod : 'includes', | ||
filterOn : [] // should allow as array to filter on multiple attributes, or even custom filter | ||
}, | ||
}; | ||
}, | ||
getInitialState : function() { | ||
return { | ||
showDropdown : false, | ||
value : '', | ||
options : [...this.props.options], | ||
inputFocused : false | ||
}; | ||
}, | ||
componentDidMount : function() { | ||
if(this.props.trigger == 'click') | ||
document.addEventListener('click', this.handleClickOutside); | ||
this.setState({ | ||
value : this.props.default | ||
}); | ||
}, | ||
componentWillUnmount : function() { | ||
if(this.props.trigger == 'click') | ||
document.removeEventListener('click', this.handleClickOutside); | ||
}, | ||
handleClickOutside : function(e){ | ||
// Close dropdown when clicked outside | ||
if(this.refs.dropdown && !this.refs.dropdown.contains(e.target)) { | ||
this.handleDropdown(false); | ||
} | ||
}, | ||
handleDropdown : function(show){ | ||
this.setState({ | ||
showDropdown : show, | ||
inputFocused : this.props.autoSuggest.clearAutoSuggestOnClick ? show : false | ||
}); | ||
}, | ||
handleInput : function(e){ | ||
e.persist(); | ||
this.setState({ | ||
value : e.target.value, | ||
inputFocused : false | ||
}, ()=>{ | ||
this.props.onEntry(e); | ||
}); | ||
}, | ||
handleSelect : function(e){ | ||
this.setState({ | ||
value : e.currentTarget.getAttribute('data-value') | ||
}, ()=>{this.props.onSelect(this.state.value);}); | ||
; | ||
}, | ||
renderTextInput : function(){ | ||
return ( | ||
<div className='dropdown-input item' | ||
onMouseEnter={this.props.trigger == 'hover' ? ()=>{this.handleDropdown(true);} : undefined} | ||
onClick= {this.props.trigger == 'click' ? ()=>{this.handleDropdown(true);} : undefined}> | ||
<input | ||
type='text' | ||
onChange={(e)=>this.handleInput(e)} | ||
value={this.state.value || ''} | ||
placeholder={this.props.placeholder} | ||
onBlur={(e)=>{ | ||
if(!e.target.checkValidity()){ | ||
this.setState({ | ||
value : this.props.default | ||
}, ()=>this.props.onEntry(e)); | ||
} | ||
}} | ||
/> | ||
</div> | ||
); | ||
}, | ||
renderDropdown : function(dropdownChildren){ | ||
if(!this.state.showDropdown) return null; | ||
if(this.props.autoSuggest && !this.state.inputFocused){ | ||
const suggestMethod = this.props.autoSuggest.suggestMethod; | ||
const filterOn = _.isString(this.props.autoSuggest.filterOn) ? [this.props.autoSuggest.filterOn] : this.props.autoSuggest.filterOn; | ||
const filteredArrays = filterOn.map((attr)=>{ | ||
const children = dropdownChildren.filter((item)=>{ | ||
if(suggestMethod === 'includes'){ | ||
return item.props[attr]?.toLowerCase().includes(this.state.value.toLowerCase()); | ||
} else if(suggestMethod === 'startsWith'){ | ||
return item.props[attr]?.toLowerCase().startsWith(this.state.value.toLowerCase()); | ||
} | ||
}); | ||
return children; | ||
}); | ||
dropdownChildren = _.uniq(filteredArrays.flat(1)); | ||
} | ||
|
||
return ( | ||
<div className='dropdown-options'> | ||
{dropdownChildren} | ||
</div> | ||
); | ||
}, | ||
render : function () { | ||
const dropdownChildren = this.state.options.map((child, i)=>{ | ||
const clone = React.cloneElement(child, { onClick: (e)=>this.handleSelect(e) }); | ||
return clone; | ||
}); | ||
return ( | ||
<div className={`dropdown-container ${this.props.className}`} | ||
ref='dropdown' | ||
onMouseLeave={this.props.trigger == 'hover' ? ()=>{this.handleDropdown(false);} : undefined}> | ||
{this.renderTextInput()} | ||
{this.renderDropdown(dropdownChildren)} | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
module.exports = Combobox; |
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,50 @@ | ||
.dropdown-container { | ||
position:relative; | ||
input { | ||
width: 100%; | ||
} | ||
.dropdown-options { | ||
position:absolute; | ||
background-color: white; | ||
z-index: 100; | ||
width: 100%; | ||
border: 1px solid gray; | ||
overflow-y: auto; | ||
max-height: 200px; | ||
|
||
&::-webkit-scrollbar { | ||
width: 14px; | ||
} | ||
&::-webkit-scrollbar-track { | ||
background: #ffffff; | ||
} | ||
&::-webkit-scrollbar-thumb { | ||
background-color: #949494; | ||
border-radius: 10px; | ||
border: 3px solid #ffffff; | ||
} | ||
|
||
.item { | ||
position:relative; | ||
font-size: 11px; | ||
font-family: Open Sans; | ||
padding: 5px; | ||
cursor: default; | ||
margin: 0 3px; | ||
//border-bottom: 1px solid darkgray; | ||
&:hover { | ||
filter: brightness(120%); | ||
background-color: rgb(163, 163, 163); | ||
} | ||
.detail { | ||
width:100%; | ||
text-align: left; | ||
color: rgb(124, 124, 124); | ||
font-style:italic; | ||
font-size: 9px; | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
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
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
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 |
---|---|---|
|
@@ -47,6 +47,7 @@ const Homebrew = createClass({ | |
editId : null, | ||
createdAt : null, | ||
updatedAt : null, | ||
lang : '' | ||
} | ||
}; | ||
}, | ||
|
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.