Constants

A constant is a reusable design decision expressed as a property-value pair. Constants are threaded throughout MDS components to maintain a consistent visual style and are available for use by product teams.

About Constants

Constants include not just official System Colors, but how color is predictably applied to backgrounds, text, and borders in specific settings. Similarly, engineers are not limited to generic spacer values, but can instead compose components more intentionally with Space insets, stack values, and other choices.

Constants as Data and Variables

Constants are managed in src/library/constants/constants.yaml, using YAML syntax to encode property-value pairs with a hierarchy.

The MDS build process transforms constants.yaml into additional generated files for use within this System site and by those using MDS:

Constants in MDS Components

Constants are used throughout the MDS library. For example, the Pagination component style in src/library/components/pagination/pagination.scss includes constants for border color, text color, font family and font size:

All components are built with and reviewed for appropriate constant use.

Styling Custom Components With Constants

A product team may want to adopt the Morningstar visual language but has limited or no bandwidth to change HTML markup within their product. In this case, a product team can apply MDS constants using SASS variables by following these steps:

Integrate a dependency on src/library/styles/_mds_constants.scss within their style compilation, enabling access to constants as variables within a product’s environment.

Apply constants to components and features developed within their product.

For example, consider a module repeated across a view. If a team wanted to update the module’s header (div.layout__header), but were unable to modify the markup, they could apply constants as SASS variables to update only CSS.

Revised Style, With Constants

Editing and Proposing Constants

Constants are managed by MDS designers in collaboration with the Morningstar design community. We add constants conservatively. Please be prepared to justify the addition of a constant by showing how it would be used across many MDS components. To request extensions or changes to the constants, email designsystem@morningstar.com.