@rescui/ui-contexts 0.4.4 → 0.5.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.
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { LayeringConsumer, withLayering, useLayeringContext } from './parts/layering-context';
2
2
  export { default as LayeringProvider } from './layering-provider';
3
3
  export type { LayeringProviderProps } from './layering-provider';
4
- export { ThemeConsumer, withTheme, useTheme, getInverseTheme } from './parts/theme-context';
4
+ export { ThemeConsumer, ThemeContext, withTheme, useTheme, useThemeWithUndefined, getInverseTheme } from './parts/theme-context';
5
5
  export { default as ThemeProvider } from './theme-provider';
6
6
  export type { ThemeProviderProps } from './theme-provider';
7
7
  export type { Theme } from './parts/theme-context';
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { LayeringConsumer, useLayeringContext, withLayering } from './parts/layering-context.js';
2
2
  export { default as LayeringProvider } from './layering-provider.js';
3
- export { ThemeConsumer, getInverseTheme, useTheme, withTheme } from './parts/theme-context.js';
3
+ export { ThemeConsumer, ThemeContext, getInverseTheme, useTheme, useThemeWithUndefined, withTheme } from './parts/theme-context.js';
4
4
  export { default as ThemeProvider } from './theme-provider.js';
@@ -1,13 +1,24 @@
1
1
  import React, { ForwardRefExoticComponent, PropsWithoutRef, RefAttributes } from 'react';
2
2
  export declare type Theme = 'light' | 'dark';
3
- export declare const ThemeContext: React.Context<Theme>;
4
- export declare const ThemeConsumer: React.Consumer<Theme>;
3
+ declare type ThemeContextValue = {
4
+ theme: Theme;
5
+ noProvider?: boolean;
6
+ };
7
+ export declare const ThemeContext: React.Context<ThemeContextValue>;
8
+ export declare const ThemeConsumer: React.Consumer<ThemeContextValue>;
5
9
  export declare const getInverseTheme: (theme: Theme) => Theme;
10
+ /**
11
+ * @deprecated please support --rs-theme-dark and --rs-theme-flip css variables and don't use react context for theme
12
+ * If you need to maintain backward compatibility use `useThemeWithUndefined` hook instead, rely on --rs-theme-dark and --rs-theme-flip css variables when theme is undefined
13
+ * */
6
14
  export declare const useTheme: (overwriteValue?: Theme) => Theme;
15
+ export declare const useThemeWithUndefined: (overwriteValue?: Theme) => Theme | undefined;
7
16
  export interface ThemeProps {
8
17
  theme?: Theme;
9
18
  }
10
19
  /**
11
- * @deprecated use `useTheme` hook instead
20
+ * @deprecated please support --rs-theme-dark and --rs-theme-flip css variables and don't use react context for theme
21
+ * If you need to maintain backward compatibility use `useThemeWithUndefined` hook instead, rely on --rs-theme-dark and --rs-theme-flip css variables when theme is undefined
12
22
  * */
13
23
  export declare const withTheme: <P extends ThemeProps = ThemeProps>(wrappedComponent: React.ComponentType<P>) => React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<unknown>>;
