forked from figma/plugin-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.html
29 lines (26 loc) · 842 Bytes
/
ui.html
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
<link rel="stylesheet" href="https://static.figma.com/api/figma-extension-api-0.0.1.css">
<h2>Bar Chart Sample</h2>
<p>
Values:
<input id="textbox" value="1, 3, 10, 28, 41, 87, 100, 114, 94, 68, 50, 23, 9, 3, 1">
</p>
<b id="errors"></b>
<p><button>Create Bar Chart</button></p>
<script>
document.querySelector('button').onclick = () => {
const text = document.querySelector('#textbox').value
let numbers = text.split(',').map(x => +x)
if (numbers.length < 2) {
showError('Error: Must have at least two values');
return
}
if (numbers.some(x => isNaN(x))) {
showError('Error: All values must be numbers');
return
}
parent.postMessage({ pluginMessage: numbers }, '*')
}
showError = errorMessage => {
document.querySelector('#errors').textContent = errorMessage
}
</script>