Meridian/Reference · StyleX in use
Tokens · StyleX in use
Themes and components.
With no theme applied, everything follows the OS. Spread
theme.dark or theme.light to force one on any subtree. Components accept a style prop of StyleX styles for overrides.components/Button.tsx
import * as stylex from "@stylexjs/stylex";
import type { StyleXStyles } from "@stylexjs/stylex";
import type { ComponentProps, ReactNode } from "react";
import { colors, radius, shadows } from "../tokens/tokens.stylex";
import { Kbd } from "./Kbd";
import { focus, transition } from "./shared";
export type ButtonVariant = "primary" | "accent" | "secondary" | "ghost" | "danger" | "dangerSolid";
export type ButtonSize = "sm" | "md" | "lg";
export interface ButtonProps extends Omit<ComponentProps<"button">, "className" | "style"> {
/** primary = ink, the main action (one per view). accent = Cobalt, the one conversion moment. */
variant?: ButtonVariant;
size?: ButtonSize;
/** Leading icon, sized 14px by the caller. */
icon?: ReactNode;
/** Shortcut shown inside the button, e.g. "⌘↵". */
shortcut?: string;
/** Square, icon-only. Requires aria-label. */
iconOnly?: boolean;
style?: StyleXStyles;
}
export function Button({
variant = "secondary",
size = "md",
icon,
shortcut,
iconOnly = false,
style,
children,
type = "button",
...props
}: ButtonProps) {
const onFill = variant === "primary" || variant === "accent" || variant === "dangerSolid";
return (
<button
type={type}
{...props}
{...stylex.props(
styles.base,
transition.colors,
focus.ring,
variants[variant],
sizes[size],
iconOnly && iconOnlySizes[size],
style,
)}
>
{icon}
{children}
{shortcut && <Kbd style={[styles.kbd, onFill && styles.kbdOnFill]}>{shortcut}</Kbd>}
</button>
);
}
const styles = stylex.create({
base: {
alignItems: "center",
borderStyle: "none",
cursor: { default: "pointer", ":disabled": "default" },
display: "inline-flex",
flexShrink: 0,
fontFamily: "inherit",
fontWeight: 500,
justifyContent: "center",
letterSpacing: "-0.01em",
lineHeight: 1,
opacity: { default: 1, ":disabled": 0.4 },
pointerEvents: { default: "auto", ":disabled": "none" },
userSelect: "none",
whiteSpace: "nowrap",
},
kbd: { height: "18px", marginInlineStart: "2px" },
/** Tint from the button's own text colour, so it reads on ink in both themes. */
kbdOnFill: {
backgroundColor: "color-mix(in srgb, currentColor 12%, transparent)",
borderColor: "color-mix(in srgb, currentColor 16%, transparent)",
color: "currentColor",
opacity: 0.75,
},
});
const variants = stylex.create({
primary: {
backgroundColor: { default: colors.ink, ":hover": colors.inkHover },
boxShadow: shadows.sm,
color: colors.inkFg,
},
accent: {
backgroundColor: { default: colors.accent, ":hover": colors.accentHover },
boxShadow: "inset 0 1px 0 rgba(255,255,255,.18), 0 1px 2px rgba(33,80,214,.35)",
color: colors.accentFg,
},
secondary: {
backgroundColor: { default: colors.surface, ":hover": colors.subtle },
boxShadow: shadows.sm,
color: colors.text,
},
ghost: {
backgroundColor: { default: "transparent", ":hover": colors.muted },
color: { default: colors.text2, ":hover": colors.text },
},
/** Outlined everywhere except the final confirm inside a dialog. */
danger: {
backgroundColor: { default: colors.surface, ":hover": colors.badSoft },
boxShadow: `inset 0 0 0 1px ${colors.badRing}`,
color: colors.badFg,
},
dangerSolid: {
backgroundColor: colors.bad,
color: "#FFFFFF",
opacity: { default: 1, ":hover": 0.9, ":disabled": 0.4 },
},
});
const sizes = stylex.create({
sm: { borderRadius: "7px", columnGap: "6px", fontSize: "12.5px", height: "28px", paddingInline: "10px" },
md: { borderRadius: radius.md, columnGap: "6px", fontSize: "13px", height: "32px", paddingInline: "12px" },
lg: { borderRadius: "10px", columnGap: "8px", fontSize: "14px", height: "40px", paddingInline: "16px" },
});
const iconOnlySizes = stylex.create({
sm: { paddingInline: 0, width: "28px" },
md: { paddingInline: 0, width: "32px" },
lg: { paddingInline: 0, width: "40px" },
});
app/layout.tsx
import "@fontsource-variable/inter";
import "@fontsource-variable/geist-mono";
import * as stylex from "@stylexjs/stylex";
import { global, theme } from "@/meridian/tokens";
<html {...stylex.props(global.html)}> // follows OS
<html {...stylex.props(theme.dark, global.html)}> // forced
Naming rules
- Constants
ramp,light,dark— never imported by components- Roles
- What it's for:
colors.surface,colors.text2 - States
- Suffix:
accentHover,borderStrong - Overrides
- A
styleprop of StyleX styles — noclassName - Never
- Colour names in components (
blue500)
Meridian Design Language53