copy to clipboard

This commit is contained in:
2025-08-29 21:54:22 +02:00
parent c102970a0d
commit 3a6b1cfee7

View File

@@ -109,7 +109,6 @@ async def main():
# Copy button
with ui.row().classes('w-full justify-end q-gutter-sm'):
copy_button = ui.button('Copy to Clipboard', icon='content_copy').props('outline')
copy_button.disable()
# Action buttons
with ui.card().classes('w-full'):
@@ -136,8 +135,24 @@ async def main():
def update_char_count():
char_count_label.text = f'{len(input_text.value)} characters'
def mock_copy():
ui.notify('Text copied to clipboard (mockup)', type='positive')
async def copy_to_clipboard():
if output_text.value:
await ui.run_javascript(f'''
navigator.clipboard.writeText({repr(output_text.value)}).then(() => {{
// Success handled by notify below
}}).catch(() => {{
// Fallback for older browsers
const textArea = document.createElement('textarea');
textArea.value = {repr(output_text.value)};
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
}});
''')
ui.notify('Text copied to clipboard!', type='positive')
else:
ui.notify('No text to copy', type='warning')
def clear_all():
input_text.value = ''
@@ -150,7 +165,7 @@ async def main():
# Connect event handlers
input_text.on('input', update_char_count)
copy_button.on_click(mock_copy)
copy_button.on_click(copy_to_clipboard)
clear_button.on_click(clear_all)
# Footer