Colors
Our default library Colors object is using System Colors and Design Tokens.
- Design Tokens
- System Colors
- Accessibility
- Dev
Design Tokens
Design Tokens provide semantic meaning to our color system by mapping contextual usage to system colors.
Each token follows the naming pattern: $[property][Semantic][Weight]
For example:
$backgroundPrimaryHeavy
: A heavy primary background color$textSuccess
: Success-themed text color$iconWarning
: Warning-themed icon color
Design Token Structure
Design tokens follow a structured naming convention: $[property][Semantic][Weight]
, where:
Property
Defines the UI element the token applies to:
background
- Background colorstext
- Text colorsicon
- Icon colorsoutline
- Border/outline colors
Semantic
Represents the contextual meaning:
neutral
- Neutral/default stateprimary
- App's primary brand colorgeneral
- General purposesuccess
- Positive/success stateswarning
- Warning/caution statesdanger
- Error/danger statesdisabled
- Disabled stateinverted
- Reversed/contrasting colorsdefault
- Default state
Weight (Optional)
Indicates the color intensity:
light
- Lighter variationmedium
- Medium intensityheavy
- Heavier/darker variation
Examples:
$backgroundPrimaryHeavy
- Dark variant of primary background$textSuccess
- Success state text color$iconWarning
- Warning state icon color
View all available design tokens in our token definition files.
Dark Mode Integration
Design tokens provide seamless dark mode support through automatic color mapping. Each token maps to appropriate system colors for both light and dark themes:
// Example mapping
$textSuccess → green10 (light mode)
$textSuccess → green60 (dark mode)
View the complete token mappings:
Custom Design Tokens
Customize the design system by:
- Using
loadSchemes()
to override existing tokens - Generating tokens from your primary brand color:
Colors.loadSchemes({
light: {
$textDefault: '#20303C'
},
dark: {
$textDefault: '#F8F8F8'
}
});
This defines the default text color token for both light and dark modes.
System Colors
The System Colors are all the colors we use in our design system. (red30, grey10 and so on).
loadColors
Load a set of colors to be used in the app.
These colors will be accessible through the Colors class and as modifiers.
usage:
import {Colors} from 'react-native-ui-lib';
Colors.loadColors({
error: '#ff2442',
success: '#00CD8B',
text: '#20303C'
});
import {View, Text, Colors} from 'react-native-ui-lib';
<View>
<Text style={{color: Colors.error}}>Error Message</Text>
<Text success>Success Message</Text>
<View>
loadSchemes
Load a set of scheme colors to support dark/light mode.
This feature works hand in hand with our modifiers
This method also supports adding and overriding design tokens:
Colors.loadSchemes({
light: {
screenBG: 'transparent',
textColor: Colors.grey10,
moonOrSun: Colors.yellow30,
mountainForeground: Colors.green30,
mountainBackground: Colors.green50,
$backgroundSuccess: Colors.green40,
$backgroundSuccessLight: Colors.green70
},
dark: {
screenBG: Colors.grey10,
textColor: Colors.white,
moonOrSun: Colors.grey80,
mountainForeground: Colors.violet10,
mountainBackground: Colors.violet20,
$backgroundSuccess: Colors.green40,
$backgroundSuccessLight: Colors.green20
}
});
<View flex padding-page bg-screenBG>
<Text h1 textColor>
Dark Mode
</Text>
</View>
Note: for dark mode support please add the following require
in your app, in an initial place, before importing react-native-ui-lib
at the first time.
require('react-native-ui-lib/config').setConfig({appScheme: 'default'});
rgba
usage:
import {Colors} from 'react-native-ui-lib';
Colors.rgba('#ff2442', 0.05); // 'rgb(255, 36, 66, 0.05)'
Colors.rgba(44, 224, 112, 0.2); // 'rgb(44, 224, 112, 0.2)'
getColorTint
usage:
import {Colors} from 'react-native-ui-lib';
Colors.getColorTint(Colors.green30, 70); // will return the value of Colors.green70
Colors.getColorTint('#ff2442', 50); // will return the 5th tint in an autogenerate 8-tints palette based on '#ff2442'
isDark
returns true
if a color is considered dark (bright colors will return false
)
import {Colors} from 'react-native-ui-lib';
Colors.isDark(Colors.grey10); // true
Colors.isDark(Colors.grey80); // false