@rokkit/app 1.0.0-next.133 → 1.0.0-next.134
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 +111 -0
- package/package.json +6 -4
- package/src/components/ThemeSwitcherToggle.svelte +1 -4
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @rokkit/app
|
|
2
|
+
|
|
3
|
+
App-level controls for Rokkit applications — color mode management and theme switching.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @rokkit/app
|
|
9
|
+
# or
|
|
10
|
+
bun add @rokkit/app
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
`@rokkit/app` provides the application-level plumbing for Rokkit projects:
|
|
16
|
+
|
|
17
|
+
- **`ColorModeManager`** — reactive class that tracks `system` / `light` / `dark` mode, resolves `system` to the actual OS preference, and syncs to the active theme target
|
|
18
|
+
- **`ThemeSwitcherToggle`** — Svelte component for a three-way light/dark/system toggle
|
|
19
|
+
- **`resolveMode`** — utility to resolve `'system'` to `'light'` or `'dark'` via `matchMedia`
|
|
20
|
+
|
|
21
|
+
Works directly with `@rokkit/unocss` dark mode: `ColorModeManager` sets `data-mode` on the `<html>` element, which the UnoCSS preset uses as its dark mode selector.
|
|
22
|
+
|
|
23
|
+
Requires Svelte 5.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### ColorModeManager
|
|
28
|
+
|
|
29
|
+
`ColorModeManager` is a Svelte 5 reactive class (`$state` internals). Instantiate it with a theme target — typically the `vibe` singleton from `@rokkit/states`.
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import { ColorModeManager } from '@rokkit/app'
|
|
33
|
+
import { vibe } from '@rokkit/states'
|
|
34
|
+
|
|
35
|
+
const modeManager = new ColorModeManager(vibe)
|
|
36
|
+
|
|
37
|
+
// Read current mode
|
|
38
|
+
console.log(modeManager.mode) // 'system' | 'light' | 'dark'
|
|
39
|
+
console.log(modeManager.resolved) // 'light' | 'dark'
|
|
40
|
+
|
|
41
|
+
// Change mode
|
|
42
|
+
modeManager.mode = 'dark'
|
|
43
|
+
modeManager.mode = 'system' // will re-resolve from OS preference
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Listening for OS preference changes
|
|
47
|
+
|
|
48
|
+
Call `listen()` inside `onMount` or a `$effect.root`. It returns a cleanup function.
|
|
49
|
+
|
|
50
|
+
```svelte
|
|
51
|
+
<script>
|
|
52
|
+
import { onMount } from 'svelte'
|
|
53
|
+
import { ColorModeManager } from '@rokkit/app'
|
|
54
|
+
import { vibe } from '@rokkit/states'
|
|
55
|
+
|
|
56
|
+
const modeManager = new ColorModeManager(vibe)
|
|
57
|
+
|
|
58
|
+
onMount(() => {
|
|
59
|
+
return modeManager.listen() // returns cleanup fn, called on destroy
|
|
60
|
+
})
|
|
61
|
+
</script>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
When `mode` is `'system'`, the manager automatically updates `resolved` whenever the OS preference changes.
|
|
65
|
+
|
|
66
|
+
### ThemeSwitcherToggle
|
|
67
|
+
|
|
68
|
+
Drop-in Svelte component that renders a three-way toggle (light / dark / system). Pass the `ColorModeManager` instance as a prop.
|
|
69
|
+
|
|
70
|
+
```svelte
|
|
71
|
+
<script>
|
|
72
|
+
import { ThemeSwitcherToggle, ColorModeManager } from '@rokkit/app'
|
|
73
|
+
import { vibe } from '@rokkit/states'
|
|
74
|
+
|
|
75
|
+
const modeManager = new ColorModeManager(vibe)
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<ThemeSwitcherToggle {modeManager} />
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### resolveMode utility
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
import { resolveMode } from '@rokkit/app'
|
|
85
|
+
|
|
86
|
+
resolveMode('system') // 'light' or 'dark' based on OS preference
|
|
87
|
+
resolveMode('dark') // 'dark'
|
|
88
|
+
resolveMode('light') // 'light'
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## API
|
|
92
|
+
|
|
93
|
+
| Export | Description |
|
|
94
|
+
| --------------------- | ----------------------------------------------------- |
|
|
95
|
+
| `ColorModeManager` | Reactive class for tracking and resolving color mode |
|
|
96
|
+
| `ThemeSwitcherToggle` | Svelte component — three-way light/dark/system toggle |
|
|
97
|
+
| `resolveMode(mode)` | Resolve `'system'` to actual `'light'` \| `'dark'` |
|
|
98
|
+
| `ColorMode` | Type: `'system' \| 'light' \| 'dark'` |
|
|
99
|
+
| `ResolvedMode` | Type: `'light' \| 'dark'` |
|
|
100
|
+
|
|
101
|
+
### ColorModeManager members
|
|
102
|
+
|
|
103
|
+
| Member | Type | Description |
|
|
104
|
+
| ---------- | --------------------- | ------------------------------------------------ |
|
|
105
|
+
| `mode` | `ColorMode` (get/set) | Current three-way mode selection |
|
|
106
|
+
| `resolved` | `ResolvedMode` (get) | Actual light or dark value |
|
|
107
|
+
| `listen()` | `() => () => void` | Start OS preference listener; returns cleanup fn |
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
Part of [Rokkit](https://github.com/jerrythomas/rokkit) — a Svelte 5 component library and design system.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rokkit/app",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.134",
|
|
4
4
|
"description": "App-level controls for Rokkit applications - theme management and UI chrome",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -21,19 +21,21 @@
|
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
23
|
"src",
|
|
24
|
+
"README.md",
|
|
24
25
|
"LICENSE"
|
|
25
26
|
],
|
|
26
27
|
"scripts": {
|
|
27
28
|
"prepublishOnly": "cp ../../LICENSE .",
|
|
29
|
+
"postpublish": "rm -f LICENSE",
|
|
28
30
|
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
29
31
|
"test": "vitest run",
|
|
30
32
|
"test:watch": "vitest",
|
|
31
33
|
"build": "echo 'No build step needed for source-only package'"
|
|
32
34
|
},
|
|
33
35
|
"dependencies": {
|
|
34
|
-
"@rokkit/core": "1.0.0-next.
|
|
35
|
-
"@rokkit/states": "1.0.0-next.
|
|
36
|
-
"@rokkit/ui": "1.0.0-next.
|
|
36
|
+
"@rokkit/core": "1.0.0-next.134",
|
|
37
|
+
"@rokkit/states": "1.0.0-next.134",
|
|
38
|
+
"@rokkit/ui": "1.0.0-next.134"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
39
41
|
"svelte": "^5.0.0"
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
import { vibe } from '@rokkit/states'
|
|
4
4
|
import { Toggle } from '@rokkit/ui'
|
|
5
5
|
import type { ThemeSwitcherToggleProps } from '../types/theme-switcher.js'
|
|
6
|
-
import {
|
|
7
|
-
defaultThemeSwitcherIcons,
|
|
8
|
-
buildThemeSwitcherOptions
|
|
9
|
-
} from '../types/theme-switcher.js'
|
|
6
|
+
import { defaultThemeSwitcherIcons, buildThemeSwitcherOptions } from '../types/theme-switcher.js'
|
|
10
7
|
import { ColorModeManager, type ColorMode } from '../utils/color-mode.svelte.js'
|
|
11
8
|
|
|
12
9
|
let {
|