Skip to content

Commit

Permalink
feat(group): Add support for custom classname on group labels
Browse files Browse the repository at this point in the history
  • Loading branch information
jenny-s51 committed Dec 13, 2024
1 parent afa8bb5 commit 3a46fe6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/module/src/components/groups/DefaultGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ interface DefaultGroupProps {
secondaryLabel?: string;
/** Flag to show the label */
showLabel?: boolean; // Defaults to true
/** Additional classes to add to the label */
labelClassName?: string;
/** Flag to show the label when hovering (effects expanded only) */
showLabelOnHover?: boolean;
/** Position of the label, top or bottom. Defaults to element.getLabelPosition() or bottom */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type DefaultGroupCollapsedProps = {
badgeBorderColor?: string;
badgeClassName?: string;
badgeLocation?: BadgeLocation;
labelClassName?: string;
} & CollapsibleGroupProps &
WithDragNodeProps &
WithSelectionProps &
Expand Down Expand Up @@ -84,7 +85,8 @@ const DefaultGroupCollapsed: React.FunctionComponent<DefaultGroupCollapsedProps>
badgeLocation,
labelIconClass,
labelIcon,
labelIconPadding
labelIconPadding,
labelClassName
}) => {
const [hovered, hoverRef] = useHover();
const [labelHover, labelHoverRef] = useHover();
Expand Down Expand Up @@ -156,7 +158,7 @@ const DefaultGroupCollapsed: React.FunctionComponent<DefaultGroupCollapsedProps>
)}
{showLabel && (
<NodeLabel
className={styles.topologyGroupLabel}
className={css(styles.topologyGroupLabel, labelClassName)}
x={collapsedWidth / 2}
y={labelPosition === LabelPosition.top ? collapsedHeight / 2 - collapsedHeight : collapsedHeight + 6}
paddingX={8}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type DefaultGroupExpandedProps = {
badgeBorderColor?: string;
badgeClassName?: string;
badgeLocation?: BadgeLocation;
labelClassName?: string;
labelIconClass?: string; // Icon to show in label
labelIcon?: string;
labelPosition?: LabelPosition;
Expand Down Expand Up @@ -139,6 +140,7 @@ const DefaultGroupExpanded: React.FunctionComponent<DefaultGroupExpandedProps> =
badgeBorderColor,
badgeClassName,
badgeLocation,
labelClassName,
labelIconClass,
labelIcon,
labelPosition,
Expand Down Expand Up @@ -254,7 +256,7 @@ const DefaultGroupExpanded: React.FunctionComponent<DefaultGroupExpandedProps> =
(showLabel || (showLabelOnHover && isHover)) && (label || element.getLabel()) ? (
<g ref={labelHoverRef} transform={isHover ? `scale(${labelScale})` : undefined}>
<NodeLabel
className={styles.topologyGroupLabel}
className={css(styles.topologyGroupLabel, labelClassName)}
x={startX * labelPositionScale}
y={startY * labelPositionScale}
paddingX={8}
Expand Down

0 comments on commit 3a46fe6

Please sign in to comment.