forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuggestions.js
More file actions
37 lines (30 loc) · 1.09 KB
/
suggestions.js
File metadata and controls
37 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { applyStyles } from '../utils/dom/css';
import {
suggestionsContainerStyle,
suggestionsTitleStyle,
suggestionsButtonStyle,
} from '../styles';
export function createSuggestions(error: SandboxError) {
const container = document.createElement('div');
applyStyles(container, suggestionsContainerStyle);
const title = document.createElement('div');
title.appendChild(document.createTextNode('Suggested solutions:'));
applyStyles(title, suggestionsTitleStyle);
container.appendChild(title);
error.suggestions.forEach(suggestion => {
const button = document.createElement('button');
button.appendChild(document.createTextNode(suggestion.title));
button.setAttribute('onmouseover', 'this.style.backgroundColor="#78CDF7"');
button.setAttribute(
'onmouseout',
`this.style.backgroundColor="${suggestionsButtonStyle['background-color']}"`
);
applyStyles(button, suggestionsButtonStyle);
button.addEventListener('click', e => {
e.preventDefault();
suggestion.action();
});
container.appendChild(button);
});
return container;
}