-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
202 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<script lang="ts"> | ||
import { clickOutside } from "@helpers/clickOutside"; | ||
import { fade } from "svelte/transition"; | ||
import InputConfigFields from "../Input/InputConfigFields.svelte"; | ||
let userConfig; | ||
let open = false; | ||
const toggle = () => (open = !open); | ||
</script> | ||
|
||
<button class="kre-nav-button" on:click|preventDefault={toggle} on:keydown={toggle}> | ||
<i class="fa fa-cog" aria-hidden="true" /><br /> | ||
Config | ||
</button> | ||
|
||
{#if open} | ||
<!-- Modal Config --> | ||
<div class="modal-window" transition:fade> | ||
<div class="modal-content" use:clickOutside={() => (open = false)} transition:fade> | ||
<span on:click={toggle} on:keydown={toggle} title="Close" class="btn modal-close"><i class="fa fa-times" /></span> | ||
|
||
<div class="modal-body"> | ||
<div class="titre"> | ||
<i class="fas fa-plus fa-left c-green" />Your Config | ||
</div> | ||
|
||
<InputConfigFields bind:userConfig /> | ||
</div> | ||
</div> | ||
</div> | ||
{/if} | ||
|
||
<style> | ||
button.kre-nav-button { | ||
background-color: transparent; | ||
border: none; | ||
cursor: pointer; | ||
} | ||
.modal-window { | ||
visibility: visible; | ||
opacity: 1; | ||
z-index: 1000; | ||
color: #1e1e43; | ||
pointer-events: auto; | ||
} | ||
.modal-content { | ||
min-height: 360px; | ||
} | ||
.modal-body { | ||
text-align: left; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<script lang="ts"> | ||
import type { Properties } from "@lib/common/types"; | ||
///////////////////////////////////////////////// | ||
// <InputConfigFields /> | ||
// Set User config | ||
///////////////////////////////////////////////// | ||
// let userConfig: Properties; | ||
let userConfig: { key: string; value: string }; | ||
let attributes = [{ key: "", value: "" }]; | ||
const saveConfig = () => { | ||
console.log("save userConfig:", userConfig); | ||
if (typeof localStorage !== "undefined") { | ||
for (const [key, value] of Object.entries(userConfig)) { | ||
console.log("saveConfig ~ key:", key, value); | ||
localStorage.setItem(key, value); | ||
} | ||
} | ||
}; | ||
$: attributes && handleProperties(); | ||
const handleProperties = () => { | ||
userConfig = attributes | ||
.filter((attribute) => attribute.key !== "" && attribute.value !== "") | ||
.reduce((allAttr, attr) => { | ||
return { | ||
...allAttr, | ||
[attr.key]: attr.value | ||
// [attr.key]: { key: attr.key, value: attr.value } | ||
}; | ||
}, {}); | ||
}; | ||
const addField = (): void => { | ||
attributes = [...attributes, { key: "", value: "" }]; | ||
}; | ||
const removeField = (i: number): void => { | ||
if (attributes.length > 1) { | ||
attributes = attributes.filter((_, index) => i !== index); | ||
} else { | ||
attributes[i] = { key: "", value: "" }; | ||
} | ||
}; | ||
$: console.log("attributes:", attributes); | ||
$: console.log("userConfig:", userConfig); | ||
</script> | ||
|
||
<div class="section"> | ||
<div class="titre">UserConfig</div> | ||
{#if attributes} | ||
{#each attributes as attribute, i} | ||
<div class="kre-section-small"> | ||
<input type="text" class="kre-field-outline" placeholder="add key" bind:value={attribute.key} /> | ||
<input type="text" class="kre-field-outline" placeholder="add value" bind:value={attribute.value} /> | ||
|
||
<button | ||
value="Remove" | ||
class="kre-delete-file {attributes.length < 2 ? 'disabled' : ''}" | ||
on:click={() => removeField(i)} | ||
> | ||
<i class="fa fa-trash" aria-hidden="true" /> | ||
</button> | ||
</div> | ||
{/each} | ||
{/if} | ||
|
||
<button class="kre-button-grey" on:click|preventDefault={addField} | ||
><i class="fa fa-plus fa-left" aria-hidden="true" />Add</button | ||
> | ||
|
||
<div class="txtright"> | ||
<button class="btn btn-default btn-sell" on:click|preventDefault={saveConfig}>Save</button> | ||
</div> | ||
</div> | ||
|
||
<style> | ||
.kre-section-small { | ||
display: flex; | ||
gap: 5px; | ||
align-items: center; | ||
} | ||
.kre-delete-file { | ||
background-color: #192146; | ||
border-radius: 50%; | ||
width: 35px; | ||
height: 35px; | ||
display: flex; | ||
cursor: pointer; | ||
} | ||
.kre-delete-file.disabled { | ||
opacity: 0.5; | ||
} | ||
.kre-delete-file i { | ||
color: white; | ||
margin: auto; | ||
} | ||
.kre-button-grey { | ||
border: 2px solid #9a9aa4; | ||
color: #9a9aa4; | ||
border-radius: 360px; | ||
cursor: pointer; | ||
display: inline-block; | ||
font-size: 15px; | ||
padding: 15px 25px; | ||
transition: all 0.3s ease-in-out; | ||
vertical-align: middle; | ||
background-color: white; | ||
} | ||
</style> |