mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 07:36:01 +00:00
42 lines
1.1 KiB
Svelte
42 lines
1.1 KiB
Svelte
<script lang="ts">
|
|
import FontIcon from '../icons/FontIcon.svelte';
|
|
|
|
import InlineButton from '../buttons/InlineButton.svelte';
|
|
|
|
import { getFormContext } from './FormProviderCore.svelte';
|
|
import TextField from './TextField.svelte';
|
|
import { _t } from '../translations';
|
|
|
|
export let name;
|
|
export let disabled = false;
|
|
export let saveOnInput = false;
|
|
|
|
const { values, setFieldValue } = getFormContext();
|
|
|
|
let showPassword = false;
|
|
|
|
$: value = $values[name];
|
|
$: isCrypted = value && value.startsWith('crypt:');
|
|
</script>
|
|
|
|
<div class="flex">
|
|
<TextField
|
|
{...$$restProps}
|
|
{disabled}
|
|
value={isCrypted ? '' : value}
|
|
on:change={e => setFieldValue(name, e.target['value'])}
|
|
on:input={e => {
|
|
if (saveOnInput) {
|
|
setFieldValue(name, e.target['value']);
|
|
}
|
|
}}
|
|
placeholder={isCrypted ? _t('common.passwordEncrypted', { defaultMessage: 'Password is encrypted' }) : undefined}
|
|
type={isCrypted || showPassword ? 'text' : 'password'}
|
|
/>
|
|
{#if !isCrypted}
|
|
<InlineButton on:click={() => (showPassword = !showPassword)} {disabled}>
|
|
<FontIcon icon="icon eye" />
|
|
</InlineButton>
|
|
{/if}
|
|
</div>
|