Skip to content

Styling

ngDiagram provides a default well-structured design system with a clear separation of concerns. Its styling is based on a minimal yet sufficient set of primitives, tokens, and component-level variables that support consistent theming and easy customization across all library components.

In addition to the design system, the library includes components, directives, and CSS classes to help you build consistent and interactive diagram interfaces.

The styling system consists of three distinct layers:

Base color values and fundamental design tokens defined in primitives. These are the foundation colors that power the entire design system:

:root {
--ngd-colors-gray-100: /* white */;
--ngd-colors-gray-300: /* light gray */;
--ngd-colors-gray-400: /* medium light gray */;
--ngd-colors-gray-500: /* medium gray */;
--ngd-colors-gray-600: /* medium dark gray */;
--ngd-colors-gray-650: /* dark gray */;
--ngd-colors-gray-700: /* darker gray */;
--ngd-colors-gray-800: /* darkest gray */;
--ngd-colors-acc1-400: /* primary accent light */;
--ngd-colors-acc1-500: /* primary accent */;
--ngd-colors-acc1-500-40: /* primary accent with 40% opacity */;
--ngd-colors-acc1-500-50: /* primary accent with 50% opacity */;
--ngd-colors-acc4-500: /* secondary accent */;
}

Note: The actual color values are defined in the library. Override these variables to customize the color palette for your design system.

Semantic design tokens that map primitives to specific use cases, supporting themes:

:root {
--ngd-node-bg-primary-default: var(--ngd-colors-gray-100);
--ngd-node-stroke-primary-default: var(--ngd-colors-gray-400);
--ngd-node-stroke-primary-hover: var(--ngd-colors-acc1-500);
/* ... more tokens */
}
html[data-theme='dark'] {
--ngd-node-bg-primary-default: var(--ngd-colors-gray-700);
--ngd-node-stroke-primary-default: var(--ngd-colors-gray-600);
--ngd-node-stroke-primary-hover: var(--ngd-colors-acc1-400);
/* ... more tokens */
}

Component-specific CSS variables that use tokens for consistent styling:

:root {
--ngd-node-background-color: var(--ngd-node-bg-primary-default);
--ngd-node-border-color: var(--ngd-node-stroke-primary-default);
--ngd-node-border-color-hover: var(--ngd-node-stroke-primary-hover);
/* ... more component variables */
}

ngDiagram supports both light and dark themes out of the box by default:

  • Light theme - Applied by default (no HTML attribute needed)
  • Dark theme - Applied when data-theme="dark" is set on the html element
<!-- Dark theme (optional) -->
<html data-theme="dark">
<!-- Dark theme is applied -->
</html>

Note: The following customization options are optional.

To quickly adapt to your design system, override primitives:

:root {
--ngd-colors-acc1-500: #your-primary-color;
--ngd-colors-gray-500: #your-gray-color;
/* Override other primitives as needed */
}

For precise control, override component variables:

:root {
--ngd-node-border-radius: 0.5rem;
--ngd-node-border-size: 0.125rem;
--ngd-group-border-radius: 1rem;
/* Customize specific component properties */
}

Applied to node containers. When the cursor hovers over the node, all ports are highlighted with the default node styling.

Applied to node containers as well. The port is highlighted only when the cursor hovers directly over it.

<!-- Node with hoverable ports -->
<div class="ng-diagram-port-hoverable-over-node">
<!-- Node content -->
<ng-diagram-port id="port-left" type="both" side="left" />
<ng-diagram-port id="port-right" type="both" side="right" />
</div>
<!-- Individual hoverable port -->
<div class="ng-diagram-port-hoverable">
<!-- Node content -->
<ng-diagram-port id="port-left" type="both" side="left" />
<ng-diagram-port id="port-right" type="both" side="right" />
</div>

Note: Directives require access to node/group data. When used outside of node templates, they won’t work. For manual control, use CSS classes instead.

Automatically adds selection styling based on the node’s selected property:

<div ngDiagramNodeSelected [node]="node">
<!-- Node content -->
</div>

Applied styling:

  • Adds ng-diagram-node-selected class when selected is true
  • Provides focus ring and outline styling
  • Works for both nodes and groups

Adds highlight styling to groups based on the highlighted property:

<div ngDiagramGroupHighlighted [node]="node">
<!-- Group content -->
</div>

Applied styling:

  • Adds ng-diagram-group-highlight class when highlighted is true
  • Provides inner outline and background highlight
  • Indicates when dragging elements can be added to the group

For cases where directives can’t be used (outside node templates), you can apply styling manually:

  • ng-diagram-node-selected
  • ng-diagram-group-highlight
<!-- Selection styling -->
<div class="ng-diagram-node-wrapper ng-diagram-node-selected">
<!-- Node content -->
</div>
<!-- Group highlight styling -->
<div class="ng-diagram-node-wrapper ng-diagram-group-highlight">
<!-- Group content -->
</div>
  1. Use primitives for global color changes - Override --ngd-colors-* variables for brand consistency
  2. Use component variables for specific adjustments - Override --ngd-* variables for precise control
  3. Leverage utility classes - Use provided classes for consistent behavior
  4. Use directives for visual state management - Let directives handle selection and highlight states
  5. Maintain layer separation - Use component variables instead of applying primitives or tokens directly within components.