@shellui/core 0.4.1 → 0.5.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 +2 -2
- package/package.json +15 -3
- package/schemas/curated-themes.json +4035 -0
- package/schemas/shellui.config.schema.json +961 -0
- package/schemas/shellui.theme.schema.json +187 -0
- package/src/app.tsx +4 -1
- package/src/components/ContentView.tsx +144 -9
- package/src/components/LoadingOverlay.tsx +1 -1
- package/src/components/ui/alert-dialog.tsx +1 -1
- package/src/components/ui/dialog.tsx +23 -5
- package/src/components/ui/drawer.tsx +282 -42
- package/src/components/ui/dropdown-menu.tsx +7 -2
- package/src/components/ui/input.tsx +21 -0
- package/src/components/ui/separator.tsx +23 -0
- package/src/components/ui/sheet.tsx +220 -0
- package/src/components/ui/sidebar.tsx +785 -221
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/constants/urls.ts +1 -0
- package/src/features/admin/utils.ts +2 -45
- package/src/features/alertDialog/DialogContext.tsx +1 -1
- package/src/features/auth/components/LoginButton.tsx +25 -18
- package/src/features/auth/components/LoginPreferencesControls.tsx +124 -0
- package/src/features/auth/components/LoginView.tsx +131 -49
- package/src/features/config/types.ts +64 -82
- package/src/features/drawer/DrawerContext.tsx +55 -19
- package/src/features/layouts/AppLayout.tsx +3 -3
- package/src/features/layouts/OverlayShell.tsx +376 -77
- package/src/features/layouts/appbar/AppBarLayout.tsx +501 -88
- package/src/features/layouts/branding/AppBrandIcon.tsx +95 -0
- package/src/features/layouts/branding/resolveThemeAsset.spec.ts +33 -0
- package/src/features/layouts/branding/resolveThemeAsset.ts +33 -0
- package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +49 -0
- package/src/features/layouts/chrome/ContentDragOverlay.tsx +19 -0
- package/src/features/layouts/chrome/DesktopBackButton.tsx +71 -0
- package/src/features/layouts/chrome/DesktopChrome.tsx +28 -0
- package/src/features/layouts/chrome/DesktopForwardButton.tsx +59 -0
- package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +16 -0
- package/src/features/layouts/chrome/constants.ts +11 -0
- package/src/features/layouts/chrome/goDesktopBack.spec.ts +218 -0
- package/src/features/layouts/chrome/goDesktopBack.ts +106 -0
- package/src/features/layouts/chrome/index.ts +26 -0
- package/src/features/layouts/chrome/runtime.ts +45 -0
- package/src/features/layouts/findMatchingNavigationItem.spec.ts +55 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.tsx +17 -1
- package/src/features/layouts/isFrameForAppUrl.spec.ts +33 -0
- package/src/features/layouts/sidebar/NavigationContent.tsx +70 -34
- package/src/features/layouts/sidebar/SidebarIcons.tsx +41 -42
- package/src/features/layouts/sidebar/SidebarInner.tsx +142 -24
- package/src/features/layouts/sidebar/SidebarLayout.tsx +100 -37
- package/src/features/layouts/sidebar/sidebarUtils.ts +0 -7
- package/src/features/layouts/sidebar/types.ts +3 -3
- package/src/features/layouts/utils.ts +73 -5
- package/src/features/layouts/windows/WindowsLayout.tsx +173 -61
- package/src/features/modal/ModalContext.tsx +21 -8
- package/src/features/overlays/OverlayDrawerPendingBar.tsx +26 -0
- package/src/features/overlays/OverlayDynamicDemoView.tsx +108 -0
- package/src/features/overlays/OverlayPendingSpinner.tsx +18 -0
- package/src/features/overlays/ResponsiveModal.tsx +483 -0
- package/src/features/overlays/overlaySize.spec.ts +71 -0
- package/src/features/overlays/overlaySize.ts +228 -0
- package/src/features/overlays/useOverlayReportedSize.ts +130 -0
- package/src/features/settings/SettingsProvider.tsx +66 -46
- package/src/features/settings/SettingsView.tsx +42 -47
- package/src/features/settings/components/Appearance.tsx +305 -55
- package/src/features/settings/components/develop/DrawerTestButtons.tsx +18 -0
- package/src/features/settings/components/develop/ModalTestButtons.tsx +23 -0
- package/src/features/settings/utils/getResolvedAppearanceForSettings.ts +11 -5
- package/src/features/theme/applyTheme.ts +143 -0
- package/src/features/theme/color.ts +83 -0
- package/src/features/theme/curated/amber-minimal.json +86 -0
- package/src/features/theme/curated/amethyst-haze.json +86 -0
- package/src/features/theme/curated/astro-vista.json +86 -0
- package/src/features/theme/curated/bold-tech.json +86 -0
- package/src/features/theme/curated/bubblegum.json +86 -0
- package/src/features/theme/curated/caffeine.json +83 -0
- package/src/features/theme/curated/candyland.json +86 -0
- package/src/features/theme/curated/catppuccin.json +86 -0
- package/src/features/theme/curated/claude.json +86 -0
- package/src/features/theme/curated/claymorphism.json +86 -0
- package/src/features/theme/curated/clean-slate.json +86 -0
- package/src/features/theme/curated/cosmic-night.json +86 -0
- package/src/features/theme/curated/cyberpunk.json +86 -0
- package/src/features/theme/curated/darkmatter.json +86 -0
- package/src/features/theme/curated/doom-64.json +86 -0
- package/src/features/theme/curated/elegant-luxury.json +86 -0
- package/src/features/theme/curated/graphite.json +86 -0
- package/src/features/theme/curated/index.ts +260 -0
- package/src/features/theme/curated/kodama-grove.json +86 -0
- package/src/features/theme/curated/light-green.json +87 -0
- package/src/features/theme/curated/midnight-bloom.json +86 -0
- package/src/features/theme/curated/mocha-mousse.json +86 -0
- package/src/features/theme/curated/modern-minimal.json +86 -0
- package/src/features/theme/curated/mono.json +84 -0
- package/src/features/theme/curated/nature.json +86 -0
- package/src/features/theme/curated/neo-brutalism.json +86 -0
- package/src/features/theme/curated/northern-lights.json +86 -0
- package/src/features/theme/curated/notebook.json +87 -0
- package/src/features/theme/curated/ocean-breeze.json +86 -0
- package/src/features/theme/curated/pastel-dreams.json +86 -0
- package/src/features/theme/curated/perpetuity.json +86 -0
- package/src/features/theme/curated/quantum-rose.json +86 -0
- package/src/features/theme/curated/retro-arcade.json +86 -0
- package/src/features/theme/curated/sage-garden.json +86 -0
- package/src/features/theme/curated/shadcn.json +83 -0
- package/src/features/theme/curated/shellui.json +82 -0
- package/src/features/theme/curated/soft-pop.json +86 -0
- package/src/features/theme/curated/solar-dusk.json +86 -0
- package/src/features/theme/curated/starry-night.json +86 -0
- package/src/features/theme/curated/sunset-horizon.json +86 -0
- package/src/features/theme/curated/supabase.json +85 -0
- package/src/features/theme/curated/t3-chat.json +83 -0
- package/src/features/theme/curated/tangerine.json +86 -0
- package/src/features/theme/curated/twitter.json +86 -0
- package/src/features/theme/curated/vercel.json +86 -0
- package/src/features/theme/curated/vintage-paper.json +86 -0
- package/src/features/theme/curated/violet-bloom.json +87 -0
- package/src/features/theme/curated/zen-inspired.json +87 -0
- package/src/features/theme/index.ts +76 -0
- package/src/features/theme/normalize.ts +159 -0
- package/src/features/theme/registry.ts +50 -0
- package/src/features/theme/resolveConfig.ts +182 -0
- package/src/features/theme/safeApplyTheme.ts +147 -0
- package/src/features/theme/themes.spec.ts +276 -0
- package/src/features/theme/themes.ts +82 -558
- package/src/features/theme/tokenKeys.ts +60 -0
- package/src/features/theme/types.ts +170 -0
- package/src/features/theme/useTheme.tsx +48 -50
- package/src/hooks/use-mobile.tsx +19 -0
- package/src/i18n/translations/en/common.json +41 -0
- package/src/i18n/translations/en/settings.json +10 -2
- package/src/i18n/translations/fr/common.json +41 -0
- package/src/i18n/translations/fr/settings.json +10 -2
- package/src/index.css +372 -128
- package/src/index.ts +71 -0
- package/src/lib/z-index.ts +4 -1
- package/src/routes/components/IndexRoute.tsx +12 -2
- package/src/routes/components/NavigationItemRoute.tsx +1 -10
- package/src/routes/hooks/useNavigationItems.ts +29 -44
- package/src/routes/routes.tsx +58 -27
- package/tailwind.config.js +27 -27
- package/src/features/layouts/sidebar/BottomNavItem.tsx +0 -88
- package/src/features/layouts/sidebar/MobileBottomNav.tsx +0 -168
|
@@ -4,10 +4,35 @@ import { useConfig } from '../../config/useConfig';
|
|
|
4
4
|
import { Button } from '../../../components/ui/button';
|
|
5
5
|
import { ButtonGroup } from '../../../components/ui/button-group';
|
|
6
6
|
import { cn } from '../../../lib/utils';
|
|
7
|
-
import { useEffect, useState, useMemo } from 'react';
|
|
8
|
-
import {
|
|
7
|
+
import { useEffect, useState, useMemo, useCallback, useRef } from 'react';
|
|
8
|
+
import {
|
|
9
|
+
getAllThemes,
|
|
10
|
+
setAvailableThemes,
|
|
11
|
+
defaultTheme,
|
|
12
|
+
type ThemeDefinition,
|
|
13
|
+
} from '../../theme/themes';
|
|
14
|
+
import { waitForThemeSwitchIdle } from '../../theme/safeApplyTheme';
|
|
9
15
|
import type { SettingsAvailableTheme } from '@shellui/sdk';
|
|
10
16
|
|
|
17
|
+
const ThemeSwitchSpinner = ({ className }: { className?: string }) => (
|
|
18
|
+
<svg
|
|
19
|
+
data-theme-switch-spinner=""
|
|
20
|
+
className={cn('animate-spin', className)}
|
|
21
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
22
|
+
width="20"
|
|
23
|
+
height="20"
|
|
24
|
+
viewBox="0 0 24 24"
|
|
25
|
+
fill="none"
|
|
26
|
+
stroke="currentColor"
|
|
27
|
+
strokeWidth="2.5"
|
|
28
|
+
strokeLinecap="round"
|
|
29
|
+
strokeLinejoin="round"
|
|
30
|
+
aria-hidden
|
|
31
|
+
>
|
|
32
|
+
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
|
|
33
|
+
</svg>
|
|
34
|
+
);
|
|
35
|
+
|
|
11
36
|
const SunIcon = () => (
|
|
12
37
|
<svg
|
|
13
38
|
xmlns="http://www.w3.org/2000/svg"
|
|
@@ -90,68 +115,183 @@ const MonitorIcon = () => (
|
|
|
90
115
|
type ThemePreviewItem = Pick<
|
|
91
116
|
ThemeDefinition | SettingsAvailableTheme,
|
|
92
117
|
'name' | 'displayName' | 'colors' | 'fontFamily' | 'letterSpacing' | 'textShadow'
|
|
93
|
-
|
|
118
|
+
> & { description?: string; recommended?: boolean };
|
|
119
|
+
|
|
120
|
+
function previewRadius(radius: string | undefined, inset = 0): string {
|
|
121
|
+
const base = radius?.trim() || '0.5rem';
|
|
122
|
+
if (inset <= 0) return base;
|
|
123
|
+
return `max(0px, calc(${base} - ${inset}px))`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function MiniSwatch({ colors }: { colors: ThemePreviewItem['colors']['light'] }) {
|
|
127
|
+
const radius = colors.radius;
|
|
128
|
+
return (
|
|
129
|
+
<div
|
|
130
|
+
className="flex flex-1 flex-col gap-1 border p-1.5"
|
|
131
|
+
style={{
|
|
132
|
+
backgroundColor: colors.background,
|
|
133
|
+
borderColor: colors.border,
|
|
134
|
+
borderRadius: previewRadius(radius, 2),
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
<div
|
|
138
|
+
className="h-3"
|
|
139
|
+
style={{ backgroundColor: colors.primary, borderRadius: previewRadius(radius, 4) }}
|
|
140
|
+
/>
|
|
141
|
+
<div className="flex gap-0.5">
|
|
142
|
+
<div
|
|
143
|
+
className="h-2 flex-1"
|
|
144
|
+
style={{ backgroundColor: colors.secondary, borderRadius: previewRadius(radius, 4) }}
|
|
145
|
+
/>
|
|
146
|
+
<div
|
|
147
|
+
className="h-2 flex-1"
|
|
148
|
+
style={{ backgroundColor: colors.accent, borderRadius: previewRadius(radius, 4) }}
|
|
149
|
+
/>
|
|
150
|
+
<div
|
|
151
|
+
className="h-2 flex-1"
|
|
152
|
+
style={{ backgroundColor: colors.muted, borderRadius: previewRadius(radius, 4) }}
|
|
153
|
+
/>
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
94
158
|
|
|
95
|
-
// Theme color preview component
|
|
96
159
|
const ThemePreview = ({
|
|
97
160
|
theme,
|
|
98
161
|
isSelected,
|
|
99
162
|
isDark,
|
|
163
|
+
isPending = false,
|
|
164
|
+
layout,
|
|
165
|
+
recommendedLabel,
|
|
100
166
|
}: {
|
|
101
167
|
theme: ThemePreviewItem;
|
|
102
168
|
isSelected: boolean;
|
|
103
169
|
isDark: boolean;
|
|
170
|
+
isPending?: boolean;
|
|
171
|
+
layout: 'single' | 'few' | 'many';
|
|
172
|
+
recommendedLabel: string;
|
|
104
173
|
}) => {
|
|
105
174
|
const colors = isDark ? theme.colors.dark : theme.colors.light;
|
|
175
|
+
const radius = colors.radius;
|
|
176
|
+
|
|
177
|
+
const pendingOverlay = (
|
|
178
|
+
<div
|
|
179
|
+
className={cn(
|
|
180
|
+
'absolute inset-0 z-10 flex items-center justify-center bg-background/55 backdrop-blur-[1px]',
|
|
181
|
+
'transition-opacity duration-300 ease-out',
|
|
182
|
+
isPending ? 'opacity-100' : 'opacity-0 pointer-events-none',
|
|
183
|
+
)}
|
|
184
|
+
style={{ borderRadius: previewRadius(radius) }}
|
|
185
|
+
aria-hidden={!isPending}
|
|
186
|
+
>
|
|
187
|
+
<ThemeSwitchSpinner className="size-5 text-primary" />
|
|
188
|
+
{isPending ? <span className="sr-only">Applying theme</span> : null}
|
|
189
|
+
</div>
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
if (layout === 'many') {
|
|
193
|
+
return (
|
|
194
|
+
<div
|
|
195
|
+
className={cn(
|
|
196
|
+
'relative overflow-hidden border-2',
|
|
197
|
+
isSelected
|
|
198
|
+
? 'border-primary shadow-md'
|
|
199
|
+
: 'border-border hover:border-muted-foreground/40',
|
|
200
|
+
)}
|
|
201
|
+
style={{ borderRadius: previewRadius(radius) }}
|
|
202
|
+
>
|
|
203
|
+
{pendingOverlay}
|
|
204
|
+
<div className="flex gap-1 p-2">
|
|
205
|
+
<MiniSwatch colors={theme.colors.light} />
|
|
206
|
+
<MiniSwatch colors={theme.colors.dark} />
|
|
207
|
+
</div>
|
|
208
|
+
<div
|
|
209
|
+
className="border-t px-2 py-1.5"
|
|
210
|
+
style={{
|
|
211
|
+
backgroundColor: colors.background,
|
|
212
|
+
borderColor: colors.border,
|
|
213
|
+
color: colors.foreground,
|
|
214
|
+
}}
|
|
215
|
+
>
|
|
216
|
+
<p
|
|
217
|
+
className="truncate text-xs font-medium"
|
|
218
|
+
style={
|
|
219
|
+
theme.fontFamily
|
|
220
|
+
? {
|
|
221
|
+
fontFamily: theme.fontFamily,
|
|
222
|
+
letterSpacing: theme.letterSpacing || 'normal',
|
|
223
|
+
textShadow: theme.textShadow || 'none',
|
|
224
|
+
}
|
|
225
|
+
: undefined
|
|
226
|
+
}
|
|
227
|
+
>
|
|
228
|
+
{theme.displayName}
|
|
229
|
+
</p>
|
|
230
|
+
{theme.recommended ? (
|
|
231
|
+
<p
|
|
232
|
+
className="text-[10px] opacity-70"
|
|
233
|
+
style={{ color: colors.mutedForeground }}
|
|
234
|
+
>
|
|
235
|
+
{recommendedLabel}
|
|
236
|
+
</p>
|
|
237
|
+
) : null}
|
|
238
|
+
</div>
|
|
239
|
+
</div>
|
|
240
|
+
);
|
|
241
|
+
}
|
|
106
242
|
|
|
107
243
|
return (
|
|
108
244
|
<div
|
|
109
245
|
className={cn(
|
|
110
|
-
'relative overflow-hidden
|
|
246
|
+
'relative overflow-hidden border-2',
|
|
111
247
|
isSelected ? 'border-primary shadow-lg' : 'border-border',
|
|
248
|
+
layout === 'single' && 'max-w-sm',
|
|
112
249
|
)}
|
|
113
|
-
style={{ backgroundColor: colors.background }}
|
|
250
|
+
style={{ backgroundColor: colors.background, borderRadius: previewRadius(radius) }}
|
|
114
251
|
>
|
|
115
|
-
|
|
116
|
-
|
|
252
|
+
{pendingOverlay}
|
|
253
|
+
<div className={cn('space-y-2', layout === 'single' ? 'p-4' : 'p-3')}>
|
|
117
254
|
<div
|
|
118
|
-
className=
|
|
119
|
-
style={{ backgroundColor: colors.primary }}
|
|
255
|
+
className={layout === 'single' ? 'h-10' : 'h-8'}
|
|
256
|
+
style={{ backgroundColor: colors.primary, borderRadius: previewRadius(radius, 2) }}
|
|
120
257
|
/>
|
|
121
|
-
{/* Secondary colors */}
|
|
122
258
|
<div className="flex gap-1">
|
|
123
259
|
<div
|
|
124
|
-
className="h-6 flex-1
|
|
125
|
-
style={{
|
|
260
|
+
className="h-6 flex-1"
|
|
261
|
+
style={{
|
|
262
|
+
backgroundColor: colors.background,
|
|
263
|
+
borderRadius: previewRadius(radius, 4),
|
|
264
|
+
}}
|
|
126
265
|
/>
|
|
127
266
|
<div
|
|
128
|
-
className="h-6 flex-1
|
|
129
|
-
style={{
|
|
267
|
+
className="h-6 flex-1"
|
|
268
|
+
style={{
|
|
269
|
+
backgroundColor: colors.secondary,
|
|
270
|
+
borderRadius: previewRadius(radius, 4),
|
|
271
|
+
}}
|
|
130
272
|
/>
|
|
131
273
|
<div
|
|
132
|
-
className="h-6 flex-1
|
|
133
|
-
style={{ backgroundColor: colors.accent }}
|
|
274
|
+
className="h-6 flex-1"
|
|
275
|
+
style={{ backgroundColor: colors.accent, borderRadius: previewRadius(radius, 4) }}
|
|
134
276
|
/>
|
|
135
277
|
</div>
|
|
136
|
-
{/* Accent colors */}
|
|
137
278
|
<div className="flex gap-1">
|
|
138
279
|
<div
|
|
139
|
-
className="h-4 flex-1
|
|
140
|
-
style={{ backgroundColor: colors.muted }}
|
|
280
|
+
className="h-4 flex-1"
|
|
281
|
+
style={{ backgroundColor: colors.muted, borderRadius: previewRadius(radius, 4) }}
|
|
141
282
|
/>
|
|
142
283
|
<div
|
|
143
|
-
className="h-4 flex-1
|
|
144
|
-
style={{ backgroundColor: colors.border }}
|
|
284
|
+
className="h-4 flex-1"
|
|
285
|
+
style={{ backgroundColor: colors.border, borderRadius: previewRadius(radius, 4) }}
|
|
145
286
|
/>
|
|
146
287
|
</div>
|
|
147
288
|
</div>
|
|
148
|
-
{/* Theme name overlay */}
|
|
149
289
|
<div
|
|
150
|
-
className="
|
|
151
|
-
style={{ backgroundColor: colors.background }}
|
|
290
|
+
className="px-2 py-1.5"
|
|
291
|
+
style={{ backgroundColor: colors.background, color: colors.foreground }}
|
|
152
292
|
>
|
|
153
293
|
<p
|
|
154
|
-
className=
|
|
294
|
+
className={cn('font-medium text-center', layout === 'single' ? 'text-sm' : 'text-xs')}
|
|
155
295
|
style={
|
|
156
296
|
theme.fontFamily
|
|
157
297
|
? {
|
|
@@ -159,11 +299,19 @@ const ThemePreview = ({
|
|
|
159
299
|
letterSpacing: theme.letterSpacing || 'normal',
|
|
160
300
|
textShadow: theme.textShadow || 'none',
|
|
161
301
|
}
|
|
162
|
-
:
|
|
302
|
+
: undefined
|
|
163
303
|
}
|
|
164
304
|
>
|
|
165
305
|
{theme.displayName}
|
|
166
306
|
</p>
|
|
307
|
+
{layout === 'single' && theme.description ? (
|
|
308
|
+
<p
|
|
309
|
+
className="mt-0.5 text-center text-xs opacity-70"
|
|
310
|
+
style={{ color: colors.mutedForeground }}
|
|
311
|
+
>
|
|
312
|
+
{theme.description}
|
|
313
|
+
</p>
|
|
314
|
+
) : null}
|
|
167
315
|
</div>
|
|
168
316
|
</div>
|
|
169
317
|
);
|
|
@@ -177,47 +325,116 @@ export const Appearance = () => {
|
|
|
177
325
|
const currentThemeName = settings.appearance?.name ?? 'default';
|
|
178
326
|
|
|
179
327
|
const [localThemes, setLocalThemes] = useState<ThemeDefinition[]>([]);
|
|
328
|
+
const [pendingThemeName, setPendingThemeName] = useState<string | null>(null);
|
|
329
|
+
const [pendingColorScheme, setPendingColorScheme] = useState<'light' | 'dark' | 'system' | null>(
|
|
330
|
+
null,
|
|
331
|
+
);
|
|
332
|
+
// Ref lock so rapid clicks in the same render cannot all pass the busy check.
|
|
333
|
+
const switchLockRef = useRef(false);
|
|
334
|
+
const themeSwitchBusy = pendingThemeName !== null || pendingColorScheme !== null;
|
|
335
|
+
const displayedColorScheme = pendingColorScheme ?? currentTheme;
|
|
180
336
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
337
|
+
const runAppearanceSwitch = useCallback(async (work: () => void) => {
|
|
338
|
+
try {
|
|
339
|
+
work();
|
|
340
|
+
await new Promise<void>((resolve) => {
|
|
341
|
+
requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
|
|
186
342
|
});
|
|
343
|
+
await waitForThemeSwitchIdle();
|
|
344
|
+
// Cover trailing iframe settings echo so the next click won't collide.
|
|
345
|
+
await new Promise((resolve) => setTimeout(resolve, 220));
|
|
346
|
+
return true;
|
|
347
|
+
} catch {
|
|
348
|
+
return false;
|
|
187
349
|
}
|
|
350
|
+
}, []);
|
|
351
|
+
|
|
352
|
+
const selectTheme = useCallback(
|
|
353
|
+
async (themeName: string) => {
|
|
354
|
+
if (switchLockRef.current) return;
|
|
355
|
+
if (themeName === currentThemeName) return;
|
|
356
|
+
switchLockRef.current = true;
|
|
357
|
+
setPendingThemeName(themeName);
|
|
358
|
+
try {
|
|
359
|
+
await runAppearanceSwitch(() => {
|
|
360
|
+
updateSetting('appearance', { name: themeName });
|
|
361
|
+
});
|
|
362
|
+
} finally {
|
|
363
|
+
switchLockRef.current = false;
|
|
364
|
+
setPendingThemeName(null);
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
[currentThemeName, updateSetting, runAppearanceSwitch],
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
const selectColorScheme = useCallback(
|
|
371
|
+
async (colorScheme: 'light' | 'dark' | 'system') => {
|
|
372
|
+
if (switchLockRef.current) return;
|
|
373
|
+
if (colorScheme === currentTheme) return;
|
|
374
|
+
switchLockRef.current = true;
|
|
375
|
+
setPendingColorScheme(colorScheme);
|
|
376
|
+
try {
|
|
377
|
+
await runAppearanceSwitch(() => {
|
|
378
|
+
updateSetting('appearance', { colorScheme });
|
|
379
|
+
});
|
|
380
|
+
} finally {
|
|
381
|
+
switchLockRef.current = false;
|
|
382
|
+
setPendingColorScheme(null);
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
[currentTheme, updateSetting, runAppearanceSwitch],
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
useEffect(() => {
|
|
389
|
+
const available: ThemeDefinition[] =
|
|
390
|
+
config?.themes && Array.isArray(config.themes) && config.themes.length > 0
|
|
391
|
+
? (config.themes as ThemeDefinition[])
|
|
392
|
+
: [defaultTheme];
|
|
393
|
+
setAvailableThemes(available);
|
|
188
394
|
setLocalThemes(getAllThemes());
|
|
189
395
|
}, [config]);
|
|
190
396
|
|
|
191
|
-
// Use availableThemes from settings when provided (e.g. from shell when in sub-app), else local registry
|
|
192
397
|
const availableThemes = useMemo((): ThemePreviewItem[] => {
|
|
193
398
|
const fromSettings = settings.appearance?.availableThemes;
|
|
194
399
|
if (fromSettings?.length) return fromSettings;
|
|
195
400
|
return localThemes;
|
|
196
401
|
}, [settings.appearance?.availableThemes, localThemes]);
|
|
197
402
|
|
|
198
|
-
|
|
403
|
+
const sortedThemes = useMemo(() => {
|
|
404
|
+
return [...availableThemes].sort((a, b) => {
|
|
405
|
+
const ar = 'recommended' in a && a.recommended ? 0 : 1;
|
|
406
|
+
const br = 'recommended' in b && b.recommended ? 0 : 1;
|
|
407
|
+
if (ar !== br) return ar - br;
|
|
408
|
+
return a.displayName.localeCompare(b.displayName);
|
|
409
|
+
});
|
|
410
|
+
}, [availableThemes]);
|
|
411
|
+
|
|
412
|
+
const layout: 'single' | 'few' | 'many' =
|
|
413
|
+
sortedThemes.length <= 1 ? 'single' : sortedThemes.length <= 3 ? 'few' : 'many';
|
|
414
|
+
|
|
199
415
|
const [isDarkForPreview, setIsDarkForPreview] = useState(() => {
|
|
200
416
|
if (typeof window === 'undefined') return false;
|
|
201
417
|
return (
|
|
202
|
-
|
|
203
|
-
(
|
|
418
|
+
displayedColorScheme === 'dark' ||
|
|
419
|
+
(displayedColorScheme === 'system' &&
|
|
420
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches)
|
|
204
421
|
);
|
|
205
422
|
});
|
|
206
423
|
|
|
207
|
-
// Update preview mode when theme changes
|
|
208
424
|
useEffect(() => {
|
|
209
425
|
if (typeof window === 'undefined') return;
|
|
210
426
|
|
|
211
427
|
const updatePreview = () => {
|
|
212
428
|
setIsDarkForPreview(
|
|
213
|
-
|
|
214
|
-
(
|
|
429
|
+
displayedColorScheme === 'dark' ||
|
|
430
|
+
(displayedColorScheme === 'system' &&
|
|
431
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches),
|
|
215
432
|
);
|
|
216
433
|
};
|
|
217
434
|
|
|
218
435
|
updatePreview();
|
|
219
436
|
|
|
220
|
-
if (
|
|
437
|
+
if (displayedColorScheme === 'system') {
|
|
221
438
|
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
222
439
|
const handleChange = () => updatePreview();
|
|
223
440
|
|
|
@@ -229,7 +446,7 @@ export const Appearance = () => {
|
|
|
229
446
|
return () => mediaQuery.removeListener(handleChange);
|
|
230
447
|
}
|
|
231
448
|
}
|
|
232
|
-
}, [
|
|
449
|
+
}, [displayedColorScheme]);
|
|
233
450
|
|
|
234
451
|
const modeThemes = [
|
|
235
452
|
{ value: 'light' as const, label: t('appearance.themes.light'), icon: SunIcon },
|
|
@@ -237,9 +454,20 @@ export const Appearance = () => {
|
|
|
237
454
|
{ value: 'system' as const, label: t('appearance.themes.system'), icon: MonitorIcon },
|
|
238
455
|
];
|
|
239
456
|
|
|
457
|
+
// 2 columns on small screens; from md, auto-fill so cards stay ~12rem
|
|
458
|
+
// instead of stretching across a fixed 4-column grid.
|
|
459
|
+
const gridClass =
|
|
460
|
+
layout === 'single'
|
|
461
|
+
? 'grid max-w-sm grid-cols-1'
|
|
462
|
+
: layout === 'few'
|
|
463
|
+
? 'grid gap-4 [grid-template-columns:repeat(auto-fill,minmax(min(100%,14rem),1fr))]'
|
|
464
|
+
: 'grid grid-cols-2 gap-3 md:[grid-template-columns:repeat(auto-fill,minmax(12rem,1fr))]';
|
|
465
|
+
|
|
240
466
|
return (
|
|
241
|
-
<div
|
|
242
|
-
|
|
467
|
+
<div
|
|
468
|
+
className="space-y-6"
|
|
469
|
+
data-theme-switch-ui
|
|
470
|
+
>
|
|
243
471
|
<div className="space-y-2">
|
|
244
472
|
<div className="space-y-0.5">
|
|
245
473
|
<label
|
|
@@ -254,23 +482,30 @@ export const Appearance = () => {
|
|
|
254
482
|
<ButtonGroup>
|
|
255
483
|
{modeThemes.map((theme) => {
|
|
256
484
|
const Icon = theme.icon;
|
|
257
|
-
const isSelected =
|
|
485
|
+
const isSelected = displayedColorScheme === theme.value;
|
|
486
|
+
const isPending = pendingColorScheme === theme.value;
|
|
258
487
|
return (
|
|
259
488
|
<Button
|
|
260
489
|
key={theme.value}
|
|
261
490
|
variant={isSelected ? 'default' : 'outline'}
|
|
262
491
|
onClick={() => {
|
|
263
|
-
|
|
492
|
+
void selectColorScheme(theme.value);
|
|
264
493
|
}}
|
|
494
|
+
disabled={themeSwitchBusy}
|
|
265
495
|
className={cn(
|
|
266
|
-
'h-10 px-4
|
|
496
|
+
'h-10 px-4 flex items-center gap-2 cursor-pointer disabled:cursor-wait',
|
|
497
|
+
'transition-opacity duration-300 ease-out',
|
|
267
498
|
isSelected && ['font-semibold'],
|
|
268
499
|
!isSelected && ['bg-background hover:bg-accent/50', 'text-muted-foreground'],
|
|
500
|
+
themeSwitchBusy && !isPending
|
|
501
|
+
? 'opacity-40 disabled:opacity-40'
|
|
502
|
+
: 'opacity-100 disabled:opacity-100',
|
|
269
503
|
)}
|
|
270
504
|
aria-label={theme.label}
|
|
271
505
|
title={theme.label}
|
|
506
|
+
aria-busy={isPending}
|
|
272
507
|
>
|
|
273
|
-
<Icon />
|
|
508
|
+
{isPending ? <ThemeSwitchSpinner className="size-4" /> : <Icon />}
|
|
274
509
|
<span className="text-sm font-medium">{theme.label}</span>
|
|
275
510
|
</Button>
|
|
276
511
|
);
|
|
@@ -279,7 +514,6 @@ export const Appearance = () => {
|
|
|
279
514
|
</div>
|
|
280
515
|
</div>
|
|
281
516
|
|
|
282
|
-
{/* Theme Selection (Color Scheme) */}
|
|
283
517
|
<div className="space-y-2">
|
|
284
518
|
<div className="space-y-0.5">
|
|
285
519
|
<label
|
|
@@ -288,27 +522,43 @@ export const Appearance = () => {
|
|
|
288
522
|
>
|
|
289
523
|
{t('appearance.colorTheme')}
|
|
290
524
|
</label>
|
|
291
|
-
<p className="text-sm text-muted-foreground">
|
|
525
|
+
<p className="text-sm text-muted-foreground">
|
|
526
|
+
{layout === 'single'
|
|
527
|
+
? t('appearance.colorThemeDescriptionSingle')
|
|
528
|
+
: t('appearance.colorThemeDescription')}
|
|
529
|
+
</p>
|
|
292
530
|
</div>
|
|
293
|
-
<div className=
|
|
294
|
-
{
|
|
531
|
+
<div className={cn('mt-2', gridClass)}>
|
|
532
|
+
{sortedThemes.map((theme) => {
|
|
295
533
|
const isSelected = currentThemeName === theme.name;
|
|
534
|
+
const previewColors = isDarkForPreview ? theme.colors.dark : theme.colors.light;
|
|
296
535
|
return (
|
|
297
536
|
<button
|
|
298
537
|
key={theme.name}
|
|
538
|
+
type="button"
|
|
299
539
|
onClick={() => {
|
|
300
|
-
|
|
540
|
+
void selectTheme(theme.name);
|
|
301
541
|
}}
|
|
542
|
+
disabled={themeSwitchBusy}
|
|
302
543
|
className={cn(
|
|
303
|
-
'text-left transition-
|
|
304
|
-
|
|
544
|
+
'relative min-w-0 text-left transition-[opacity,transform] duration-300 ease-out',
|
|
545
|
+
themeSwitchBusy ? 'cursor-wait' : 'cursor-pointer',
|
|
546
|
+
isSelected && 'ring-2 ring-primary ring-offset-2 ring-offset-background',
|
|
547
|
+
themeSwitchBusy && pendingThemeName !== theme.name && 'opacity-40 scale-[0.99]',
|
|
548
|
+
(!themeSwitchBusy || pendingThemeName === theme.name) && 'opacity-100 scale-100',
|
|
305
549
|
)}
|
|
550
|
+
style={{ borderRadius: previewRadius(previewColors.radius) }}
|
|
306
551
|
aria-label={theme.displayName}
|
|
552
|
+
aria-pressed={isSelected}
|
|
553
|
+
aria-busy={pendingThemeName === theme.name}
|
|
307
554
|
>
|
|
308
555
|
<ThemePreview
|
|
309
556
|
theme={theme}
|
|
310
|
-
isSelected={isSelected}
|
|
557
|
+
isSelected={isSelected || pendingThemeName === theme.name}
|
|
311
558
|
isDark={isDarkForPreview}
|
|
559
|
+
isPending={pendingThemeName === theme.name}
|
|
560
|
+
layout={layout}
|
|
561
|
+
recommendedLabel={t('appearance.recommended')}
|
|
312
562
|
/>
|
|
313
563
|
</button>
|
|
314
564
|
);
|
|
@@ -55,6 +55,24 @@ export const DrawerTestButtons = () => {
|
|
|
55
55
|
>
|
|
56
56
|
{t('develop.testing.drawerTesting.buttons.drawerBottomHalf')}
|
|
57
57
|
</Button>
|
|
58
|
+
<Button
|
|
59
|
+
onClick={() =>
|
|
60
|
+
shellui.openDrawer({
|
|
61
|
+
url: urls.overlayDemo,
|
|
62
|
+
position: 'bottom',
|
|
63
|
+
dynamicSizing: true,
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
variant="outline"
|
|
67
|
+
>
|
|
68
|
+
{t('develop.testing.drawerTesting.buttons.drawerBottomDynamic')}
|
|
69
|
+
</Button>
|
|
70
|
+
<Button
|
|
71
|
+
onClick={() => openDrawer({ position: 'bottom', size: 'md', showCloseButton: false })}
|
|
72
|
+
variant="outline"
|
|
73
|
+
>
|
|
74
|
+
{t('develop.testing.drawerTesting.buttons.drawerNoClose')}
|
|
75
|
+
</Button>
|
|
58
76
|
<Button
|
|
59
77
|
onClick={() => shellui.closeDrawer()}
|
|
60
78
|
variant="outline"
|
|
@@ -21,6 +21,29 @@ export const ModalTestButtons = () => {
|
|
|
21
21
|
>
|
|
22
22
|
{t('develop.testing.modalTesting.buttons.openModal')}
|
|
23
23
|
</Button>
|
|
24
|
+
<Button
|
|
25
|
+
onClick={() => shellui.openModal({ url: urls.settings, size: 'sm' })}
|
|
26
|
+
variant="outline"
|
|
27
|
+
>
|
|
28
|
+
{t('develop.testing.modalTesting.buttons.openModalSm')}
|
|
29
|
+
</Button>
|
|
30
|
+
<Button
|
|
31
|
+
onClick={() =>
|
|
32
|
+
shellui.openModal({
|
|
33
|
+
url: urls.overlayDemo,
|
|
34
|
+
dynamicSizing: true,
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
variant="outline"
|
|
38
|
+
>
|
|
39
|
+
{t('develop.testing.modalTesting.buttons.openModalDynamic')}
|
|
40
|
+
</Button>
|
|
41
|
+
<Button
|
|
42
|
+
onClick={() => shellui.closeModal()}
|
|
43
|
+
variant="outline"
|
|
44
|
+
>
|
|
45
|
+
{t('develop.testing.modalTesting.buttons.closeModal')}
|
|
46
|
+
</Button>
|
|
24
47
|
</div>
|
|
25
48
|
<p className="text-xs text-muted-foreground mt-2">
|
|
26
49
|
{t('develop.testing.modalTesting.description')}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Appearance, Settings } from '@shellui/sdk';
|
|
2
|
-
import { getTheme,
|
|
3
|
-
import type { ShellUIConfig } from '../../config/types';
|
|
2
|
+
import { getTheme, setAvailableThemes, defaultTheme } from '../../theme/themes';
|
|
3
|
+
import type { ShellUIConfig, ThemeDefinition } from '../../config/types';
|
|
4
4
|
import { resolveColorMode } from './resolveColorMode';
|
|
5
5
|
import { toAbsoluteFontUrls } from './toAbsoluteFontUrls';
|
|
6
6
|
|
|
@@ -14,9 +14,15 @@ export const getResolvedAppearanceForSettings = (
|
|
|
14
14
|
): Appearance | undefined => {
|
|
15
15
|
if (typeof window === 'undefined') return undefined;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const available: ThemeDefinition[] =
|
|
18
|
+
config?.themes && Array.isArray(config.themes) && config.themes.length > 0
|
|
19
|
+
? (config.themes as ThemeDefinition[])
|
|
20
|
+
: [defaultTheme];
|
|
21
|
+
setAvailableThemes(available);
|
|
22
|
+
|
|
23
|
+
const themeName =
|
|
24
|
+
settings.appearance?.name || config?.activeTheme || config?.defaultTheme || defaultTheme.name;
|
|
25
|
+
const themeDef = getTheme(themeName) || getTheme(defaultTheme.name);
|
|
20
26
|
if (!themeDef) return undefined;
|
|
21
27
|
|
|
22
28
|
const colorScheme = settings.appearance?.colorScheme ?? 'system';
|