Skip to content

Commit 8790c0e

Browse files
authored
Disable action buttons when errors present (#503)
1 parent 4d7ad69 commit 8790c0e

File tree

6 files changed

+236
-190
lines changed

6 files changed

+236
-190
lines changed

packages/ui/src/cairo/App.svelte

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import Dropdown from '../common/Dropdown.svelte';
1616
import OverflowMenu from '../common/OverflowMenu.svelte';
1717
import FileIcon from '../common/icons/FileIcon.svelte';
18+
import ErrorDisabledActionButtons from '../common/ErrorDisabledActionButtons.svelte';
1819
1920
import type { KindedOptions, Kind, Contract, OptionsErrorMessages } from '@openzeppelin/wizard-cairo';
2021
import { ContractBuilder, buildGeneric, printContract, sanitizeKind, OptionsError } from '@openzeppelin/wizard-cairo';
@@ -88,6 +89,8 @@
8889
$: code = printContract(contract);
8990
$: highlightedCode = injectHyperlinks(hljs.highlight(code, {language: 'cairo'}).value);
9091
92+
$: hasErrors = errors[tab] !== undefined;
93+
9194
const language = 'cairo';
9295
9396
let copied = false;
@@ -141,30 +144,34 @@
141144
</OverflowMenu>
142145
</div>
143146

144-
<div class="action flex flex-row gap-2 shrink-0">
145-
<button class="action-button p-3 min-w-[40px]" on:click={copyHandler} title="Copy to Clipboard">
146-
{#if copied}
147-
<CheckIcon />
148-
{:else}
149-
<CopyIcon />
150-
{/if}
151-
</button>
152-
153-
<Dropdown let:active>
154-
<button class="action-button with-text" class:active slot="button">
155-
<DownloadIcon />
156-
Download
147+
{#if hasErrors}
148+
<ErrorDisabledActionButtons />
149+
{:else}
150+
<div class="action flex flex-row gap-2 shrink-0">
151+
<button class="action-button p-3 min-w-[40px]" on:click={copyHandler} title="Copy to Clipboard">
152+
{#if copied}
153+
<CheckIcon />
154+
{:else}
155+
<CopyIcon />
156+
{/if}
157157
</button>
158158

159-
<button class="download-option" on:click={downloadCairoHandler}>
160-
<FileIcon />
161-
<div class="download-option-content">
162-
<p>Single file</p>
163-
<p>Requires a Scarb project with <code>openzeppelin</code> as a dependency.</p>
164-
</div>
165-
</button>
166-
</Dropdown>
167-
</div>
159+
<Dropdown let:active>
160+
<button class="action-button with-text" class:active slot="button">
161+
<DownloadIcon />
162+
Download
163+
</button>
164+
165+
<button class="download-option" on:click={downloadCairoHandler}>
166+
<FileIcon />
167+
<div class="download-option-content">
168+
<p>Single file</p>
169+
<p>Requires a Scarb project with <code>openzeppelin</code> as a dependency.</p>
170+
</div>
171+
</button>
172+
</Dropdown>
173+
</div>
174+
{/if}
168175
</div>
169176

170177
<div class="flex flex-row grow">
@@ -227,15 +234,6 @@
227234
background-color: transparent;
228235
}
229236
230-
.action-button {
231-
padding: 7px;
232-
border-radius: 20px;
233-
transition: background-color ease-in-out .2s;
234-
}
235-
.with-text {
236-
padding-right: var(--size-3);
237-
}
238-
239237
.tab button:hover, :global(.overflow-btn):hover {
240238
background-color: var(--gray-2);
241239
}
@@ -250,7 +248,11 @@
250248
order: unset;
251249
}
252250
253-
.action-button {
251+
:global(.action-button) {
252+
padding: 7px;
253+
border-radius: 20px;
254+
transition: background-color ease-in-out .2s;
255+
254256
background-color: var(--gray-1);
255257
border: 1px solid var(--gray-3);
256258
color: var(--gray-6);
@@ -265,10 +267,18 @@
265267
}
266268
267269
:global(.icon) {
268-
margin-right: 0 var(--size-1);
270+
margin: 0 var(--size-1);
269271
}
270272
}
271273
274+
:global(.action-button.disabled) {
275+
color: var(--gray-4);
276+
}
277+
278+
:global(.with-text) {
279+
padding-right: var(--size-3);
280+
}
281+
272282
.controls {
273283
background-color: white;
274284
padding: var(--size-4);

packages/ui/src/cairo_alpha/App.svelte

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import Dropdown from '../common/Dropdown.svelte';
1616
import OverflowMenu from '../common/OverflowMenu.svelte';
1717
import FileIcon from '../common/icons/FileIcon.svelte';
18+
import ErrorDisabledActionButtons from '../common/ErrorDisabledActionButtons.svelte';
1819
1920
import type { KindedOptions, Kind, Contract, OptionsErrorMessages } from '@openzeppelin/wizard-cairo-alpha';
2021
import { ContractBuilder, buildGeneric, printContract, sanitizeKind, OptionsError } from '@openzeppelin/wizard-cairo-alpha';
@@ -88,6 +89,8 @@
8889
$: code = printContract(contract);
8990
$: highlightedCode = injectHyperlinks(hljs.highlight(code, {language: 'cairo'}).value);
9091
92+
$: hasErrors = errors[tab] !== undefined;
93+
9194
const language = 'cairo';
9295
9396
let copied = false;
@@ -141,6 +144,9 @@
141144
</OverflowMenu>
142145
</div>
143146

147+
{#if hasErrors}
148+
<ErrorDisabledActionButtons />
149+
{:else}
144150
<div class="action flex flex-row gap-2 shrink-0">
145151
<button class="action-button p-3 min-w-[40px]" on:click={copyHandler} title="Copy to Clipboard">
146152
{#if copied}
@@ -165,6 +171,7 @@
165171
</button>
166172
</Dropdown>
167173
</div>
174+
{/if}
168175
</div>
169176

170177
<div class="flex flex-row grow">
@@ -227,15 +234,6 @@
227234
background-color: transparent;
228235
}
229236
230-
.action-button {
231-
padding: 7px;
232-
border-radius: 20px;
233-
transition: background-color ease-in-out .2s;
234-
}
235-
.with-text {
236-
padding-right: var(--size-3);
237-
}
238-
239237
.tab button:hover, :global(.overflow-btn):hover {
240238
background-color: var(--gray-2);
241239
}
@@ -250,7 +248,11 @@
250248
order: unset;
251249
}
252250
253-
.action-button {
251+
:global(.action-button) {
252+
padding: 7px;
253+
border-radius: 20px;
254+
transition: background-color ease-in-out .2s;
255+
254256
background-color: var(--gray-1);
255257
border: 1px solid var(--gray-3);
256258
color: var(--gray-6);
@@ -265,10 +267,18 @@
265267
}
266268
267269
:global(.icon) {
268-
margin-right: 0 var(--size-1);
270+
margin: 0 var(--size-1);
269271
}
270272
}
271273
274+
:global(.action-button.disabled) {
275+
color: var(--gray-4);
276+
}
277+
278+
:global(.with-text) {
279+
padding-right: var(--size-3);
280+
}
281+
272282
.controls {
273283
background-color: white;
274284
padding: var(--size-4);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<script lang="ts">
2+
import CopyIcon from './icons/CopyIcon.svelte';
3+
import DownloadIcon from './icons/DownloadIcon.svelte';
4+
import Tooltip from './Tooltip.svelte';
5+
</script>
6+
7+
<!-- Fake Copy and Download buttons for display when there are errors in the input options -->
8+
<div class="action flex flex-row gap-2 shrink-0">
9+
<Tooltip
10+
let:trigger
11+
theme="light-red border"
12+
hideOnClick={false}
13+
interactive
14+
>
15+
<button
16+
use:trigger
17+
class="action-button p-3 min-w-[40px]"
18+
class:disabled={true}
19+
>
20+
<CopyIcon />
21+
</button>
22+
<div slot="content">
23+
<p>There are errors in the input options.</p>
24+
<p>Fix them to continue.</p>
25+
</div>
26+
</Tooltip>
27+
<Tooltip
28+
let:trigger
29+
theme="light-red border"
30+
hideOnClick={false}
31+
interactive
32+
>
33+
<button
34+
use:trigger
35+
class="action-button with-text"
36+
class:disabled={true}
37+
>
38+
<DownloadIcon />
39+
Download
40+
</button>
41+
<div slot="content">
42+
<p>There are errors in the input options.</p>
43+
<p>Fix them to continue.</p>
44+
</div>
45+
</Tooltip>
46+
</div>

0 commit comments

Comments
 (0)