mirror of
https://github.com/maputnik/editor.git
synced 2026-01-06 13:30:03 +00:00
Merge pull request #199 from orangemug/fix/issue-97-layer-list-cutoff
Fixed layer list cutoff (#97)
This commit is contained in:
@@ -4,11 +4,72 @@ import classnames from 'classnames'
|
|||||||
import Autocomplete from 'react-autocomplete'
|
import Autocomplete from 'react-autocomplete'
|
||||||
|
|
||||||
|
|
||||||
|
const MAX_HEIGHT = 140;
|
||||||
|
|
||||||
|
class AutocompleteMenu extends React.Component {
|
||||||
|
static propTypes = {
|
||||||
|
keepMenuWithinWindowBounds: PropTypes.bool,
|
||||||
|
style: PropTypes.object,
|
||||||
|
children: PropTypes.node
|
||||||
|
}
|
||||||
|
|
||||||
|
calcMaxHeight() {
|
||||||
|
if(this.props.keepMenuWithinWindowBounds) {
|
||||||
|
const maxHeight = window.innerHeight - this.autocompleteMenuEl.getBoundingClientRect().top;
|
||||||
|
const limitedMaxHeight = Math.min(maxHeight, MAX_HEIGHT);
|
||||||
|
|
||||||
|
if(limitedMaxHeight != this.state.maxHeight) {
|
||||||
|
this.setState({
|
||||||
|
maxHeight: limitedMaxHeight
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
componentDidMount() {
|
||||||
|
this.calcMaxHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
this.calcMaxHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
maxHeight: MAX_HEIGHT
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static defaultProps = {
|
||||||
|
style: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const maxHeight = this.state.maxHeight - this.props.style.marginBottom || 0;
|
||||||
|
const style = {
|
||||||
|
maxHeight: maxHeight+"px"
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={(el) => {
|
||||||
|
this.autocompleteMenuEl = el;
|
||||||
|
}}
|
||||||
|
className={"maputnik-autocomplete-menu"}
|
||||||
|
style={style}
|
||||||
|
>
|
||||||
|
{this.props.children}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class AutocompleteInput extends React.Component {
|
class AutocompleteInput extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
value: PropTypes.string,
|
value: PropTypes.string,
|
||||||
options: PropTypes.array,
|
options: PropTypes.array,
|
||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
|
keepMenuWithinWindowBounds: PropTypes.bool
|
||||||
}
|
}
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
@@ -17,14 +78,16 @@ class AutocompleteInput extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const AutocompleteMenu = (items, value, style) => <div className={"maputnik-autocomplete-menu"}>{items}</div>
|
|
||||||
|
|
||||||
return <Autocomplete
|
return <Autocomplete
|
||||||
wrapperProps={{
|
wrapperProps={{
|
||||||
className: "maputnik-autocomplete",
|
className: "maputnik-autocomplete",
|
||||||
style: null
|
style: null
|
||||||
}}
|
}}
|
||||||
renderMenu={AutocompleteMenu}
|
renderMenu={(items) => {
|
||||||
|
return <AutocompleteMenu keepMenuWithinWindowBounds={this.props.keepMenuWithinWindowBounds} style={{marginBottom: 4}}>
|
||||||
|
{items}
|
||||||
|
</AutocompleteMenu>
|
||||||
|
}}
|
||||||
inputProps={{
|
inputProps={{
|
||||||
className: "maputnik-string"
|
className: "maputnik-string"
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -12,16 +12,19 @@ class LayerSourceLayer extends React.Component {
|
|||||||
value: PropTypes.string,
|
value: PropTypes.string,
|
||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
sourceLayerIds: PropTypes.array,
|
sourceLayerIds: PropTypes.array,
|
||||||
|
isFixed: PropTypes.bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
onChange: () => {},
|
onChange: () => {},
|
||||||
sourceLayerIds: [],
|
sourceLayerIds: [],
|
||||||
|
isFixed: false
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <InputBlock label={"Source Layer"} doc={styleSpec.latest.layer['source-layer'].doc}>
|
return <InputBlock label={"Source Layer"} doc={styleSpec.latest.layer['source-layer'].doc}>
|
||||||
<AutocompleteInput
|
<AutocompleteInput
|
||||||
|
keepMenuWithinWindowBounds={!!this.props.isFixed}
|
||||||
value={this.props.value}
|
value={this.props.value}
|
||||||
onChange={this.props.onChange}
|
onChange={this.props.onChange}
|
||||||
options={this.props.sourceLayerIds.map(l => [l, l])}
|
options={this.props.sourceLayerIds.map(l => [l, l])}
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ class AddModal extends React.Component {
|
|||||||
}
|
}
|
||||||
{this.state.type !== 'background' && this.state.type !== 'raster' &&
|
{this.state.type !== 'background' && this.state.type !== 'raster' &&
|
||||||
<LayerSourceLayerBlock
|
<LayerSourceLayerBlock
|
||||||
|
isFixed={true}
|
||||||
sourceLayerIds={layers}
|
sourceLayerIds={layers}
|
||||||
value={this.state['source-layer']}
|
value={this.state['source-layer']}
|
||||||
onChange={v => this.setState({ 'source-layer': v })}
|
onChange={v => this.setState({ 'source-layer': v })}
|
||||||
|
|||||||
Reference in New Issue
Block a user