Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix: import theme CSS in example apps, fix default theme typography (#625)

Cindy Zhang0543f4d13872
diff --git a/apps/example-nextjs/README.md b/apps/example-nextjs/README.md
index d325bd39ca..e8b0a9b510 100644
--- a/apps/example-nextjs/README.md
+++ b/apps/example-nextjs/README.md
@@ -84,12 +84,21 @@ module.exports = {
@stylex;
```
-Import it in your root layout:
+Import it in your root layout, along with the base CSS and theme CSS:
```tsx
+import '@xds/core/reset.css';
+import '@xds/core/typography.css';
+import '@xds/theme-default/theme.css';
import './globals.css';
```
+The CSS import order matters:
+1. `reset.css` — baseline resets (`@layer reset`)
+2. `typography.css` — prose styles (`@layer typography`)
+3. `theme.css` — theme component overrides (`@layer xds.theme`)
+4. `globals.css` — StyleX extraction (`@stylex;` directive)
+
### 5. Next.js config
`next.config.mjs` — add `transpilePackages` so Next.js compiles XDS source:
diff --git a/apps/example-nextjs/src/app/layout.tsx b/apps/example-nextjs/src/app/layout.tsx
index 6149a4007d..9736981013 100644
--- a/apps/example-nextjs/src/app/layout.tsx
+++ b/apps/example-nextjs/src/app/layout.tsx
@@ -1,6 +1,7 @@
import type {Metadata} from 'next';
import '@xds/core/reset.css';
import '@xds/core/typography.css';
+import '@xds/theme-default/theme.css';
import './globals.css';
import {Providers} from './providers';
diff --git a/apps/example-vite/README.md b/apps/example-vite/README.md
index 1617d0256e..5c008df078 100644
--- a/apps/example-vite/README.md
+++ b/apps/example-vite/README.md
@@ -47,10 +47,25 @@ const lightningcssTargets = {
export default defineConfig({
plugins: [
+ // Declare CSS layer order so theme overrides beat component base styles.
+ {
+ name: 'xds-css-layer-order',
+ transformIndexHtml() {
+ return [
+ {
+ tag: 'style',
+ children:
+ '@layer reset, typography, priority1, priority2, priority3, priority4, priority5, priority6, priority7, priority8, priority9, xds.theme;',
+ injectTo: 'head-prepend',
+ },
+ ];
+ },
+ },
stylex.vite({
dev: process.env.NODE_ENV === 'development',
runtimeInjection: false,
treeshakeCompensation: true,
+ useCSSLayers: true,
unstable_moduleResolution: {
type: 'commonJS',
rootDir: __dirname,
@@ -91,12 +106,21 @@ export default defineConfig({
}
```
-Import it in `src/main.tsx`:
+Import it in `src/main.tsx`, along with the base CSS and theme CSS:
```tsx
+import '@xds/core/reset.css';
+import '@xds/core/typography.css';
+import '@xds/theme-default/theme.css';
import './index.css';
```
+The CSS import order matters:
+1. `reset.css` — baseline resets (`@layer reset`)
+2. `typography.css` — prose styles (`@layer typography`)
+3. `theme.css` — theme component overrides (`@layer xds.theme`)
+4. `index.css` — StyleX extraction placeholder
+
### 4. Theme provider
Wrap your app with `XDSTheme` and the default theme:
diff --git a/apps/example-vite/src/main.tsx b/apps/example-vite/src/main.tsx
index 4ef3cd25c7..c528e506d9 100644
--- a/apps/example-vite/src/main.tsx
+++ b/apps/example-vite/src/main.tsx
@@ -2,6 +2,7 @@ import {StrictMode} from 'react';
import {createRoot} from 'react-dom/client';
import '@xds/core/reset.css';
import '@xds/core/typography.css';
+import '@xds/theme-default/theme.css';
import './index.css';
import App from './App';
diff --git a/apps/example-vite/vite.config.ts b/apps/example-vite/vite.config.ts
index d4bbd43468..93e76d3811 100644
--- a/apps/example-vite/vite.config.ts
+++ b/apps/example-vite/vite.config.ts
@@ -23,10 +23,28 @@ const lightningcssTargets = {
// https://vite.dev/config/
export default defineConfig({
plugins: [
+ // Declare CSS layer order so theme overrides beat component base styles.
+ // Without this, layers are ordered by first appearance — and the StyleX
+ // priority layers (component styles) would come after xds.theme,
+ // preventing theme overrides from taking effect.
+ {
+ name: 'xds-css-layer-order',
+ transformIndexHtml() {
+ return [
+ {
+ tag: 'style',
+ children:
+ '@layer reset, typography, priority1, priority2, priority3, priority4, priority5, priority6, priority7, priority8, priority9, xds.theme;',
+ injectTo: 'head-prepend',
+ },
+ ];
+ },
+ },
stylex.vite({
dev: process.env.NODE_ENV === 'development',
runtimeInjection: false,
treeshakeCompensation: true,
+ useCSSLayers: true,
unstable_moduleResolution: {
type: 'commonJS',
rootDir: __dirname,
diff --git a/packages/themes/default/src/defaultTheme.ts b/packages/themes/default/src/defaultTheme.ts
index 8493c11eb1..11e7d43cab 100644
--- a/packages/themes/default/src/defaultTheme.ts
+++ b/packages/themes/default/src/defaultTheme.ts
@@ -45,7 +45,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-semibold)',
lineHeight: '1.2',
color: 'var(--color-text-primary)',
- margin: '0',
},
'level:2': {
fontFamily: 'var(--font-heading)',
@@ -53,7 +52,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-semibold)',
lineHeight: '1.333',
color: 'var(--color-text-primary)',
- margin: '0',
},
'level:3': {
fontFamily: 'var(--font-heading)',
@@ -61,7 +59,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-semibold)',
lineHeight: '1.25',
color: 'var(--color-text-primary)',
- margin: '0',
},
'level:4': {
fontFamily: 'var(--font-heading)',
@@ -69,7 +66,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-semibold)',
lineHeight: 'var(--leading-base)',
color: 'var(--color-text-primary)',
- margin: '0',
},
'level:5': {
fontFamily: 'var(--font-heading)',
@@ -77,7 +73,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-semibold)',
lineHeight: 'var(--leading-base)',
color: 'var(--color-text-primary)',
- margin: '0',
},
'level:6': {
fontFamily: 'var(--font-heading)',
@@ -85,7 +80,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-semibold)',
lineHeight: '1.333',
color: 'var(--color-text-primary)',
- margin: '0',
},
// Editorial variant — larger scale for content-heavy pages
'variant:editorial+level:1': {
@@ -94,7 +88,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-semibold)',
lineHeight: '1.5',
color: 'var(--color-text-primary)',
- margin: '0',
},
'variant:editorial+level:2': {
fontFamily: 'var(--font-heading)',
@@ -102,7 +95,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-semibold)',
lineHeight: '1.333',
color: 'var(--color-text-primary)',
- margin: '0',
},
'variant:editorial+level:3': {
fontFamily: 'var(--font-heading)',
@@ -110,7 +102,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-semibold)',
lineHeight: '1.4',
color: 'var(--color-text-primary)',
- margin: '0',
},
'variant:editorial+level:4': {
fontFamily: 'var(--font-heading)',
@@ -118,7 +109,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-semibold)',
lineHeight: '1.5',
color: 'var(--color-text-primary)',
- margin: '0',
},
'variant:editorial+level:5': {
fontFamily: 'var(--font-heading)',
@@ -126,7 +116,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-semibold)',
lineHeight: 'var(--leading-base)',
color: 'var(--color-text-primary)',
- margin: '0',
},
'variant:editorial+level:6': {
fontFamily: 'var(--font-heading)',
@@ -134,7 +123,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-semibold)',
lineHeight: '1.333',
color: 'var(--color-text-primary)',
- margin: '0',
},
},
@@ -148,15 +136,13 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-normal)',
lineHeight: 'var(--leading-base)',
color: 'var(--color-text-primary)',
- margin: '0',
},
'type:large': {
fontFamily: 'var(--font-heading)',
fontSize: 'var(--text-lg)',
- fontWeight: 'var(--font-weight-normal)',
+ fontWeight: 'var(--font-weight-semibold)',
lineHeight: '1.5',
color: 'var(--color-text-primary)',
- margin: '0',
},
'type:label': {
fontFamily: 'var(--font-heading)',
@@ -164,7 +150,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-medium)',
lineHeight: 'var(--leading-base)',
color: 'var(--color-text-primary)',
- margin: '0',
},
'type:supporting': {
fontFamily: 'var(--font-heading)',
@@ -172,7 +157,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-normal)',
lineHeight: '1.333',
color: 'var(--color-text-secondary)',
- margin: '0',
},
'type:code': {
fontFamily: 'var(--font-code)',
@@ -180,7 +164,6 @@ export const defaultTheme = defineTheme({
fontWeight: 'var(--font-weight-normal)',
lineHeight: 'var(--leading-base)',
color: 'var(--color-text-primary)',
- margin: '0',
},
},
},