Theming

Theming is a core concept in Mineral UI. Themes provide a consistent look and feel across pages with varied functionality. Mineral UI makes it simple to implement and maintain theming across your app.

The theme system is flexible enough to be applied globally or at a component level. This page lists of all Mineral UI theme variables for your reference.

Implementation #

Consider the signature of createStyledComponent:

const MyComponent = createStyledComponent('div', props => ({
  backgroundColor: props.theme.color_primary
}));

The ThemeProvider(s) in your app provides the theme to other Mineral UI and/or Glamorous components within that ThemeProvider. Your app must have a ThemeProvider at its root and can optionally nest additional ThemeProviders to apply a custom theme to sections of your app. Nested ThemeProviders shallowly merge their theme with the parent theme.

The theme itself (see the default mineralTheme below for an example) is a simple shallow object of variables that are shared across components.

Each component can also have a “theme”, which is not a file, but rather a set of variables available to override default values. E.g., if Mineral UI’s Button component looked like this:

const Button = createStyledComponent('button', props => ({
  color: props.theme.Button_color || props.theme.color_primary
}));

The themes distributed as part of Mineral UI include a value for color_primary but do not include a value for Button_color. In our component code, we leave the component-level variable Button_color as a hook for you to define if you’d like. Component-level theme variables start with the capitalized component name to differentiate from the global variables. When you’d like to override the Mineral UI theme at a component level in your app, you can use createThemedComponent:

const MyButton = createThemedComponent(Button, {
  Button_color: 'tomato'
});

Theme Variables #

Themes in Mineral UI are made of the following variables. The values below come from the default mineralTheme. Note the naming convention: ‘property_target_variant_state’.

VariableValue
borderRadius_10.1875em
directionltr
fontFamilyOpen Sans
fontFamily_system-apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"
fontFamily_monospacemonospace
fontSize_base16
fontSize_h12.125em
fontSize_h21.75em
fontSize_h31.375em
fontSize_h41.125em
fontSize_h50.875em
fontSize_h60.875em
fontSize_mouse0.6875em
fontSize_prose1em
fontSize_ui0.875em
fontWeight_regular400
fontWeight_semiBold600
fontWeight_bold700
fontWeight_extraBold800
lineHeight1.25
lineHeight_prose1.5
shadow_10 1px 2px 0 rgba(0,0,0,0.4)
shadow_20 2px 4px 0 rgba(0,0,0,0.2), 0 1px 2px 0 rgba(0,0,0,0.4)
shadow_30 4px 8px 0 rgba(0,0,0,0.2), 0 2px 4px 0 rgba(0,0,0,0.4)
shadow_40 8px 16px 0 rgba(0,0,0,0.2), 0 4px 8px 0 rgba(0,0,0,0.4)
shadow_50 24px 24px -8px rgba(0,0,0,0.4), 0 8px 16px 0 rgba(0,0,0,0.4)
size_small1.5em
size_medium2em
size_large2.5em
size_jumbo3.25em
spacing_quarter0.125em
spacing_half0.25em
spacing_single0.5em
spacing_oneAndAHalf0.75em
spacing_double1em
spacing_triple1.5em
spacing_quad2em
zIndex_100100
zIndex_200200
zIndex_400400
zIndex_800800
zIndex_16001600
color_theme_10#e1f3fc
color_theme_20#c0e5fc
color_theme_30#9fd9fc
color_theme_40#79c7f7
color_theme_50#51b3f0
color_theme_60#2f9fe0
color_theme_70#1b8bcc
color_theme_80#0f75b0
color_theme_90#0a6091
color_theme_100#084d75
color_gray_10#f5f7fa
color_gray_20#ebeff5
color_gray_30#dde3ed
color_gray_40#c8d1e0
color_gray_50#afbacc
color_gray_60#8e99ab
color_gray_70#707a8a
color_gray_80#58606e
color_gray_90#434a54
color_gray_100#333840
color_black#1d1f24
color_white#fff
backgroundColor_disabled#ebeff5
backgroundColor_danger#db2929
backgroundColor_danger_active#c71818
backgroundColor_danger_activeMuted#f79999
backgroundColor_danger_focus#db2929
backgroundColor_danger_hover#eb4d4d
backgroundColor_success#0a8f4c
backgroundColor_success_active#06783f
backgroundColor_success_activeMuted#95f5c3
backgroundColor_success_focus#0a8f4c
backgroundColor_success_hover#10a35a
backgroundColor_warning#e05b2b
backgroundColor_warning_active#cf4615
backgroundColor_warning_activeMuted#fab69d
backgroundColor_warning_focus#e05b2b
backgroundColor_warning_hover#ed774c
backgroundColor_input_danger#fce3e3
backgroundColor_input_success#e8fcf2
backgroundColor_input_warning#fcf1dc
backgroundColor_link_focus#dde3ed
borderColor#c8d1e0
borderColor_active#51b3f0
borderColor_focus#0f75b0
borderColor_hover#2f9fe0
borderColor_danger#ad0e0e
borderColor_danger_active#7d0606
borderColor_danger_focus#c71818
borderColor_danger_hover#db2929
borderColor_success#0a8f4c
borderColor_success_active#046132
borderColor_success_focus#06783f
borderColor_success_hover#1fc06f
borderColor_warning#d19411
borderColor_warning_active#916504
borderColor_warning_focus#cf4615
borderColor_warning_hover#e3a322
color_caption#58606e
color_placeholder#8e99ab
color_text#333840
color_text_disabled#afbacc
color_text_danger#ad0e0e
color_text_danger_active#940909
color_text_danger_hover#c71818
color_text_danger_focus#ad0e0e
color_text_ondanger#fff
color_text_primary#0f75b0
color_text_primary_active#0a6091
color_text_primary_hover#1b8bcc
color_text_primary_focus#0f75b0
color_text_onprimary#fff
color_text_success#06783f
color_text_success_active#046132
color_text_success_focus#06783f
color_text_success_hover#0a8f4c
color_text_onsuccess#fff
color_text_warning#bd3909
color_text_warning_active#a83207
color_text_warning_focus#bd3909
color_text_warning_hover#cf4615
color_text_onwarning#fff
Copyright © 2017 CA
We welcome feedback and contributions on GitHub