-
-
Notifications
You must be signed in to change notification settings - Fork 477
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 fix-cjs-files
- Loading branch information
Showing
49 changed files
with
16,044 additions
and
10,828 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
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 |
---|---|---|
|
@@ -13,4 +13,4 @@ | |
"reason": "Current version of Webpack Dev Server doesn't work with v4" | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.container { | ||
font: var(--main-font); | ||
white-space: nowrap; | ||
} | ||
|
||
.label { | ||
font-size: 11px; | ||
font-weight: bold; | ||
margin-bottom: 7px; | ||
} | ||
|
||
.input { | ||
border: 1px solid #aaa; | ||
border-radius: 4px; | ||
display: block; | ||
width: 100%; | ||
color: #7f7f7f; | ||
height: 27px; | ||
} | ||
|
||
.option { | ||
padding: 4px 0; | ||
cursor: pointer; | ||
} |
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,88 @@ | ||
import {createRef} from 'preact'; | ||
import PureComponent from '../lib/PureComponent'; | ||
|
||
import s from './Dropdown.css'; | ||
|
||
export default class Dropdown extends PureComponent { | ||
input = createRef(); | ||
|
||
state = { | ||
query: '', | ||
showOptions: false | ||
}; | ||
|
||
componentDidMount() { | ||
document.addEventListener('click', this.handleClickOutside, true); | ||
} | ||
|
||
componentWillUnmount() { | ||
document.removeEventListener('click', this.handleClickOutside, true); | ||
} | ||
|
||
render() { | ||
const {label, options} = this.props; | ||
|
||
const filteredOptions = | ||
this.state.query | ||
? options.filter((option) => | ||
option.toLowerCase().includes(this.state.query.toLowerCase()) | ||
) | ||
: options; | ||
|
||
return ( | ||
<div className={s.container}> | ||
<div className={s.label}>{label}:</div> | ||
<div> | ||
<input ref={this.input} | ||
className={s.input} | ||
type="text" | ||
value={this.state.query} | ||
onInput={this.handleInput} | ||
onFocus={this.handleFocus}/> | ||
{this.state.showOptions ? ( | ||
<div className={s.options}> | ||
{filteredOptions.map((option) => ( | ||
<div key={option} | ||
className={s.option} | ||
onClick={this.getOptionClickHandler(option)}> | ||
{option} | ||
</div> | ||
))} | ||
</div> | ||
) : null} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
handleClickOutside = (event) => { | ||
const el = this.input.current; | ||
if (el && event && !el.contains(event.target)) { | ||
this.setState({showOptions: false}); | ||
// If the query is not in the options, reset the selection | ||
if (this.state.query && !this.props.options.some((option) => option === this.state.query)) { | ||
this.setState({query: ''}); | ||
this.props.onSelectionChange(undefined); | ||
} | ||
} | ||
}; | ||
|
||
handleInput = (event) => { | ||
const {value} = event.target; | ||
this.setState({query: value}); | ||
if (!value) { | ||
this.props.onSelectionChange(undefined); | ||
} | ||
} | ||
|
||
handleFocus = () => { | ||
// move the cursor to the end of the input | ||
this.input.current.value = this.state.query; | ||
this.setState({showOptions: true}); | ||
} | ||
|
||
getOptionClickHandler = (option) => () => { | ||
this.props.onSelectionChange(option); | ||
this.setState({query: option, showOptions: false}); | ||
}; | ||
} |
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.