BlueBase exports a ThemeConsumer
component to utilise current theme. This is a render prop component, which means it takes a function as a child. The function gets an object in the param with the following interface:
The following snippet illustrates how to use a ThemeConsumer
component.
The following example shows how to use ThemeConsumer
component to create a theme picker. This renders a picker component with a list of all installed themes. It not only uses the current theme to style itself, but also utilises the changeTheme
method to switch themes.
Theming in BlueBase provides an elaborate mechanism to customise component styles. Following is a list of options to do this in a sequence of lowest to highest priority.
Component styles in all of the following methods can be thunks as well.
defaultStlyes
static propIn BlueBase it is possible to provide a defaultStyles
static property to a component. This is very similar to the defaultProps
concept of React.
In terms of priority, this method has the least priority, and these styles may be overwritten by any of the following methods.
Use this method to define the default styles of the component. These will represent a state of the component without any customisation.
It is also possible to save styles of a component in the ComponentRegistry.
In terms of priority, these styles override defaultStyles
but they can be overwritten by following methods.
Us this method when you want to define global styles of a component, but you also want other plugins to able to customise them.
styles
propIn BlueBase, ComponentStyles have the following structure:
This is very similar to React Native's StyleSheet.create API.
Thunks
Describe best practices: root, hover, etc.
There are following configuration in BlueBase:
Key
Default
Description
theme.mode
light
This is the theme mode. Can be "light" or "dark".
theme.name
bluebase-light
This is the slug of the selected theme. Changing this value will cause a re-render to all themed components.
theme.overrides
Theme
Theme overrides. These are applied to all installed themes.
BlueBase supports different types of theme customisation requirements so that a developer can do a single usage customisation or globally override a theme.
There may be use cases where you may need to keep specific values same, no matter which theme is selected, i.e. primary colours, etc.
To do this, use the theme.overrides
config. This change is global, and overrides all installed themes.
BlueBase ships with two built-in themes: BlueBase Light
& BlueBase Dark
. You can extend any of the two to create you own theme.
Using the ThemeProvider
overrides prop. This change is only for this tree.
Nesting themes
Overriding themes
It is possible to nest multiple themes in a single project. To theme a specific portion of your app, use the ThemeProvider
component.
In the example above, we pass the theme
prop to the ThemeProvider
component. This prop takes the key of the theme to use for children components. If this prop is not set, the globally selected theme is used.
The ThemeProvider
component can also be used to override a theme for a one time usage.
The theme specifies the color of the components, darkness of the surfaces, level of shadow, appropriate opacity of ink elements, etc.
Themes let you apply a consistent tone to your app. It allows you to customize all design aspects of your project in order to meet the specific needs of your business or brand.
To promote greater consistency between apps, each theme has light and dark variants By default, components use the light theme type.
If you wish to customize the theme, you need to use the ThemeProvider
component in order to inject a theme into your application. However, this is optional; BlueBase components come with a default theme.
ThemeProvider
relies on the context feature of React to pass the theme down to the components, so you need to make sure that ThemeProvider
is a parent of the components you are trying to customize. You can learn more about this in the API section.
The community has built great tools to build a theme:
mui-theme-creator: A tool to help design and customize themes for the MUI component library. Includes basic site templates to show various components and how they are affected by the theme
Material palette generator: The Material palette generator can be used to generate a palette for any color you input.
TODO: Move code splitting guide from this page to here.