-
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
6 changed files
with
183 additions
and
150 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
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
43 changes: 25 additions & 18 deletions
43
packages/geoview-core/src/core/components/legend/legend-layer-items.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,35 +1,42 @@ | ||
import { useTheme } from '@mui/material'; | ||
import { memo, useMemo } from 'react'; | ||
import { Box, ListItem, Tooltip, ListItemText, ListItemIcon, List, BrowserNotSupportedIcon } from '@/ui'; | ||
import { TypeLegendLayer } from '@/core/components/layers/types'; | ||
import { TypeLegendItem } from '@/core/components/layers/types'; | ||
import { getSxClasses } from './legend-styles'; | ||
import { logger } from '@/core/utils/logger'; | ||
|
||
interface ItemsListProps { | ||
items: TypeLegendLayer['items']; | ||
items: TypeLegendItem[]; | ||
} | ||
|
||
// ItemsList component | ||
export const ItemsList = memo(function ItemsList({ items }: ItemsListProps) { | ||
logger.logDebug('legend1 item list', items); | ||
|
||
// Hooks | ||
const theme = useTheme(); | ||
const sxClasses = useMemo(() => getSxClasses(theme), [theme]); | ||
|
||
if (!items?.length) { | ||
return null; | ||
} | ||
|
||
// Direct mapping since we only reach this code if items has content | ||
const listItems = items.map((item) => ( | ||
// Extracted ListItem Component | ||
const LegendListItem = memo( | ||
({ item }: { item: TypeLegendItem }): JSX.Element => ( | ||
<ListItem key={`${item.icon}-${item.name}`} className={!item.isVisible ? 'unchecked' : 'checked'}> | ||
<ListItemIcon>{item.icon ? <Box component="img" alt={item.name} src={item.icon} /> : <BrowserNotSupportedIcon />}</ListItemIcon> | ||
<Tooltip title={item.name} placement="top" enterDelay={1000}> | ||
<ListItemText primary={item.name} /> | ||
</Tooltip> | ||
</ListItem> | ||
)); | ||
) | ||
); | ||
LegendListItem.displayName = 'LegendListItem'; | ||
|
||
return <List sx={sxClasses.subList}>{listItems}</List>; | ||
export const ItemsList = memo(function ItemsList({ items }: ItemsListProps): JSX.Element | null { | ||
logger.logTraceRender('components/legend/legend-layer-items'); | ||
|
||
// Hooks | ||
const theme = useTheme(); | ||
const sxClasses = useMemo(() => getSxClasses(theme), [theme]); | ||
|
||
if (!items?.length) return null; | ||
|
||
// Direct mapping since we only reach this code if items has content | ||
return ( | ||
<List sx={sxClasses.subList}> | ||
{items.map((item) => ( | ||
<LegendListItem item={item} key={`${item.icon}-${item.name}`} /> | ||
))} | ||
</List> | ||
); | ||
}); |
Oops, something went wrong.