Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,57 +39,29 @@ function chooseRendererByType($type): FC<NodeProps> | ComponentClass<NodeProps>
return renderer;
}

// Node hover style
const nodeBorderHoveredStyle = css`
box-shadow: 0px 0px 0px 1px #323130;
`;

// Other nodes selected style except botAsks, UserAnswers and InvalidPromptBrick
const nodeBorderSelectedStyle = css`
box-shadow: 0px 0px 0px 2px #0078d4;
`;

// BotAsks, UserAnswers and InvalidPromptBrick nodes focused style
const nodeBorderDoubleFocusedStyle = css`
outline: 2px solid #0078d4;
`;

// BotAsks, UserAnswers and InvalidPromptBrick nodes selected style
const nodeBorderDoubleSelectedStyle = css`
outline: 2px solid #0078d4;
border-radius: 0px;
box-shadow: 0px 0px 0px 6px rgba(0, 120, 212, 0.3);
`;
export const ElementRenderer: FC<NodeProps> = ({ id, data, onEvent, onResize }): JSX.Element => {
const ChosenRenderer = chooseRendererByType(data.$type);
let elementType = '';
let doubleSelected = false;
switch (data.$type) {
case ObiTypes.BotAsks:
case ObiTypes.UserAnswers:
case ObiTypes.InvalidPromptBrick:
elementType = data.$type;
doubleSelected = true;
break;
default:
elementType = '';
doubleSelected = false;
break;
}
const selectedId = `${id}${elementType}`;
const { focusedId, focusedEvent } = useContext(NodeRendererContext);
const { getNodeIndex, selectedIds } = useContext(SelectionContext);
const nodeFocused = focusedId === id || focusedEvent === id;
const nodeSelected = selectedIds.includes(selectedId);
const nodeSelected = selectedIds.includes(id);

const declareElementAttributes = (selectedId: string, id: string) => {
return {
[AttrNames.SelectableElement]: true,
[AttrNames.NodeElement]: true,
[AttrNames.FocusableElement]: true,
[AttrNames.FocusedId]: id,
[AttrNames.SelectableElement]: true,
[AttrNames.SelectedId]: selectedId,
[AttrNames.FocusableElement]: true,
[AttrNames.SelectionIndex]: getNodeIndex(id),
[AttrNames.SelectionIndex]: getNodeIndex(selectedId),
};
};

Expand All @@ -104,15 +76,13 @@ export const ElementRenderer: FC<NodeProps> = ({ id, data, onEvent, onResize }):
display: inline-block;
position: relative;
border-radius: 1px 1px 0 0;
${nodeSelected && !doubleSelected && nodeBorderSelectedStyle};
${nodeFocused && !doubleSelected && nodeBorderSelectedStyle};
${nodeFocused && doubleSelected && nodeBorderDoubleFocusedStyle};
${nodeSelected && doubleSelected && nodeBorderDoubleSelectedStyle};
${nodeSelected && nodeBorderSelectedStyle};
${nodeFocused && nodeBorderSelectedStyle};
&:hover {
${!nodeFocused && !nodeSelected && nodeBorderHoveredStyle}
}
`}
{...declareElementAttributes(selectedId, id)}
{...declareElementAttributes(id, id)}
>
<ChosenRenderer
id={id}
Expand Down