@tamagui/next-theme 1.1.2 → 1.1.4
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/dist/cjs/NextTheme.js +9 -273
- package/dist/cjs/NextTheme.js.map +3 -3
- package/dist/cjs/NextThemeProvider.js +245 -0
- package/dist/cjs/NextThemeProvider.js.map +7 -0
- package/dist/cjs/ThemeSettingContext.js +36 -0
- package/dist/cjs/ThemeSettingContext.js.map +7 -0
- package/dist/cjs/UseThemeProps.js +17 -0
- package/dist/cjs/UseThemeProps.js.map +7 -0
- package/dist/cjs/constants.js +35 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/helpers.js +52 -0
- package/dist/cjs/helpers.js.map +7 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/cjs/useIsomorphicLayoutEffect.js +30 -0
- package/dist/cjs/useIsomorphicLayoutEffect.js.map +7 -0
- package/dist/cjs/useRootTheme.js +49 -0
- package/dist/cjs/useRootTheme.js.map +7 -0
- package/dist/cjs/useTheme.js +34 -0
- package/dist/cjs/useTheme.js.map +7 -0
- package/dist/esm/NextTheme.js +8 -265
- package/dist/esm/NextTheme.js.map +3 -3
- package/dist/esm/NextThemeProvider.js +215 -0
- package/dist/esm/NextThemeProvider.js.map +7 -0
- package/dist/esm/ThemeSettingContext.js +12 -0
- package/dist/esm/ThemeSettingContext.js.map +7 -0
- package/dist/esm/UseThemeProps.js +1 -0
- package/dist/esm/UseThemeProps.js.map +7 -0
- package/dist/esm/constants.js +9 -0
- package/dist/esm/constants.js.map +7 -0
- package/dist/esm/helpers.js +26 -0
- package/dist/esm/helpers.js.map +7 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/esm/useIsomorphicLayoutEffect.js +6 -0
- package/dist/esm/useIsomorphicLayoutEffect.js.map +7 -0
- package/dist/esm/useRootTheme.js +19 -0
- package/dist/esm/useRootTheme.js.map +7 -0
- package/dist/esm/useTheme.js +9 -0
- package/dist/esm/useTheme.js.map +7 -0
- package/package.json +3 -3
- package/src/NextTheme.tsx +10 -408
- package/src/NextThemeProvider.tsx +297 -0
- package/src/ThemeSettingContext.tsx +9 -0
- package/src/UseThemeProps.tsx +46 -0
- package/src/constants.tsx +3 -0
- package/src/helpers.tsx +25 -0
- package/src/types.tsx +5 -0
- package/src/useIsomorphicLayoutEffect.tsx +4 -0
- package/src/useRootTheme.tsx +21 -0
- package/src/useTheme.tsx +11 -0
- package/types/NextTheme.d.ts +8 -53
- package/types/NextThemeProvider.d.ts +4 -0
- package/types/ThemeSettingContext.d.ts +4 -0
- package/types/UseThemeProps.d.ts +43 -0
- package/types/constants.d.ts +4 -0
- package/types/helpers.d.ts +4 -0
- package/types/types.d.ts +5 -0
- package/types/useIsomorphicLayoutEffect.d.ts +3 -0
- package/types/useRootTheme.d.ts +3 -0
- package/types/useTheme.d.ts +6 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ValueObject } from './types'
|
|
2
|
+
|
|
3
|
+
export interface UseThemeProps {
|
|
4
|
+
/** List of all available theme names */
|
|
5
|
+
themes: string[]
|
|
6
|
+
/** Forced theme name for the current page */
|
|
7
|
+
forcedTheme?: string
|
|
8
|
+
/** Update the theme */
|
|
9
|
+
set: (theme: string) => void
|
|
10
|
+
toggle: () => void
|
|
11
|
+
/** Active theme name - will return "system" if not overriden, see "resolvedTheme" for getting resolved system value */
|
|
12
|
+
current?: string
|
|
13
|
+
/** @deprecated Use `current` instead (deprecating avoid confusion with useTheme) */
|
|
14
|
+
theme?: string
|
|
15
|
+
/** If `enableSystem` is true and the active theme is "system", this returns whether the system preference resolved to "dark" or "light". Otherwise, identical to `theme` */
|
|
16
|
+
resolvedTheme?: string
|
|
17
|
+
/** If enableSystem is true, returns the System theme preference ("dark" or "light"), regardless what the active theme is */
|
|
18
|
+
systemTheme?: 'dark' | 'light'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ThemeProviderProps {
|
|
22
|
+
children?: any
|
|
23
|
+
/** List of all available theme names */
|
|
24
|
+
themes?: string[]
|
|
25
|
+
/** Forced theme name for the current page */
|
|
26
|
+
forcedTheme?: string
|
|
27
|
+
/** Whether to switch between dark and light themes based on prefers-color-scheme */
|
|
28
|
+
enableSystem?: boolean
|
|
29
|
+
systemTheme?: string
|
|
30
|
+
/** Disable all CSS transitions when switching themes */
|
|
31
|
+
disableTransitionOnChange?: boolean
|
|
32
|
+
/** Whether to indicate to browsers which color scheme is used (dark or light) for built-in UI like inputs and buttons */
|
|
33
|
+
enableColorScheme?: boolean
|
|
34
|
+
/** Key used to store theme setting in localStorage */
|
|
35
|
+
storageKey?: string
|
|
36
|
+
/** Default theme name (for v0.0.12 and lower the default was light). If `enableSystem` is false, the default theme is light */
|
|
37
|
+
defaultTheme?: string
|
|
38
|
+
/** HTML attribute modified based on the active theme. Accepts `class` and `data-*` (meaning any data attribute, `data-mode`, `data-color`, etc.) */
|
|
39
|
+
attribute?: string | 'class'
|
|
40
|
+
/** Mapping of theme name to HTML attribute value. Object where key is the theme name and value is the attribute value */
|
|
41
|
+
value?: ValueObject
|
|
42
|
+
onChangeTheme?: (name: string) => void
|
|
43
|
+
|
|
44
|
+
// avoids warning
|
|
45
|
+
skipNextHead?: boolean
|
|
46
|
+
}
|
package/src/helpers.tsx
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { MEDIA } from './constants'
|
|
2
|
+
|
|
3
|
+
export const helpers = {}
|
|
4
|
+
// Helpers
|
|
5
|
+
|
|
6
|
+
export const getTheme = (key: string, fallback?: string) => {
|
|
7
|
+
if (typeof window === 'undefined') return undefined
|
|
8
|
+
let theme
|
|
9
|
+
try {
|
|
10
|
+
theme = localStorage.getItem(key) || undefined
|
|
11
|
+
} catch (e) {
|
|
12
|
+
// Unsupported
|
|
13
|
+
}
|
|
14
|
+
return theme || fallback
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const getSystemTheme = (e?: MediaQueryList) => {
|
|
18
|
+
if (!e) {
|
|
19
|
+
e = window.matchMedia(MEDIA)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const isDark = e.matches
|
|
23
|
+
const systemTheme = isDark ? 'dark' : 'light'
|
|
24
|
+
return systemTheme
|
|
25
|
+
}
|
package/src/types.tsx
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useLayoutEffect, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
// note this only works for light being default for now...
|
|
5
|
+
|
|
6
|
+
export const useRootTheme = () => {
|
|
7
|
+
const [val, setVal] = useState('light')
|
|
8
|
+
|
|
9
|
+
if (typeof document !== 'undefined') {
|
|
10
|
+
useLayoutEffect(() => {
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
const classes = [...document.documentElement.classList]
|
|
13
|
+
const isDark = classes.includes('t_dark')
|
|
14
|
+
React.startTransition(() => {
|
|
15
|
+
setVal(isDark ? 'dark' : 'light')
|
|
16
|
+
})
|
|
17
|
+
}, [])
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return [val, setVal] as const
|
|
21
|
+
}
|
package/src/useTheme.tsx
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useContext } from 'react'
|
|
2
|
+
|
|
3
|
+
import { ThemeSettingContext } from './ThemeSettingContext'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated renamed to `useThemeSetting` to avoid confusion with core `useTheme` hook
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const useTheme = () => useContext(ThemeSettingContext)
|
|
10
|
+
|
|
11
|
+
export const useThemeSetting = () => useContext(ThemeSettingContext)
|
package/types/NextTheme.d.ts
CHANGED
|
@@ -1,54 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
toggle: () => void;
|
|
10
|
-
/** Active theme name - will return "system" if not overriden, see "resolvedTheme" for getting resolved system value */
|
|
11
|
-
current?: string;
|
|
12
|
-
/** @deprecated Use `current` instead (deprecating avoid confusion with useTheme) */
|
|
13
|
-
theme?: string;
|
|
14
|
-
/** If `enableSystem` is true and the active theme is "system", this returns whether the system preference resolved to "dark" or "light". Otherwise, identical to `theme` */
|
|
15
|
-
resolvedTheme?: string;
|
|
16
|
-
/** If enableSystem is true, returns the System theme preference ("dark" or "light"), regardless what the active theme is */
|
|
17
|
-
systemTheme?: 'dark' | 'light';
|
|
18
|
-
}
|
|
19
|
-
export interface ThemeProviderProps {
|
|
20
|
-
children?: any;
|
|
21
|
-
/** List of all available theme names */
|
|
22
|
-
themes?: string[];
|
|
23
|
-
/** Forced theme name for the current page */
|
|
24
|
-
forcedTheme?: string;
|
|
25
|
-
/** Whether to switch between dark and light themes based on prefers-color-scheme */
|
|
26
|
-
enableSystem?: boolean;
|
|
27
|
-
systemTheme?: string;
|
|
28
|
-
/** Disable all CSS transitions when switching themes */
|
|
29
|
-
disableTransitionOnChange?: boolean;
|
|
30
|
-
/** Whether to indicate to browsers which color scheme is used (dark or light) for built-in UI like inputs and buttons */
|
|
31
|
-
enableColorScheme?: boolean;
|
|
32
|
-
/** Key used to store theme setting in localStorage */
|
|
33
|
-
storageKey?: string;
|
|
34
|
-
/** Default theme name (for v0.0.12 and lower the default was light). If `enableSystem` is false, the default theme is light */
|
|
35
|
-
defaultTheme?: string;
|
|
36
|
-
/** HTML attribute modified based on the active theme. Accepts `class` and `data-*` (meaning any data attribute, `data-mode`, `data-color`, etc.) */
|
|
37
|
-
attribute?: string | 'class';
|
|
38
|
-
/** Mapping of theme name to HTML attribute value. Object where key is the theme name and value is the attribute value */
|
|
39
|
-
value?: ValueObject;
|
|
40
|
-
onChangeTheme?: (name: string) => void;
|
|
41
|
-
skipNextHead?: boolean;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* @deprecated renamed to `useThemeSetting` to avoid confusion with core `useTheme` hook
|
|
45
|
-
*/
|
|
46
|
-
export declare const useTheme: () => UseThemeProps;
|
|
47
|
-
export declare const useThemeSetting: () => UseThemeProps;
|
|
48
|
-
interface ValueObject {
|
|
49
|
-
[themeName: string]: string;
|
|
50
|
-
}
|
|
51
|
-
export declare const useRootTheme: () => readonly [string, React.Dispatch<React.SetStateAction<string>>];
|
|
52
|
-
export declare const NextThemeProvider: React.FC<ThemeProviderProps>;
|
|
53
|
-
export {};
|
|
1
|
+
export * from './NextThemeProvider';
|
|
2
|
+
export * from './ThemeSettingContext';
|
|
3
|
+
export * from './UseThemeProps';
|
|
4
|
+
export * from './helpers';
|
|
5
|
+
export * from './constants';
|
|
6
|
+
export * from './useTheme';
|
|
7
|
+
export * from './types';
|
|
8
|
+
export * from './useRootTheme';
|
|
54
9
|
//# sourceMappingURL=NextTheme.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ValueObject } from './types';
|
|
2
|
+
export interface UseThemeProps {
|
|
3
|
+
/** List of all available theme names */
|
|
4
|
+
themes: string[];
|
|
5
|
+
/** Forced theme name for the current page */
|
|
6
|
+
forcedTheme?: string;
|
|
7
|
+
/** Update the theme */
|
|
8
|
+
set: (theme: string) => void;
|
|
9
|
+
toggle: () => void;
|
|
10
|
+
/** Active theme name - will return "system" if not overriden, see "resolvedTheme" for getting resolved system value */
|
|
11
|
+
current?: string;
|
|
12
|
+
/** @deprecated Use `current` instead (deprecating avoid confusion with useTheme) */
|
|
13
|
+
theme?: string;
|
|
14
|
+
/** If `enableSystem` is true and the active theme is "system", this returns whether the system preference resolved to "dark" or "light". Otherwise, identical to `theme` */
|
|
15
|
+
resolvedTheme?: string;
|
|
16
|
+
/** If enableSystem is true, returns the System theme preference ("dark" or "light"), regardless what the active theme is */
|
|
17
|
+
systemTheme?: 'dark' | 'light';
|
|
18
|
+
}
|
|
19
|
+
export interface ThemeProviderProps {
|
|
20
|
+
children?: any;
|
|
21
|
+
/** List of all available theme names */
|
|
22
|
+
themes?: string[];
|
|
23
|
+
/** Forced theme name for the current page */
|
|
24
|
+
forcedTheme?: string;
|
|
25
|
+
/** Whether to switch between dark and light themes based on prefers-color-scheme */
|
|
26
|
+
enableSystem?: boolean;
|
|
27
|
+
systemTheme?: string;
|
|
28
|
+
/** Disable all CSS transitions when switching themes */
|
|
29
|
+
disableTransitionOnChange?: boolean;
|
|
30
|
+
/** Whether to indicate to browsers which color scheme is used (dark or light) for built-in UI like inputs and buttons */
|
|
31
|
+
enableColorScheme?: boolean;
|
|
32
|
+
/** Key used to store theme setting in localStorage */
|
|
33
|
+
storageKey?: string;
|
|
34
|
+
/** Default theme name (for v0.0.12 and lower the default was light). If `enableSystem` is false, the default theme is light */
|
|
35
|
+
defaultTheme?: string;
|
|
36
|
+
/** HTML attribute modified based on the active theme. Accepts `class` and `data-*` (meaning any data attribute, `data-mode`, `data-color`, etc.) */
|
|
37
|
+
attribute?: string | 'class';
|
|
38
|
+
/** Mapping of theme name to HTML attribute value. Object where key is the theme name and value is the attribute value */
|
|
39
|
+
value?: ValueObject;
|
|
40
|
+
onChangeTheme?: (name: string) => void;
|
|
41
|
+
skipNextHead?: boolean;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=UseThemeProps.d.ts.map
|
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated renamed to `useThemeSetting` to avoid confusion with core `useTheme` hook
|
|
3
|
+
*/
|
|
4
|
+
export declare const useTheme: () => import("./UseThemeProps").UseThemeProps;
|
|
5
|
+
export declare const useThemeSetting: () => import("./UseThemeProps").UseThemeProps;
|
|
6
|
+
//# sourceMappingURL=useTheme.d.ts.map
|