Skip to content

Commit 467ca17

Browse files
authored
feat(context menu): add prop to hide the context menu kebab (#250)
Add demo option to hide kebab context menus (#14) add condition to contextSpace to fix label size add check to TaskPill remove hideContextMenuKebab from withContextMenuProps add hideContextMenuKebab to NodeLabelProps to fix error
1 parent ad0be9c commit 467ca17

File tree

7 files changed

+29
-5
lines changed

7 files changed

+29
-5
lines changed

packages/demo-app-ts/src/demos/topologyPackageDemo/DemoNode.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ const DemoNode: React.FunctionComponent<DemoNodeProps> = observer(
180180
showStatusDecorator={detailsLevel === ScaleDetailsLevel.high && options.showStatus}
181181
statusDecoratorTooltip={nodeElement.getNodeStatus()}
182182
onContextMenu={options.contextMenus ? onContextMenu : undefined}
183+
hideContextMenuKebab={options.hideKebabMenu}
183184
onShowCreateConnector={detailsLevel !== ScaleDetailsLevel.low ? onShowCreateConnector : undefined}
184185
onHideCreateConnector={onHideCreateConnector}
185186
labelIcon={options.icons && LabelIcon && <LabelIcon noVerticalAlign />}

packages/demo-app-ts/src/demos/topologyPackageDemo/OptionsContextBar.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ const OptionsContextBar: React.FC = observer(() => {
125125
>
126126
Context Menus
127127
</SelectOption>
128+
<SelectOption
129+
hasCheckbox
130+
value="Hide context kebab menu"
131+
isSelected={options.nodeOptions.hideKebabMenu}
132+
isDisabled={!options.nodeOptions.contextMenus}
133+
onClick={() =>
134+
options.setNodeOptions({ ...options.nodeOptions, hideKebabMenu: !options.nodeOptions.hideKebabMenu })
135+
}
136+
>
137+
Hide kebab for context menu
138+
</SelectOption>
128139
<SelectOption
129140
hasCheckbox
130141
value="Rectangle Groups"

packages/demo-app-ts/src/demos/topologyPackageDemo/generator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export interface GeneratorNodeOptions {
8888
badges?: boolean;
8989
icons?: boolean;
9090
contextMenus?: boolean;
91+
hideKebabMenu?: boolean;
9192
hulledOutline?: boolean;
9293
}
9394

packages/module/src/components/nodes/DefaultNode.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ interface DefaultNodeProps {
120120
contextMenuOpen?: boolean;
121121
/** Flag indicating the label should move to the top layer when the node is hovered, set to `false` if you are already using TOP_LAYER on hover */
122122
raiseLabelOnHover?: boolean; // TODO: Update default to be false, assume demo code will be followed
123+
/** Hide context menu kebab for the node */
124+
hideContextMenuKebab?: boolean;
123125
}
124126

125127
const SCALE_UP_TIME = 200;
@@ -169,7 +171,8 @@ const DefaultNodeInner: React.FunctionComponent<DefaultNodeInnerProps> = observe
169171
onShowCreateConnector,
170172
onContextMenu,
171173
contextMenuOpen,
172-
raiseLabelOnHover = true
174+
raiseLabelOnHover = true,
175+
hideContextMenuKebab
173176
}) => {
174177
const [hovered, hoverRef] = useHover();
175178
const status = nodeStatus || element.getNodeStatus();
@@ -370,6 +373,7 @@ const DefaultNodeInner: React.FunctionComponent<DefaultNodeInnerProps> = observe
370373
badgeLocation={badgeLocation}
371374
onContextMenu={onContextMenu}
372375
contextMenuOpen={contextMenuOpen}
376+
hideContextMenuKebab={hideContextMenuKebab}
373377
hover={isHover}
374378
labelIconClass={labelIconClass}
375379
labelIcon={labelIcon}

packages/module/src/components/nodes/labels/NodeLabel.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export type NodeLabelProps = {
4343
badgeBorderColor?: string;
4444
badgeClassName?: string;
4545
badgeLocation?: BadgeLocation;
46+
hideContextMenuKebab?: boolean;
4647
} & Partial<WithContextMenuProps>;
4748

4849
/**
@@ -77,6 +78,7 @@ const NodeLabel: React.FunctionComponent<NodeLabelProps> = ({
7778
dropTarget,
7879
onContextMenu,
7980
contextMenuOpen,
81+
hideContextMenuKebab,
8082
actionIcon,
8183
actionIconClassName,
8284
onActionIconClick,
@@ -124,7 +126,7 @@ const NodeLabel: React.FunctionComponent<NodeLabelProps> = ({
124126
const height = Math.max(textSize.height, badgeSize?.height ?? 0) + paddingY * 2;
125127
const iconSpace = labelIconClass || labelIcon ? (height + paddingY * 0.5) / 2 : 0;
126128
const actionSpace = actionIcon && actionSize ? actionSize.width : 0;
127-
const contextSpace = onContextMenu && contextSize ? contextSize.width : 0;
129+
const contextSpace = !hideContextMenuKebab && onContextMenu && contextSize ? contextSize.width : 0;
128130
const primaryWidth = iconSpace + badgeSpace + paddingX + textSize.width + actionSpace + contextSpace + paddingX;
129131
const secondaryWidth = secondaryLabel && secondaryTextSize ? secondaryTextSize.width + 2 * paddingX : 0;
130132
const width = Math.max(primaryWidth, secondaryWidth);
@@ -184,6 +186,7 @@ const NodeLabel: React.FunctionComponent<NodeLabelProps> = ({
184186
labelIcon,
185187
actionIcon,
186188
actionSize,
189+
hideContextMenuKebab,
187190
onContextMenu,
188191
contextSize,
189192
secondaryLabel,
@@ -293,7 +296,7 @@ const NodeLabel: React.FunctionComponent<NodeLabelProps> = ({
293296
/>
294297
</>
295298
)}
296-
{textSize && onContextMenu && (
299+
{textSize && onContextMenu && !hideContextMenuKebab && (
297300
<>
298301
<line
299302
className={css(styles.topologyNodeSeparator)}

packages/module/src/pipelines/components/nodes/TaskNode.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export interface TaskNodeProps {
100100
onContextMenu?: (e: React.MouseEvent) => void;
101101
/** Flag indicating that the context menu for the node is currently open */
102102
contextMenuOpen?: boolean;
103+
/** Hide context menu kebab for the node */
104+
hideContextMenuKebab?: boolean;
103105
/** Number of shadowed pills to show */
104106
shadowCount?: number;
105107
/** Offset for each shadow */

packages/module/src/pipelines/components/nodes/TaskPill.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const TaskPill: React.FC<TaskPillProps> = observer(
7171
hasWhenExpression = false,
7272
onContextMenu,
7373
contextMenuOpen,
74+
hideContextMenuKebab,
7475
actionIcon,
7576
actionIconClassName,
7677
onActionIconClick,
@@ -160,7 +161,7 @@ const TaskPill: React.FC<TaskPillProps> = observer(
160161
const actionSpace = actionIcon && actionSize ? actionSize.width + paddingX : 0;
161162

162163
const contextStartX = actionStartX + actionSpace;
163-
const contextSpace = onContextMenu && contextSize ? contextSize.width + paddingX / 2 : 0;
164+
const contextSpace = !hideContextMenuKebab && onContextMenu && contextSize ? contextSize.width + paddingX / 2 : 0;
164165

165166
const pillWidth = contextStartX + contextSpace + paddingX / 2;
166167

@@ -198,6 +199,7 @@ const TaskPill: React.FC<TaskPillProps> = observer(
198199
badge,
199200
actionIcon,
200201
actionSize,
202+
hideContextMenuKebab,
201203
onContextMenu,
202204
contextSize,
203205
verticalLayout,
@@ -429,7 +431,7 @@ const TaskPill: React.FC<TaskPillProps> = observer(
429431
/>
430432
</>
431433
)}
432-
{textSize && onContextMenu && (
434+
{textSize && onContextMenu && !hideContextMenuKebab && (
433435
<>
434436
<line
435437
className={css(topologyStyles.topologyNodeSeparator)}

0 commit comments

Comments
 (0)