Skip to content

Commit

Permalink
Show button as disabled when form submission is in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
amosjyng committed Jun 18, 2024
1 parent 0bacb42 commit 0da00c4
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 6 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src-svelte/src/lib/controls/Button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ export const Regular: StoryObj = Template.bind({}) as any;
Regular.args = {
text: "Simulate",
};

export const Disabled: StoryObj = Template.bind({}) as any;
Disabled.args = {
text: "Simulate",
disabled: true,
};
20 changes: 20 additions & 0 deletions src-svelte/src/lib/controls/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { createEventDispatcher } from "svelte";
export let unwrapped = false;
export let disabled = false;
export let leftEnd = false;
export let rightEnd = false;
export let ariaLabel: string | undefined = undefined;
Expand All @@ -17,6 +18,7 @@
class="cut-corners inner"
class:left-end={leftEnd}
class:right-end={rightEnd}
class:disabled
type="submit"
aria-label={ariaLabel}
on:click={handleClick}
Expand All @@ -28,6 +30,7 @@
class="cut-corners outer"
class:left-end={leftEnd}
class:right-end={rightEnd}
class:disabled
type="submit"
aria-label={ariaLabel}
on:click={handleClick}
Expand Down Expand Up @@ -75,6 +78,23 @@
transform: translateY(0.08rem) scale(0.98);
}
.inner.disabled,
.disabled .inner {
filter: grayscale(1);
color: var(--color-faded);
pointer-events: none;
}
.inner.disabled:hover,
.disabled .inner:hover {
filter: grayscale(1);
}
.inner.disabled:active,
.disabled .inner:active {
transform: none;
}
.outer {
--background-color: #eee;
display: inline-block;
Expand Down
2 changes: 1 addition & 1 deletion src-svelte/src/lib/controls/ButtonView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
export let text: string;
</script>

<Button>{text}</Button>
<Button {...$$restProps}>{text}</Button>
18 changes: 18 additions & 0 deletions src-svelte/src/routes/api-calls/new/ApiCallEditor.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,21 @@ EditContinuedConversation.parameters = {
},
},
};

export const Busy: StoryObj = Template.bind({}) as any;
Busy.args = {
expectingResponse: true,
};
Busy.parameters = {
stores: {
apiCallEditing: {
canonicalRef: {
id: "c13c1e67-2de3-48de-a34c-a32079c03316",
snippet:
"Sure, here's a joke for you: Why don't scientists trust atoms? " +
"Because they make up everything!",
},
prompt: CONTINUE_CONVERSATION_CALL.request.prompt,
},
},
};
5 changes: 3 additions & 2 deletions src-svelte/src/routes/api-calls/new/ApiCallEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import { snackbarError } from "$lib/snackbar/Snackbar.svelte";
import { goto } from "$app/navigation";
let expectingResponse = false;
export let expectingResponse = false;
async function submitApiCall() {
if (expectingResponse) {
Expand Down Expand Up @@ -69,7 +69,8 @@
<PromptComponent editable bind:prompt={$prompt} />

<div class="action">
<Button on:click={submitApiCall}>Submit</Button>
<Button disabled={expectingResponse} on:click={submitApiCall}>Submit</Button
>
</div>
</InfoBox>

Expand Down
4 changes: 3 additions & 1 deletion src-svelte/src/routes/chat/Form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
bind:this={textareaInput}
bind:value={currentMessage}
/>
<Button ariaLabel="Send" unwrapped rightEnd><IconSend /></Button>
<Button ariaLabel="Send" disabled={chatBusy} unwrapped rightEnd
><IconSend /></Button
>
</form>

<style>
Expand Down
4 changes: 2 additions & 2 deletions src-svelte/src/routes/storybook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const components: ComponentTestConfig[] = [
},
{
path: ["reusable", "button"],
variants: ["regular"],
variants: ["regular", "disabled"],
},
{
path: ["reusable", "infobox"],
Expand Down Expand Up @@ -178,7 +178,7 @@ const components: ComponentTestConfig[] = [
},
{
path: ["screens", "llm-call", "new"],
variants: ["blank", "edit-continued-conversation"],
variants: ["blank", "edit-continued-conversation", "busy"],
screenshotEntireBody: true,
},
{
Expand Down

0 comments on commit 0da00c4

Please sign in to comment.