mirror of
https://github.com/wukko/cobalt.git
synced 2025-02-15 15:26:34 +01:00
web/SettingsInput: hide sensitive input & allow to show it with a button
also fixed padding & svg rendering in safari
This commit is contained in:
parent
62dccf7b51
commit
c5d8d33870
3 changed files with 64 additions and 12 deletions
|
@ -17,5 +17,7 @@
|
||||||
"export": "export",
|
"export": "export",
|
||||||
"yes": "yes",
|
"yes": "yes",
|
||||||
"no": "no",
|
"no": "no",
|
||||||
"clear": "clear"
|
"clear": "clear",
|
||||||
|
"show_input": "show input",
|
||||||
|
"hide_input": "hide input"
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,17 +15,18 @@
|
||||||
import IconX from "@tabler/icons-svelte/IconX.svelte";
|
import IconX from "@tabler/icons-svelte/IconX.svelte";
|
||||||
import IconCheck from "@tabler/icons-svelte/IconCheck.svelte";
|
import IconCheck from "@tabler/icons-svelte/IconCheck.svelte";
|
||||||
|
|
||||||
|
import IconEye from "@tabler/icons-svelte/IconEye.svelte";
|
||||||
|
import IconEyeClosed from "@tabler/icons-svelte/IconEyeClosed.svelte";
|
||||||
|
|
||||||
export let settingId: Id;
|
export let settingId: Id;
|
||||||
export let settingContext: Context;
|
export let settingContext: Context;
|
||||||
export let placeholder: string;
|
export let placeholder: string;
|
||||||
export let altText: string;
|
export let altText: string;
|
||||||
export let type: "url" | "uuid" = "url";
|
export let type: "url" | "uuid" = "url";
|
||||||
|
|
||||||
export let isPassword = false;
|
export let sensitive = false;
|
||||||
export let showInstanceWarning = false;
|
export let showInstanceWarning = false;
|
||||||
|
|
||||||
let inputType = isPassword ? "password" : "text";
|
|
||||||
|
|
||||||
const regex = {
|
const regex = {
|
||||||
url: "https?:\\/\\/[a-z0-9.\\-]+(:\\d+)?/?",
|
url: "https?:\\/\\/[a-z0-9.\\-]+(:\\d+)?/?",
|
||||||
uuid: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$",
|
uuid: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$",
|
||||||
|
@ -36,6 +37,10 @@
|
||||||
let inputFocused = false;
|
let inputFocused = false;
|
||||||
let validInput = false;
|
let validInput = false;
|
||||||
|
|
||||||
|
let inputHidden = true;
|
||||||
|
|
||||||
|
$: inputType = sensitive && inputHidden ? "password" : "text";
|
||||||
|
|
||||||
const writeToSettings = (value: string, type: "url" | "uuid" | "text") => {
|
const writeToSettings = (value: string, type: "url" | "uuid" | "text") => {
|
||||||
updateSetting({
|
updateSetting({
|
||||||
[settingContext]: {
|
[settingContext]: {
|
||||||
|
@ -62,13 +67,20 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="settings-input-holder">
|
<div id="settings-input-holder">
|
||||||
<div id="input-container" class:focused={inputFocused} aria-hidden="false">
|
<div
|
||||||
|
id="input-container"
|
||||||
|
class:focused={inputFocused}
|
||||||
|
class:extra-button={sensitive && inputValue.length > 0}
|
||||||
|
aria-hidden="false"
|
||||||
|
>
|
||||||
<input
|
<input
|
||||||
id="input-box"
|
id="input-box"
|
||||||
bind:this={input}
|
bind:this={input}
|
||||||
bind:value={inputValue}
|
bind:value={inputValue}
|
||||||
on:input={() => (validInput = input.checkValidity())}
|
on:input={() => {
|
||||||
on:input={() => (inputFocused = true)}
|
validInput = input.checkValidity();
|
||||||
|
inputFocused = true;
|
||||||
|
}}
|
||||||
on:focus={() => (inputFocused = true)}
|
on:focus={() => (inputFocused = true)}
|
||||||
on:blur={() => (inputFocused = false)}
|
on:blur={() => (inputFocused = false)}
|
||||||
spellcheck="false"
|
spellcheck="false"
|
||||||
|
@ -78,8 +90,7 @@
|
||||||
pattern={regex[type]}
|
pattern={regex[type]}
|
||||||
aria-label={altText}
|
aria-label={altText}
|
||||||
aria-hidden="false"
|
aria-hidden="false"
|
||||||
|
{...{ type: inputType }}
|
||||||
{ ...{ type: inputType } }
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{#if inputValue.length === 0}
|
{#if inputValue.length === 0}
|
||||||
|
@ -87,6 +98,22 @@
|
||||||
{placeholder}
|
{placeholder}
|
||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if sensitive && inputValue.length > 0}
|
||||||
|
<button
|
||||||
|
class="input-inner-button"
|
||||||
|
on:click={() => (inputHidden = !inputHidden)}
|
||||||
|
aria-label={$t(
|
||||||
|
inputHidden ? "button.show_input" : "button.hide_input"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{#if inputHidden}
|
||||||
|
<IconEye />
|
||||||
|
{:else}
|
||||||
|
<IconEyeClosed />
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="settings-input-buttons">
|
<div id="settings-input-buttons">
|
||||||
|
@ -117,7 +144,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
#input-container {
|
#input-container {
|
||||||
padding: 0 18px;
|
padding: 0 16px;
|
||||||
border-radius: var(--border-radius);
|
border-radius: var(--border-radius);
|
||||||
color: var(--secondary);
|
color: var(--secondary);
|
||||||
background-color: var(--button);
|
background-color: var(--button);
|
||||||
|
@ -129,6 +156,10 @@
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#input-container.extra-button {
|
||||||
|
padding-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
#input-container,
|
#input-container,
|
||||||
#input-box {
|
#input-box {
|
||||||
font-size: 13.5px;
|
font-size: 13.5px;
|
||||||
|
@ -182,11 +213,30 @@
|
||||||
.settings-input-button :global(svg) {
|
.settings-input-button :global(svg) {
|
||||||
height: 21px;
|
height: 21px;
|
||||||
width: 21px;
|
width: 21px;
|
||||||
stroke-width: 1.5px;
|
stroke-width: 1.8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings-input-button[disabled] {
|
.settings-input-button[disabled] {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.input-inner-button {
|
||||||
|
height: 34px;
|
||||||
|
width: 34px;
|
||||||
|
padding: 0;
|
||||||
|
box-shadow: none;
|
||||||
|
/* 4px is padding outside of the button */
|
||||||
|
border-radius: calc(var(--border-radius) - 4px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-inner-button :global(svg) {
|
||||||
|
height: 18px;
|
||||||
|
width: 18px;
|
||||||
|
stroke-width: 1.8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(svg) {
|
||||||
|
will-change: transform;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
placeholder="00000000-0000-0000-0000-000000000000"
|
placeholder="00000000-0000-0000-0000-000000000000"
|
||||||
altText={$t("settings.processing.access_key.input.alt_text")}
|
altText={$t("settings.processing.access_key.input.alt_text")}
|
||||||
type="uuid"
|
type="uuid"
|
||||||
isPassword
|
sensitive
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue