Skip to content

Theming

The SDK includes a powerful theming system that supports custom colors, derived colors, and responsive styling.

Basic Theme Configuration

typescript
import { ThemeProvider } from '@wlloyalty/wll-react-sdk'

const customTheme = {
 background: '#F0F0F0',
  text: '#000000',
  primary: '#392ed7',
  accent: '#ff6a3d',
  surface: '#f8f7fc',
  surfaceText: '#000000',
  positive: '#008000',
  negative: '#ff0000',
}

function App() {
  return (
    <ThemeProvider theme={customTheme}>
      {/* Your app content */}
    </ThemeProvider>
  )
}

Base Theme Properties

PropertyTypeDescription
accentstringSecondary brand color
backgroundstringPage background
primarystringPrimary brand color
surfacestringComponent background
surfaceTextstringText on surface
textstringDefault text color
negativestringNegative actions/states
positivestringPositive actions/states

Derived Colors

The theme system automatically generates derived colors for various use cases, these are not customisable:

Contrast Colors

typescript
type DerivedProperties = {
  accentText: string      // Readable text on accent
  primaryText: string     // Readable text on primary
  positiveText: string    // Readable text on positive
  negativeText: string    // Readable text on negative
}

Color Variations

typescript
type DerivedColors = {
  [percentage in 5 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 95]: string
}

type ColorVariations = {
  derivedSurfaceText: DerivedColors  // Text opacity variations
  derivedSurface: DerivedColors      // Surface color variations
  alphaDerivedPrimary: DerivedColors // Primary with alpha
  alphaDerivedText: DerivedColors    // Text with alpha
}

Color Utilities

Contrast Calculation

typescript
// Automatically selects white or black based on background
const textColor = getReadableTextColor(backgroundColor)

State Colors

typescript
// Handles inactive/disabled states
const color = getStateColor(baseColor, type, count)

Alpha Variations

typescript
// Generates alpha variations of a color
const alphaColors = getAlphaDerivedColors(color)

Using Theme in Components

typescript
function MyComponent() {
  const { theme } = useWllSdk()

  return (
    <View style={{
      backgroundColor: theme.surface,
      borderColor: theme.alphaDerivedPrimary[20]
    }}>
      <Text style={{ color: theme.surfaceText }}>
        Themed Content
      </Text>
    </View>
  )
}

Responsive Sizing

The theme includes predefined sizes for consistent spacing:

typescript
const sizes = {
  borderRadiusSm: 8,
  borderRadiusLg: 12,
}

Released under the MIT License.