Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: require a filename for save as dialog #57

Merged
merged 8 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/lib/components/core/header/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ import {
faVolumeHigh,
faVolumeXmark,
} from "@fortawesome/free-solid-svg-icons";
import { Xml, serialization } from "blockly";
import { serialization } from "blockly";
import JSZip from "jszip";
import type { Writable } from "svelte/store";
import { get } from "svelte/store";
import MicroPythonIO from "../../../micropython";
import About from "../popups/popups/About.svelte";
Expand Down Expand Up @@ -100,6 +101,7 @@ async function saveProjectAs() {
name: "SAVEAS",
placeholder: "GIVE_FILENAME",
confirm: "SAVE",
requireValue: true,
},
allowInteraction: false,
});
Expand Down
61 changes: 35 additions & 26 deletions src/lib/components/core/popups/popups/Prompt.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ interface Props {
placeholder: string;
confirm: string;
value?: string;
requireValue?: boolean;
}
let { name, placeholder, confirm, value = $bindable("") }: Props = $props();

let {
name,
placeholder,
confirm,
value = $bindable(""),
requireValue = false,
}: Props = $props();
const popupState = getContext<Writable<PopupState>>("state");

function cancel() {
Expand All @@ -30,32 +38,33 @@ function onsubmit(event: SubmitEvent) {
</script>

<form class="content" {onsubmit}>
<h2>{$_(name)}</h2>
<TextInput
bind:value
placeholder={$_(placeholder)}
mode={"secondary"}
rounded={true}
focus={true}
/>
<div class="actions">
<Button onclick={cancel} mode={"secondary"} name={$_("CANCEL")} />
<Button onclick={save} mode={"primary"} name={$_(confirm)} />
</div>
<h2>{$_(name)}</h2>
<TextInput
bind:value
placeholder={$_(placeholder)}
mode={"secondary"}
rounded={true}
focus={true}
required={requireValue}
/>
<div class="actions">
<Button onclick={cancel} mode={"secondary"} name={$_("CANCEL")}/>
<Button type="submit" mode={"primary"} name={$_(confirm)}/>
</div>
</form>

<style>
.content {
padding: 20px;
display: flex;
flex-direction: column;
min-width: 400px;
text-align: center;
}

.actions {
display: flex;
justify-content: space-between;
margin-top: 20px;
}
.content {
padding: 20px;
display: flex;
flex-direction: column;
min-width: 400px;
text-align: center;
}

.actions {
display: flex;
justify-content: space-between;
margin-top: 20px;
}
</style>
126 changes: 67 additions & 59 deletions src/lib/components/ui/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ interface Props {
disabled?: boolean;
mode: "primary" | "secondary" | "outlined" | "accent";
bold?: boolean;
type?: "button" | "submit";
}

const {
name,
mode,
Expand All @@ -22,11 +24,13 @@ const {
bold,
icon,
disabled,
type = "button",
}: Props = $props();

let btn: HTMLButtonElement = $state();

const open = writable(false);

function onContext() {
if (!context) return;

Expand All @@ -35,70 +39,74 @@ function onContext() {
</script>

{#if $open}
<ContextMenu {open} source={btn} content={context} />
<ContextMenu {open} source={btn} content={context}/>
{/if}

<button
bind:this={btn}
{onclick}
{disabled}
type="button"
class="btn"
class:primary={mode === "primary"}
class:secondary={mode === "secondary"}
class:outlined={mode === "outlined"}
class:accent={mode === "accent"}
class:bold
bind:this={btn}
{onclick}
{disabled}
{type}
class="btn"
class:primary={mode === "primary"}
class:secondary={mode === "secondary"}
class:outlined={mode === "outlined"}
class:accent={mode === "accent"}
class:bold
>
{#if icon}
{#if typeof icon === "string"}
<img class="icon" src={icon} alt="Icon" />
{:else}
<Fa {icon} />
{/if}
{/if}
{#if name}{name}{/if}
{#if icon}
{#if typeof icon === "string"}
<img class="icon" src={icon} alt="Icon"/>
{:else}
<Fa {icon}/>
{/if}
{/if}
{#if name}{name}{/if}
</button>

<style>
.btn {
display: flex;
gap: 5px;
align-items: center;
cursor: pointer;
border-radius: 20px;
background: none;
border: none;
padding: 10px 15px;
}

.icon {
height: 1em;
}

.primary {
background: var(--primary);
color: var(--on-primary);
}
.secondary {
background: var(--secondary);
color: var(--on-secondary);
}
.outlined {
border: 1px solid var(--accent);
color: var(--on-primary);
}
.accent {
background: var(--accent);
color: var(--on-accent);
}
.bold {
font-weight: bolder;
font-size: 1.1em;
}

.btn[disabled] {
filter: opacity(.5);
cursor: unset;
}
.btn {
display: flex;
gap: 5px;
align-items: center;
cursor: pointer;
border-radius: 20px;
background: none;
border: none;
padding: 10px 15px;
}

.icon {
height: 1em;
}

.primary {
background: var(--primary);
color: var(--on-primary);
}

.secondary {
background: var(--secondary);
color: var(--on-secondary);
}

.outlined {
border: 1px solid var(--accent);
color: var(--on-primary);
}

.accent {
background: var(--accent);
color: var(--on-accent);
}

.bold {
font-weight: bolder;
font-size: 1.1em;
}

.btn[disabled] {
filter: opacity(.5);
cursor: unset;
}
</style>
73 changes: 40 additions & 33 deletions src/lib/components/ui/TextInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ interface Props {
mode: "primary" | "secondary";
rounded: boolean;
focus?: boolean;
required?: boolean;
}

let {
placeholder,
value = $bindable(""),
mode,
rounded,
focus,
required,
}: Props = $props();

let input: HTMLInputElement;
Expand All @@ -23,42 +26,46 @@ onMount(() => {
</script>

<input
bind:this={input}
class="input"
type="text"
{placeholder}
bind:value
class:primary={mode === "primary"}
class:secondary={mode === "secondary"}
class:rounded
bind:this={input}
class="input"
type="text"
{placeholder}
bind:value
class:primary={mode === "primary"}
class:secondary={mode === "secondary"}
class:rounded
{required}
/>

<style>
.input {
border: none;
padding: 5px 10px;
margin: 0;
width: 100%;
outline: 0;
font-size: 1em;
}
.input {
border: none;
padding: 5px 10px;
margin: 0;
width: 100%;
outline: 0;
font-size: 1em;
}

.primary {
background: var(--primary);
color: var(--on-primary);
}

.secondary {
background: var(--secondary);
color: var(--on-secondary);
}

.rounded {
border-radius: 20px;
}

.primary {
background: var(--primary);
color: var(--on-primary);
}
.secondary {
background: var(--secondary);
color: var(--on-secondary);
}
.rounded {
border-radius: 20px;
}
.primary::placeholder {
color: var(--text-muted);
}

.primary::placeholder {
color: var(--text-muted);
}
.secondary::placeholder {
color: var(--on-secondary-muted);
}
.secondary::placeholder {
color: var(--on-secondary-muted);
}
</style>