feat: add input setting type
This commit is contained in:
parent
25253c56fc
commit
e7dd4ddc7b
1 changed files with 52 additions and 0 deletions
52
client/src/lib/Apps/Settings/SettingsInput.svelte
Normal file
52
client/src/lib/Apps/Settings/SettingsInput.svelte
Normal file
|
@ -0,0 +1,52 @@
|
|||
<script lang="ts">
|
||||
import { onMount, tick } from 'svelte'
|
||||
import { settingsStore } from '../../stores/settingsStore'
|
||||
import type { SettingsStoreData } from '../../stores/settingsStore'
|
||||
import { tooltip as tooltipAction } from '@svelte-plugins/tooltips'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export let setting: keyof SettingsStoreData
|
||||
export let tooltip: string
|
||||
export let width: string = 'auto'
|
||||
|
||||
let value: string
|
||||
|
||||
const handleSubmit = async () => {
|
||||
await tick()
|
||||
// @ts-expect-error
|
||||
settingsStore.update(setting, value)
|
||||
}
|
||||
|
||||
const checkKeyPress = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Enter') {
|
||||
handleSubmit()
|
||||
}
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
await tick()
|
||||
// @ts-expect-error
|
||||
value = get(settingsStore)[setting]
|
||||
})
|
||||
</script>
|
||||
|
||||
<span class="flex flex-row gap-2">
|
||||
<input
|
||||
bind:value
|
||||
type="text"
|
||||
on:keydown={checkKeyPress}
|
||||
style="width: {width};"
|
||||
class="text-slate-800 rounded-lg p-0.5 text-center"
|
||||
/>
|
||||
<button
|
||||
class="bg-blue-500 px-4 py-2 rounded-lg hover:brightness-75 font-medium"
|
||||
on:click={handleSubmit}
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
<label
|
||||
class="text-xl text-slate-100 font-medium my-auto"
|
||||
use:tooltipAction={{ content: tooltip, action: 'hover', arrow: false }}
|
||||
for={setting}><slot /></label
|
||||
>
|
||||
</span>
|
Loading…
Reference in a new issue