Skip to main content

Theme System

The theme system provides design tokens and CSS variables that automatically adapt to the store's theme. The theme object gives you access to the variables configured in each store, allowing your components to integrate seamlessly with each store's unique styling. The theme API is exported from @tiendanube/nube-sdk-ui.

Available Theme Tokens

Import with: import { theme } from "@tiendanube/nube-sdk-ui";

Base and main colors

TokenDescription
theme.color.accentPrimary accent color.
theme.color.main.foregroundMain text color.
theme.color.main.backgroundMain background color.

Status colors (each has .light, .medium, .dark)

TokenDescription
theme.color.successSuccess color variants.
theme.color.warningWarning color variants.
theme.color.dangerDanger color variants.
theme.color.infoInfo color variants.
theme.color.neutralNeutral color variants.

Text colors

TokenDescription
theme.color.text.highHigh contrast text.
theme.color.text.mediumMedium contrast text.
theme.color.text.lowLow contrast text.

Typography

TokenDescription
theme.typography.body.font, .fontSize, .lineHeight for body text.
theme.typography.xlExtra large: .fontSize, .lineHeight.
theme.typography.lgLarge: .fontSize, .lineHeight.
theme.typography.baseBase: .fontSize, .lineHeight.
theme.typography.mdMedium: .fontSize, .lineHeight.
theme.typography.smSmall: .fontSize, .lineHeight.
theme.typography.xsExtra small: .fontSize, .lineHeight.

Borders

TokenDescription
theme.border.colorDefault border color.
theme.border.radiusDefault border radius.
theme.box.border.colorBox border color.
theme.box.border.radiusBox border radius.

Component tokens

TokenDescription
theme.button.foreground, .background, .border.color, .border.radius, .border.width
theme.label.foreground, .background
theme.input.border.colorInput border color.
theme.header.foreground, .background, .logo.* (maxWidth, maxHeight, font, fontSize, fontWeight, textTransform, letterSpacing)
theme.footer.foreground, .background
theme.heading.font, .fontWeight, .textTransform, .letterSpacing

For the full theme shape and types, see @tiendanube/nube-sdk-ui.

Using Theme Colors

Theme colors automatically adapt to the store's theme:

import type { NubeSDK } from "@tiendanube/nube-sdk-types";
import { StyleSheet, theme } from "@tiendanube/nube-sdk-ui";
import { Button } from "@tiendanube/nube-sdk-jsx";

const styles = StyleSheet.create({
adaptiveButton: {
backgroundColor: theme.color.accent,
color: theme.color.main.foreground,
},
});

function MyComponent() {
return <Button style={styles.adaptiveButton}>Adaptive button</Button>;
}

export function App(nube: NubeSDK) {
nube.render("before_main_content", <MyComponent />);
}

Theme Color Opacity

You can create transparent versions of theme base colors using predefined opacity values:

Testing this example

In order to see this example in action, navigate to the checkout in your store.

import type { NubeSDK } from "@tiendanube/nube-sdk-types";
import { StyleSheet, theme } from "@tiendanube/nube-sdk-ui";
import { Box, Text } from "@tiendanube/nube-sdk-jsx";

const styles = StyleSheet.create({
container: {
gap: "8px",
padding: "16px",
},
heavy: {
backgroundColor: theme.color.accent.opacity(80),
padding: "12px",
},
medium: {
backgroundColor: theme.color.accent.opacity(50),
padding: "12px",
},
light: {
backgroundColor: theme.color.accent.opacity(20),
padding: "12px",
},
});

function MyComponent() {
return (
<Box style={styles.container}>
<Box style={styles.heavy}>
<Text>80% opacity</Text>
</Box>
<Box style={styles.medium}>
<Text>50% opacity</Text>
</Box>
<Box style={styles.light}>
<Text>20% opacity</Text>
</Box>
</Box>
);
}

export function App(nube: NubeSDK) {
nube.render("before_main_content", <MyComponent />);
}

Available opacity values: 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90 (percentage). Use with theme colors that support .opacity(), e.g. theme.color.accent, theme.color.main.background.