@marwes-ui/react 1.0.1 → 1.0.2
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 +47 -1
- package/dist/index.d.ts +12 -3
- package/dist/index.js +205 -112
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
<img alt="Marwes Design System" src="https://raw.githubusercontent.com/niklas-westman/marwes/main/.github/assets/banner
|
|
3
|
+
<img alt="Marwes Design System" src="https://raw.githubusercontent.com/niklas-westman/marwes/main/.github/assets/banner.png" width="100%" style="border-radius: 40px;">
|
|
4
4
|
|
|
5
5
|
<br>
|
|
6
6
|
<br>
|
|
@@ -312,6 +312,52 @@ export function App() {
|
|
|
312
312
|
|
|
313
313
|
`defaultMode` sets the initial uncontrolled mode. `toggleMode()` updates the provider, so Marwes components, preset CSS, and custom app styles that use `--mw-*` variables all move together without duplicating local theme state.
|
|
314
314
|
|
|
315
|
+
### System And Persisted Preference
|
|
316
|
+
|
|
317
|
+
`mode` is always the rendered visual mode: `ThemeMode.light` or `ThemeMode.dark`. `preference` is the app or user choice: `ThemeMode.light`, `ThemeMode.dark`, or `"system"`. Use `preference` and `defaultPreference` when your UI needs a system option; keep using `mode`, `defaultMode`, and `onModeChange` when you only need concrete light/dark compatibility.
|
|
318
|
+
|
|
319
|
+
```tsx
|
|
320
|
+
import { Button, ButtonVariant, MarwesProvider, ThemeMode, useThemeMode } from "@marwes-ui/react"
|
|
321
|
+
|
|
322
|
+
function ThemeMenu() {
|
|
323
|
+
const { mode, preference, systemMode, isSystem, setPreference, setMode } = useThemeMode()
|
|
324
|
+
|
|
325
|
+
return (
|
|
326
|
+
<div>
|
|
327
|
+
<p>
|
|
328
|
+
Rendering {mode}; preference is {preference}; system is {systemMode}.
|
|
329
|
+
</p>
|
|
330
|
+
<Button variant={ButtonVariant.secondary} onClick={() => setPreference("system")}>
|
|
331
|
+
Use system
|
|
332
|
+
</Button>
|
|
333
|
+
<Button variant={ButtonVariant.secondary} onClick={() => setMode(ThemeMode.dark)}>
|
|
334
|
+
Use dark
|
|
335
|
+
</Button>
|
|
336
|
+
{isSystem ? "Following system" : null}
|
|
337
|
+
</div>
|
|
338
|
+
)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export function App() {
|
|
342
|
+
return (
|
|
343
|
+
<MarwesProvider
|
|
344
|
+
defaultPreference="system"
|
|
345
|
+
storageKey="marwes-theme"
|
|
346
|
+
enableSystem
|
|
347
|
+
>
|
|
348
|
+
<ThemeMenu />
|
|
349
|
+
<AppShell />
|
|
350
|
+
</MarwesProvider>
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
`useThemeMode().mode` never returns `"system"`; it is always the concrete mode Marwes rendered. `useThemeMode().preference` returns the active app/user preference, and `setPreference("system")` is the system-capable setter. `setMode(mode)` remains a concrete light/dark convenience.
|
|
356
|
+
|
|
357
|
+
`storageKey` is opt-in and defaults to `false`. Storage reads and writes are failure-safe, so private browsing or unavailable storage will fall back to normal provider state. `enableSystem` defaults to `true`; set it to `false` to avoid `matchMedia` detection and resolve `"system"` through the light fallback.
|
|
358
|
+
|
|
359
|
+
This layer does not provide SSR no-flash behavior. Server output can still render the fallback mode before the client applies a stored or system preference. Use it for client-side preference and persistence, not for a no-flash SSR guarantee.
|
|
360
|
+
|
|
315
361
|
For a simple brand pass, override shared values once and let Marwes fill the rest. If your product needs different brand colors in light and dark mode, control `mode` and switch between two small `ThemeInput` override objects:
|
|
316
362
|
|
|
317
363
|
```tsx
|
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ThemeInput, ThemeMode, FontLoadingConfig, ResolvedTheme, ButtonOptions, InputOptions, SelectOptions, SelectAppearance as SelectAppearance$1, SelectOption as SelectOption$1, TextareaOptions, RichTextOptions, InputOtpOptions, CurrencyCode, iconRegistry, IconSize, IconStrokeWidth, AvatarOptions, CheckboxProps as CheckboxProps$1, DividerOptions, DividerSize, DividerOrientation, SpinnerOptions, SpacingOptions, SpacingSize, HeadingOptions, HeadingSize, ParagraphOptions, ParagraphSize, ToastOptions, ToastVariant, ToastIntent, ToastPlacement, TooltipOptions, IconNameType, RadioOptions, BadgeOptions, SwitchOptions, SliderOptions, TabOptions, DialogOptions } from '@marwes-ui/core';
|
|
3
|
-
export { AvatarSize, AvatarType, BadgeVariant, ButtonAction, ButtonSize, ButtonVariant, Density, FontLoadingConfig, FontLoadingMode, FontLoadingOptions, IconName, MwAvailableFont, MwFontFallback, MwGoogleFontFamily, MwStyledTheme, MwThemeVarName, MwThemeVarNames, MwThemeVarReference, MwThemeVars, ResolvedTheme, SpacingSize, Spacings, SwitchSize, Theme, ThemeInput, ThemeMode, ToneName, createFontStack, mwAvailableFonts, mwFontFallbacks, mwGoogleFontFamilies, mwStyledTheme, mwThemeVarNames, mwThemeVars, mwVar } from '@marwes-ui/core';
|
|
2
|
+
import { ThemeInput, ThemePreference, ThemeMode, FontLoadingConfig, ResolvedTheme, ButtonOptions, InputOptions, SelectOptions, SelectAppearance as SelectAppearance$1, SelectOption as SelectOption$1, TextareaOptions, RichTextOptions, InputOtpOptions, CurrencyCode, iconRegistry, IconSize, IconStrokeWidth, AvatarOptions, CheckboxProps as CheckboxProps$1, DividerOptions, DividerSize, DividerOrientation, SpinnerOptions, SpacingOptions, SpacingSize, HeadingOptions, HeadingSize, ParagraphOptions, ParagraphSize, ToastOptions, ToastVariant, ToastIntent, ToastPlacement, TooltipOptions, IconNameType, RadioOptions, BadgeOptions, SwitchOptions, SliderOptions, TabOptions, DialogOptions } from '@marwes-ui/core';
|
|
3
|
+
export { AvatarSize, AvatarType, BadgeVariant, ButtonAction, ButtonSize, ButtonVariant, Density, FontLoadingConfig, FontLoadingMode, FontLoadingOptions, IconName, MwAvailableFont, MwFontFallback, MwGoogleFontFamily, MwStyledTheme, MwThemeVarName, MwThemeVarNames, MwThemeVarReference, MwThemeVars, ResolvedTheme, SpacingSize, Spacings, SwitchSize, Theme, ThemeInput, ThemeMode, ThemePreference, ToneName, createFontStack, mwAvailableFonts, mwFontFallbacks, mwGoogleFontFamilies, mwStyledTheme, mwThemeVarNames, mwThemeVars, mwVar } from '@marwes-ui/core';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
|
|
6
6
|
type MarwesProviderProps = {
|
|
7
7
|
theme?: ThemeInput;
|
|
8
|
+
defaultPreference?: ThemePreference;
|
|
9
|
+
preference?: ThemePreference;
|
|
8
10
|
defaultMode?: ThemeMode;
|
|
9
11
|
mode?: ThemeMode;
|
|
10
12
|
fontLoading?: FontLoadingConfig;
|
|
13
|
+
onPreferenceChange?: (preference: ThemePreference) => void;
|
|
11
14
|
onModeChange?: (mode: ThemeMode) => void;
|
|
15
|
+
storageKey?: string | false;
|
|
16
|
+
enableSystem?: boolean;
|
|
12
17
|
children: React.ReactNode;
|
|
13
18
|
};
|
|
14
|
-
declare function MarwesProvider({ theme, defaultMode, mode: controlledMode, fontLoading, onModeChange, children, }: MarwesProviderProps): react_jsx_runtime.JSX.Element;
|
|
19
|
+
declare function MarwesProvider({ theme, defaultPreference, preference: controlledPreference, defaultMode, mode: controlledMode, fontLoading, onPreferenceChange, onModeChange, storageKey, enableSystem, children, }: MarwesProviderProps): react_jsx_runtime.JSX.Element;
|
|
15
20
|
|
|
16
21
|
declare function useTheme(): ResolvedTheme;
|
|
17
22
|
|
|
18
23
|
type ThemeModeContextValue = {
|
|
19
24
|
mode: ThemeMode;
|
|
25
|
+
preference: ThemePreference;
|
|
26
|
+
systemMode: ThemeMode;
|
|
20
27
|
setMode: (mode: ThemeMode) => void;
|
|
28
|
+
setPreference: (preference: ThemePreference) => void;
|
|
21
29
|
toggleMode: () => void;
|
|
22
30
|
isDark: boolean;
|
|
23
31
|
isLight: boolean;
|
|
32
|
+
isSystem: boolean;
|
|
24
33
|
};
|
|
25
34
|
declare function useThemeMode(): ThemeModeContextValue;
|
|
26
35
|
|