Theming

Customise elements to match your dApps styles.

Default Themes

We're using CSS Variables, aka CSS Custom Properties for the theming system. We ship a light and a dark mode.

For the styles to appear please add leap-ui class to a parent element of any component you use.

For the theme to be applied, you will need to add leap-ui class to a parent element. And to use the dark mode, you'll have to add dark class to the same parent element. Here's an example

import {
  IBCSwaps,
  type IBCSwapsProps,
  WalletClientContextProvider
} from '@leapwallet/elements'
import { useState } from 'react'
import { useElementsWalletConfig } from './elements-wallet-config'
import { useTheme } from './use-theme'

import '@leapwallet/elements/styles.css'

const YourDapp = () => {
  const walletClientConfig = useElementsWalletConfig()

  // useTheme is just an example hook to get the current theme
  // let's say the theme variable is 'dark' or 'light'
  const theme = useTheme()

  return (
    <div className={`leap-ui ${theme === 'dark' ? 'dark' : ''}`}>
      <WalletClientContextProvider value={walletClientConfig}>
        <IBCSwaps />
      </WalletClientContextProvider>
    </div>
  )
}

Customisation

The default themes are great starters, however we give you complete control over the theme. However for most dApps, changing a few theme variables is enough. Let's say we're integrating the swaps modal on the stride app, here's the variables I would change

/*
 * The Stride dApp is in light mode, so we will update .leap-ui declaration
 */
.leap-ui {
  /*
   * Stride primary colour is #E50571
   * Convert it to HSL - hsl(331deg, 95.7%, 45.9%)
   * We set the --primary variable to 331 95.7% 45.9%
   */
  --primary: 331 95.7% 45.9%;
  /*
   * Primary Foreground colour - white
   */
  --primary-foreground: 0 0% 100%;
  /*
   * Ring colour - hsl(323deg, 94.2%, 59.2%)
   */
  --ring: 323 94.2% 59.2%;
  /*
   * Background colour - white
   */
  --background: 0 0% 100%;
  /*
   * Foreground colour - hsl(331deg, 100%, 11.8%)
   */
  --foreground: 331 100% 11.8%;
}

Find the full theme for stride and other dApps here - https://git.new/elements-themes

Let's compare the default light theme and the stride light theme

If you want the UI to look exactly like your dApp, here's all the CSS custom properties that you can modify with their descriptions

Troubleshooting Common Issues

>>> The default styles for elements are not coming up

It's most likely because you haven't added the following CSS import to your app

import '@leapwallet/elements/styles.css'

>>> I have customised the CSS variables, but it doesn't change the theme

This happens due to the cascading nature of CSS. Here's a few solutions (in-order) you should try

#1 Import your customisation styles after element's stylesheets

import '@leapwallet/elements/styles.css'
import './styles/elements-customisations.css'

#2 Add an additional selector to the customisations block

.leap-ui.my-dapp-class {
    --font-family: 'Helvetica', 'SF Pro', sans-serif;
}
const YourDapp = () => {
    return (
        <div className={`leap-ui my-dapp-class`}>
          <WalletClientContextProvider value={walletClientConfig}>
            <IBCSwaps />
          </WalletClientContextProvider>
        </div>
    )
}

Last updated