@dfosco/storyboard-react-primer 4.0.0-beta.8 → 4.0.0

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/ThemeSync.jsx +9 -45
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dfosco/storyboard-react-primer",
3
- "version": "4.0.0-beta.8",
3
+ "version": "4.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -12,7 +12,7 @@
12
12
  "src"
13
13
  ],
14
14
  "dependencies": {
15
- "@dfosco/storyboard-react": "4.0.0-beta.8"
15
+ "@dfosco/storyboard-react": "4.0.0"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "@primer/react": ">=37",
package/src/ThemeSync.jsx CHANGED
@@ -1,39 +1,14 @@
1
1
  /**
2
2
  * ThemeSync — invisible React component that bridges the storyboard-core
3
- * toolbar theme switcher with Primer's ThemeProvider context.
3
+ * theme store with Primer's ThemeProvider context.
4
4
  *
5
- * Listens for `storyboard:theme:changed` custom events dispatched by the
6
- * core theme store and calls setColorMode/setDayScheme/setNightScheme on
7
- * Primer's useTheme() hook accordingly.
8
- *
9
- * On mount it reads localStorage to initialize Primer to the correct
10
- * scheme before the Svelte CoreUIBar has loaded.
11
- *
12
- * When prototype sync is disabled (via "Apply theme to" settings), the
13
- * prototype is forced to light mode regardless of the selected theme.
5
+ * Uses the useThemeState hook to subscribe to core theme changes and
6
+ * applies them to Primer's setColorMode/setDayScheme/setNightScheme.
14
7
  */
15
8
 
16
9
  import { useEffect } from 'react'
17
10
  import { useTheme } from '@primer/react'
18
-
19
- const THEME_STORAGE_KEY = 'sb-color-scheme'
20
- const THEME_SYNC_STORAGE_KEY = 'sb-theme-sync'
21
-
22
- const DEFAULT_SYNC = {
23
- prototype: true,
24
- toolbar: false,
25
- codeBoxes: true,
26
- }
27
-
28
- function readSyncTargets() {
29
- try {
30
- const raw = localStorage.getItem(THEME_SYNC_STORAGE_KEY)
31
- if (!raw) return DEFAULT_SYNC
32
- return { ...DEFAULT_SYNC, ...JSON.parse(raw) }
33
- } catch {
34
- return DEFAULT_SYNC
35
- }
36
- }
11
+ import { useThemeState, useThemeSyncTargets } from '@dfosco/storyboard-react'
37
12
 
38
13
  function applyToPrimer(setColorMode, setDayScheme, setNightScheme, themeValue) {
39
14
  if (themeValue === 'system' || !themeValue) {
@@ -49,25 +24,14 @@ function applyToPrimer(setColorMode, setDayScheme, setNightScheme, themeValue) {
49
24
 
50
25
  export default function ThemeSync() {
51
26
  const { setColorMode, setDayScheme, setNightScheme } = useTheme()
27
+ const { theme } = useThemeState()
28
+ const { prototype: protoSync } = useThemeSyncTargets()
52
29
 
53
- // Restore saved theme on mount
54
- useEffect(() => {
55
- const saved = localStorage.getItem(THEME_STORAGE_KEY)
56
- const syncTargets = readSyncTargets()
57
- const prototypeTheme = syncTargets.prototype ? saved : 'light'
58
- applyToPrimer(setColorMode, setDayScheme, setNightScheme, prototypeTheme)
59
- }, []) // eslint-disable-line react-hooks/exhaustive-deps
30
+ const effectiveTheme = protoSync ? theme : 'light'
60
31
 
61
- // Listen for theme changes from the Svelte CoreUIBar
62
32
  useEffect(() => {
63
- function handleThemeChanged(e) {
64
- const { prototypeTheme } = e.detail || {}
65
- if (typeof prototypeTheme !== 'string') return
66
- applyToPrimer(setColorMode, setDayScheme, setNightScheme, prototypeTheme)
67
- }
68
- document.addEventListener('storyboard:theme:changed', handleThemeChanged)
69
- return () => document.removeEventListener('storyboard:theme:changed', handleThemeChanged)
70
- }, [setColorMode, setDayScheme, setNightScheme])
33
+ applyToPrimer(setColorMode, setDayScheme, setNightScheme, effectiveTheme)
34
+ }, [effectiveTheme, setColorMode, setDayScheme, setNightScheme])
71
35
 
72
36
  return null
73
37
  }