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
de6510b
commit 37b23e1
Showing
10 changed files
with
183 additions
and
111 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
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
58 changes: 58 additions & 0 deletions
58
frontend/src/modules/LayerSpike/layers/components/editNameComponent.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,58 @@ | ||
import React from "react"; | ||
|
||
import { usePublishSubscribeTopicValue } from "../PublishSubscribeHandler"; | ||
import { ItemDelegateTopic } from "../delegates/ItemDelegate"; | ||
import { Item } from "../interfaces"; | ||
|
||
type EditItemNameComponentProps = { | ||
item: Item; | ||
}; | ||
|
||
export function EditNameComponent(props: EditItemNameComponentProps): React.ReactNode { | ||
const itemName = usePublishSubscribeTopicValue(props.item.getItemDelegate(), ItemDelegateTopic.NAME); | ||
|
||
const [editingName, setEditingName] = React.useState<boolean>(false); | ||
const [currentName, setCurrentName] = React.useState<string>(itemName); | ||
|
||
function handleNameDoubleClick() { | ||
setEditingName(true); | ||
} | ||
|
||
function handleNameChange(e: React.ChangeEvent<HTMLInputElement>) { | ||
setCurrentName(e.target.value); | ||
} | ||
|
||
function handleBlur() { | ||
setEditingName(false); | ||
props.item.getItemDelegate().setName(currentName); | ||
} | ||
|
||
function handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) { | ||
if (e.key === "Enter") { | ||
setEditingName(false); | ||
props.item.getItemDelegate().setName(currentName); | ||
} | ||
} | ||
|
||
return ( | ||
<div | ||
className="flex-grow font-bold flex items-center pt-1" | ||
onDoubleClick={handleNameDoubleClick} | ||
title="Double-click to edit name" | ||
> | ||
{editingName ? ( | ||
<input | ||
type="text" | ||
className="p-0.5 w-full" | ||
value={currentName} | ||
onChange={handleNameChange} | ||
onBlur={handleBlur} | ||
onKeyDown={handleKeyDown} | ||
autoFocus | ||
/> | ||
) : ( | ||
itemName | ||
)} | ||
</div> | ||
); | ||
} |
28 changes: 28 additions & 0 deletions
28
frontend/src/modules/LayerSpike/layers/components/removeButtonComponent.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,28 @@ | ||
import { Delete } from "@mui/icons-material"; | ||
|
||
import { Item } from "../interfaces"; | ||
|
||
export type RemoveButtonComponentProps = { | ||
item: Item; | ||
}; | ||
|
||
export function RemoveButtonComponent(props: RemoveButtonComponentProps): React.ReactNode { | ||
function handleRemove() { | ||
const parentGroup = props.item.getItemDelegate().getParentGroup(); | ||
if (parentGroup) { | ||
parentGroup.removeChild(props.item); | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<div | ||
className="hover:cursor-pointer rounded text-red-800 hover:text-red-600" | ||
onClick={handleRemove} | ||
title="Remove item" | ||
> | ||
<Delete fontSize="inherit" /> | ||
</div> | ||
</> | ||
); | ||
} |
27 changes: 27 additions & 0 deletions
27
frontend/src/modules/LayerSpike/layers/components/visibilityToggleComponent.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,27 @@ | ||
import { Visibility, VisibilityOff } from "@mui/icons-material"; | ||
|
||
import { usePublishSubscribeTopicValue } from "../PublishSubscribeHandler"; | ||
import { ItemDelegateTopic } from "../delegates/ItemDelegate"; | ||
import { Item } from "../interfaces"; | ||
|
||
export type VisibilityToggleComponentProps = { | ||
item: Item; | ||
}; | ||
|
||
export function VisibilityToggleComponent(props: VisibilityToggleComponentProps): React.ReactNode { | ||
const isVisible = usePublishSubscribeTopicValue(props.item.getItemDelegate(), ItemDelegateTopic.VISIBILITY); | ||
|
||
function handleToggleLayerVisibility() { | ||
props.item.getItemDelegate().setIsVisible(!isVisible); | ||
} | ||
|
||
return ( | ||
<div | ||
className="hover:cursor-pointer rounded text-blue-800 hover:text-blue-600" | ||
onClick={handleToggleLayerVisibility} | ||
title="Toggle visibility" | ||
> | ||
{isVisible ? <Visibility fontSize="inherit" /> : <VisibilityOff fontSize="inherit" />} | ||
</div> | ||
); | ||
} |
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
Oops, something went wrong.