This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
forked from adamseckel/intercom-inserter-figma-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.html
190 lines (162 loc) · 4.14 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<style>
* {
box-sizing: border-box;
}
p {
font-size: 10px;
font-weight: 600;
color: #333;
margin: 0;
}
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
.section {
/* background: rgba(0, 0, 0, 0.06); */
padding: 8px 16px;
border-bottom: 1px solid #e5e5e5;
}
.section:last-of-type {
border-bottom: 0;
}
.property {
margin: 8px 0;
}
button#create {
width: 100%;
}
.btn {
font-size: 14px;
line-height: 18px;
font-weight: 500;
text-decoration: none;
border: 1px solid;
border-color: rgba(0, 0, 0, 0.2);
border-radius: 4px;
padding: 5px 12px 7px;
display: inline-block;
cursor: pointer;
transition: box-shadow linear 40ms;
}
.btn.o__primary {
background-color: #286efa;
color: #fff;
}
.btn.o__secondary {
background-color: #fff;
color: #222;
}
.btn[disabled='true'] {
opacity: 0.5;
}
.btn.o__subtle {
border-color: transparent;
}
</style>
<div class="section">
<p>
Component:
<select disabled id="component" value="Button">
<option value="button">Button</option>
</select>
</p>
</div>
<div class="section" style="text-align: center;">
<button id="button" class="btn o__primary" role="button" type="button">
Save
</button>
</div>
<div class="section">
<p>Properties</p>
<p class="property">
Label:
<input id="label" value="Save" />
</p>
<p class="property">
Type:
<select id="type" value="Primary">
<option value="Primary">Primary</option>
<option value="Secondary">Secondary</option>
</select>
</p>
<p class="property">
State:
<select id="state">
<option selected value> No state </option>
<option value="Destructive">Destructive</option>
<option value="Live">Live</option>
<option value="On-Blue">On-Blue</option>
</select>
</p>
<p class="property">
Icon:
<select id="icon" value="" disabled>
<option selected value> No icon </option>
<option value="app">app</option>
<option value="apple">apple</option>
<option value="archive">archive</option>
</select>
</p>
<p class="property">
Subtle: <input id="subtle" type="checkbox" value="" disabled />
</p>
<p class="property">
Disabled: <input id="disabled" type="checkbox" value="" />
</p>
</div>
<div class="section">
<button id="create">Create</button>
</div>
<script>
document.getElementById('type').onchange = e => {
if (e.target.value === 'Secondary') {
document.getElementById('button').classList.remove('o__primary');
document.getElementById('button').classList.add('o__secondary');
document.getElementById('subtle').removeAttribute('disabled');
} else {
document.getElementById('button').classList.add('o__primary');
document.getElementById('button').classList.remove('o__secondary');
document.getElementById('subtle').setAttribute('disabled', true);
}
};
document.getElementById('label').onkeyup = e => {
document.getElementById('button').innerText = e.target.value;
};
document.getElementById('disabled').onchange = e => {
document
.getElementById('button')
.setAttribute('disabled', e.target.checked);
};
document.getElementById('subtle').onchange = e => {
document.getElementById('button').classList.toggle('o__subtle');
};
const ids = ['component', 'label', 'type', 'state', 'icon'];
const booleanIds = ['subtle', 'disabled'];
document.getElementById('create').onclick = () => {
const values = ids.reduce(
(v, id) => ({
...v,
[id]: document.getElementById(id).value,
}),
{},
);
const checkboxes = booleanIds.reduce(
(c, id) => ({
...c,
[id]: document.getElementById(id).checked,
}),
{},
);
const allValues = {
...values,
...checkboxes,
};
console.log({ allValues });
parent.postMessage(
{ pluginMessage: { type: 'create-component', values: allValues } },
'*',
);
};
</script>