Re-enabled copy feedback and extracted it to it's own component. Still WIP, but further work is still waiting on better InkScape

This commit is contained in:
Gnarwhal 2024-09-19 19:45:59 +01:00
parent 951760b619
commit 92a63d0a7f
Signed by: Gnarwhal
GPG key ID: 80DB5B37E4C96776
7 changed files with 24 additions and 39 deletions

View file

@ -0,0 +1,17 @@
'use client'
import { useState } from 'react';
import * as style from './copy.css';
export default function Copy({ className, text, children }: { className?: string, text: string, children: React.ReactNode }) {
const [copied, set_copied ] = useState(false);
function make_copy_text(text: string) {
return () => {
navigator.clipboard.writeText(text);
set_copied(true);
setTimeout(() => { set_copied(false); }, 2000);
};
}
return <button onClick={make_copy_text(text)} className={`${style.copy} ${className ?? ''}`}>{copied ? '[ Copied ]' : '[ Copy ]'} {children}</button>
}