Skip to content
Cartly Developers

Admin Design Tokens

CSS custom properties (--adm-*) for the Cartly admin panel. Use these tokens in embedded apps and App Bridge extensions to match the admin's visual language across light and dark modes.

Overview

The Cartly admin panel (v1.16+) uses a token-based design system. All colours, spacing, typography, and border values are expressed as CSS custom properties prefixed with --adm-. These tokens are defined on the .cartly-admin class and cascade to all children — including embedded app iframes that receive the token map via postMessage.

The token set supports dark mode (default) and light mode. The active mode is stored in localStorage under the key cartly-admin-theme and applied as a data-theme attribute on <html>.

--adm-* Token Reference

Colours — Background

TokenDark valueUsage
--adm-bg-canvas#0a0a0aOutermost page background
--adm-bg-surface#111111Cards, panels, sidebars
--adm-bg-elevated#1a1a1aModals, dropdowns, popovers
--adm-bg-subtle#1f1f1fHover states, stripes

Colours — Text

TokenUsage
--adm-text-primaryBody copy, labels
--adm-text-secondaryMeta text, descriptions
--adm-text-tertiaryPlaceholders, disabled
--adm-text-inverseText on accent/danger fills

Colours — Semantic

TokenUsage
--adm-accentPrimary action buttons, links
--adm-accent-hoverHover state for accent
--adm-accent-fgText on accent background
--adm-dangerDestructive actions, errors
--adm-danger-hoverHover state for danger
--adm-warningWarnings, amber badges
--adm-successConfirmations, green badges
--adm-borderDividers, card outlines
--adm-border-subtleLight separators inside cards

Spacing

TokenValue
--adm-space-14px
--adm-space-28px
--adm-space-312px
--adm-space-416px
--adm-space-624px
--adm-space-832px

Typography

TokenValue
--adm-text-xs11px
--adm-text-sm13px
--adm-text-base14px
--adm-text-lg16px
--adm-font-normal400
--adm-font-medium500
--adm-font-semibold600

Border Radius

TokenValue
--adm-radius-sm4px
--adm-radius-md6px
--adm-radius-lg8px
--adm-radius-xl12px
--adm-radius-full9999px
css
/* Use --adm-* tokens to match the Cartly admin visual language */
.my-app-sidebar {
  background: var(--adm-bg-surface);
  border: 1px solid var(--adm-border);
  border-radius: var(--adm-radius-md);
  color: var(--adm-text-primary);
}

.my-app-button {
  background: var(--adm-accent);
  color: var(--adm-accent-fg);
  padding: var(--adm-space-2) var(--adm-space-4);
  border-radius: var(--adm-radius-sm);
  font-size: var(--adm-text-sm);
  font-weight: var(--adm-font-medium);
}

.my-app-button:hover {
  background: var(--adm-accent-hover);
}

.my-app-danger-zone {
  border-color: var(--adm-danger);
  color: var(--adm-danger);
}

cartly-admin Wrapper

Critical: the --adm-* tokens are scoped to the .cartly-admin CSS class. Any element that uses these tokens must be a descendant of an element with this class. Without the wrapper, the custom properties resolve to initial (empty string in most browsers) and the UI will render unstyled.

All admin routes in the Cartly admin panel are wrapped in <div class="cartly-admin"> in frontend/app/routes/admin.tsx. If your embedded app renders in a separate context (e.g. a full-screen app frame or a custom iframe), you must add the wrapper class yourself.

html
<!-- CORRECT: wrap admin content in .cartly-admin -->
<!-- Without this class, --adm-* tokens resolve to initial (undefined). -->
<div class="cartly-admin">
  <div class="my-embedded-panel">
    <!-- tokens work here -->
  </div>
</div>

<!-- In React (embedded app iframe via App Bridge): -->
import { useEffect } from 'react';

export function AppPanel({ children }) {
  // The host frame sets data-theme="dark"|"light" on the cartly-admin
  // wrapper based on the merchant's preference. Your iframe inherits
  // the CSS variables via the postMessage theme token push — apply
  // them to your root element.
  useEffect(() => {
    // cartly-bridge.js calls this when theme changes
    window.CartlyBridge?.onThemeChange((tokens) => {
      const root = document.documentElement;
      Object.entries(tokens).forEach(([k, v]) => root.style.setProperty(k, v));
    });
  }, []);

  return <div className="cartly-admin">{children}</div>;
}

Theme Bridge

The admin supports dark and light modes. The active theme is stored in localStorage (key: cartly-admin-theme) and applied as data-theme="dark" | "light" on <html>.

A pre-paint inline script in <head> reads localStorage and sets the attribute before React hydrates — preventing a flash-of-wrong-theme. A post-mount useEffect in AdminThemeBridge.tsx then re-applies and keeps it in sync with user preference changes.

When the merchant changes theme in the admin topbar, the new preference is written to localStorage and the attribute is toggled immediately via the bridge component — no page reload.

javascript
// Theme bridge — how Cartly admin handles dark/light mode.
//
// Problem: React hydrates on the server with class="light" baked in.
// After hydration React sets the class per JSX — but by then the page
// has already painted with the wrong tokens, causing a flash.
//
// Solution: two-phase approach
//   Phase 1 — pre-paint script in <head> reads localStorage and sets
//              data-theme on <html> BEFORE React loads.
//   Phase 2 — post-mount useEffect in AdminThemeBridge.tsx re-applies
//              the theme attribute and persists changes to localStorage.
//
// Source: frontend/app/components/admin/AdminThemeBridge.tsx
//         frontend/app/root.tsx (inline script in <head>)

// Pre-paint script (inlined in HTML <head>, runs synchronously):
(function() {
  try {
    var t = localStorage.getItem('cartly-admin-theme') || 'dark';
    document.documentElement.setAttribute('data-theme', t);
  } catch(e) {}
})();

// Post-mount hook (in AdminThemeBridge component):
useEffect(() => {
  const saved = localStorage.getItem('cartly-admin-theme') ?? 'dark';
  document.documentElement.setAttribute('data-theme', saved);
}, []);

Embedded Apps

Apps embedded via App Bridge (iframe) receive the current --adm-* token map as a postMessage payload of type CARTLY_THEME_TOKENS on load and on every theme change. Apply the received tokens to your iframe's root element to stay in sync with the host admin panel:

javascript
window.addEventListener('message', (e) => {
  if (e.data?.type !== 'CARTLY_THEME_TOKENS') return;
  const root = document.documentElement;
  Object.entries(e.data.tokens).forEach(([k, v]) => {
    root.style.setProperty(k, v);
  });
});

For full-screen app routes (routes that render outside the standard admin layout), wrap your content in .cartly-admin and set data-theme yourself based on the received tokens or the localStorage value.

See App Bridge documentation for the full postMessage protocol.