Skip to content

Styling and theming

Mosyn owns the grid surface, tile boundaries, selection treatment, resize handles, and drag overlays. Your application owns everything inside a tile. This guide covers both halves: theming Mosyn’s chrome, and styling your own content.

Import Mosyn’s stylesheet once, before rendering a grid.

main.tsx
import 'mosyn/style.css';

MosynManager takes three appearance props. They apply to every root and nested grid beneath it, including drag feedback.

<MosynManager
dark
dots={false}
theme={{
gridBackground: '#101826',
tileBackground: '#172235',
tileColor: '#e6edf7',
tileSelectedBorder: '#2dd4bf',
actionBackground: '#0f766e',
}}
>
<Mosyn tiles={tiles} />
</MosynManager>

dark and dots default to false. Every theme key is optional — provide only the tokens your design system needs to replace, and the rest fall back to the built-in light or dark values.

theme accepts the MosynTheme object below. Each key maps to a CSS custom property on the grid element, so anything you can express in CSS — including color-mix() or a var() reference to your own design tokens — is a valid value.

Token CSS variable What it colours
gridBackground --mosyn-grid-background The grid surface
gridDots --mosyn-grid-dots Dot pattern, when dots is on
tileBackground --mosyn-tile-background Tile fill
tileColor --mosyn-tile-color Default text colour inside a tile
tileBorder --mosyn-tile-border Tile border at rest
tileHoverBorder --mosyn-tile-hover-border Tile border on hover
tileSelectedBorder --mosyn-tile-selected-border Selected tile border
resizeHandleBackground --mosyn-resize-handle-background Resize handle fill
resizeHandleBorder --mosyn-resize-handle-border Resize handle border
spaceBackground --mosyn-space-background Empty-slot affordance fill
spaceBorder --mosyn-space-border Empty-slot affordance border
spaceColor --mosyn-space-color Empty-slot affordance text
ghostBackground --mosyn-ghost-background Drag placement preview
ghostSuccessBackground --mosyn-ghost-success-background Preview on a valid drop
actionBackground --mosyn-action-background Contextual action preview
actionErrorBackground --mosyn-action-error-background Action preview on an invalid drop
edgeBackground --mosyn-edge-background Edge-fit (split) preview
edgeErrorBackground --mosyn-edge-error-background Edge preview on an invalid drop

Every appearance prop also exists on <Mosyn />, so a nested workspace can look different from the grid that contains it. The two props resolve differently, and the difference matters:

  • dark and dots replace. A grid uses its own value, or the provider’s when it does not set one.
  • theme merges. Provider tokens and grid tokens are shallow-merged, with the grid’s winning. You override a few tokens without restating the rest.
NestedGrid.tsx
function NestedGrid({ tile }: { tile: Tile }) {
return (
<Mosyn
tiles={tile.children ?? []}
container={tile}
dark={false}
theme={{ gridBackground: '#effaf7', tileBackground: '#ffffff' }}
/>
);
}

Because theme merges, that nested grid keeps every accent token from the provider — ghosts, edges, and actions still match the app — while replacing only the two surface colours.

Naming a whole palette once and switching between them by key keeps the theme out of your components. Pair each Mosyn theme with the tokens your own tile content needs, so both change together.

theme.ts
import type { MosynTheme } from 'mosyn';
export interface AppTheme {
label: string;
/** Mirrors the theme's own light/dark intent for the `dark` prop. */
dark: boolean;
mosyn: MosynTheme;
/** Tokens your tile content reads. */
card: { background: string; foreground: string; accent: string };
}
export const THEMES: Record<'mint' | 'midnight', AppTheme> = {
mint: {
label: 'Mint',
dark: false,
mosyn: {
gridBackground: '#effaf7',
tileBackground: '#ffffff',
tileColor: '#123d36',
tileBorder: '#c7e8df',
tileHoverBorder: '#0f8a74',
tileSelectedBorder: '#087861',
ghostBackground: '#0f8a74',
actionBackground: '#087861',
edgeBackground: '#087861',
},
card: { background: '#dff5f2', foreground: '#164e63', accent: '#159b8c' },
},
midnight: {
label: 'Midnight',
dark: true,
mosyn: {
gridBackground: '#0b1324',
tileBackground: '#14203a',
tileColor: '#e5edff',
tileBorder: '#2b3d5f',
tileHoverBorder: '#67a8ff',
tileSelectedBorder: '#8ab8ff',
ghostBackground: '#387ee8',
actionBackground: '#387ee8',
edgeBackground: '#387ee8',
},
card: { background: '#172d4d', foreground: '#d7e7ff', accent: '#67a8ff' },
},
};

Switching is then a state change, and dark travels with the palette rather than being tracked separately:

Dashboard.tsx
const [name, setName] = useState<'mint' | 'midnight'>('mint');
const theme = THEMES[name];
return (
<MosynManager dark={theme.dark} theme={theme.mosyn}>
<Mosyn tiles={tiles} />
</MosynManager>
);

Mosyn themes its own chrome, not what you render inside a tile. To keep tiles consistent with the grid, put the palette on a context and read it from your renderers.

ThemedCard.tsx
const ThemeContext = createContext<AppTheme>(THEMES.mint);
function ThemedCard({ label }: { label: string }) {
const { card } = useContext(ThemeContext);
return (
<div
className="card"
style={{ background: card.background, color: card.foreground }}
>
{label}
</div>
);
}

When a nested grid runs its own palette, give it its own provider so tiles inside it pick up the nested theme rather than the root one. A tile that transfers between grids keeps the context of wherever it is rendered, so its appearance follows the move.

Give the root element of a renderer a full width and height so it tracks the tile’s geometry.

MetricTile.tsx
export function MetricTile() {
return (
<section className="metric-tile">
<span>Monthly revenue</span>
<strong>$48,250</strong>
</section>
);
}
dashboard.css
.metric-tile {
display: flex;
width: 100%;
height: 100%;
padding: 1rem;
flex-direction: column;
justify-content: space-between;
border-radius: 0.5rem;
background: #effcf8;
color: #123d37;
}

A tile is a drag handle by default, which swallows clicks on buttons and inputs inside it. Pass DragCancel selectors to exclude them.

<Mosyn tiles={tiles} DragCancel={['button', 'input', '.no-drag']} />

Prefer theme tokens where one exists — they apply per grid and survive future style changes. For structural changes that no token covers (radius, shadow, spacing), the shipped stylesheet uses stable selectors. Override them in a stylesheet loaded after mosyn/style.css.

dashboard.css
.mosyn-tile {
border-radius: 0.75rem;
box-shadow: 0 8px 24px rgb(24 68 61 / 8%);
}
Selector Purpose
.mosyn-grid Root grid surface
.mosyn-grid.mosyn-nested Nested grid surface
.mosyn-grid.mosyn-disabled View-only grid
.mosyn-tile Tile outer element
.mosyn-tile.mosyn-selected Selected tile
.mosyn-tile-content Tile content wrapper
.mosyn-resize-handle Resize handle
#mosyn-ghost Drag placement preview
#mosyn-action Contextual action preview
#mosyn-edge Edge-fit preview

Grids also carry data-mosyn-theme="dark" | "light" and data-mosyn-dots="true" | "false", which you can target when a rule should only apply in one mode.

dashboard.css
.mosyn-grid[data-mosyn-theme='dark'] .mosyn-tile {
box-shadow: 0 8px 24px rgb(0 0 0 / 45%);
}