Concepts
Core Plex UI implementation concepts. Dark mode setup, theme persistence, responsive breakpoints, and runtime helpers for adaptive React UIs
Dark mode
Light and dark mode are fully supported, while your app controls how the value is applied and persisted.
To set the current view mode, apply a [data-theme] attribute on the html element. Without it, the light theme applies: Plex UI does not follow prefers-color-scheme on its own. data-theme sets color-scheme for the color tokens (they use light-dark()), switches the shadow tokens and drives Tailwind's dark: variant. Setting color-scheme yourself flips only the colors, so shadows and dark: utilities stay light.
<html data-theme="dark">
<!-- ... -->
</html>The attribute can also be nested inside content scopes:
<html data-theme="dark">
<body>
<div>Dark mode content (root scope)</div>
<div data-theme="light">Light mode content (nested scope)</div>
</body>
</html>Tailwind
Tailwind is configured to use [data-theme] for dark mode behavior.
<div class="bg-white dark:bg-black">
<!-- ... -->
</div>JavaScript helpers
import { applyDocumentTheme, getDocumentTheme, useDocumentTheme } from "@plexui/ui/theme";
applyDocumentTheme("dark");
const currentTheme = getDocumentTheme(); // "light" | "dark"
function Sample() {
const theme = useDocumentTheme(); // live value from html[data-theme]; "light" on the server and during hydration
return null;
}Persistent theme example
import { applyDocumentTheme } from "@plexui/ui/theme";
import { create } from "zustand";
import { createJSONStorage, persist } from "zustand/middleware";
export type Theme = "light" | "dark" | "system";
type ThemeState = { theme: Theme };
const INITIAL_STATE: ThemeState = { theme: "system" };
const store = create(
persist(() => INITIAL_STATE, {
name: "plexui:user:theme",
storage: createJSONStorage(() => localStorage),
}),
);
// Apply the saved (or system) theme once on startup, then on every change
applyDocumentTheme(resolveTheme(store.getState().theme));
store.subscribe((state) => applyDocumentTheme(resolveTheme(state.theme)));
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", () => applyDocumentTheme(resolveTheme(store.getState().theme)));
function getSystemTheme(): "light" | "dark" {
return window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
}
function resolveTheme(theme?: Theme): "light" | "dark" {
if (theme == null || theme === "system") return getSystemTheme();
return theme;
}
export function setTheme(theme: Theme) {
store.setState({ theme });
}Responsive design
Write styles mobile-first: base styles apply to all sizes, then override upward from breakpoints.
Default breakpoints
useBreakpoint uses these values. Tailwind's responsive variants use them once you add the opt-in @plexui/ui/styles/variables-tailwind-theme.css import (Installation); with the default import Tailwind keeps its own breakpoints (sm is 640px and there is no xs).
| Name | Size | Common device | Example usage |
|---|---|---|---|
xs | 380px | Portrait mobile | Very small screen overrides |
sm | 576px | Landscape mobile, phablet | Collapsed mobile nav, single-column list/detail |
md | 768px | Tablet | Expanded primary nav, fixed left sidebar |
lg | 1024px | Laptop | Tight multi-column layouts |
xl | 1280px | Desktop | Spacious layouts |
2xl | 1536px | Widescreen | Largest breakpoints |
Tailwind usage
<div className="flex flex-col lg:flex-row" />React usage
import { useBreakpoint } from "@plexui/ui/hooks/useBreakpoints";
function SampleComponent() {
const isMedium = useBreakpoint("md");
return null;
}useBreakpoint returns false on the first render, on the server and the client alike, then follows the viewport. It reads the --breakpoint-* variables and falls back to the table above (with a console warning in development) when they are not defined.
Phone layout
Components take their phone presentation in a window 767px wide or narrower. Inside a PhoneLayout they take it at any width: a Dialog becomes a phone sheet, a Button takes its phone size, a Menu opens as a phone menu inside the box. Use it to show a phone screen on a desktop page, such as a preview in a phone frame. For one dialog only, set layout="phone" on Dialog's content instead.
import { PhoneLayout } from "@plexui/ui/components/PhoneLayout";
<PhoneLayout style={{ width: 393, height: 852, borderRadius: 55, overflow: "hidden" }}>
<Page>…</Page>
</PhoneLayout><script setup lang="ts">
import { PhoneLayout } from "@plexui/vue/components/PhoneLayout";
</script>
<template>
<PhoneLayout :style="{ width: '393px', height: '852px', borderRadius: '55px', overflow: 'hidden' }">
<Page>…</Page>
</PhoneLayout>
</template>PhoneLayout renders a div and passes its props and attributes on (a class or a style for its size and corners). It marks the box with data-plex-layout="phone": the style sheets apply their phone rules inside such an element at any window width, and their desktop rules (768px and up) do not apply there.
- Dialogs and menus stay in the box. A Dialog opened inside it portals into the box and covers it instead of the window; a Menu opens in the box and keeps inside it. Popovers, selects and tooltips still open at the end of the page and take the window's presentation.
- Give the box a size, and let a child of it scroll rather than the box, so a dialog stays in place. The box has layout containment, so it is the containing block of the fixed layers of the dialogs inside it, and it clips its overflow as a screen does.
- Safe areas. Set
--safe-area-inset-topand--safe-area-inset-bottomon the box when the frame draws a status bar or a home indicator: phone sheets and bars read them before the window's safe area.
usePhoneLayout() (React, from @plexui/ui/components/PhoneLayout) returns whether components where it is called are laid out as on a phone: inside a PhoneLayout or a Dialog with layout="phone", or in a window 767px wide or narrower. In Vue, usePhoneLayout() from @plexui/vue/components/PhoneLayout returns the same as a computed ref. On the server, and until the component mounts, it is false outside a PhoneLayout.