{"id":1849,"date":"2018-10-04T09:53:59","date_gmt":"2018-10-04T09:53:59","guid":{"rendered":"https:\/\/developer.microsoft.com\/en-us\/office\/blogs\/?p=1849"},"modified":"2018-10-04T09:53:59","modified_gmt":"2018-10-04T09:53:59","slug":"mvp-article-using-theme-colors-in-list-formatting","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/mvp-article-using-theme-colors-in-list-formatting\/","title":{"rendered":"MVP Article &#8211; Using Theme Colors in List Formatting"},"content":{"rendered":"<p>List formatting for modern list views is an incredibly powerful tool that allows you to quickly and easily add instant meaning, visual appeal, and dynamic visualizations directly to your lists. With some simple <a href=\"https:\/\/docs.microsoft.com\/en-us\/sharepoint\/dev\/declarative-customization\/column-formatting\">column formats<\/a>, a <a href=\"https:\/\/docs.microsoft.com\/en-us\/sharepoint\/dev\/declarative-customization\/view-formatting\">view format<\/a>, or maybe even a combination \u2013 power users can take advantage of all the power of the modern list view while adding visual semantics that bring contextual meaning and dramatically increases the value for end users.<\/p>\n<p>Awesome! But how do you make sure your formats don\u2019t clash with the rest of the site?<\/p>\n<p>List formatting allows you to specify inline styles for your custom elements including attributes like color, background-color, and more. Using these directly ensures you always get the chosen color. This is great when that\u2019s what you want, but what happens when a user changes the site\u2019s theme or a site is associated with a hub site that provides its own set of colors?<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-1850\" src=\"https:\/\/officedevblogs.wpengine.com\/wp-content\/uploads\/2018\/10\/themes.png\" alt=\"\" width=\"1052\" height=\"193\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/10\/themes.png 2848w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/10\/themes-300x55.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/10\/themes-1024x188.png 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/10\/themes-768x141.png 768w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/10\/themes-1536x282.png 1536w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/10\/themes-2048x375.png 2048w\" sizes=\"(max-width: 1052px) 100vw, 1052px\" \/><\/p>\n<p>Fortunately, list formatting also allows you to specify classes for your custom elements. In addition to the <a href=\"https:\/\/docs.microsoft.com\/en-us\/sharepoint\/dev\/declarative-customization\/column-formatting#style-guidelines\">predefined classes<\/a>, like the <em>sp-field-severity<\/em> classes, you can take advantage of many of the Office UI Fabric classes to ensure your colors always match the theme (even <a href=\"https:\/\/developer.microsoft.com\/en-us\/fabric#\/styles\/themegenerator\">custom themes<\/a>).<\/p>\n<h2>Theme Colors<\/h2>\n<p>The <a href=\"https:\/\/developer.microsoft.com\/en-us\/fabric#\/styles\/colors\">Office UI Fabric<\/a> provides 9 theme colors and 11 neutral colors in addition to the 23 named colors. Each of these can be combined with prefixes to apply to an element\u2019s text, border, or background. There are also hover versions of each! This gives you well over 250 classes just for applying colors.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1851\" src=\"https:\/\/officedevblogs.wpengine.com\/wp-content\/uploads\/2018\/10\/ListFormattingWithThemesFade.gif\" alt=\"\" width=\"799\" height=\"364\" \/><\/p>\n<p>You specify how you want the color applied by using the following naming conventions:<\/p>\n<p style=\"padding-left: 30px\"><em>ms-[location]-[color]<\/em><\/p>\n<p style=\"padding-left: 30px\"><em>ms-[location]-[color]&#8211;hover<\/em><\/p>\n<p>Here\u2019s a handy table with examples:<\/p>\n<table width=\"100%\">\n<tbody>\n<tr>\n<td width=\"33%\"><strong>Location<\/strong><\/td>\n<td width=\"66%\"><strong>Example<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"33%\">Text<\/td>\n<td width=\"66%\"><em>ms-fontColor-neutralPrimary<\/em><\/td>\n<\/tr>\n<tr>\n<td width=\"33%\">Text Hover<\/td>\n<td width=\"66%\"><em>ms-fontColor-neutralSecondary&#8211;hover<\/em><\/td>\n<\/tr>\n<tr>\n<td width=\"33%\">Background<\/td>\n<td width=\"66%\"><em>ms-bgColor-themePrimary<\/em><\/td>\n<\/tr>\n<tr>\n<td width=\"33%\">Background Hover<\/td>\n<td width=\"66%\"><em>ms-bgColor-themeLight&#8211;hover<\/em><\/td>\n<\/tr>\n<tr>\n<td width=\"33%\">Border<\/td>\n<td width=\"66%\"><em>ms-borderColor-tealDark<\/em><\/td>\n<\/tr>\n<tr>\n<td width=\"33%\">Border Hover<\/td>\n<td width=\"66%\"><em>ms-borderColor-magenta<\/em><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Keep in mind these only apply colors and that you\u2019ll still need to specify other properties (such as <em>border style<\/em>\/<em>width<\/em>) via individual style attributes. In these cases, don\u2019t use rollup styles like <em>border<\/em> since this will override the color. Use the individual <em>border-width<\/em>, <em>border-left-style<\/em>, etc. attributes.<\/p>\n<p>Using these classes is also the only way to apply hover styles within List Formatting.<\/p>\n<p>Finally, unlike the other named colors (like <em>ms-bgColor-yellow<\/em>), white and black are theme sensitive and will swap values when used on light or dark themes.<\/p>\n<h2>Typography<\/h2>\n<p>Just like with colors, List Formatting lets you specify font sizes and weights using inline styles. However, you can ensure you match the rest of SharePoint by taking advantage of the <a href=\"https:\/\/developer.microsoft.com\/en-us\/fabric#\/styles\/typography\">typography classes<\/a> provided by the Office UI Fabric.<\/p>\n<p>The 10 base classes (<em>ms-font<\/em>) allow you to match size and weight together in a single class and represent the recommendations laid out in the Office Design Language. However, there are also 10 size classes (<em>ms-fontSize<\/em>) that only affect font-size that you can combine with the 4 weight classes (<em>ms-fontWeight<\/em>) that change the text\u2019s boldness.<\/p>\n<h2>Resources<\/h2>\n<p>Exploring the Office UI Fabric site will let you know what classes are already available as you design your formats so that you can focus on your customizations while ensuring you match the overall style and colors of your SharePoint site (even as they change).<\/p>\n<p>Additionally, <a href=\"https:\/\/aka.ms\/sppnp\">SharePoint Patterns and Practices (PnP)<\/a> provides several <a href=\"https:\/\/github.com\/SharePoint\/sp-dev-list-formatting\">column and view formatting samples<\/a> to inspire you and help you get started. PnP also provides <a href=\"http:\/\/bit.ly\/ListFormatter\">List Formatter<\/a>, a free tool that makes creating and updating your formats simpler than ever!<\/p>\n<p>The theme sensitive formats shown in the animation above can all be found here:<\/p>\n<ul>\n<li>Complete: <a href=\"https:\/\/github.com\/SharePoint\/sp-dev-list-formatting\/tree\/master\/column-samples\/yesno-checkbox\">Yes\/No Checkboxes<\/a><\/li>\n<li>Title: <a href=\"https:\/\/github.com\/SharePoint\/sp-dev-list-formatting\/tree\/master\/column-samples\/text-strikethrough\">Strikethrough on Completion<\/a><\/li>\n<li>Progress Column: <a href=\"https:\/\/github.com\/SharePoint\/sp-dev-list-formatting\/tree\/master\/column-samples\/number-data-bar\">Percent Data Bars<\/a><\/li>\n<li>Assigned To: <a href=\"https:\/\/github.com\/SharePoint\/sp-dev-list-formatting\/tree\/master\/column-samples\/person-currentuser-format\">Highlight the Current User<\/a><\/li>\n<li>Due: <a href=\"https:\/\/github.com\/SharePoint\/sp-dev-list-formatting\/tree\/master\/column-samples\/date-range-format\">Overdue Item<\/a><\/li>\n<li>Action: <a href=\"https:\/\/github.com\/SharePoint\/sp-dev-list-formatting\/tree\/master\/column-samples\/generic-start-flow\">Launch a Flow for the Selected Item<\/a><\/li>\n<li>View: <a href=\"https:\/\/github.com\/SharePoint\/sp-dev-list-formatting\/tree\/master\/view-samples\/person-currentuser-rowclass\">Current User\u2019s Rows<\/a><\/li>\n<\/ul>\n<p>For detailed guidance and reference, be sure to read the official documentation for <a href=\"https:\/\/aka.ms\/spdev-column-formatting\">column formatting<\/a> and the new <a href=\"https:\/\/docs.microsoft.com\/en-us\/sharepoint\/dev\/declarative-customization\/view-formatting\">view formatting<\/a>.<\/p>\n<h2>About the Author<\/h2>\n<p><img decoding=\"async\" class=\"size-full wp-image-1853\" style=\"float: left;margin: 10px\" src=\"https:\/\/officedevblogs.wpengine.com\/wp-content\/uploads\/2018\/10\/chris-1.png\" alt=\"\" width=\"200\" height=\"200\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/10\/chris-1.png 200w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/10\/chris-1-150x150.png 150w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/10\/chris-1-24x24.png 24w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/10\/chris-1-48x48.png 48w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/10\/chris-1-96x96.png 96w\" sizes=\"(max-width: 200px) 100vw, 200px\" \/><a href=\"https:\/\/twitter.com\/theChrisKent\">Chris Kent<\/a> is a Microsoft Office Development MVP and the Office 365 Practice Lead for DMI. He is a frequent contributor to <a href=\"http:\/\/aka.ms\/sppnp\">SharePoint Patterns and Practices (PnP)<\/a> and a member of the SharePoint PnP Core Team where is especially focused on List Formatting and the SharePoint Framework. He is passionate about mapping technology to real-world solutions.<\/p>\n<p>Chris is a highly-rated speaker and has presented at user groups, SharePoint Saturdays, webinars, and conferences. He posts regularly to his blog, <a href=\"https:\/\/thechriskent.com\">thechriskent.com<\/a>, tweets the twitters <a href=\"https:\/\/twitter.com\/thechriskent\">@thechriskent<\/a>, and works on multiple projects over at <a href=\"https:\/\/github.com\/thechriskent\">GitHub<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><i>SharePoint Team, Microsoft &#8211; 4th of October 2018<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MVP Article &#8211; List formatting for modern list views is an incredibly powerful tool that allows you to quickly and easily add instant meaning, visual appeal, and dynamic visualizations directly to your lists. How to use Theme Colors in List Formatting?<\/p>\n","protected":false},"author":69078,"featured_media":25159,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[78,36],"class_list":["post-1849","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-365-developer","tag-data-visualizations","tag-office-ui-fabric"],"acf":[],"blog_post_summary":"<p>MVP Article &#8211; List formatting for modern list views is an incredibly powerful tool that allows you to quickly and easily add instant meaning, visual appeal, and dynamic visualizations directly to your lists. How to use Theme Colors in List Formatting?<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/1849","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/users\/69078"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=1849"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/1849\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/25159"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=1849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=1849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=1849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}