-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
134 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,4 +58,4 @@ export const sxClassesRotationButton = { | |
height: '1.5em', | ||
color: 'primary.light', | ||
}, | ||
}; | ||
}; |
191 changes: 102 additions & 89 deletions
191
packages/geoview-core/src/core/components/legend-2/legend-overview/legend-layer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,102 @@ | ||
|
||
import { useTranslation } from 'react-i18next'; | ||
import { TypeDisplayLanguage, sxClasses } from '@/app'; | ||
import { Box, ListItem, Tooltip, ListItemText, ListItemIcon, IconButton, KeyboardArrowDownIcon, Collapse, List, KeyboardArrowUpIcon } from '@/ui'; | ||
import { TypeLegendLayer } from '../types'; | ||
import { useState } from 'react'; | ||
import { getSxClasses } from './legend-overview-styles'; | ||
import { useTheme } from '@mui/material'; | ||
|
||
interface LegendLayerProps { | ||
layer: TypeLegendLayer | ||
} | ||
|
||
export function LegendLayer(props: LegendLayerProps): JSX.Element { | ||
const { layer } = props; | ||
const { t, i18n } = useTranslation<string>(); | ||
const layerName = layer.layerName[i18n.language as TypeDisplayLanguage]; | ||
const theme = useTheme(); | ||
const sxClasses = getSxClasses(theme); | ||
const [isGroupOpen, setGroupOpen] = useState(true); | ||
|
||
|
||
/** | ||
* Handle expand/shrink of layer groups. | ||
*/ | ||
const handleExpandGroupClick = () => { | ||
setGroupOpen(!isGroupOpen); | ||
}; | ||
|
||
|
||
//renders the layers children, if any | ||
function renderChildren() { | ||
if(!layer.children?.length) { return null; } | ||
|
||
return ( | ||
<List sx={{ width: '100%', padding: '20px', margin:'20px 0px' }}> | ||
{layer.children.map((item) => <LegendLayer layer={item} /> )} | ||
</List> | ||
); | ||
} | ||
|
||
//renders the layers items if any | ||
function renderItems() { | ||
if(!layer.children?.length) { return null; } | ||
return ( | ||
<List sx={{ width: '100%' }}> | ||
{layer.children.map((item) => <LegendLayer layer={item} /> )} | ||
</List> | ||
); | ||
} | ||
|
||
function renderArrowButtons() { | ||
if(layer.children?.length || layer.items?.length) { | ||
return ( | ||
<ListItemIcon style={{ justifyContent: 'right' }}> | ||
<IconButton color="primary"> | ||
{isGroupOpen ? <KeyboardArrowDownIcon /> : <KeyboardArrowUpIcon />} | ||
</IconButton> | ||
</ListItemIcon> | ||
) | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
function renderCollapsible() { | ||
if(!(layer.children?.length || layer.items?.length)) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Collapse in={isGroupOpen} sx={sxClasses.collapsibleContainer} timeout="auto"> | ||
{renderChildren()} | ||
</Collapse> | ||
) | ||
} | ||
|
||
return ( | ||
<Box> | ||
<ListItem key={layerName} sx={sxClasses.legendLayerListItem} divider onClick={handleExpandGroupClick}> | ||
<Tooltip title={layerName} placement="top" enterDelay={1000}> | ||
<ListItemText primary={layerName} /> | ||
</Tooltip> | ||
{renderArrowButtons()} | ||
</ListItem> | ||
{renderCollapsible()} | ||
</Box> | ||
); | ||
} | ||
import { useTranslation } from 'react-i18next'; | ||
import { useState } from 'react'; | ||
import { useTheme } from '@mui/material'; | ||
import { TypeDisplayLanguage } from '@/app'; | ||
import { | ||
Box, | ||
ListItem, | ||
Tooltip, | ||
ListItemText, | ||
ListItemIcon, | ||
IconButton, | ||
KeyboardArrowDownIcon, | ||
Collapse, | ||
List, | ||
KeyboardArrowUpIcon, | ||
} from '@/ui'; | ||
import { TypeLegendLayer } from '../types'; | ||
import { getSxClasses } from './legend-overview-styles'; | ||
|
||
interface LegendLayerProps { | ||
layer: TypeLegendLayer; | ||
} | ||
|
||
export function LegendLayer(props: LegendLayerProps): JSX.Element { | ||
const { layer } = props; | ||
const { i18n } = useTranslation<string>(); | ||
const layerName = layer.layerName[i18n.language as TypeDisplayLanguage]; | ||
const theme = useTheme(); | ||
const sxClasses = getSxClasses(theme); | ||
const [isGroupOpen, setGroupOpen] = useState(true); | ||
|
||
/** | ||
* Handle expand/shrink of layer groups. | ||
*/ | ||
const handleExpandGroupClick = () => { | ||
setGroupOpen(!isGroupOpen); | ||
}; | ||
|
||
// renders the layers children, if any | ||
function renderChildren() { | ||
if (!layer.children?.length) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<List sx={{ width: '100%', padding: '20px', margin: '20px 0px' }}> | ||
{layer.children.map((item) => ( | ||
<LegendLayer layer={item} key={item.layerPath} /> | ||
))} | ||
</List> | ||
); | ||
} | ||
|
||
// renders the layers items if any | ||
/* function renderItems() { | ||
if (!layer.children?.length) { | ||
return null; | ||
} | ||
return ( | ||
<List sx={{ width: '100%' }}> | ||
{layer.children.map((item) => ( | ||
<LegendLayer layer={item} key={item.layerPath} /> | ||
))} | ||
</List> | ||
); | ||
} */ | ||
|
||
function renderArrowButtons() { | ||
if (layer.children?.length || layer.items?.length) { | ||
return ( | ||
<ListItemIcon style={{ justifyContent: 'right' }}> | ||
<IconButton color="primary">{isGroupOpen ? <KeyboardArrowDownIcon /> : <KeyboardArrowUpIcon />}</IconButton> | ||
</ListItemIcon> | ||
); | ||
} | ||
return null; | ||
} | ||
|
||
function renderCollapsible() { | ||
if (!(layer.children?.length || layer.items?.length)) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Collapse in={isGroupOpen} sx={sxClasses.collapsibleContainer} timeout="auto"> | ||
{renderChildren()} | ||
</Collapse> | ||
); | ||
} | ||
|
||
return ( | ||
<Box> | ||
<ListItem key={layerName} sx={sxClasses.legendLayerListItem} divider onClick={handleExpandGroupClick}> | ||
<Tooltip title={layerName} placement="top" enterDelay={1000}> | ||
<ListItemText primary={layerName} /> | ||
</Tooltip> | ||
{renderArrowButtons()} | ||
</ListItem> | ||
{renderCollapsible()} | ||
</Box> | ||
); | ||
} |
54 changes: 27 additions & 27 deletions
54
packages/geoview-core/src/core/components/legend-2/legend-overview/legend-overview-styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import { Theme } from '@mui/material/styles'; | ||
|
||
export const getSxClasses = (theme: Theme) => ({ | ||
container: { | ||
padding: '10px 0px 20px 0px', | ||
}, | ||
title: { | ||
textAlign: 'left', | ||
font: theme.footerPanel.titleFont, | ||
fontSize: '20px', | ||
}, | ||
subtitle: { | ||
font: theme.footerPanel.titleFont, | ||
fontWeight: 'normal', | ||
fontSize: '0.9em', | ||
textAlign: 'left', | ||
marginBottom: '15px' | ||
}, | ||
legendLayerListItem: { | ||
padding: "6px 4px" | ||
}, | ||
collapsibleContainer: { | ||
width: '100%', | ||
padding: '10px 0', | ||
margin: '0px 10px' | ||
} | ||
}); | ||
import { Theme } from '@mui/material/styles'; | ||
|
||
export const getSxClasses = (theme: Theme) => ({ | ||
container: { | ||
padding: '10px 0px 20px 0px', | ||
}, | ||
title: { | ||
textAlign: 'left', | ||
font: theme.footerPanel.titleFont, | ||
fontSize: '20px', | ||
}, | ||
subtitle: { | ||
font: theme.footerPanel.titleFont, | ||
fontWeight: 'normal', | ||
fontSize: '0.9em', | ||
textAlign: 'left', | ||
marginBottom: '15px', | ||
}, | ||
legendLayerListItem: { | ||
padding: '6px 4px', | ||
}, | ||
collapsibleContainer: { | ||
width: '100%', | ||
padding: '10px 0', | ||
margin: '0px 10px', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters