diff options
author | 2021-09-06 01:23:19 -0700 | |
---|---|---|
committer | 2021-09-06 01:23:19 -0700 | |
commit | 6185f9f7b15908b48f9ae2e1d532634f5b59c9f9 (patch) | |
tree | 12ec4f4a8a469a7d92f2a127ed2e4d34013f6e7c /docs/src/components/Examples/Codebar.tsx | |
parent | e686c3c50469d18db93da7ce79ddcac8659c3166 (diff) | |
parent | 6dc05575a65bf6bdc6f52848d274b1f333a36076 (diff) | |
download | astro-6185f9f7b15908b48f9ae2e1d532634f5b59c9f9.tar.gz astro-6185f9f7b15908b48f9ae2e1d532634f5b59c9f9.tar.zst astro-6185f9f7b15908b48f9ae2e1d532634f5b59c9f9.zip |
Docs/example and templates v2 (#1100)
Diffstat (limited to 'docs/src/components/Examples/Codebar.tsx')
-rw-r--r-- | docs/src/components/Examples/Codebar.tsx | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/docs/src/components/Examples/Codebar.tsx b/docs/src/components/Examples/Codebar.tsx new file mode 100644 index 000000000..f2bca6b8d --- /dev/null +++ b/docs/src/components/Examples/Codebar.tsx @@ -0,0 +1,43 @@ +import type { FunctionalComponent } from 'preact'; +import { h, Fragment } from 'preact'; +import{useState,useRef,useEffect} from 'preact/hooks' + +export type CodeBar ={ + content:string + command:string +} + +const CodeBar:FunctionalComponent=({content,command})=>{ + const [clicked,setClicked]=useState(false) + const [titleTxt,setTitleTxt] = useState("Copy Command to Clipboard") + useEffect(()=>{ + const timeout = setTimeout(()=>{ + setClicked(false) + setTitleTxt("Copy Command to Clipboard") + },1500) + return ()=> clearTimeout(timeout) + },[clicked]) + /** + * + */ + function onClick(e){ + setClicked(true) + setTitleTxt("Copied to Clipboard!") + const titleAttr= e.target + const clipboard = navigator.clipboard + return clipboard.writeText(`${command}`) + } + + return( + <div style="cursor:pointer;" onClick={onClick} title={titleTxt} > + <code > + {content} + </code> + </div> + ) +} + +export default CodeBar + + + |