Skip to content

Commit

Permalink
add choice component
Browse files Browse the repository at this point in the history
  • Loading branch information
dlaxcess committed Feb 1, 2024
1 parent 3d97f56 commit 7e012c4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 36 deletions.
4 changes: 3 additions & 1 deletion svelte/components/Input/Config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ export default class Config {
default: { display: "Active storage", value: "ipfs" },
fieldsGroups: {
ipfs: {
display: "IPFS",
editable: false,
fields: [
{ key: "apiEndPoint", value: "", fixed: true, undeletable: true },
{ key: "apiKey", value: "", fixed: true, undeletable: true }
]
},
swarm: {
display: "Swarm",
editable: false,
fields: [
{ key: "apiEndPoint", value: "", fixed: true, undeletable: true },
Expand Down Expand Up @@ -97,7 +99,7 @@ export default class Config {
document.dispatchEvent(this.propertyChangedEvent);
}


//////////////////////////////////////////////
// actual localStorage storage structure
let storage = {
Expand Down
38 changes: 38 additions & 0 deletions svelte/components/Input/Config/ConfigFieldChoice.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<script lang="ts">
import { clickOutside } from "@helpers/clickOutside";
export let attributes;
export let namespace;
$: attribute = attributes[namespace];
$: defaultChoice = attribute.default.value;
let open = false;
const handleToggleOpen = () => (open = !open);
</script>

<div
class="select-wrapper select-network"
use:clickOutside={() => (open = false)}
on:click={handleToggleOpen}
on:keydown={handleToggleOpen}
>
<div class="select" class:open>
<div class="select-trigger">
<span>{attribute.fieldsGroups[defaultChoice].display}</span>
</div>

<div class="custom-options">
{#each Object.entries(attribute.fieldsGroups) as [key, choice]}
<span
class="custom-option {key == attribute.default.value && 'selected'}"
on:click={() => (attributes[namespace].default.value = key)}
on:keydown={() => (attributes[namespace].default.value = key)}
>
{choice.display}
</span>
{/each}
</div>
</div>
</div>
37 changes: 2 additions & 35 deletions svelte/components/Input/Config/InputConfigFields.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import type { UserConfig } from "./configTypes";
import { onMount } from "svelte";
import { clickOutside } from "@helpers/clickOutside";
import Config from "./Config";
import ConfigFieldChoice from "./ConfigFieldChoice.svelte";
import ConfigFieldsLoop from "./ConfigFieldsLoop.svelte";
/////////////////////////////////////////////////
Expand Down Expand Up @@ -103,10 +103,6 @@
};
$: console.log("attributes refresh:", attributes);
let open = false;
const handleToggleOpen = () => (open = !open);
</script>

<div class="section">
Expand All @@ -116,36 +112,7 @@
<div class="titre">{attribute.display}</div>
{/if}
{#if Object.keys(attribute.fieldsGroups).length > 1}
<div
class="select-wrapper select-network"
use:clickOutside={() => (open = false)}
on:click={handleToggleOpen}
on:keydown={handleToggleOpen}
>
<div class="select" class:open>
<div class="select-trigger">
<span>{attribute.default.value}</span>
</div>

<div class="custom-options">
<span
class="custom-option {'ipfs' == attribute.default.value && 'selected'}"
on:click={() => (attribute.default.value = "ipfs")}
on:keydown={() => (attribute.default.value = "ipfs")}
>
IPFS
</span>

<span
class="custom-option {'swarm' == attribute.default.value && 'selected'}"
on:click={() => (attribute.default.value = "swarm")}
on:keydown={() => (attribute.default.value = "swarm")}
>
Swarm
</span>
</div>
</div>
</div>
<ConfigFieldChoice bind:attributes {namespace} />
{/if}
<ConfigFieldsLoop
bind:attributesObject
Expand Down

0 comments on commit 7e012c4

Please sign in to comment.