forked from 10up/figma-to-wordpress-theme-json-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcss-vars.html
More file actions
187 lines (162 loc) · 4.55 KB
/
css-vars.html
File metadata and controls
187 lines (162 loc) · 4.55 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
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
<style>
:root {
--spacing: 0.8rem;
}
* {
box-sizing: border-box;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
sans-serif;
}
body {
background-color: var(--figma-color-bg);
color: var(--figma-color-text);
margin: 0;
padding: var(--spacing);
min-height: 400px;
min-width: 800px;
position: relative;
overflow: hidden;
}
html,
body {
height: 100%;
}
main {
display: flex;
flex-direction: column;
gap: var(--spacing);
max-height: calc(100% - 20px);
overflow-y: auto;
}
button {
appearance: none;
border-radius: 4px;
padding: var(--spacing);
background-color: var(--figma-color-bg-brand);
border: none;
color: var(--figma-color-text-onbrand);
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segma UI",
Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
sans-serif;
font-weight: bold;
cursor: pointer;
width: 100%;
}
button:disabled {
background-color: var(--figma-color-bg-disabled);
color: var(--figma-color-text-disabled);
cursor: not-allowed;
}
.info-text {
font-size: 0.9rem;
margin-bottom: var(--spacing);
color: var(--figma-color-text-secondary);
}
.options {
display: flex;
flex-direction: column;
gap: calc(var(--spacing) / 2);
margin-bottom: var(--spacing);
background-color: var(--figma-color-bg-secondary);
padding: var(--spacing);
border-radius: 4px;
}
.option-row {
display: flex;
align-items: center;
gap: calc(var(--spacing) / 2);
}
.option-row label {
font-size: 0.9rem;
cursor: pointer;
}
.option-row input[type="checkbox"] {
cursor: pointer;
}
.status {
background-color: var(--figma-color-bg-secondary);
padding: var(--spacing);
border-radius: 4px;
font-size: 0.9rem;
color: var(--figma-color-text-secondary);
margin-top: var(--spacing);
display: none;
}
.status.success {
background-color: var(--figma-color-bg-success);
color: var(--figma-color-text-onbrand);
}
.status.error {
background-color: var(--figma-color-bg-danger);
color: var(--figma-color-text-onbrand);
}
code {
background-color: var(--figma-color-bg);
padding: 2px 4px;
border-radius: 2px;
font-family: monospace;
font-size: 0.85em;
}
</style>
<main>
<div class="info-text">
Apply CSS custom property syntax to your Figma variables for easier handoff to developers.
<br><br>
Variables will get code syntax in the format: <code>var(--wp--custom--xxx, originalValue)</code>
</div>
<div class="options">
<div class="option-row">
<input type="checkbox" id="overwrite-existing-vars" />
<label for="overwrite-existing-vars">Overwrite existing CSS variable syntax</label>
</div>
</div>
<!--
<button id="apply-vars-btn" type="button">Apply CSS Variable Syntax to All Variables</button>
-->
<div id="status" class="status"></div>
</main>
<script>
const overwriteCheckbox = document.getElementById("overwrite-existing-vars");
const applyButton = document.getElementById("apply-vars-btn");
const statusDiv = document.getElementById("status");
// Apply CSS var syntax to Figma variables
applyButton.addEventListener("click", () => {
const overwriteExisting = overwriteCheckbox.checked;
// Disable button during processing
applyButton.disabled = true;
applyButton.textContent = "Applying...";
// Hide previous status
statusDiv.style.display = "none";
statusDiv.className = "status";
// Send message to plugin
parent.postMessage({
pluginMessage: {
type: "APPLY_CSS_VAR_SYNTAX",
options: {
overwriteExisting
}
}
}, "*");
});
window.onmessage = ({ data: { pluginMessage } }) => {
if (pluginMessage.type === "CSS_VAR_SYNTAX_RESULT") {
// Re-enable the apply button
applyButton.disabled = false;
applyButton.textContent = "Apply CSS Variable Syntax to All Variables";
// Show status
statusDiv.style.display = "block";
if (pluginMessage.error) {
console.error("Error applying CSS var syntax:", pluginMessage.error);
statusDiv.className = "status error";
statusDiv.textContent = "Error: " + pluginMessage.error;
} else {
const result = pluginMessage.result;
const message = `✅ Applied CSS var syntax to ${result.updatedCount} variables${result.skippedCount > 0 ? `, skipped ${result.skippedCount} existing variables` : ''}`;
console.log("CSS var syntax applied:", result);
statusDiv.className = "status success";
statusDiv.textContent = message;
}
}
};
</script>