2024-06-01 12:47:14 -05:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { autoGrowHeight } from '$lib/actions/autogrow';
|
|
|
|
|
import { shortcut } from '$lib/actions/shortcut';
|
|
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
content?: string;
|
|
|
|
|
class?: string;
|
|
|
|
|
onContentUpdate?: (newContent: string) => void;
|
|
|
|
|
placeholder?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let { content = '', class: className = '', onContentUpdate = () => null, placeholder = '' }: Props = $props();
|
2024-06-01 12:47:14 -05:00
|
|
|
|
2025-03-31 07:15:52 -07:00
|
|
|
let newContent = $derived(content);
|
2024-06-01 12:47:14 -05:00
|
|
|
|
|
|
|
|
const updateContent = () => {
|
|
|
|
|
if (content === newContent) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
onContentUpdate(newContent);
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<textarea
|
2024-11-14 16:59:30 +01:00
|
|
|
bind:value={newContent}
|
2024-06-01 12:47:14 -05:00
|
|
|
class="resize-none {className}"
|
2024-11-14 08:43:25 -06:00
|
|
|
onfocusout={updateContent}
|
2024-06-01 12:47:14 -05:00
|
|
|
{placeholder}
|
|
|
|
|
use:shortcut={{
|
|
|
|
|
shortcut: { key: 'Enter', ctrl: true },
|
|
|
|
|
onShortcut: (e) => e.currentTarget.blur(),
|
|
|
|
|
}}
|
2024-11-14 16:59:30 +01:00
|
|
|
use:autoGrowHeight={{ value: newContent }}
|
2024-06-01 12:47:14 -05:00
|
|
|
data-testid="autogrow-textarea">{content}</textarea
|
|
|
|
|
>
|