@kwantis-id3/frontend-library 0.2.2 → 0.2.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.
@@ -12,7 +12,7 @@ export type KwantisColorsObject = {
12
12
  statusCritical: string;
13
13
  statusNeutral: string;
14
14
  };
15
- export default function KwantisThemeContextProvider(props: React.PropsWithChildren<{
15
+ export declare const KwantisThemeContextProvider: (props: React.PropsWithChildren<{
16
16
  theme?: KwantisColorsObject;
17
- }>): JSX.Element;
17
+ }>) => JSX.Element;
18
18
  export declare const useKwantisThemeContext: () => KwantisColorsObject;
@@ -0,0 +1 @@
1
+ export { KwantisColors, KwantisColorsObject, KwantisThemeContextProvider, useKwantisThemeContext, } from "./ThemeContext";
@@ -1 +1,2 @@
1
1
  export { Button, ButtonProps } from "./button";
2
+ export { KwantisColors, KwantisColorsObject, KwantisThemeContextProvider, useKwantisThemeContext, } from "./ThemeContext";
package/dist/esm/index.js CHANGED
@@ -4794,6 +4794,41 @@ var useTheme = function useTheme() {
4794
4794
  return reactExports.useContext(ThemeContext);
4795
4795
  };
4796
4796
 
4797
+ var getTheme = function getTheme(outerTheme, theme) {
4798
+ if (typeof theme === 'function') {
4799
+ var mergedTheme = theme(outerTheme);
4800
+
4801
+ if (process.env.NODE_ENV !== 'production' && (mergedTheme == null || typeof mergedTheme !== 'object' || Array.isArray(mergedTheme))) {
4802
+ throw new Error('[ThemeProvider] Please return an object from your theme function, i.e. theme={() => ({})}!');
4803
+ }
4804
+
4805
+ return mergedTheme;
4806
+ }
4807
+
4808
+ if (process.env.NODE_ENV !== 'production' && (theme == null || typeof theme !== 'object' || Array.isArray(theme))) {
4809
+ throw new Error('[ThemeProvider] Please make your theme prop a plain object');
4810
+ }
4811
+
4812
+ return _extends({}, outerTheme, theme);
4813
+ };
4814
+
4815
+ var createCacheWithTheme = /* #__PURE__ */weakMemoize(function (outerTheme) {
4816
+ return weakMemoize(function (theme) {
4817
+ return getTheme(outerTheme, theme);
4818
+ });
4819
+ });
4820
+ var ThemeProvider = function ThemeProvider(props) {
4821
+ var theme = reactExports.useContext(ThemeContext);
4822
+
4823
+ if (props.theme !== theme) {
4824
+ theme = createCacheWithTheme(theme)(props.theme);
4825
+ }
4826
+
4827
+ return /*#__PURE__*/reactExports.createElement(ThemeContext.Provider, {
4828
+ value: theme
4829
+ }, props.children);
4830
+ };
4831
+
4797
4832
  var typePropName = '__EMOTION_TYPE_PLEASE_DO_NOT_USE__';
4798
4833
  var labelPropName = '__EMOTION_LABEL_PLEASE_DO_NOT_USE__';
4799
4834
 
@@ -4888,7 +4923,12 @@ const defaultThemeColors = {
4888
4923
  statusCritical: "#FF4040",
4889
4924
  statusNeutral: "#CCCCCC",
4890
4925
  };
4891
- React.createContext(defaultThemeColors);
4926
+ const KwantisThemeContext = React.createContext(defaultThemeColors);
4927
+ const KwantisThemeContextProvider = (props) => {
4928
+ const [themeColors] = reactExports.useState(props.theme || defaultThemeColors);
4929
+ return (React.createElement(KwantisThemeContext.Provider, { value: themeColors },
4930
+ React.createElement(ThemeProvider, { theme: themeColors }, props.children)));
4931
+ };
4892
4932
  const isEmpty = (obj) => {
4893
4933
  return Object.keys(obj).length === 0;
4894
4934
  };
@@ -5111,5 +5151,5 @@ const Button = (props) => {
5111
5151
  return reactExports.createElement(Button, null, props.label);
5112
5152
  };
5113
5153
 
5114
- export { Button };
5154
+ export { Button, KwantisThemeContextProvider, useKwantisThemeContext };
5115
5155
  //# sourceMappingURL=index.js.map