Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Theme

The theme class provides a quick way to fulfill the ITheme interface. Themed components pick out styling aliases from the ITheme interface to style themselves. The Theme class allows for pervasive styling changes to occur to a application. For example, updating one of the red normal colour constant colours will update that colour across the application.

The only required argument is a base colour that is used to determine the secondary and accent colours for the theme.

const theme = new Theme({ base: 'blue' });

The base colour name can be one of the aliases properties in the IColours interface.

The theme is a nested structure of classes that can all be overridden and customised.

import {
  Theme,
  Constants,
  Font,
  FontSize,
  Colours
} from '@ef-carbon/react-native-style';

// Customise the divisions used for the font size
const fontSize = new FontSize({ base: {
  200: 9,   // smallest
  300: 12,  // smaller
  400: 14,  // small
  500: 16   // normal
}});

// Package up the font size into the font constants. The rest of the font constants will use their default values
const font = new Font({ size: fontSize });

// Override some of the colours used to determine the theme mixins
const colours = new Colours({
  // Specify the specific shades of grey
  grey: {
    100: '#eff3f5',  // theme.constants.colour.grey.lightest
    200: '#dbe6ec',  // theme.constants.colour.grey.lighter
    300: '#99a9b3',  // theme.constants.colour.grey.light
    500: '#67747c',  // theme.constants.colour.grey.normal
    600: '#3b444f',  // theme.constants.colour.grey.darkened
    700: '#2c3643'   // theme.constants.colour.grey.dark
  },
  // Provide a starting value for the central blue value.
  // The rest of the shades will be automatically calculated
  // by adjusting the lightness of the colour
  blue: '#1c5ff5'  // theme.constants.colour.blue.normal
});

// Package up the colours and font constants
const constants = new Constants({ font, colour: colours });

// Use the constants in the theme that will
// be used for the style mixins
const theme = new Theme({
  base: 'blue',
  constants
});
see

ITheme

see

Constants

see

ThemeColour

see

ThemeFont

see

Margin

see

Padding

see

ThemeOpacity

see

ThemeBorder

see

IConstants

see

IThemeColour

see

IThemeFont

see

IMargin

see

IPadding

see

IThemeOpacity

see

IThemeBorder

Hierarchy

  • Theme

Implements

Index

Constructors

constructor

  • new Theme(__namedParameters: object): Theme
  • Parameters

    • __namedParameters: object
      • base: "red" | "pink" | "purple" | "deepPurple" | "indigo" | "blue" | "lightBlue" | "cyan" | "teal" | "green" | "lightGreen" | "lime" | "yellow" | "amber" | "orange" | "deepOrange" | "brown" | "grey" | "blueGrey" | "black" | "white"
      • border: undefined | IThemeBorder
      • colour: undefined | IThemeColour
      • constants: undefined | IConstants
      • font: undefined | IThemeFont<IFontStyles>
      • margin: undefined | IMargin
      • opacity: undefined | IThemeOpacity
      • padding: undefined | IPadding

    Returns Theme

Properties

border

border: Readonly<IBorder>

colour

colour: Readonly<IColour>

constants

constants: Readonly<IConstants>

font

font: Readonly<IFont>

margin

margin: Readonly<IMargin>

opacity

opacity: Readonly<IOpacity>

padding

padding: Readonly<IPadding>