11import { Layer } from "@/_lib/interfaces/layer" ;
22import { Dispatch , SetStateAction , useMemo } from "react" ;
33import { IconButton } from "@/_components/buttons/icon-button" ;
4- import CloseIcon from "@/_icons/close-icon" ;
4+ import { useTranslations } from "next-intl" ;
5+ import KeyboardArrowLeftIcon from "@/_icons/keyboard-arrow-left" ;
56
67export default function LayerMenu ( {
78 className,
@@ -16,6 +17,8 @@ export default function LayerMenu({
1617 visible : boolean ;
1718 setVisible : ( visible : boolean ) => void ;
1819} ) {
20+ const t = useTranslations ( "LayerMenu" ) ;
21+
1922 function handleOnChange ( key : string , layer : Layer ) {
2023 layer . visible = ! layer . visible ;
2124 setLayers ( new Map ( layers . set ( key , layer ) ) ) ;
@@ -36,53 +39,50 @@ export default function LayerMenu({
3639 }
3740
3841 return (
39- < menu
40- style = { { height : "calc(100vh - 19rem)" } }
41- className = { `${ className } ${ visible ? "left-0" : "-left-60" } w-48 text-sm font-medium text-gray-900 dark:text-white bg-white dark:bg-black border border-gray-200 dark:border-gray-700 border-top-0 absolute z-50 transition-all duration-700` }
42+ < div
43+ className = { `${ className } ${ visible ? "left-0" : "-left-60" } w-48 ${ layers . size > 0 && layers . size * 40 < 200 ? "h-fit" : "h-[calc(100vh-12rem)]" } text-sm font-medium text-gray-900 dark:text-white bg-white dark:bg-black border border-gray-200 dark:border-gray-700 border-top-0 absolute z-50 transition-all duration-700` }
4244 >
43- < li
45+ < h1
4446 key = "global"
45- className = "w-full border-b border-gray-200 dark:border-gray-700 rounded-t-lg "
47+ className = "w-fullrounded-t-lg border-b border-gray-200 dark:border-gray-700"
4648 >
47- < div className = "flex items-center justify-between ps-3" >
48- < div className = "flex items-center" >
49- < input
50- id = "global"
51- type = "checkbox"
52- className = "w-4 h-4 accent-purple-600 bg-gray-100 border-gray-300 dark:border-gray-700 rounded focus:ring-blue-500 dark:focus:ring-blue-800"
53- checked = { globalCheck }
54- style = { { width : 14 } }
55- onChange = { ( e ) => handleGlobalChange ( e . target . checked ) }
56- />
57- < h6 className = "ml-2" > Layers</ h6 >
58- </ div >
49+ < div className = "flex items-center space-between" >
5950 < IconButton onClick = { ( ) => setVisible ( false ) } >
60- < CloseIcon ariaLabel = "close" />
51+ < KeyboardArrowLeftIcon ariaLabel = "close" />
6152 </ IconButton >
53+ < h6 className = "ml-2" > { t ( "title" ) } </ h6 >
54+ < button
55+ className = "text-purple-600 ml-auto px-4 hover:text-purple-800 "
56+ onClick = { ( ) => handleGlobalChange ( ! globalCheck ) }
57+ >
58+ { globalCheck ? t ( "hideAll" ) : t ( "showAll" ) }
59+ </ button >
6260 </ div >
63- </ li >
64- { [ ...layers . entries ( ) ] . map ( ( e ) => (
65- < li
66- key = { e [ 0 ] }
67- className = "w-full border-b border-gray-200 dark:border-gray-700 rounded-t-lg"
68- >
69- < div className = "flex items-center ps-3" >
70- < input
71- id = { e [ 0 ] }
72- type = "checkbox"
73- className = "w-4 h-4 accent-purple-600 bg-gray-100 border-gray-300 dark:border-gray-700 rounded focus:ring-blue-500 dark:focus:ring-blue-800"
74- checked = { e [ 1 ] . visible }
75- onChange = { ( ) => handleOnChange ( e [ 0 ] , e [ 1 ] ) }
76- > </ input >
77- < label
78- htmlFor = { e [ 0 ] }
79- className = "w-full py-3 ms-2 text-sm font-medium text-gray-90"
80- >
81- { e [ 1 ] . name }
82- </ label >
83- </ div >
84- </ li >
85- ) ) }
86- </ menu >
61+ </ h1 >
62+
63+ < menu
64+ className = { `w-full ${ layers . size > 0 && layers . size * 40 > 200 ? "h-[calc(100vh-15rem)] overflow-y-auto scrollbar" : "" } ` }
65+ >
66+ { [ ...layers . entries ( ) ] . map ( ( e ) => (
67+ < li key = { e [ 0 ] } className = "w-full rounded-t-lg" >
68+ < div className = "flex items-center ps-3" >
69+ < input
70+ id = { e [ 0 ] }
71+ type = "checkbox"
72+ className = "w-4 h-4 accent-purple-600 rounded focus:ring-blue-500 dark:focus:ring-blue-800"
73+ checked = { e [ 1 ] . visible }
74+ onChange = { ( ) => handleOnChange ( e [ 0 ] , e [ 1 ] ) }
75+ > </ input >
76+ < label
77+ htmlFor = { e [ 0 ] }
78+ className = "w-full py-3 ms-2 text-sm font-medium text-gray-90"
79+ >
80+ { e [ 1 ] . name }
81+ </ label >
82+ </ div >
83+ </ li >
84+ ) ) }
85+ </ menu >
86+ </ div >
8787 ) ;
8888}
0 commit comments