Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
node-version-file: .nvmrc
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm lint
- run: pnpm format:check
- run: pnpm check
- run: pnpm build
- run: pnpm exec playwright install --with-deps chromium
Expand Down
24 changes: 24 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json",
"singleQuote": true,
"ignorePatterns": [
"dist",
".astro",
"pnpm-lock.yaml",
"public",
"*.astro",
"docs",
"_features",
"_data",
"_includes",
"_layouts",
"_posts",
"_sass",
"*.md",
"*.yml",
"index.html",
"netlify.toml",
"renovate.json",
"*.yaml"
]
}
11 changes: 11 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["typescript"],
"categories": {
"correctness": "error"
},
"ignorePatterns": ["dist", ".astro", "public"],
"rules": {
"curly": ["error", "all"]
}
}
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"plugins": ["prettier-plugin-astro"],
"overrides": [{ "files": "*.astro", "options": { "parser": "astro" } }]
}
76 changes: 66 additions & 10 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,71 @@
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';

// Material themes that have a matching bundled Shiki theme (code blocks follow these 5 only);
// every other theme falls back to github-dark/light by its light/dark type.
/** @type {Record<string, string>} */
const CODE_THEMES = {
'material-theme': 'oceanic',
'material-theme-darker': 'darker',
'material-theme-lighter': 'lighter',
'material-theme-palenight': 'palenight',
'material-theme-ocean': 'deepocean',
};

export default defineConfig({
site: 'https://material-theme.com',
trailingSlash: 'always',
build: { format: 'directory' },
integrations: [
starlight({
title: 'Material Theme UI',
social: [{ icon: 'github', label: 'GitHub', href: 'https://github.com/mallowigi/material-theme-docs' }],
sidebar: [],
}),
],
site: 'https://material-theme.com',
trailingSlash: 'always',
build: { format: 'directory' },
integrations: [
starlight({
title: 'Material Theme UI',
customCss: ['./src/styles/custom.css'],
head: [
{ tag: 'link', attrs: { rel: 'preconnect', href: 'https://fonts.googleapis.com' } },
{
tag: 'link',
attrs: { rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: '' },
},
{
tag: 'link',
attrs: {
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/css2?family=Google+Sans:ital,opsz,wght@0,17..18,400..700;1,17..18,400..700&family=Source+Code+Pro:wght@400;500&display=swap',
},
},
],
social: [
{
icon: 'github',
label: 'GitHub',
href: 'https://github.com/mallowigi/material-theme-docs',
},
],
sidebar: [],
components: {
ThemeProvider: './src/components/overrides/ThemeProvider.astro',
ThemeSelect: './src/components/overrides/ThemeSelect.astro',
PageTitle: './src/components/overrides/PageTitle.astro',
Footer: './src/components/overrides/Footer.astro',
},
expressiveCode: {
themes: /** @type {any} */ (['github-dark', 'github-light', ...Object.keys(CODE_THEMES)]),
themeCssSelector: (theme) =>
CODE_THEMES[theme.name]
? `[data-material-theme='${CODE_THEMES[theme.name]}']`
: `[data-theme='${theme.type}']`,
styleOverrides: {
codeBackground: 'var(--mt-code-bg, var(--sl-color-gray-6))',
borderColor: 'var(--sl-color-hairline-light)',
frames: {
editorTabBarBackground: 'var(--sl-color-bg-nav)',
editorActiveTabBackground: 'var(--mt-code-bg, var(--sl-color-gray-6))',
editorActiveTabIndicatorTopColor: 'var(--sl-color-accent)',
terminalTitlebarBackground: 'var(--sl-color-bg-nav)',
terminalBackground: 'var(--mt-code-bg, var(--sl-color-gray-6))',
},
},
},
}),
],
});
8 changes: 4 additions & 4 deletions e2e/not-found.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect, test } from '@playwright/test';

test('an unknown URL returns 404 with the Starlight 404 page', async ({ page }) => {
const response = await page.goto('/this-page-does-not-exist/');
expect(response?.status()).toBe(404);
await expect(page.getByRole('heading', { level: 1 })).toHaveText('404');
await expect(page.locator('main')).toContainText(/couldn.t find|not found/i);
const response = await page.goto('/this-page-does-not-exist/');
expect(response?.status()).toBe(404);
await expect(page.getByRole('heading', { level: 1 })).toHaveText('404');
await expect(page.locator('main')).toContainText(/couldn.t find|not found/i);
});
69 changes: 69 additions & 0 deletions e2e/themes.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { expect, test, type Page } from '@playwright/test';

const KEY = 'material-theme';
const html = (page: Page) => page.locator('html');

async function openPicker(page: Page) {
await page.getByRole('button', { name: 'Open theme switcher' }).click();
await expect(page.getByRole('dialog', { name: /theme/i })).toBeVisible();
}

