@primer/styled-react 0.0.0-20260610121450 → 0.0.0-20260722001252
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/components/BaseStyles.d.ts +23 -14
- package/dist/components/BaseStyles.d.ts.map +1 -1
- package/dist/components/BaseStyles.js +27 -48
- package/dist/components/FeatureFlaggedTheming.d.ts +11 -11
- package/dist/components/FeatureFlaggedTheming.d.ts.map +1 -1
- package/dist/components/FeatureFlaggedTheming.js +20 -43
- package/dist/components/ThemeContext.d.ts +19 -0
- package/dist/components/ThemeContext.d.ts.map +1 -0
- package/dist/components/ThemeContext.js +9 -0
- package/dist/components/ThemeProvider.d.ts +21 -31
- package/dist/components/ThemeProvider.d.ts.map +1 -1
- package/dist/components/ThemeProvider.js +104 -147
- package/dist/components/useFeatureFlaggedTheme.d.ts +8 -0
- package/dist/components/useFeatureFlaggedTheme.d.ts.map +1 -0
- package/dist/components/useFeatureFlaggedTheme.js +19 -0
- package/dist/components/useTheme.d.ts +20 -0
- package/dist/components/useTheme.d.ts.map +1 -0
- package/dist/components/useTheme.js +12 -0
- package/dist/index.d.ts +6 -67
- package/dist/index.js +6 -6
- package/dist/legacy-theme/ts/color-schemes.js +4252 -0
- package/dist/polymorphic.d.ts +23 -26
- package/dist/polymorphic.d.ts.map +1 -1
- package/dist/styled-props.d.ts +7 -3
- package/dist/styled-props.d.ts.map +1 -1
- package/dist/sx.d.ts +20 -20
- package/dist/sx.d.ts.map +1 -1
- package/dist/sx.js +6 -8
- package/dist/theme-get.d.ts +4 -1
- package/dist/theme-get.d.ts.map +1 -1
- package/dist/theme-get.js +7 -9
- package/dist/theme-types.d.ts +94 -0
- package/dist/theme-types.d.ts.map +1 -0
- package/dist/theme.d.ts +1090 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +14 -0
- package/package.json +15 -9
- package/dist/index.d.ts.map +0 -1
|
@@ -1,17 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import React, { CSSProperties, JSX, PropsWithChildren } from "react";
|
|
2
|
+
import * as styledSystem from "styled-system";
|
|
3
|
+
//#region src/components/BaseStyles.d.ts
|
|
4
|
+
interface SystemCommonProps extends styledSystem.ColorProps, styledSystem.SpaceProps, styledSystem.DisplayProps {}
|
|
5
|
+
interface SystemTypographyProps extends styledSystem.TypographyProps {
|
|
6
|
+
whiteSpace?: 'normal' | 'nowrap' | 'pre' | 'pre-wrap' | 'pre-line';
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
className?: string;
|
|
13
|
-
style?: CSSProperties;
|
|
14
|
-
color?: string;
|
|
8
|
+
type BaseStylesProps = PropsWithChildren & {
|
|
9
|
+
as?: React.ComponentType<any> | keyof JSX.IntrinsicElements;
|
|
10
|
+
className?: string;
|
|
11
|
+
style?: CSSProperties;
|
|
12
|
+
color?: string;
|
|
15
13
|
} & SystemTypographyProps & SystemCommonProps;
|
|
16
|
-
|
|
14
|
+
declare function BaseStyles({
|
|
15
|
+
children,
|
|
16
|
+
color,
|
|
17
|
+
fontFamily,
|
|
18
|
+
lineHeight,
|
|
19
|
+
className,
|
|
20
|
+
as: Component,
|
|
21
|
+
style,
|
|
22
|
+
...rest
|
|
23
|
+
}: BaseStylesProps): JSX.Element;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { BaseStyles, BaseStylesProps, SystemCommonProps, SystemTypographyProps };
|
|
17
26
|
//# sourceMappingURL=BaseStyles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseStyles.d.ts","
|
|
1
|
+
{"version":3,"file":"BaseStyles.d.ts","names":[],"sources":["../../src/components/BaseStyles.tsx"],"mappings":";;;UAUiB,iBAAA,SACP,YAAA,CAAa,UAAA,EACnB,YAAA,CAAa,UAAA,EACb,YAAA,CAAa,YAAA;AAAA,UAEA,qBAAA,SAA8B,YAAA,CAAa,eAAe;EACzE,UAAA;AAAA;AAAA,KA+EU,eAAA,GAAkB,iBAAA;EAE5B,EAAA,GAAK,KAAA,CAAM,aAAA,cAA2B,GAAA,CAAI,iBAAA;EAC1C,SAAA;EACA,KAAA,GAAQ,aAAA;EACR,KAAA;AAAA,IACE,qBAAA,GACF,iBAAA;AAAA,iBAEc,UAAA;EACd,QAAA;EACA,KAAA;EACA,UAAA;EACA,UAAA;EACA,SAAA;EACA,EAAA,EAAI,SAAA;EACJ,KAAA;EAAA,GACG;AAAA,GACF,eAAA,GAAe,GAAA,CAAA,OAAA"}
|
|
@@ -1,51 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
1
|
+
import { useTheme } from "./useTheme.js";
|
|
2
|
+
import { createGlobalStyle } from "styled-components";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { clsx } from "clsx";
|
|
5
|
+
import "focus-visible";
|
|
6
|
+
//#region src/components/BaseStyles.tsx
|
|
7
7
|
const GlobalStyle = createGlobalStyle(["*{box-sizing:border-box;}body{margin:0;}table{border-collapse:collapse;}[data-color-mode='light'] input{color-scheme:light;}[data-color-mode='dark'] input{color-scheme:dark;}@media (prefers-color-scheme:light){[data-color-mode='auto'][data-light-theme*='light']{color-scheme:light;}}@media (prefers-color-scheme:dark){[data-color-mode='auto'][data-dark-theme*='dark']{color-scheme:dark;}}[role='button']:focus:not(:focus-visible):not(:global(.focus-visible)),[role='tabpanel'][tabindex='0']:focus:not(:focus-visible):not(:global(.focus-visible)),button:focus:not(:focus-visible):not(:global(.focus-visible)),summary:focus:not(:focus-visible):not(:global(.focus-visible)),a:focus:not(:focus-visible):not(:global(.focus-visible)){outline:none;box-shadow:none;}[tabindex='0']:focus:not(:focus-visible):not(:global(.focus-visible)),details-dialog:focus:not(:focus-visible):not(:global(.focus-visible)){outline:none;}.BaseStyles{font-family:var(--BaseStyles-fontFamily,var(--fontStack-system));line-height:var(--BaseStyles-lineHeight,1.5);color:var(--BaseStyles-fgColor,var(--fgColor-default));:where(a:not([class*='prc-']):not([class*='PRC-']):not([class*='Primer_Brand__'])){color:var(--fgColor-accent,var(--color-accent-fg));text-decoration:none;&:hover{text-decoration:underline;}}}"]);
|
|
8
|
-
function BaseStyles({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
return /*#__PURE__*/jsxs(Component, {
|
|
30
|
-
className: clsx('BaseStyles', className),
|
|
31
|
-
"data-portal-root": true
|
|
32
|
-
/**
|
|
33
|
-
* We need to map valid primer/react color modes onto valid color modes for primer/primitives
|
|
34
|
-
* valid color modes for primer/primitives: auto | light | dark
|
|
35
|
-
* valid color modes for primer/primer: auto | day | night | light | dark
|
|
36
|
-
*/,
|
|
37
|
-
"data-color-mode": colorMode === 'auto' ? 'auto' : colorScheme?.includes('dark') ? 'dark' : 'light',
|
|
38
|
-
"data-light-theme": dayScheme,
|
|
39
|
-
"data-dark-theme": nightScheme,
|
|
40
|
-
style: {
|
|
41
|
-
...baseStyles,
|
|
42
|
-
...style
|
|
43
|
-
},
|
|
44
|
-
...rest,
|
|
45
|
-
children: [/*#__PURE__*/jsx(GlobalStyle, {
|
|
46
|
-
colorScheme: colorScheme?.includes('dark') ? 'dark' : 'light'
|
|
47
|
-
}), children]
|
|
48
|
-
});
|
|
8
|
+
function BaseStyles({ children, color, fontFamily, lineHeight, className, as: Component = "div", style, ...rest }) {
|
|
9
|
+
const { colorMode, colorScheme, dayScheme, nightScheme } = useTheme();
|
|
10
|
+
const baseStyles = {
|
|
11
|
+
["--BaseStyles-fgColor"]: color,
|
|
12
|
+
["--BaseStyles-fontFamily"]: fontFamily,
|
|
13
|
+
["--BaseStyles-lineHeight"]: lineHeight
|
|
14
|
+
};
|
|
15
|
+
return /*#__PURE__*/ jsxs(Component, {
|
|
16
|
+
className: clsx("BaseStyles", className),
|
|
17
|
+
"data-portal-root": true,
|
|
18
|
+
"data-color-mode": colorMode === "auto" ? "auto" : colorScheme?.includes("dark") ? "dark" : "light",
|
|
19
|
+
"data-light-theme": dayScheme,
|
|
20
|
+
"data-dark-theme": nightScheme,
|
|
21
|
+
style: {
|
|
22
|
+
...baseStyles,
|
|
23
|
+
...style
|
|
24
|
+
},
|
|
25
|
+
...rest,
|
|
26
|
+
children: [/*#__PURE__*/ jsx(GlobalStyle, { colorScheme: colorScheme?.includes("dark") ? "dark" : "light" }), children]
|
|
27
|
+
});
|
|
49
28
|
}
|
|
50
|
-
|
|
29
|
+
//#endregion
|
|
51
30
|
export { BaseStyles };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
1
|
+
import { BaseStylesProps as BaseStylesProps$1 } from "./BaseStyles.js";
|
|
2
|
+
import { ThemeProviderProps as ThemeProviderProps$1 } from "./ThemeProvider.js";
|
|
3
|
+
import React from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/components/FeatureFlaggedTheming.d.ts
|
|
6
|
+
type ThemeProviderProps = ThemeProviderProps$1;
|
|
7
|
+
type BaseStylesProps = BaseStylesProps$1;
|
|
8
|
+
declare const ThemeProvider: React.FC<React.PropsWithChildren<ThemeProviderProps>>;
|
|
9
|
+
declare function BaseStyles(props: BaseStylesProps): React.JSX.Element;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { BaseStyles, BaseStylesProps, ThemeProvider, ThemeProviderProps };
|
|
12
12
|
//# sourceMappingURL=FeatureFlaggedTheming.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeatureFlaggedTheming.d.ts","
|
|
1
|
+
{"version":3,"file":"FeatureFlaggedTheming.d.ts","names":[],"sources":["../../src/components/FeatureFlaggedTheming.tsx"],"mappings":";;;;;KAYY,kBAAA,GAAqB,oBAAwB;AAAA,KAE7C,eAAA,GAAkB,iBAAqB;AAAA,cAEtC,aAAA,EAAe,KAAA,CAAM,EAAA,CAAG,KAAA,CAAM,iBAAA,CAAkB,kBAAA;AAAA,iBAQ7C,UAAA,CAAW,KAAA,EAAO,eAAA,GAAe,KAAA,CAAA,GAAA,CAAA,OAAA"}
|
|
@@ -1,45 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
children: children
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return /*#__PURE__*/jsx(ThemeProvider$2, {
|
|
20
|
-
...props,
|
|
21
|
-
children: children
|
|
22
|
-
});
|
|
1
|
+
import { ThemeProvider as ThemeProvider$2 } from "./ThemeProvider.js";
|
|
2
|
+
import { BaseStyles as BaseStyles$2 } from "./BaseStyles.js";
|
|
3
|
+
import { BaseStyles, ThemeProvider } from "@primer/react";
|
|
4
|
+
import { useFeatureFlag } from "@primer/react/experimental";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
//#region src/components/FeatureFlaggedTheming.tsx
|
|
7
|
+
const ThemeProvider$1 = ({ children, ...props }) => {
|
|
8
|
+
if (useFeatureFlag("primer_react_styled_react_use_primer_theme_providers")) return /*#__PURE__*/ jsx(ThemeProvider, {
|
|
9
|
+
...props,
|
|
10
|
+
children
|
|
11
|
+
});
|
|
12
|
+
return /*#__PURE__*/ jsx(ThemeProvider$2, {
|
|
13
|
+
...props,
|
|
14
|
+
children
|
|
15
|
+
});
|
|
23
16
|
};
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const primerTheme = useTheme$2();
|
|
28
|
-
if (enabled) {
|
|
29
|
-
return primerTheme;
|
|
30
|
-
}
|
|
31
|
-
return styledTheme;
|
|
17
|
+
function BaseStyles$1(props) {
|
|
18
|
+
if (useFeatureFlag("primer_react_styled_react_use_primer_theme_providers")) return /*#__PURE__*/ jsx(BaseStyles, { ...props });
|
|
19
|
+
return /*#__PURE__*/ jsx(BaseStyles$2, { ...props });
|
|
32
20
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (enabled) {
|
|
36
|
-
return /*#__PURE__*/jsx(BaseStyles$1, {
|
|
37
|
-
...props
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return /*#__PURE__*/jsx(BaseStyles$2, {
|
|
41
|
-
...props
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { BaseStyles, ThemeProvider, useTheme };
|
|
21
|
+
//#endregion
|
|
22
|
+
export { BaseStyles$1 as BaseStyles, ThemeProvider$1 as ThemeProvider };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ColorMode, ColorModeWithAuto, Theme } from "./ThemeProvider.js";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/components/ThemeContext.d.ts
|
|
5
|
+
declare const ThemeContext: React.Context<{
|
|
6
|
+
theme?: Theme;
|
|
7
|
+
colorScheme?: string;
|
|
8
|
+
colorMode?: ColorModeWithAuto;
|
|
9
|
+
resolvedColorMode?: ColorMode;
|
|
10
|
+
resolvedColorScheme?: string;
|
|
11
|
+
dayScheme?: string;
|
|
12
|
+
nightScheme?: string;
|
|
13
|
+
setColorMode: React.Dispatch<React.SetStateAction<ColorModeWithAuto>>;
|
|
14
|
+
setDayScheme: React.Dispatch<React.SetStateAction<string>>;
|
|
15
|
+
setNightScheme: React.Dispatch<React.SetStateAction<string>>;
|
|
16
|
+
}>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ThemeContext };
|
|
19
|
+
//# sourceMappingURL=ThemeContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeContext.d.ts","names":[],"sources":["../../src/components/ThemeContext.ts"],"mappings":";;;;cAGa,YAAA,EAAY,KAAA,CAAA,OAAA;UACf,KAAA;;cAEI,iBAAA;sBACQ,SAAA;;;;gBAIN,KAAA,CAAM,QAAA,CAAS,KAAA,CAAM,cAAA,CAAe,iBAAA;gBACpC,KAAA,CAAM,QAAA,CAAS,KAAA,CAAM,cAAA;kBACnB,KAAA,CAAM,QAAA,CAAS,KAAA,CAAM,cAAA;AAAA"}
|
|
@@ -1,35 +1,25 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/components/ThemeProvider.d.ts
|
|
4
|
+
declare const defaultColorMode = "day";
|
|
5
|
+
type Theme = {
|
|
6
|
+
[key: string]: any;
|
|
5
7
|
};
|
|
6
8
|
type ColorMode = 'day' | 'night' | 'light' | 'dark';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
type ColorModeWithAuto = ColorMode | 'auto';
|
|
10
|
+
type ThemeProviderProps = {
|
|
11
|
+
theme?: Theme;
|
|
12
|
+
colorMode?: ColorModeWithAuto;
|
|
13
|
+
dayScheme?: string;
|
|
14
|
+
nightScheme?: string;
|
|
15
|
+
preventSSRMismatch?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* No-op. Exists solely to match @primer/react's ThemeProvider API.
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
contextOnly?: boolean;
|
|
19
21
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
colorScheme?: string;
|
|
24
|
-
colorMode?: ColorModeWithAuto;
|
|
25
|
-
resolvedColorMode?: ColorMode;
|
|
26
|
-
resolvedColorScheme?: string;
|
|
27
|
-
dayScheme?: string;
|
|
28
|
-
nightScheme?: string;
|
|
29
|
-
setColorMode: React.Dispatch<React.SetStateAction<ColorModeWithAuto>>;
|
|
30
|
-
setDayScheme: React.Dispatch<React.SetStateAction<string>>;
|
|
31
|
-
setNightScheme: React.Dispatch<React.SetStateAction<string>>;
|
|
32
|
-
};
|
|
33
|
-
export declare function useColorSchemeVar(values: Partial<Record<string, string>>, fallback: string): string;
|
|
34
|
-
export default ThemeProvider;
|
|
22
|
+
declare const ThemeProvider: React.FC<React.PropsWithChildren<ThemeProviderProps>>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { ColorMode, ColorModeWithAuto, Theme, ThemeProvider, ThemeProvider as default, ThemeProviderProps, defaultColorMode };
|
|
35
25
|
//# sourceMappingURL=ThemeProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.d.ts","
|
|
1
|
+
{"version":3,"file":"ThemeProvider.d.ts","names":[],"sources":["../../src/components/ThemeProvider.tsx"],"mappings":";;;cAQa,gBAAA;AAAA,KAKD,KAAA;EAAA,CAAU,GAAW;AAAA;AAAA,KACrB,SAAA;AAAA,KACA,iBAAA,GAAoB,SAAS;AAAA,KAE7B,kBAAA;EACV,KAAA,GAAQ,KAAA;EACR,SAAA,GAAY,iBAAiB;EAC7B,SAAA;EACA,WAAA;EACA,kBAAA;EARU;;;;EAaV,WAAA;AAAA;AAAA,cA8BW,aAAA,EAAe,KAAA,CAAM,EAAA,CAAG,KAAA,CAAM,iBAAA,CAAkB,kBAAA"}
|
|
@@ -1,163 +1,120 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const ThemeContext = /*#__PURE__*/React.createContext({
|
|
14
|
-
setColorMode: () => null,
|
|
15
|
-
setDayScheme: () => null,
|
|
16
|
-
setNightScheme: () => null
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
// inspired from __NEXT_DATA__, we use application/json to avoid CSRF policy with inline scripts
|
|
20
|
-
const serverHandoffCache = new Map();
|
|
1
|
+
import { theme as theme$1 } from "../theme.js";
|
|
2
|
+
import { ThemeContext } from "./ThemeContext.js";
|
|
3
|
+
import { useTheme as useTheme$1 } from "./useTheme.js";
|
|
4
|
+
import { useId, useSyncedState } from "@primer/react";
|
|
5
|
+
import React from "react";
|
|
6
|
+
import { ThemeProvider as ThemeProvider$1 } from "styled-components";
|
|
7
|
+
import deepmerge from "deepmerge";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
const defaultDayScheme = "light";
|
|
10
|
+
const defaultNightScheme = "dark";
|
|
11
|
+
const serverHandoffCache = /* @__PURE__ */ new Map();
|
|
21
12
|
const emptyHandoff = {};
|
|
22
|
-
const getServerHandoff = id => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
serverHandoffCache.set(id, empty);
|
|
38
|
-
return empty;
|
|
13
|
+
const getServerHandoff = (id) => {
|
|
14
|
+
if (typeof document === "undefined") return emptyHandoff;
|
|
15
|
+
const cached = serverHandoffCache.get(id);
|
|
16
|
+
if (cached !== void 0) return cached;
|
|
17
|
+
try {
|
|
18
|
+
const serverData = document.getElementById(`__PRIMER_DATA_${id}__`)?.textContent;
|
|
19
|
+
if (serverData) {
|
|
20
|
+
const parsed = JSON.parse(serverData);
|
|
21
|
+
serverHandoffCache.set(id, parsed);
|
|
22
|
+
return parsed;
|
|
23
|
+
}
|
|
24
|
+
} catch (_error) {}
|
|
25
|
+
const empty = {};
|
|
26
|
+
serverHandoffCache.set(id, empty);
|
|
27
|
+
return empty;
|
|
39
28
|
};
|
|
40
29
|
const emptySubscribe = () => () => {};
|
|
41
|
-
const ThemeProvider = ({
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
type: "application/json",
|
|
87
|
-
id: `__PRIMER_DATA_${uniqueDataId}__`,
|
|
88
|
-
dangerouslySetInnerHTML: {
|
|
89
|
-
__html: JSON.stringify({
|
|
90
|
-
resolvedServerColorMode: resolvedColorMode
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
}) : null]
|
|
94
|
-
})
|
|
95
|
-
});
|
|
30
|
+
const ThemeProvider$2 = ({ children, ...props }) => {
|
|
31
|
+
const { theme: fallbackTheme, colorMode: fallbackColorMode, dayScheme: fallbackDayScheme, nightScheme: fallbackNightScheme } = useTheme$1();
|
|
32
|
+
const theme = props.theme ?? fallbackTheme ?? theme$1;
|
|
33
|
+
const uniqueDataId = useId();
|
|
34
|
+
const [colorMode, setColorMode] = useSyncedState(props.colorMode ?? fallbackColorMode ?? "day");
|
|
35
|
+
const [dayScheme, setDayScheme] = useSyncedState(props.dayScheme ?? fallbackDayScheme ?? defaultDayScheme);
|
|
36
|
+
const [nightScheme, setNightScheme] = useSyncedState(props.nightScheme ?? fallbackNightScheme ?? defaultNightScheme);
|
|
37
|
+
const clientColorMode = resolveColorMode(colorMode, useSystemColorMode());
|
|
38
|
+
const resolvedColorMode = React.useSyncExternalStore(emptySubscribe, () => clientColorMode, () => getServerHandoff(uniqueDataId).resolvedServerColorMode ?? clientColorMode);
|
|
39
|
+
const colorScheme = chooseColorScheme(resolvedColorMode, dayScheme, nightScheme);
|
|
40
|
+
const { resolvedTheme, resolvedColorScheme } = React.useMemo(() => applyColorScheme(theme, colorScheme), [theme, colorScheme]);
|
|
41
|
+
const contextValue = React.useMemo(() => ({
|
|
42
|
+
theme: resolvedTheme,
|
|
43
|
+
colorScheme,
|
|
44
|
+
colorMode,
|
|
45
|
+
resolvedColorMode,
|
|
46
|
+
resolvedColorScheme,
|
|
47
|
+
dayScheme,
|
|
48
|
+
nightScheme,
|
|
49
|
+
setColorMode,
|
|
50
|
+
setDayScheme,
|
|
51
|
+
setNightScheme
|
|
52
|
+
}), [
|
|
53
|
+
resolvedTheme,
|
|
54
|
+
colorScheme,
|
|
55
|
+
colorMode,
|
|
56
|
+
resolvedColorMode,
|
|
57
|
+
resolvedColorScheme,
|
|
58
|
+
dayScheme,
|
|
59
|
+
nightScheme,
|
|
60
|
+
setColorMode,
|
|
61
|
+
setDayScheme,
|
|
62
|
+
setNightScheme
|
|
63
|
+
]);
|
|
64
|
+
return /*#__PURE__*/ jsx(ThemeContext.Provider, {
|
|
65
|
+
value: contextValue,
|
|
66
|
+
children: /*#__PURE__*/ jsxs(ThemeProvider$1, {
|
|
67
|
+
theme: resolvedTheme,
|
|
68
|
+
children: [children, props.preventSSRMismatch ? /*#__PURE__*/ jsx("script", {
|
|
69
|
+
type: "application/json",
|
|
70
|
+
id: `__PRIMER_DATA_${uniqueDataId}__`,
|
|
71
|
+
dangerouslySetInnerHTML: { __html: JSON.stringify({ resolvedServerColorMode: resolvedColorMode }) }
|
|
72
|
+
}) : null]
|
|
73
|
+
})
|
|
74
|
+
});
|
|
96
75
|
};
|
|
97
|
-
function useTheme() {
|
|
98
|
-
return React.useContext(ThemeContext);
|
|
99
|
-
}
|
|
100
|
-
function useColorSchemeVar(values, fallback) {
|
|
101
|
-
const {
|
|
102
|
-
colorScheme = ''
|
|
103
|
-
} = useTheme();
|
|
104
|
-
return values[colorScheme] ?? fallback;
|
|
105
|
-
}
|
|
106
76
|
function subscribeToSystemColorMode(callback) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
media?.addEventListener('change', callback);
|
|
111
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
112
|
-
return () => media?.removeEventListener('change', callback);
|
|
77
|
+
const media = window?.matchMedia?.("(prefers-color-scheme: dark)");
|
|
78
|
+
media?.addEventListener("change", callback);
|
|
79
|
+
return () => media?.removeEventListener("change", callback);
|
|
113
80
|
}
|
|
114
81
|
function useSystemColorMode() {
|
|
115
|
-
|
|
82
|
+
return React.useSyncExternalStore(subscribeToSystemColorMode, getSystemColorMode, () => "day");
|
|
116
83
|
}
|
|
117
84
|
function getSystemColorMode() {
|
|
118
|
-
|
|
119
|
-
return window?.matchMedia?.('(prefers-color-scheme: dark)')?.matches ? 'night' : 'day';
|
|
85
|
+
return window?.matchMedia?.("(prefers-color-scheme: dark)")?.matches ? "night" : "day";
|
|
120
86
|
}
|
|
121
87
|
function resolveColorMode(colorMode, systemColorMode) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return colorMode;
|
|
127
|
-
}
|
|
88
|
+
switch (colorMode) {
|
|
89
|
+
case "auto": return systemColorMode;
|
|
90
|
+
default: return colorMode;
|
|
91
|
+
}
|
|
128
92
|
}
|
|
129
93
|
function chooseColorScheme(colorMode, dayScheme, nightScheme) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return nightScheme;
|
|
137
|
-
}
|
|
94
|
+
switch (colorMode) {
|
|
95
|
+
case "day":
|
|
96
|
+
case "light": return dayScheme;
|
|
97
|
+
case "dark":
|
|
98
|
+
case "night": return nightScheme;
|
|
99
|
+
}
|
|
138
100
|
}
|
|
139
101
|
function applyColorScheme(theme, colorScheme) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
return {
|
|
158
|
-
resolvedTheme: deepmerge(theme, theme.colorSchemes[colorScheme]),
|
|
159
|
-
resolvedColorScheme: colorScheme
|
|
160
|
-
};
|
|
102
|
+
if (!theme.colorSchemes) return {
|
|
103
|
+
resolvedTheme: theme,
|
|
104
|
+
resolvedColorScheme: void 0
|
|
105
|
+
};
|
|
106
|
+
if (!theme.colorSchemes[colorScheme]) {
|
|
107
|
+
console.error(`\`${colorScheme}\` scheme not defined in \`theme.colorSchemes\``);
|
|
108
|
+
const defaultColorScheme = Object.keys(theme.colorSchemes)[0];
|
|
109
|
+
return {
|
|
110
|
+
resolvedTheme: deepmerge(theme, theme.colorSchemes[defaultColorScheme]),
|
|
111
|
+
resolvedColorScheme: defaultColorScheme
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
resolvedTheme: deepmerge(theme, theme.colorSchemes[colorScheme]),
|
|
116
|
+
resolvedColorScheme: colorScheme
|
|
117
|
+
};
|
|
161
118
|
}
|
|
162
|
-
|
|
163
|
-
export { ThemeProvider
|
|
119
|
+
//#endregion
|
|
120
|
+
export { ThemeProvider$2 as ThemeProvider, ThemeProvider$2 as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useTheme as useTheme$1 } from "./useTheme.js";
|
|
2
|
+
|
|
3
|
+
//#region src/components/useFeatureFlaggedTheme.d.ts
|
|
4
|
+
declare function useTheme(): ReturnType<typeof useTheme$1>;
|
|
5
|
+
declare function useColorSchemeVar(values: Partial<Record<string, string>>, fallback: string): string;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { useColorSchemeVar, useTheme };
|
|
8
|
+
//# sourceMappingURL=useFeatureFlaggedTheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFeatureFlaggedTheme.d.ts","names":[],"sources":["../../src/components/useFeatureFlaggedTheme.ts"],"mappings":";;;iBAIgB,QAAA,IAAY,UAAU,QAAQ,UAAA;AAAA,iBAU9B,iBAAA,CAAkB,MAAA,EAAQ,OAAO,CAAC,MAAA,mBAAyB,QAAA"}
|