24
+ export {};
@@ -15,19 +15,38 @@ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (
15
15
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
16
16
 
17
17
  import React, { createContext, useContext } from 'react';
18
- var ThemeContext = /*#__PURE__*/createContext('light');
18
+ var ThemeContext = /*#__PURE__*/createContext({
19
+ theme: 'light',
20
+ noProvider: true
21
+ });
19
22
  var ThemeConsumer = ThemeContext.Consumer;
20
23
 
21
24
  var getInverseTheme = function getInverseTheme(theme) {
22
25
  return theme === 'light' ? 'dark' : 'light';
23
26
  };
27
+ /**
28
+ * @deprecated please support --rs-theme-dark and --rs-theme-flip css variables and don't use react context for theme
29
+ * If you need to maintain backward compatibility use `useThemeWithUndefined` hook instead, rely on --rs-theme-dark and --rs-theme-flip css variables when theme is undefined
30
+ * */
31
+
24
32
 
25
33
  var useTheme = function useTheme(overwriteValue) {
26
- var themeFromContext = useContext(ThemeContext);
27
- return overwriteValue || themeFromContext;
34
+ var _useContext = useContext(ThemeContext),
35
+ theme = _useContext.theme;
36
+
37
+ return overwriteValue || theme;
38
+ };
39
+
40
+ var useThemeWithUndefined = function useThemeWithUndefined(overwriteValue) {
41
+ var _useContext2 = useContext(ThemeContext),
42
+ theme = _useContext2.theme,
43
+ noProvider = _useContext2.noProvider;
44
+
45
+ return overwriteValue || (noProvider ? undefined : theme);
28
46
  };
29
47
  /**
30
- * @deprecated use `useTheme` hook instead
48
+ * @deprecated please support --rs-theme-dark and --rs-theme-flip css variables and don't use react context for theme
49
+ * If you need to maintain backward compatibility use `useThemeWithUndefined` hook instead, rely on --rs-theme-dark and --rs-theme-flip css variables when theme is undefined
31
50
  * */
32
51
 
33
52
 
@@ -37,7 +56,8 @@ var withTheme = function withTheme(wrappedComponent) {
37
56
  var theme = _ref.theme,
38
57
  restProps = _objectWithoutProperties(_ref, _excluded);
39
58
 
40
- return /*#__PURE__*/React.createElement(ThemeConsumer, null, function (themeFromContext) {
59
+ return /*#__PURE__*/React.createElement(ThemeConsumer, null, function (_ref2) {
60
+ var themeFromContext = _ref2.theme;
41
61
  return /*#__PURE__*/React.createElement(WrappedComponent, _objectSpread({
42
62
  ref: ref,
43
63
  theme: theme || themeFromContext
@@ -48,4 +68,4 @@ var withTheme = function withTheme(wrappedComponent) {
48
68
  return ComponentWithTheme;
49
69
  };
50
70
 
51
- export { ThemeConsumer, ThemeContext, getInverseTheme, useTheme, withTheme };
71
+ export { ThemeConsumer, ThemeContext, getInverseTheme, useTheme, useThemeWithUndefined, withTheme };
@@ -3,12 +3,14 @@ import PropTypes from 'prop-types';
3
3
  import { Theme } from './parts/theme-context';
4
4
  export declare type ThemeProviderProps = {
5
5
  theme: Theme;
6
+ ignoreThemeValueForCSSApi?: boolean;
6
7
  children?: React.ReactNode;
7
8
  };
8
9
  declare const ThemeProvider: {
9
- ({ theme, children }: ThemeProviderProps): JSX.Element;
10
+ ({ theme, children, ignoreThemeValueForCSSApi }: ThemeProviderProps): JSX.Element;
10
11
  propTypes: {
11
12
  theme: PropTypes.Validator<string>;
13
+ ignoreThemeValueForCSSApi: PropTypes.Requireable<boolean>;
12
14
  };
13
15
  };
14
16
  export default ThemeProvider;
@@ -4,13 +4,19 @@ import { ThemeContext } from './parts/theme-context.js';
4
4
 
5
5
  var ThemeProvider = function ThemeProvider(_ref) {
6
6
  var theme = _ref.theme,
7
- children = _ref.children;
7
+ children = _ref.children,
8
+ _ref$ignoreThemeValue = _ref.ignoreThemeValueForCSSApi,
9
+ ignoreThemeValueForCSSApi = _ref$ignoreThemeValue === void 0 ? false : _ref$ignoreThemeValue;
8
10
  return /*#__PURE__*/React.createElement(ThemeContext.Provider, {
9
- value: theme
11
+ value: {
12
+ theme: theme,
13
+ noProvider: ignoreThemeValueForCSSApi
14
+ }
10
15
  }, children);
11
16
  };
12
17
 
13
18
  ThemeProvider.propTypes = {
14
- theme: PropTypes.oneOf(['light', 'dark']).isRequired
19
+ theme: PropTypes.oneOf(['light', 'dark']).isRequired,
20
+ ignoreThemeValueForCSSApi: PropTypes.bool
15
21
  };
16
22
  export { ThemeProvider as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rescui/ui-contexts",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "author": "JetBrains",
@@ -23,10 +23,10 @@
23
23
  "react": ">=16.8.0 <19"
24
24
  },
25
25
  "devDependencies": {
26
- "@rescui/scripts": "^0.2.3"
26
+ "@rescui/scripts": "^0.3.0"
27
27
  },
28
28
  "scripts": {
29
29
  "build": "rescui-scripts build"
30
30
  },
31
- "gitHead": "e21b6f80037993b094ceaff022db6d4cd176a88d"
31
+ "gitHead": "51da8a7188f4c558c563065a4ff4ef5c8e74994c"
32
32
  }