test('the saved theme is on <html> before the body is parsed (no flash)', async ({ page }) => {
await page.addInitScript((key) => {
localStorage.setItem(key, 'dracula');
new MutationObserver((_, observer) => {
if (!document.body) {
return;
}

(window as any).__themeAtBody = document.documentElement.dataset.materialTheme;
observer.disconnect();
}).observe(document, { childList: true, subtree: true });
}, KEY);
await page.goto('/');
expect(await page.evaluate(() => (window as any).__themeAtBody)).toBe('dracula');
});

test('a picked theme persists across reload and navigation', async ({ page }) => {
await page.goto('/');
await openPicker(page);
await page.locator('[data-mt-theme="dracula"]').click();
await expect(html(page)).toHaveAttribute('data-material-theme', 'dracula');

await page.reload();
await expect(html(page)).toHaveAttribute('data-material-theme', 'dracula');

await page.goto('/another-page-that-404s/');
await expect(html(page)).toHaveAttribute('data-material-theme', 'dracula');
});

test('?theme= overrides the saved theme without replacing it', async ({ page }) => {
await page.addInitScript((key) => localStorage.setItem(key, 'dracula'), KEY);
await page.goto('/?theme=monokai');
await expect(html(page)).toHaveAttribute('data-material-theme', 'monokai');
expect(await page.evaluate((key) => localStorage.getItem(key), KEY)).toBe('dracula');
});

test('all 32 themes can be picked and set light or dark accordingly', async ({ page }) => {
await page.goto('/');
await openPicker(page);
const cards = page.locator('[data-mt-theme]');
await expect(cards).toHaveCount(32);

for (const name of await cards.evaluateAll((els) =>
els.map((e) => (e as HTMLElement).dataset.mtTheme!),
)) {
await page.locator(`[data-mt-theme="${name}"]`).click();
await expect(html(page)).toHaveAttribute('data-material-theme', name);
const { scheme, theme } = await html(page).evaluate((el) => ({
scheme: getComputedStyle(el).colorScheme,
theme: el.dataset.theme,
}));
expect(scheme, name).toBe(theme);
}
});

test('there is no light/dark toggle', async ({ page }) => {
await page.goto('/');
await expect(page.locator('starlight-theme-select')).toHaveCount(0);
});
23 changes: 16 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
{
"name": "material-theme-docs",
"type": "module",
"version": "2.0.0",
"private": true,
"packageManager": "pnpm@10.26.1",
"engines": {
"node": ">=26"
},
"type": "module",
"scripts": {
"dev": "astro dev",
"build": "astro build",
"preview": "astro preview",
"check": "astro check",
"serve": "netlify serve",
"test:e2e": "playwright test"
"test:e2e": "playwright test",
"lint": "oxlint",
"format": "oxfmt && prettier --write \"src/**/*.astro\"",
"format:check": "oxfmt --check && prettier --check \"src/**/*.astro\""
},
"dependencies": {
"@astrojs/starlight": "^0.43.1",
"astro": "^7.3.6",
"js-yaml": "5.5.0",
"sharp": "^0.35.3"
},
"devDependencies": {
"@astrojs/check": "latest",
"@playwright/test": "latest",
"@types/js-yaml": "4.0.9",
"netlify-cli": "latest",
"oxfmt": "0.79.0",
"oxlint": "1.94.0",
"prettier": "3.10.1",
"prettier-plugin-astro": "1.1.2",
"typescript": "^6.0.3"
}
},
"engines": {
"node": ">=26"
},
"packageManager": "pnpm@10.26.1"
}
30 changes: 15 additions & 15 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { defineConfig } from '@playwright/test';
const baseURL = process.env.BASE_URL ?? 'http://localhost:8888';

export default defineConfig({
testDir: './e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
reporter: process.env.CI ? [['github'], ['html', { open: 'never' }]] : 'list',
use: { baseURL },
// `netlify serve` builds the site and serves it with the same redirect/header rules as production.
webServer: process.env.BASE_URL
? undefined
: {
command: 'BROWSER=none pnpm exec netlify serve --offline --port 8888',
url: baseURL,
reuseExistingServer: !process.env.CI,
timeout: 180_000,
},
testDir: './e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
reporter: process.env.CI ? [['github'], ['html', { open: 'never' }]] : 'list',
use: { baseURL },
// `netlify serve` builds the site and serves it with the same redirect/header rules as production.
webServer: process.env.BASE_URL
? undefined
: {
command: 'BROWSER=none pnpm exec netlify serve --offline --port 8888',
url: baseURL,
reuseExistingServer: !process.env.CI,
timeout: 180_000,
},
});
Loading
Loading