@x-wave/blog 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -25
- package/index.js +504 -478
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,14 +65,14 @@ Import the i18n setup and framework styles in your app entry point:
|
|
|
65
65
|
```ts
|
|
66
66
|
// src/main.tsx
|
|
67
67
|
import '@x-wave/blog/locales' // Initialises i18next with en, es, zh
|
|
68
|
-
import '@x-wave/blog/styles' //
|
|
68
|
+
import '@x-wave/blog/styles' // Compiled CSS with variables and component styles (required)
|
|
69
69
|
import { createRoot } from 'react-dom/client'
|
|
70
70
|
import App from './App'
|
|
71
71
|
|
|
72
72
|
createRoot(document.getElementById('root')!).render(<App />)
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
> **The styles import is required** for the UI components and layout to render correctly.
|
|
75
|
+
> **The styles import is required** for the UI components and layout to render correctly. This imports a single compiled CSS file (`index.css`) that contains all framework styles, CSS variables, and component styles.
|
|
76
76
|
|
|
77
77
|
**Add custom translations:**
|
|
78
78
|
|
|
@@ -348,34 +348,36 @@ import type { NavigationEntry, BlogConfig, HeaderLink } from '@x-wave/blog/types
|
|
|
348
348
|
|
|
349
349
|
### CSS variables
|
|
350
350
|
|
|
351
|
-
The framework
|
|
351
|
+
The framework uses CSS custom properties (`--xw-*` prefix) for theming. These are automatically injected when the framework initializes, but you can override them:
|
|
352
352
|
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
// Your custom styles here
|
|
353
|
+
```css
|
|
354
|
+
/* In your app.css */
|
|
355
|
+
.xw-blog-root {
|
|
356
|
+
--xw-primary: #007bff;
|
|
357
|
+
--xw-background: #fafafa;
|
|
358
|
+
--xw-foreground: #1a1a1a;
|
|
359
|
+
/* ... other variables */
|
|
360
|
+
}
|
|
362
361
|
```
|
|
363
362
|
|
|
364
|
-
Or
|
|
363
|
+
Or in JavaScript:
|
|
365
364
|
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
$color-background: #fafafa;
|
|
365
|
+
```javascript
|
|
366
|
+
const blogRoot = document.querySelector('.xw-blog-root')
|
|
367
|
+
blogRoot.style.setProperty('--xw-primary', '#007bff')
|
|
368
|
+
blogRoot.style.setProperty('--xw-background', '#fafafa')
|
|
371
369
|
```
|
|
372
370
|
|
|
373
|
-
Available variables include:
|
|
374
|
-
-
|
|
375
|
-
-
|
|
376
|
-
-
|
|
377
|
-
-
|
|
378
|
-
-
|
|
371
|
+
Available CSS variables include:
|
|
372
|
+
- `--xw-primary`, `--xw-secondary`
|
|
373
|
+
- `--xw-background`, `--xw-foreground`
|
|
374
|
+
- `--xw-card`, `--xw-card-foreground`
|
|
375
|
+
- `--xw-muted`, `--xw-muted-foreground`
|
|
376
|
+
- `--xw-accent`, `--xw-accent-foreground`
|
|
377
|
+
- `--xw-border`, `--xw-ring`
|
|
378
|
+
- And more—defined in `packages/styles/main.scss`
|
|
379
|
+
|
|
380
|
+
All CSS variables are scoped to `.xw-blog-root` for isolation and to prevent conflicts with your application styles.
|
|
379
381
|
|
|
380
382
|
### Config options
|
|
381
383
|
|
|
@@ -388,7 +390,7 @@ interface BlogConfig {
|
|
|
388
390
|
supportedLanguages: readonly string[] // e.g. ['en', 'es', 'zh']
|
|
389
391
|
navigationData: NavigationEntry[] // Menu structure
|
|
390
392
|
basePath?: string // Base path for all routes (default: '')
|
|
391
|
-
header?: {
|
|
393
|
+
header?: { // Optional: omit to hide built-in header
|
|
392
394
|
navLinks?: HeaderLink[] // Top-level nav links
|
|
393
395
|
dropdownItems?: HeaderDropdownItem[] // Support dropdown menu
|
|
394
396
|
}
|
|
@@ -397,6 +399,68 @@ interface BlogConfig {
|
|
|
397
399
|
|
|
398
400
|
**Key properties:**
|
|
399
401
|
|
|
402
|
+
- **`header`**: Optional. If omitted entirely, the built-in header component will not be rendered. Use this when you want to implement a custom header.
|
|
403
|
+
|
|
404
|
+
### Custom headers
|
|
405
|
+
|
|
406
|
+
If you need a custom header instead of the built-in one, simply omit the `header` config and use the provided hooks:
|
|
407
|
+
|
|
408
|
+
```tsx
|
|
409
|
+
import { useTheme, useSearchModal } from '@x-wave/blog'
|
|
410
|
+
import { Moon, Sun, MagnifyingGlass } from '@phosphor-icons/react'
|
|
411
|
+
|
|
412
|
+
function CustomHeader() {
|
|
413
|
+
const { theme, setTheme } = useTheme()
|
|
414
|
+
const { openSearchModal } = useSearchModal()
|
|
415
|
+
|
|
416
|
+
return (
|
|
417
|
+
<header>
|
|
418
|
+
<h1>My Custom Header</h1>
|
|
419
|
+
|
|
420
|
+
{/* Theme toggle button */}
|
|
421
|
+
<button onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
|
|
422
|
+
{theme === 'dark' ? <Sun /> : <Moon />}
|
|
423
|
+
</button>
|
|
424
|
+
|
|
425
|
+
{/* Search button */}
|
|
426
|
+
<button onClick={openSearchModal}>
|
|
427
|
+
<MagnifyingGlass />
|
|
428
|
+
</button>
|
|
429
|
+
</header>
|
|
430
|
+
)
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function App() {
|
|
434
|
+
return (
|
|
435
|
+
<BlogProvider
|
|
436
|
+
config={{
|
|
437
|
+
title: 'My Docs',
|
|
438
|
+
supportedLanguages: ['en'],
|
|
439
|
+
navigationData: NAVIGATION_DATA,
|
|
440
|
+
// No header config = no built-in header
|
|
441
|
+
}}
|
|
442
|
+
blog={blog}
|
|
443
|
+
>
|
|
444
|
+
<CustomHeader />
|
|
445
|
+
<Router>
|
|
446
|
+
<Routes>
|
|
447
|
+
<Route path="/:language/*" element={<DocumentationRoutes />} />
|
|
448
|
+
</Routes>
|
|
449
|
+
</Router>
|
|
450
|
+
</BlogProvider>
|
|
451
|
+
)
|
|
452
|
+
}
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
**Available hooks:**
|
|
456
|
+
|
|
457
|
+
- **`useTheme()`**: Returns `{ theme, setTheme, effectiveTheme }` for managing light/dark/system theme
|
|
458
|
+
- **`useSearchModal()`**: Returns `{ openSearchModal, closeSearchModal }` for controlling the search modal
|
|
459
|
+
|
|
460
|
+
These are the exact functions used by the built-in header, so you get the same functionality with full customization.
|
|
461
|
+
|
|
462
|
+
**Key properties (continued):**
|
|
463
|
+
|
|
400
464
|
| Property | Type | Required | Description |
|
|
401
465
|
|---|---|---|---|
|
|
402
466
|
| `title` | `string` | Yes | Site title displayed in header and sidebar |
|