@hh.ru/magritte-ui-theme-wrapper 1.1.0

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.
@@ -0,0 +1,10 @@
1
+ import { FC, ReactNode } from 'react';
2
+ import { THEME_MAP } from '@hh.ru/magritte-design-tokens/themes';
3
+ export declare const ThemeContext: import("react").Context<"hh-day" | "hh-night" | "zp-day">;
4
+ export declare const THEME_NAMES: Array<keyof typeof THEME_MAP>;
5
+ interface ThemeWrapperProps {
6
+ theme?: keyof typeof THEME_MAP;
7
+ children: ReactNode | ((cssClass?: string) => ReactNode);
8
+ }
9
+ export declare const ThemeWrapper: FC<ThemeWrapperProps>;
10
+ export {};
@@ -0,0 +1,18 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { createContext, useContext } from 'react';
3
+ import { THEME_DEFAULT, THEME_MAP } from '@hh.ru/magritte-design-tokens/themes';
4
+
5
+ const ThemeContext = createContext(THEME_DEFAULT);
6
+ const THEME_NAMES = Object.keys(THEME_MAP);
7
+ const ThemeWrapper = ({ theme, children }) => {
8
+ const contextTheme = useContext(ThemeContext);
9
+ const currentTheme = theme || contextTheme;
10
+ const cssClass = currentTheme !== THEME_DEFAULT ? THEME_MAP[currentTheme] : undefined;
11
+ if (typeof children === 'function') {
12
+ return jsx(ThemeContext.Provider, { value: currentTheme, children: children(cssClass) });
13
+ }
14
+ return (jsx(ThemeContext.Provider, { value: currentTheme, children: cssClass ? jsx("div", { className: cssClass, children: children }) : children }));
15
+ };
16
+
17
+ export { THEME_NAMES, ThemeContext, ThemeWrapper };
18
+ //# sourceMappingURL=ThemeWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThemeWrapper.js","sources":["../src/ThemeWrapper.tsx"],"sourcesContent":["import { createContext, FC, ReactNode, useContext } from 'react';\n\nimport { THEME_MAP, THEME_DEFAULT } from '@hh.ru/magritte-design-tokens/themes';\n\nexport const ThemeContext = createContext<keyof typeof THEME_MAP>(THEME_DEFAULT);\n\nexport const THEME_NAMES = Object.keys(THEME_MAP) as Array<keyof typeof THEME_MAP>;\n\ninterface ThemeWrapperProps {\n theme?: keyof typeof THEME_MAP;\n children: ReactNode | ((cssClass?: string) => ReactNode);\n}\n\nexport const ThemeWrapper: FC<ThemeWrapperProps> = ({ theme, children }) => {\n const contextTheme = useContext(ThemeContext);\n const currentTheme = theme || contextTheme;\n const cssClass = currentTheme !== THEME_DEFAULT ? THEME_MAP[currentTheme] : undefined;\n\n if (typeof children === 'function') {\n return <ThemeContext.Provider value={currentTheme}>{children(cssClass)}</ThemeContext.Provider>;\n }\n\n return (\n <ThemeContext.Provider value={currentTheme}>\n {cssClass ? <div className={cssClass}>{children}</div> : children}\n </ThemeContext.Provider>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;MAIa,YAAY,GAAG,aAAa,CAAyB,aAAa,EAAE;AAEpE,MAAA,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAmC;AAOtE,MAAA,YAAY,GAA0B,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAI;AACvE,IAAA,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;AAC9C,IAAA,MAAM,YAAY,GAAG,KAAK,IAAI,YAAY,CAAC;AAC3C,IAAA,MAAM,QAAQ,GAAG,YAAY,KAAK,aAAa,GAAG,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;AAEtF,IAAA,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;AAChC,QAAA,OAAOA,GAAC,CAAA,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,EAAA,QAAA,EAAG,QAAQ,CAAC,QAAQ,CAAC,GAAyB,CAAC;KACnG;IAED,QACIA,GAAC,CAAA,YAAY,CAAC,QAAQ,EAAC,EAAA,KAAK,EAAE,YAAY,EACrC,QAAA,EAAA,QAAQ,GAAGA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,QAAQ,EAAA,QAAA,EAAG,QAAQ,EAAA,CAAO,GAAG,QAAQ,EAC7C,CAAA,EAC1B;AACN;;;;"}
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@hh.ru/magritte-ui-theme-wrapper/ThemeWrapper';
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { THEME_NAMES, ThemeContext, ThemeWrapper } from './ThemeWrapper.js';
2
+ import 'react/jsx-runtime';
3
+ import 'react';
4
+ import '@hh.ru/magritte-design-tokens/themes';
5
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@hh.ru/magritte-ui-theme-wrapper",
3
+ "version": "1.1.0",
4
+ "main": "index.js",
5
+ "types": "index.d.ts",
6
+ "sideEffects": [
7
+ "index.css"
8
+ ],
9
+ "scripts": {
10
+ "build": "yarn root:build $(pwd)",
11
+ "build-test-branch": "yarn root:build-test-branch $(pwd)",
12
+ "prepack": "yarn root:prepack $(pwd)",
13
+ "postpublish": "yarn root:postpublish $(pwd)",
14
+ "stylelint-check": "yarn root:stylelint-check $(pwd)",
15
+ "eslint-check": "yarn root:eslint-check $(pwd)",
16
+ "ts-config": "yarn root:ts-config $(pwd)",
17
+ "ts-check": "yarn root:ts-check $(pwd)",
18
+ "test": "exit 0",
19
+ "watch": "yarn root:watch $(pwd)"
20
+ },
21
+ "dependencies": {
22
+ "@hh.ru/magritte-design-tokens": "23.2.0"
23
+ },
24
+ "peerDependencies": {
25
+ "classnames": ">=2.3.2",
26
+ "react": ">=18.2.0",
27
+ "react-dom": ">=18.2.0"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "gitHead": "fb6e7a383f8c329c0b5bc46df4d4bb11e44d9d24"
33
+ }