11import React , { useState , useRef , useEffect } from "react" ;
2- import "./StructDownloadButton.css" ;
32
43const defaultFormats = [
54 { format : "cif" , label : "CIF" } ,
65 { format : "xsf" , label : "XSF" } ,
76 { format : "xyz" , label : "XYZ" } ,
87] ;
98
10- // one to one copy of the MCXD StructDownloadButton (w/css in .css file)
119export function StructDownloadButton ( props ) {
1210 const dl_url = `${ props . aiida_rest_url } /nodes/${ props . uuid } /download` ;
1311 const downloadFormats = props . download_formats || defaultFormats ;
1412
1513 const [ open , setOpen ] = useState ( false ) ;
1614 const ref = useRef ( null ) ;
1715
16+ // Close menu when clicking outside
1817 useEffect ( ( ) => {
1918 function handleClick ( e ) {
2019 if ( ref . current && ! ref . current . contains ( e . target ) ) {
@@ -26,12 +25,14 @@ export function StructDownloadButton(props) {
2625 } , [ ] ) ;
2726
2827 return (
29- < div ref = { ref } className = "download-wrapper" >
28+ < div ref = { ref } className = "ae:relative ae:inline-block" >
29+ { /* Download button */ }
3030 < button
3131 type = "button"
32- className = "download-button"
3332 title = "Download"
3433 onClick = { ( ) => setOpen ( ! open ) }
34+ className = "ae:bg-blue-600 ae:text-white ae:text-xs ae:px-1 ae:py-1 ae:rounded-md ae:cursor-pointer
35+ ae:hover:bg-blue-800 ae:focus:bg-blue-700 ae:focus:ring-3 ae:focus:ring-[#2563eb4d]"
3536 >
3637 < svg
3738 xmlns = "http://www.w3.org/2000/svg"
@@ -40,7 +41,7 @@ export function StructDownloadButton(props) {
4041 viewBox = "0 0 24 24"
4142 fill = "none"
4243 stroke = "currentColor"
43- strokeWidth = "1"
44+ strokeWidth = "1.25 "
4445 strokeLinecap = "round"
4546 strokeLinejoin = "round"
4647 >
@@ -50,16 +51,23 @@ export function StructDownloadButton(props) {
5051 </ svg >
5152 </ button >
5253
54+ { /* Dropdown menu */ }
5355 { open && (
54- < div className = "download-menu-container" >
55- < ul className = "download-menu" >
56- { downloadFormats . map ( ( { format, label } ) => (
57- < li key = { format } >
58- < a href = { `${ dl_url } ?download_format=${ format } ` } > { label } </ a >
59- </ li >
60- ) ) }
61- </ ul >
62- </ div >
56+ < ul
57+ className = "ae:absolute ae:top-full ae:left-1/2 ae:-translate-x-1/2 ae:mt-1 ae:min-w-max
58+ ae:border ae:border-gray-200 ae:rounded-md ae:shadow-md text-sm z-50"
59+ >
60+ { downloadFormats . map ( ( { format, label } ) => (
61+ < li key = { format } >
62+ < a
63+ href = { `${ dl_url } ?download_format=${ format } ` }
64+ className = "ae:block ae:px-3 ae:py-1 ae:text-gray-900 ae:hover:bg-gray-100 ae:whitespace-nowrap"
65+ >
66+ { label }
67+ </ a >
68+ </ li >
69+ ) ) }
70+ </ ul >
6371 ) }
6472 </ div >
6573 ) ;
0 commit comments