Skip to main content

Default Theme

The BaseTheme<TColors> theme object is where you define your application's color palette, type scale, borders, border radius values, and more.

info

First of all you need to install @flexnative/theme-context. Fallow instructions here on how to install and how to use @flexnative/theme-context.

Base Theme Interface

The BaseTheme interface acts as the contract for the theme object in FlexNative. It defines the structure of the data available through the ThemeContext, including colors, metrics, and configuration flags.

Definition

The interface uses a generic TColors to support custom color extensions while maintaining type safety.

export interface BaseTheme<TColors> {
colors: BaseColors & TColors;
scheme: ColorSchemeName;
isDark: boolean;
borders: Borders;
spaces: Record<Spaces, number>;
fontSize: Record<FontSize, number>;
}

Properties

PropertyTypeDescription
colorsBaseColors & TColorsThe active color palette. This includes standard semantic colors (primary, success, etc.) merged with any custom colors defined in TColors.
schemeColorSchemeNameThe current color scheme preference, usually 'light' or 'dark'.
isDarkbooleanA convenient boolean flag derived from the scheme. Returns true if the theme is dark.
bordersBordersContains configuration for border width and radius.
spacesRecord<Spaces, number>A dictionary of spacing values (margins, paddings) keyed by size names (e.g., sm, md).
fontSizeRecord<FontSize, number>A dictionary of font size values keyed by size names.

BaseColors

Default theme colors. You can extend the BaseColors with your own color properties.

NameTypeRequiredLight ValueDark Value
whiteColorValuetrue #FFFFFF #FFFFFF
blackColorValuetrue #3d3d3d #1f1f1f
defaultColorValuetrue #f5f5f5 #3D3D3D
backgroundColorValuetrue #fafafa #141414
cardColorValuetrue #ffffff #3d3d3d
textColorValuetrue #424242 #F5F5F5
borderColorValuetrue #00000014 #42424226
placeholderColorValuetrue #666666 #0000001A
infoColorValuetrue #0058e9 #0058e9
successColorValuetrue #37b400 #37b400
warningColorValuetrue #ffc000 #ffc000
errorColorValuetrue #f31700 #f31700
darkColorValuetrue #3d3d3d #3d3d3d
secondaryColorValuetrue #666666 #C2C2C2
lightColorValuetrue #ebebeb #E0E0E0
primaryColorValuetrue #ff6358 #EA5A51

Spaces

Spacing values for layout, such as margins and paddings. This is a key part of the theme that helps maintain consistent spacing across components.

NameTypeValueDescription
nonenumber0No spacing.
xxxsnumber2Spacing of 2 units.
xxsnumber4Spacing of 4 units.
xsnumber6Spacing of 6 units.
smnumber8Spacing of 8 units.
mdnumber12Spacing of 12 units.
defaultnumber16Spacing of 16 units.
lgnumber18Spacing of 18 units.
xlnumber24Spacing of 24 units.
xxlnumber32Spacing of 32 units.
xxxlnumber36Spacing of 36 units.
numbernumberA custom numeric spacing value.

FontSize

Represents the possible font sizes used for text elements.

NameTypeValueDescription
xxsnumber8A small font size, 8 units.
xsnumber12The default font size, 12 units.
smnumber14A medium font size, 14 units.
mdnumber16A large font size, 16 units.
lgnumber18A large font size, 18 units.
xlnumber20A large font size, 20 units.
xxlnumber24A large font size, 24 units.
numbernumberA custom numeric font size.

Borders

Border styles for components. This can include border widths, radius to ensure a consistent look and feel across your UI components.

BorderWidth

Represents the possible border width values.

NameTypeValueDescription
nonenumber0No border width (0).
hairlinenumberA hairline border width, typically the thinnest possible line on the device. See StyleSheet.hairlineWidth.
thinnumber1A thin border width, 1 unit.
basenumber2A base border width, 2 units.
thicknumber3A thick border width, 3 unit.
numbernumberA custom numeric border width.

BorderRadius

Represents the possible border radius values.

NameTypeValueDescription
nonenumber0No border radius (0).
smallnumber2A small border radius (2 units).
mediumnumber4A medium border radius (4 units).
largenumber6A large border radius (6 units).
fullnumber99999A fully rounded border radius (99999 units).
numbernumberA custom numeric border radius.

Usage Example

When creating a custom theme, you conform to this interface. Typically, you start with the default theme and override specific properties.

import { BaseTheme, defaultTheme } from '@flexnative/theme-context';

// 1. Define your custom colors type
interface MyCustomColors {
brand: string;
accent: string;
}

// 2. Create the theme object
const myAppTheme: BaseTheme<MyCustomColors> = {
...defaultTheme(),
colors: {
...defaultTheme().colors,
brand: '#5E72E4',
accent: '#11CDEF',
},
// Overriding standard metrics
borders: {
width: { ...defaultTheme().borders.width, thin: 1 },
radius: { ...defaultTheme().borders.radius, small: 4 }
}
};