forked from equinor/webviz
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
9a90e20
commit 03838ed
Showing
7 changed files
with
104 additions
and
9 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
47 changes: 47 additions & 0 deletions
47
frontend/src/modules/_shared/components/Layers/addLayerDropdown.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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from "react"; | ||
|
||
import { Menu } from "@lib/components/Menu"; | ||
import { MenuItem } from "@lib/components/MenuItem"; | ||
import { LayerGroup } from "@modules/_shared/layers/LayerGroup"; | ||
import { LayerManager } from "@modules/_shared/layers/LayerManager"; | ||
import { Dropdown, MenuButton } from "@mui/base"; | ||
import { Add, ArrowDropDown } from "@mui/icons-material"; | ||
|
||
import { LayerFactory } from "./layersPanel"; | ||
|
||
export type AddLayerDropdownProps<TLayerType extends string> = { | ||
parent: LayerGroup | LayerManager; | ||
layerTypeToStringMapping: Record<TLayerType, string>; | ||
layerFactory: LayerFactory<TLayerType>; | ||
}; | ||
|
||
export function AddLayerDropdown<TLayerType extends string>(props: AddLayerDropdownProps<TLayerType>): React.ReactNode { | ||
function handleAddLayer(type: TLayerType) { | ||
props.parent.addLayer(props.layerFactory.makeLayer(type)); | ||
} | ||
|
||
return ( | ||
<Dropdown> | ||
<MenuButton> | ||
<div className="hover:cursor-pointer hover:bg-blue-100 p-0.5 rounded text-sm flex items-center gap-2"> | ||
<Add fontSize="inherit" /> | ||
<span>Add layer</span> | ||
<ArrowDropDown fontSize="inherit" /> | ||
</div> | ||
</MenuButton> | ||
<Menu anchorOrigin="bottom-end" className="text-sm p-1"> | ||
{Object.keys(props.layerTypeToStringMapping).map((layerType, index) => { | ||
return ( | ||
<MenuItem | ||
key={index} | ||
className="text-sm p-0.5" | ||
onClick={() => handleAddLayer(layerType as TLayerType)} | ||
> | ||
{props.layerTypeToStringMapping[layerType as TLayerType]} | ||
</MenuItem> | ||
); | ||
})} | ||
</Menu> | ||
</Dropdown> | ||
); | ||
} |
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
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