mirror of
https://github.com/maputnik/editor.git
synced 2026-01-06 21:40:01 +00:00
Show error if style fails to load and disabled button if input is empty
This commit is contained in:
@@ -15,6 +15,7 @@ class Button extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
return <button
|
return <button
|
||||||
onClick={this.props.onClick}
|
onClick={this.props.onClick}
|
||||||
|
disabled={this.props.disabled}
|
||||||
aria-label={this.props["aria-label"]}
|
aria-label={this.props["aria-label"]}
|
||||||
className={classnames("maputnik-button", this.props.className)}
|
className={classnames("maputnik-button", this.props.className)}
|
||||||
data-wd-key={this.props["data-wd-key"]}
|
data-wd-key={this.props["data-wd-key"]}
|
||||||
|
|||||||
@@ -51,7 +51,9 @@ class OpenModal extends React.Component {
|
|||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {};
|
this.state = {
|
||||||
|
isUrlEmpty: true
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
clearError() {
|
clearError() {
|
||||||
@@ -102,6 +104,7 @@ class OpenModal extends React.Component {
|
|||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
error: `Failed to load: '${styleUrl}'`,
|
||||||
activeRequest: null,
|
activeRequest: null,
|
||||||
activeRequestUrl: null
|
activeRequestUrl: null
|
||||||
});
|
});
|
||||||
@@ -154,6 +157,13 @@ class OpenModal extends React.Component {
|
|||||||
this.props.onOpenToggle();
|
this.props.onOpenToggle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onChangeUrl = () => {
|
||||||
|
const length = this.styleUrlElement.value.length;
|
||||||
|
this.setState({
|
||||||
|
isUrlEmpty: length < 1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const styleOptions = publicStyles.map(style => {
|
const styleOptions = publicStyles.map(style => {
|
||||||
return <PublicStyle
|
return <PublicStyle
|
||||||
@@ -197,9 +207,21 @@ class OpenModal extends React.Component {
|
|||||||
<p>
|
<p>
|
||||||
Load from a URL. Note that the URL must have <a href="https://enable-cors.org" target="_blank" rel="noopener noreferrer">CORS enabled</a>.
|
Load from a URL. Note that the URL must have <a href="https://enable-cors.org" target="_blank" rel="noopener noreferrer">CORS enabled</a>.
|
||||||
</p>
|
</p>
|
||||||
<input data-wd-key="open-modal.url.input" type="text" ref={(input) => this.styleUrlElement = input} className="maputnik-input" placeholder="Enter URL..."/>
|
<input
|
||||||
|
data-wd-key="open-modal.url.input"
|
||||||
|
type="text"
|
||||||
|
ref={(input) => this.styleUrlElement = input}
|
||||||
|
className="maputnik-input"
|
||||||
|
placeholder="Enter URL..."
|
||||||
|
onChange={this.onChangeUrl}
|
||||||
|
/>
|
||||||
<div>
|
<div>
|
||||||
<Button data-wd-key="open-modal.url.button" className="maputnik-big-button" onClick={this.onOpenUrl}>Open URL</Button>
|
<Button
|
||||||
|
data-wd-key="open-modal.url.button"
|
||||||
|
className="maputnik-big-button"
|
||||||
|
onClick={this.onOpenUrl}
|
||||||
|
disabled={this.state.isUrlEmpty}
|
||||||
|
>Open URL</Button>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,12 @@
|
|||||||
background-color: lighten($color-midgray, 12);
|
background-color: lighten($color-midgray, 12);
|
||||||
color: $color-white;
|
color: $color-white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
background-color: darken($color-midgray, 5);
|
||||||
|
color: $color-midgray;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.maputnik-big-button {
|
.maputnik-big-button {
|
||||||
|
|||||||
Reference in New Issue
Block a user