@blankways/ui 0.1.0-alpha.1 → 0.2.0-alpha.1
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 +157 -139
- package/dist/cli/cli.options.js +21 -1
- package/dist/cli/cli.types.d.ts +1 -0
- package/dist/cli.js +2 -1
- package/dist/commands/add.command.d.ts +2 -0
- package/dist/commands/add.command.js +30 -82
- package/dist/commands/dev.command.d.ts +3 -0
- package/dist/commands/dev.command.js +76 -0
- package/dist/commands/doctor.command.js +12 -1
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.js +3 -0
- package/dist/commands/init.command.js +15 -10
- package/dist/commands/install.command.d.ts +2 -0
- package/dist/commands/install.command.js +36 -0
- package/dist/commands/list.command.js +10 -5
- package/dist/commands/registry.command.d.ts +2 -0
- package/dist/commands/registry.command.js +69 -0
- package/dist/commands/styles.command.d.ts +1 -2
- package/dist/commands/styles.command.js +15 -39
- package/dist/config/config.helpers.d.ts +4 -1
- package/dist/config/config.helpers.js +61 -8
- package/dist/constants/cli.constants.d.ts +14 -3
- package/dist/constants/cli.constants.js +14 -9
- package/dist/doctor/checks/barrels.check.d.ts +1 -0
- package/dist/doctor/checks/barrels.check.js +60 -0
- package/dist/doctor/checks/contracts.check.d.ts +1 -0
- package/dist/doctor/checks/contracts.check.js +45 -0
- package/dist/doctor/checks/icons.check.js +8 -3
- package/dist/doctor/checks/index.d.ts +3 -0
- package/dist/doctor/checks/index.js +3 -0
- package/dist/doctor/checks/motion.check.js +2 -2
- package/dist/doctor/checks/namespaces.check.d.ts +1 -0
- package/dist/doctor/checks/namespaces.check.js +76 -0
- package/dist/doctor/checks/themes.check.js +18 -40
- package/dist/doctor/doctor.helpers.js +5 -1
- package/dist/doctor/doctor.types.d.ts +4 -0
- package/dist/helpers/args.helpers.d.ts +2 -0
- package/dist/helpers/args.helpers.js +9 -0
- package/dist/helpers/barrels.helpers.d.ts +15 -0
- package/dist/helpers/barrels.helpers.js +157 -0
- package/dist/index.d.ts +12 -9
- package/dist/index.js +11 -9
- package/dist/registry/index.d.ts +2 -0
- package/dist/registry/index.js +2 -0
- package/dist/registry/lockfile.d.ts +18 -0
- package/dist/registry/lockfile.js +32 -0
- package/dist/registry/registry.helpers.d.ts +3 -13
- package/dist/registry/registry.helpers.js +30 -116
- package/dist/registry/registry.providers.d.ts +13 -0
- package/dist/registry/registry.providers.js +159 -0
- package/dist/registry/registry.service.d.ts +14 -0
- package/dist/registry/registry.service.js +126 -0
- package/dist/types/config.types.d.ts +29 -0
- package/dist/types/registry.types.d.ts +31 -0
- package/dist/types/registry.types.js +2 -0
- package/dist/ui-api/index.d.ts +16 -0
- package/dist/ui-api/index.js +30 -0
- package/dist/ui-api/ui-api.d.ts +18 -0
- package/dist/ui-api/ui-api.js +194 -0
- package/package.json +7 -5
- package/styles.css +16 -0
- package/dist/registry-data/README.md +0 -71
- package/dist/registry-data/avatar/Avatar.tsx +0 -64
- package/dist/registry-data/avatar/component.json +0 -30
- package/dist/registry-data/avatar/index.ts +0 -1
- package/dist/registry-data/badge/Badge.tsx +0 -76
- package/dist/registry-data/badge/component.json +0 -30
- package/dist/registry-data/badge/index.ts +0 -1
- package/dist/registry-data/brand-logo/BrandLogo.tsx +0 -24
- package/dist/registry-data/brand-logo/component.json +0 -26
- package/dist/registry-data/brand-logo/index.ts +0 -1
- package/dist/registry-data/button/Button.tsx +0 -76
- package/dist/registry-data/button/component.json +0 -33
- package/dist/registry-data/button/index.ts +0 -1
- package/dist/registry-data/button-link/ButtonLink.tsx +0 -83
- package/dist/registry-data/button-link/component.json +0 -33
- package/dist/registry-data/button-link/index.ts +0 -5
- package/dist/registry-data/button-styles/component.json +0 -19
- package/dist/registry-data/button-styles/index.ts +0 -45
- package/dist/registry-data/cn/cn.ts +0 -6
- package/dist/registry-data/cn/component.json +0 -16
- package/dist/registry-data/confirm-dialog/ConfirmDialog.tsx +0 -134
- package/dist/registry-data/confirm-dialog/component.json +0 -34
- package/dist/registry-data/confirm-dialog/index.ts +0 -1
- package/dist/registry-data/container/Container.tsx +0 -22
- package/dist/registry-data/container/component.json +0 -28
- package/dist/registry-data/container/index.ts +0 -1
- package/dist/registry-data/cursor-glow/CursorGlow.tsx +0 -29
- package/dist/registry-data/cursor-glow/component.json +0 -28
- package/dist/registry-data/cursor-glow/index.ts +0 -1
- package/dist/registry-data/dropdown-menu/DropdownMenu.tsx +0 -157
- package/dist/registry-data/dropdown-menu/component.json +0 -34
- package/dist/registry-data/dropdown-menu/index.ts +0 -5
- package/dist/registry-data/empty-state/EmptyState.tsx +0 -92
- package/dist/registry-data/empty-state/component.json +0 -30
- package/dist/registry-data/empty-state/index.ts +0 -5
- package/dist/registry-data/eyebrow/Eyebrow.tsx +0 -68
- package/dist/registry-data/eyebrow/component.json +0 -30
- package/dist/registry-data/eyebrow/index.ts +0 -1
- package/dist/registry-data/field-styles/component.json +0 -19
- package/dist/registry-data/field-styles/index.ts +0 -42
- package/dist/registry-data/form-dialog/FormDialog.tsx +0 -128
- package/dist/registry-data/form-dialog/component.json +0 -34
- package/dist/registry-data/form-dialog/index.ts +0 -1
- package/dist/registry-data/icons/component.json +0 -22
- package/dist/registry-data/icons/index.ts +0 -21
- package/dist/registry-data/icons-form/component.json +0 -17
- package/dist/registry-data/icons-form/index.ts +0 -1
- package/dist/registry-data/icons-sidebar/component.json +0 -17
- package/dist/registry-data/icons-sidebar/index.ts +0 -1
- package/dist/registry-data/icons-theme/component.json +0 -17
- package/dist/registry-data/icons-theme/index.ts +0 -1
- package/dist/registry-data/icons-toast/component.json +0 -17
- package/dist/registry-data/icons-toast/index.ts +0 -1
- package/dist/registry-data/info-dialog/InfoDialog.tsx +0 -119
- package/dist/registry-data/info-dialog/component.json +0 -36
- package/dist/registry-data/info-dialog/index.ts +0 -1
- package/dist/registry-data/input/Input.tsx +0 -96
- package/dist/registry-data/input/component.json +0 -33
- package/dist/registry-data/input/index.ts +0 -1
- package/dist/registry-data/multi-combobox/MultiCombobox.tsx +0 -205
- package/dist/registry-data/multi-combobox/component.json +0 -35
- package/dist/registry-data/multi-combobox/index.ts +0 -5
- package/dist/registry-data/remote-provider/RemoteProvider.tsx +0 -8
- package/dist/registry-data/remote-provider/component.json +0 -25
- package/dist/registry-data/remote-provider/index.ts +0 -3
- package/dist/registry-data/reveal/Reveal.tsx +0 -22
- package/dist/registry-data/reveal/component.json +0 -30
- package/dist/registry-data/reveal/index.ts +0 -1
- package/dist/registry-data/section/Section.tsx +0 -80
- package/dist/registry-data/section/component.json +0 -30
- package/dist/registry-data/section/index.ts +0 -1
- package/dist/registry-data/section-heading/SectionHeading.tsx +0 -105
- package/dist/registry-data/section-heading/component.json +0 -32
- package/dist/registry-data/section-heading/index.ts +0 -1
- package/dist/registry-data/select/Select.tsx +0 -197
- package/dist/registry-data/select/component.json +0 -34
- package/dist/registry-data/select/index.ts +0 -1
- package/dist/registry-data/sidebar/Sidebar.tsx +0 -432
- package/dist/registry-data/sidebar/SidebarCollapsible.tsx +0 -77
- package/dist/registry-data/sidebar/SidebarParts.tsx +0 -373
- package/dist/registry-data/sidebar/component.json +0 -47
- package/dist/registry-data/sidebar/index.ts +0 -4
- package/dist/registry-data/sidebar/useSidebar.ts +0 -29
- package/dist/registry-data/styles-base/component.json +0 -19
- package/dist/registry-data/styles-base/index.css +0 -67
- package/dist/registry-data/styles-components/component.json +0 -19
- package/dist/registry-data/styles-components/index.css +0 -30
- package/dist/registry-data/styles-motion/component.json +0 -20
- package/dist/registry-data/styles-motion/index.css +0 -381
- package/dist/registry-data/styles-tokens/component.json +0 -17
- package/dist/registry-data/styles-tokens/index.css +0 -77
- package/dist/registry-data/styles-utilities/component.json +0 -19
- package/dist/registry-data/styles-utilities/index.css +0 -29
- package/dist/registry-data/switch/Switch.tsx +0 -91
- package/dist/registry-data/switch/component.json +0 -34
- package/dist/registry-data/switch/index.ts +0 -1
- package/dist/registry-data/tabs/Tabs.tsx +0 -226
- package/dist/registry-data/tabs/component.json +0 -32
- package/dist/registry-data/tabs/index.ts +0 -1
- package/dist/registry-data/textarea/Textarea.tsx +0 -94
- package/dist/registry-data/textarea/component.json +0 -33
- package/dist/registry-data/textarea/index.ts +0 -1
- package/dist/registry-data/theme-core/component.json +0 -17
- package/dist/registry-data/theme-core/theme.ts +0 -84
- package/dist/registry-data/theme-dark/component.json +0 -19
- package/dist/registry-data/theme-dark/index.ts +0 -7
- package/dist/registry-data/theme-light/component.json +0 -19
- package/dist/registry-data/theme-light/index.ts +0 -7
- package/dist/registry-data/theme-provider/ThemeContext.tsx +0 -177
- package/dist/registry-data/theme-provider/component.json +0 -30
- package/dist/registry-data/theme-provider/index.ts +0 -2
- package/dist/registry-data/theme-selector/ThemeSelector.tsx +0 -269
- package/dist/registry-data/theme-selector/component.json +0 -35
- package/dist/registry-data/theme-selector/selector.ts +0 -1
- package/dist/registry-data/theme-system/component.json +0 -19
- package/dist/registry-data/theme-system/index.ts +0 -7
- package/dist/registry-data/theme-toggle/ThemeToggle.tsx +0 -71
- package/dist/registry-data/theme-toggle/component.json +0 -31
- package/dist/registry-data/theme-toggle/toggle.ts +0 -1
- package/dist/registry-data/toast/Toast.tsx +0 -260
- package/dist/registry-data/toast/ToastTypeIcon.tsx +0 -83
- package/dist/registry-data/toast/component.json +0 -43
- package/dist/registry-data/toast/index.ts +0 -3
- package/dist/registry-data/toast/useToast.ts +0 -47
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { State, type StateId } from '@blankways/state'
|
|
2
|
-
import { useCompute, useState } from '@blankways/state-react'
|
|
3
|
-
import {
|
|
4
|
-
createContext,
|
|
5
|
-
useCallback,
|
|
6
|
-
useContext,
|
|
7
|
-
useEffect,
|
|
8
|
-
useMemo,
|
|
9
|
-
type ReactNode,
|
|
10
|
-
} from 'react'
|
|
11
|
-
import {
|
|
12
|
-
DEFAULT_THEMES,
|
|
13
|
-
DARK_THEME,
|
|
14
|
-
getStoredPreference,
|
|
15
|
-
LIGHT_THEME,
|
|
16
|
-
normalizePreference,
|
|
17
|
-
resolveTheme,
|
|
18
|
-
systemTheme,
|
|
19
|
-
THEME_STORAGE_KEY,
|
|
20
|
-
type SystemThemes,
|
|
21
|
-
type Theme,
|
|
22
|
-
type ThemePreference,
|
|
23
|
-
} from './theme.js'
|
|
24
|
-
|
|
25
|
-
const DEFAULT_SYSTEM_THEMES: SystemThemes = {
|
|
26
|
-
light: LIGHT_THEME,
|
|
27
|
-
dark: DARK_THEME,
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const DEFAULT_THEME_COLORS: Partial<Record<Theme, string>> = {
|
|
31
|
-
[LIGHT_THEME]: '#ffffff',
|
|
32
|
-
[DARK_THEME]: '#0a0a0a',
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type ThemeContextValue = {
|
|
36
|
-
/** Reactive concrete theme, never `system`. */
|
|
37
|
-
theme: StateId<Theme>
|
|
38
|
-
/** Reactive visitor choice, which may be `system` or any registered theme. */
|
|
39
|
-
preference: StateId<ThemePreference>
|
|
40
|
-
/** Themes this provider accepts. */
|
|
41
|
-
themes: readonly Theme[]
|
|
42
|
-
/** How the OS light/dark preference maps to registered themes. */
|
|
43
|
-
systemThemes: SystemThemes
|
|
44
|
-
/** Persists and applies a new preference. */
|
|
45
|
-
setPreference: (preference: ThemePreference) => void
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export type ThemeProviderProps = {
|
|
49
|
-
children: ReactNode
|
|
50
|
-
themes?: readonly Theme[]
|
|
51
|
-
defaultTheme?: Theme
|
|
52
|
-
storageKey?: string
|
|
53
|
-
systemThemes?: SystemThemes
|
|
54
|
-
themeColors?: Partial<Record<Theme, string>>
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export const ThemeContext = createContext<ThemeContextValue | null>(null)
|
|
58
|
-
|
|
59
|
-
/** Reads the active theme context. */
|
|
60
|
-
export function useTheme(): ThemeContextValue {
|
|
61
|
-
const context = useContext(ThemeContext)
|
|
62
|
-
if (!context) {
|
|
63
|
-
throw new Error('useTheme must be used within a ThemeProvider')
|
|
64
|
-
}
|
|
65
|
-
return context
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** Applies a string theme to `<html data-theme>` and persists the choice. */
|
|
69
|
-
export function ThemeProvider({
|
|
70
|
-
children,
|
|
71
|
-
themes = DEFAULT_THEMES,
|
|
72
|
-
defaultTheme = DEFAULT_THEMES[0],
|
|
73
|
-
storageKey = THEME_STORAGE_KEY,
|
|
74
|
-
systemThemes = DEFAULT_SYSTEM_THEMES,
|
|
75
|
-
themeColors,
|
|
76
|
-
}: ThemeProviderProps) {
|
|
77
|
-
const colors = useMemo(
|
|
78
|
-
() => ({ ...DEFAULT_THEME_COLORS, ...themeColors }),
|
|
79
|
-
[themeColors],
|
|
80
|
-
)
|
|
81
|
-
const preference = useState<ThemePreference>(
|
|
82
|
-
normalizePreference(getStoredPreference(storageKey), themes, defaultTheme),
|
|
83
|
-
)
|
|
84
|
-
const system = useState<Theme>(systemTheme(systemThemes))
|
|
85
|
-
const theme = useCompute(
|
|
86
|
-
[preference, system] as const,
|
|
87
|
-
([currentPreference, currentSystem]): Theme =>
|
|
88
|
-
resolveTheme(currentPreference, currentSystem, defaultTheme),
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
const setPreference = useCallback(
|
|
92
|
-
(next: ThemePreference) => {
|
|
93
|
-
State.set(preference, normalizePreference(next, themes, defaultTheme))
|
|
94
|
-
},
|
|
95
|
-
[defaultTheme, preference, themes],
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
const value = useMemo<ThemeContextValue>(
|
|
99
|
-
() => ({ theme, preference, themes, systemThemes, setPreference }),
|
|
100
|
-
[preference, setPreference, systemThemes, theme, themes],
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
useEffect(() => {
|
|
104
|
-
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const query = window.matchMedia('(prefers-color-scheme: dark)')
|
|
109
|
-
const onChange = () =>
|
|
110
|
-
State.set(system, query.matches ? systemThemes.dark : systemThemes.light)
|
|
111
|
-
onChange()
|
|
112
|
-
query.addEventListener('change', onChange)
|
|
113
|
-
return () => query.removeEventListener('change', onChange)
|
|
114
|
-
}, [system, systemThemes])
|
|
115
|
-
|
|
116
|
-
useEffect(() => {
|
|
117
|
-
const applyTheme = (current: Theme, animate = false) => {
|
|
118
|
-
if (typeof document === 'undefined') return
|
|
119
|
-
|
|
120
|
-
const run = () => {
|
|
121
|
-
const root = document.documentElement
|
|
122
|
-
root.dataset.theme = current
|
|
123
|
-
root.style.colorScheme = current === systemThemes.dark ? 'dark' : 'light'
|
|
124
|
-
document
|
|
125
|
-
.querySelector('meta[name="theme-color"]')
|
|
126
|
-
?.setAttribute('content', colors[current] ?? '#ffffff')
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const reduceMotion =
|
|
130
|
-
typeof window !== 'undefined' &&
|
|
131
|
-
typeof window.matchMedia === 'function' &&
|
|
132
|
-
window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
133
|
-
const withTransitions = document as Document & {
|
|
134
|
-
startViewTransition?: (callback: () => void) => void
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (
|
|
138
|
-
animate &&
|
|
139
|
-
!reduceMotion &&
|
|
140
|
-
typeof withTransitions.startViewTransition === 'function'
|
|
141
|
-
) {
|
|
142
|
-
withTransitions.startViewTransition(run)
|
|
143
|
-
} else {
|
|
144
|
-
run()
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const persistPreference = (current: ThemePreference) => {
|
|
149
|
-
if (typeof window === 'undefined') return
|
|
150
|
-
try {
|
|
151
|
-
if (current === 'system') {
|
|
152
|
-
window.localStorage.removeItem(storageKey)
|
|
153
|
-
} else {
|
|
154
|
-
window.localStorage.setItem(storageKey, current)
|
|
155
|
-
}
|
|
156
|
-
} catch {
|
|
157
|
-
/* storage unavailable: the choice lasts for this visit only */
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
applyTheme(State.get(theme))
|
|
162
|
-
|
|
163
|
-
const themeWatcher = State.watch(theme, () => {
|
|
164
|
-
applyTheme(State.get(theme), true)
|
|
165
|
-
})
|
|
166
|
-
const preferenceWatcher = State.watch(preference, () => {
|
|
167
|
-
persistPreference(State.get(preference))
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
return () => {
|
|
171
|
-
State.unwatch(themeWatcher)
|
|
172
|
-
State.unwatch(preferenceWatcher)
|
|
173
|
-
}
|
|
174
|
-
}, [colors, preference, storageKey, systemThemes, theme])
|
|
175
|
-
|
|
176
|
-
return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>
|
|
177
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "theme-provider",
|
|
3
|
-
"kind": "theme",
|
|
4
|
-
"framework": "react",
|
|
5
|
-
"description": "React context provider that applies and persists the active theme.",
|
|
6
|
-
"dependencies": [
|
|
7
|
-
"theme-core",
|
|
8
|
-
"styles-motion"
|
|
9
|
-
],
|
|
10
|
-
"peers": [
|
|
11
|
-
"@blankways/state",
|
|
12
|
-
"@blankways/state-react@0.1.0-alpha.1",
|
|
13
|
-
"react",
|
|
14
|
-
"react-dom"
|
|
15
|
-
],
|
|
16
|
-
"suggestions": [
|
|
17
|
-
"theme-toggle",
|
|
18
|
-
"styles-motion"
|
|
19
|
-
],
|
|
20
|
-
"files": [
|
|
21
|
-
{
|
|
22
|
-
"source": "ThemeContext.tsx",
|
|
23
|
-
"target": "themes/ThemeContext.tsx"
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"source": "index.ts",
|
|
27
|
-
"target": "themes/index.ts"
|
|
28
|
-
}
|
|
29
|
-
]
|
|
30
|
-
}
|
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import type { StateId } from '@blankways/state'
|
|
2
|
-
import { Show, useAttributes, useMatch } from '@blankways/state-react'
|
|
3
|
-
import { useId, useMemo, type CSSProperties } from 'react'
|
|
4
|
-
import { cn } from '../internals/cn.js'
|
|
5
|
-
import { Check } from '../icons/form.js'
|
|
6
|
-
import { useTheme } from './ThemeContext.js'
|
|
7
|
-
import {
|
|
8
|
-
DARK_THEME,
|
|
9
|
-
LIGHT_THEME,
|
|
10
|
-
SYSTEM_PREFERENCE,
|
|
11
|
-
type SystemThemes,
|
|
12
|
-
type Theme,
|
|
13
|
-
type ThemePreference,
|
|
14
|
-
} from './theme.js'
|
|
15
|
-
|
|
16
|
-
type Palette = {
|
|
17
|
-
paper: string
|
|
18
|
-
surface: string
|
|
19
|
-
line: string
|
|
20
|
-
ink: string
|
|
21
|
-
muted: string
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type ThemePaletteOverrides = Partial<Record<Theme, Partial<Palette>>>
|
|
25
|
-
|
|
26
|
-
/** Default palettes for the automatically registered themes. */
|
|
27
|
-
const DEFAULT_PALETTES: Record<string, Palette> = {
|
|
28
|
-
[LIGHT_THEME]: {
|
|
29
|
-
paper: '#ffffff',
|
|
30
|
-
surface: '#f7f7f7',
|
|
31
|
-
line: '#e4e4e4',
|
|
32
|
-
ink: '#111111',
|
|
33
|
-
muted: '#d4d4d4',
|
|
34
|
-
},
|
|
35
|
-
[DARK_THEME]: {
|
|
36
|
-
paper: '#0a0a0a',
|
|
37
|
-
surface: '#121212',
|
|
38
|
-
line: '#2a2a2a',
|
|
39
|
-
ink: '#f5f5f5',
|
|
40
|
-
muted: '#3f3f3f',
|
|
41
|
-
},
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const CUSTOM_PALETTE: Palette = {
|
|
45
|
-
paper: '#1f1f1f',
|
|
46
|
-
surface: '#2e2e2e',
|
|
47
|
-
line: '#454545',
|
|
48
|
-
ink: '#f5f5f5',
|
|
49
|
-
muted: '#6e6e6e',
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function paletteFor(theme: Theme, overrides: ThemePaletteOverrides): Palette {
|
|
53
|
-
return {
|
|
54
|
-
...(DEFAULT_PALETTES[theme] ?? CUSTOM_PALETTE),
|
|
55
|
-
...overrides[theme],
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function MiniWindow({
|
|
60
|
-
theme,
|
|
61
|
-
palettes,
|
|
62
|
-
}: {
|
|
63
|
-
theme: Theme
|
|
64
|
-
palettes: ThemePaletteOverrides
|
|
65
|
-
}) {
|
|
66
|
-
const palette = paletteFor(theme, palettes)
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<div
|
|
70
|
-
aria-hidden="true"
|
|
71
|
-
className="absolute inset-0 flex"
|
|
72
|
-
style={{ background: palette.paper }}
|
|
73
|
-
>
|
|
74
|
-
<div
|
|
75
|
-
className="flex w-1/4 flex-col gap-1.5 p-1.5"
|
|
76
|
-
style={{
|
|
77
|
-
background: palette.surface,
|
|
78
|
-
borderRight: `1px solid ${palette.line}`,
|
|
79
|
-
}}
|
|
80
|
-
>
|
|
81
|
-
<span className="h-1.5 w-3/4 rounded-full bg-brand-500" />
|
|
82
|
-
<span className="h-1 rounded-full" style={{ background: palette.muted }} />
|
|
83
|
-
<span
|
|
84
|
-
className="h-1 w-2/3 rounded-full"
|
|
85
|
-
style={{ background: palette.muted }}
|
|
86
|
-
/>
|
|
87
|
-
</div>
|
|
88
|
-
<div className="flex flex-1 flex-col gap-2 p-[0.5625rem]">
|
|
89
|
-
<span
|
|
90
|
-
className="h-2 w-1/3 rounded-full"
|
|
91
|
-
style={{ background: palette.ink }}
|
|
92
|
-
/>
|
|
93
|
-
<div className="grid grid-cols-2 gap-1.5">
|
|
94
|
-
<span
|
|
95
|
-
className="h-7 rounded-2xl"
|
|
96
|
-
style={{
|
|
97
|
-
background: palette.surface,
|
|
98
|
-
border: `1px solid ${palette.line}`,
|
|
99
|
-
}}
|
|
100
|
-
/>
|
|
101
|
-
<span
|
|
102
|
-
className="h-7 rounded-2xl"
|
|
103
|
-
style={{
|
|
104
|
-
background: palette.surface,
|
|
105
|
-
border: `1px solid ${palette.line}`,
|
|
106
|
-
}}
|
|
107
|
-
/>
|
|
108
|
-
</div>
|
|
109
|
-
<span className="h-1.5 rounded-full" style={{ background: palette.muted }} />
|
|
110
|
-
<span
|
|
111
|
-
className="h-1.5 w-4/5 rounded-full"
|
|
112
|
-
style={{ background: palette.muted }}
|
|
113
|
-
/>
|
|
114
|
-
</div>
|
|
115
|
-
</div>
|
|
116
|
-
)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function ThemePreview({
|
|
120
|
-
preference,
|
|
121
|
-
palettes,
|
|
122
|
-
systemThemes,
|
|
123
|
-
}: {
|
|
124
|
-
preference: ThemePreference
|
|
125
|
-
palettes: ThemePaletteOverrides
|
|
126
|
-
systemThemes: SystemThemes
|
|
127
|
-
}) {
|
|
128
|
-
return (
|
|
129
|
-
<div className="relative aspect-[16/10] overflow-hidden rounded-2xl border border-line">
|
|
130
|
-
{preference === SYSTEM_PREFERENCE ? (
|
|
131
|
-
<>
|
|
132
|
-
<MiniWindow theme={systemThemes.light} palettes={palettes} />
|
|
133
|
-
<div
|
|
134
|
-
className="absolute inset-0"
|
|
135
|
-
style={{ clipPath: 'polygon(100% 0, 100% 100%, 0 100%)' }}
|
|
136
|
-
>
|
|
137
|
-
<MiniWindow theme={systemThemes.dark} palettes={palettes} />
|
|
138
|
-
</div>
|
|
139
|
-
</>
|
|
140
|
-
) : (
|
|
141
|
-
<MiniWindow theme={preference} palettes={palettes} />
|
|
142
|
-
)}
|
|
143
|
-
</div>
|
|
144
|
-
)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function labelFor(preference: ThemePreference) {
|
|
148
|
-
if (preference === LIGHT_THEME) return 'Light'
|
|
149
|
-
if (preference === DARK_THEME) return 'Dark'
|
|
150
|
-
if (preference === SYSTEM_PREFERENCE) return 'System'
|
|
151
|
-
return preference
|
|
152
|
-
.replace(/[-_]/g, ' ')
|
|
153
|
-
.replace(/\b\w/g, character => character.toUpperCase())
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function OptionCard({
|
|
157
|
-
option,
|
|
158
|
-
name,
|
|
159
|
-
index,
|
|
160
|
-
checked,
|
|
161
|
-
label,
|
|
162
|
-
palettes,
|
|
163
|
-
systemThemes,
|
|
164
|
-
onSelect,
|
|
165
|
-
}: {
|
|
166
|
-
option: ThemePreference
|
|
167
|
-
name: string
|
|
168
|
-
index: number
|
|
169
|
-
checked: StateId<boolean>
|
|
170
|
-
label: string
|
|
171
|
-
palettes: ThemePaletteOverrides
|
|
172
|
-
systemThemes: SystemThemes
|
|
173
|
-
onSelect: (option: ThemePreference) => void
|
|
174
|
-
}) {
|
|
175
|
-
const bind = useAttributes<HTMLInputElement>({ checked })
|
|
176
|
-
|
|
177
|
-
return (
|
|
178
|
-
<label
|
|
179
|
-
className="motion-lift group flex h-full w-full cursor-pointer flex-col gap-3 rounded-2xl border border-line bg-surface p-[0.5625rem] text-left hover:border-line-strong focus-within:ring-2 focus-within:ring-brand-500 has-checked:border-brand-500"
|
|
180
|
-
style={{ '--index': index } as CSSProperties}
|
|
181
|
-
>
|
|
182
|
-
<ThemePreview
|
|
183
|
-
preference={option}
|
|
184
|
-
palettes={palettes}
|
|
185
|
-
systemThemes={systemThemes}
|
|
186
|
-
/>
|
|
187
|
-
<span className="flex items-center justify-between px-[0.188rem] text-sm font-medium text-ink">
|
|
188
|
-
<span>{label}</span>
|
|
189
|
-
<span className="relative inline-flex size-5 items-center justify-center rounded-full border border-line-strong">
|
|
190
|
-
<input
|
|
191
|
-
ref={bind}
|
|
192
|
-
type="radio"
|
|
193
|
-
name={name}
|
|
194
|
-
value={option}
|
|
195
|
-
className="peer sr-only"
|
|
196
|
-
onChange={() => onSelect(option)}
|
|
197
|
-
/>
|
|
198
|
-
<Show when={checked}>
|
|
199
|
-
<span className="motion-icon-swap check-draw absolute inset-[-1px] inline-flex items-center justify-center rounded-full bg-brand-500 text-[#111111]">
|
|
200
|
-
<Check className="size-3" strokeWidth={3} aria-hidden="true" />
|
|
201
|
-
</span>
|
|
202
|
-
</Show>
|
|
203
|
-
</span>
|
|
204
|
-
</span>
|
|
205
|
-
</label>
|
|
206
|
-
)
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export type ThemeSelectorProps = {
|
|
210
|
-
/** Accessible name of the radio group. */
|
|
211
|
-
label: string
|
|
212
|
-
/** Themes to offer. Defaults to the provider's themes. */
|
|
213
|
-
themes?: readonly Theme[]
|
|
214
|
-
/** Adds the `system` preference. Enabled by default. */
|
|
215
|
-
includeSystem?: boolean
|
|
216
|
-
/** Overrides labels for any preference. */
|
|
217
|
-
labels?: Partial<Record<ThemePreference, string>>
|
|
218
|
-
/** Overrides preview colors for any registered theme. */
|
|
219
|
-
palettes?: ThemePaletteOverrides
|
|
220
|
-
className?: string
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/** Cards with a mini preview for every registered theme plus `system`. */
|
|
224
|
-
export function ThemeSelector({
|
|
225
|
-
label,
|
|
226
|
-
themes,
|
|
227
|
-
includeSystem = true,
|
|
228
|
-
labels,
|
|
229
|
-
palettes = {},
|
|
230
|
-
className,
|
|
231
|
-
}: ThemeSelectorProps) {
|
|
232
|
-
const {
|
|
233
|
-
themes: contextThemes,
|
|
234
|
-
systemThemes,
|
|
235
|
-
preference,
|
|
236
|
-
setPreference,
|
|
237
|
-
} = useTheme()
|
|
238
|
-
const providerThemes = themes ?? contextThemes
|
|
239
|
-
const options = useMemo<readonly ThemePreference[]>(
|
|
240
|
-
() =>
|
|
241
|
-
includeSystem
|
|
242
|
-
? [...providerThemes, SYSTEM_PREFERENCE]
|
|
243
|
-
: [...providerThemes],
|
|
244
|
-
[includeSystem, providerThemes],
|
|
245
|
-
)
|
|
246
|
-
const match = useMatch(preference, options)
|
|
247
|
-
const name = useId()
|
|
248
|
-
|
|
249
|
-
return (
|
|
250
|
-
<fieldset className={cn('min-w-0', className)}>
|
|
251
|
-
<legend className="sr-only">{label}</legend>
|
|
252
|
-
<div className="stagger-children grid gap-4 sm:grid-cols-3">
|
|
253
|
-
{options.map((option, index) => (
|
|
254
|
-
<OptionCard
|
|
255
|
-
key={option}
|
|
256
|
-
option={option}
|
|
257
|
-
name={name}
|
|
258
|
-
index={index}
|
|
259
|
-
checked={match[index]}
|
|
260
|
-
label={labels?.[option] ?? labelFor(option)}
|
|
261
|
-
palettes={palettes}
|
|
262
|
-
systemThemes={systemThemes}
|
|
263
|
-
onSelect={setPreference}
|
|
264
|
-
/>
|
|
265
|
-
))}
|
|
266
|
-
</div>
|
|
267
|
-
</fieldset>
|
|
268
|
-
)
|
|
269
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "theme-selector",
|
|
3
|
-
"kind": "theme",
|
|
4
|
-
"framework": "react",
|
|
5
|
-
"description": "Accessible cards for choosing any registered string theme.",
|
|
6
|
-
"dependencies": [
|
|
7
|
-
"theme-provider",
|
|
8
|
-
"icons-form",
|
|
9
|
-
"cn",
|
|
10
|
-
"styles-motion"
|
|
11
|
-
],
|
|
12
|
-
"peers": [
|
|
13
|
-
"@blankways/state",
|
|
14
|
-
"@blankways/state-react@0.1.0-alpha.1",
|
|
15
|
-
"lucide-react",
|
|
16
|
-
"react"
|
|
17
|
-
],
|
|
18
|
-
"suggestions": [
|
|
19
|
-
"styles-tokens",
|
|
20
|
-
"styles-base",
|
|
21
|
-
"styles-components",
|
|
22
|
-
"styles-utilities",
|
|
23
|
-
"styles-motion"
|
|
24
|
-
],
|
|
25
|
-
"files": [
|
|
26
|
-
{
|
|
27
|
-
"source": "ThemeSelector.tsx",
|
|
28
|
-
"target": "themes/ThemeSelector.tsx"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"source": "selector.ts",
|
|
32
|
-
"target": "themes/selector.ts"
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ThemeSelector.js'
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "theme-system",
|
|
3
|
-
"kind": "theme",
|
|
4
|
-
"framework": "react",
|
|
5
|
-
"description": "System theme preference constant.",
|
|
6
|
-
"dependencies": [
|
|
7
|
-
"theme-core"
|
|
8
|
-
],
|
|
9
|
-
"peers": [
|
|
10
|
-
"react"
|
|
11
|
-
],
|
|
12
|
-
"suggestions": [],
|
|
13
|
-
"files": [
|
|
14
|
-
{
|
|
15
|
-
"source": "index.ts",
|
|
16
|
-
"target": "themes/system.ts"
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { ThemePreference } from './theme.js'
|
|
2
|
-
|
|
3
|
-
/** Preference that follows the operating system setting. */
|
|
4
|
-
export const SYSTEM_THEME_PREFERENCE: ThemePreference = 'system'
|
|
5
|
-
|
|
6
|
-
/** Alias used by theme controls that expose a system option. */
|
|
7
|
-
export const systemPreference: ThemePreference = 'system'
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { State } from '@blankways/state'
|
|
2
|
-
import { Show, useAttributes, useCompute, useMatch } from '@blankways/state-react'
|
|
3
|
-
import { useMemo, useRef, type ReactNode } from 'react'
|
|
4
|
-
import { cn } from '../internals/cn.js'
|
|
5
|
-
import { Moon, Sun } from '../icons/theme.js'
|
|
6
|
-
import { useTheme } from './ThemeContext.js'
|
|
7
|
-
import { DARK_THEME, LIGHT_THEME, type Theme } from './theme.js'
|
|
8
|
-
|
|
9
|
-
const DEFAULT_ICONS: Partial<Record<Theme, ReactNode>> = {
|
|
10
|
-
[LIGHT_THEME]: <Sun className="size-5" />,
|
|
11
|
-
[DARK_THEME]: <Moon className="size-5" />,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type ThemeToggleProps = {
|
|
15
|
-
className?: string
|
|
16
|
-
/** Themes to cycle through. Defaults to the provider's themes. */
|
|
17
|
-
themes?: readonly Theme[]
|
|
18
|
-
/** Overrides the icon shown for a theme. */
|
|
19
|
-
icons?: Partial<Record<Theme, ReactNode>>
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Accessible button that cycles through the registered themes. */
|
|
23
|
-
export function ThemeToggle({
|
|
24
|
-
className,
|
|
25
|
-
themes,
|
|
26
|
-
icons,
|
|
27
|
-
}: ThemeToggleProps) {
|
|
28
|
-
const { theme, themes: contextThemes, setPreference } = useTheme()
|
|
29
|
-
const options = useMemo(
|
|
30
|
-
() => (themes && themes.length > 0 ? themes : contextThemes),
|
|
31
|
-
[contextThemes, themes],
|
|
32
|
-
)
|
|
33
|
-
const matches = useMatch(theme, options)
|
|
34
|
-
const buttonRef = useRef<HTMLButtonElement>(null)
|
|
35
|
-
const label = useCompute(
|
|
36
|
-
[theme] as const,
|
|
37
|
-
([current]): string => `Switch theme, current theme: ${current}`,
|
|
38
|
-
)
|
|
39
|
-
useAttributes(buttonRef, { 'aria-label': label, 'data-theme': theme })
|
|
40
|
-
|
|
41
|
-
const cycle = () => {
|
|
42
|
-
const current = State.get(theme)
|
|
43
|
-
const index = options.indexOf(current)
|
|
44
|
-
const next = options[(index + 1) % options.length] ?? options[0] ?? LIGHT_THEME
|
|
45
|
-
setPreference(next)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const mergedIcons = useMemo(() => ({ ...DEFAULT_ICONS, ...icons }), [icons])
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<button
|
|
52
|
-
ref={buttonRef}
|
|
53
|
-
type="button"
|
|
54
|
-
onClick={cycle}
|
|
55
|
-
className={cn(
|
|
56
|
-
'motion-press inline-flex size-10 items-center justify-center rounded-2xl border border-line bg-paper text-ink hover:bg-surface',
|
|
57
|
-
className,
|
|
58
|
-
)}
|
|
59
|
-
>
|
|
60
|
-
<span aria-hidden="true">
|
|
61
|
-
{options.map((option, index) => (
|
|
62
|
-
<Show key={option} when={matches[index]}>
|
|
63
|
-
<span className="motion-icon-swap">
|
|
64
|
-
{mergedIcons[option] ?? <Sun className="size-5" />}
|
|
65
|
-
</span>
|
|
66
|
-
</Show>
|
|
67
|
-
))}
|
|
68
|
-
</span>
|
|
69
|
-
</button>
|
|
70
|
-
)
|
|
71
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "theme-toggle",
|
|
3
|
-
"kind": "theme",
|
|
4
|
-
"framework": "react",
|
|
5
|
-
"description": "Button that cycles through any registered string themes.",
|
|
6
|
-
"dependencies": [
|
|
7
|
-
"theme-provider",
|
|
8
|
-
"icons-theme",
|
|
9
|
-
"cn",
|
|
10
|
-
"styles-motion"
|
|
11
|
-
],
|
|
12
|
-
"peers": [
|
|
13
|
-
"@blankways/state",
|
|
14
|
-
"@blankways/state-react@0.1.0-alpha.1",
|
|
15
|
-
"lucide-react",
|
|
16
|
-
"react"
|
|
17
|
-
],
|
|
18
|
-
"suggestions": [
|
|
19
|
-
"styles-motion"
|
|
20
|
-
],
|
|
21
|
-
"files": [
|
|
22
|
-
{
|
|
23
|
-
"source": "ThemeToggle.tsx",
|
|
24
|
-
"target": "themes/ThemeToggle.tsx"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"source": "toggle.ts",
|
|
28
|
-
"target": "themes/toggle.ts"
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ThemeToggle.js'
|