@mirohq/design-system-theme-provider 0.1.8

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/main.js ADDED
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var designSystemStitches = require('@mirohq/design-system-stitches');
7
+ var designSystemUseTheme = require('@mirohq/design-system-use-theme');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
12
+
13
+ const ThemeProvider = ({
14
+ defaultTheme,
15
+ themes,
16
+ children
17
+ }) => {
18
+ let themeToUse = "";
19
+ const { theme } = designSystemUseTheme.useTheme();
20
+ const defaultThemeExists = defaultTheme !== void 0 && (themes == null ? void 0 : themes[defaultTheme]) !== void 0;
21
+ const currentThemeExists = theme != null && (themes == null ? void 0 : themes[theme]) !== void 0;
22
+ if (!currentThemeExists && defaultThemeExists) {
23
+ console.warn("Set theme not found, setting the default theme.");
24
+ themeToUse = defaultTheme.toString();
25
+ }
26
+ if (!defaultThemeExists && theme == null) {
27
+ console.warn(
28
+ "Default theme not found, falling back to the Miro Design System basics."
29
+ );
30
+ }
31
+ if (currentThemeExists) {
32
+ themeToUse = theme;
33
+ }
34
+ const classNameTheme = (currentThemeExists || defaultThemeExists) && themeToUse !== "" ? designSystemStitches.createTheme(themes[themeToUse]) : "";
35
+ return /* @__PURE__ */ React__default["default"].createElement("div", {
36
+ "data-theme-provider": true,
37
+ className: classNameTheme
38
+ }, children);
39
+ };
40
+
41
+ exports.ThemeProvider = ThemeProvider;
42
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sources":["../src/theme-provider.tsx"],"sourcesContent":["import type { PropsWithChildren } from 'react'\nimport type * as themes from '@mirohq/design-system-themes'\nimport React from 'react'\nimport { createTheme } from '@mirohq/design-system-stitches'\nimport { useTheme } from '@mirohq/design-system-use-theme'\n\ninterface ThemesProp {\n [Key: string]: Partial<typeof themes.base>\n}\n\nexport interface ThemeProviderProps<Themes extends ThemesProp = ThemesProp> {\n /**\n * The default theme to use if no theme is provided.\n */\n defaultTheme?: keyof Themes\n\n /**\n * Theme config for all available themes.\n */\n themes?: Themes\n}\n\nexport const ThemeProvider = <Themes extends ThemesProp = ThemesProp>({\n defaultTheme,\n themes,\n children,\n}: PropsWithChildren<ThemeProviderProps<Themes>>): JSX.Element => {\n let themeToUse = ''\n const { theme } = useTheme()\n\n const defaultThemeExists =\n defaultTheme !== undefined && themes?.[defaultTheme] !== undefined\n\n const currentThemeExists = theme != null && themes?.[theme] !== undefined\n\n if (!currentThemeExists && defaultThemeExists) {\n console.warn('Set theme not found, setting the default theme.')\n themeToUse = defaultTheme.toString()\n }\n\n if (!defaultThemeExists && theme == null) {\n console.warn(\n 'Default theme not found, falling back to the Miro Design System basics.'\n )\n }\n\n if (currentThemeExists) {\n themeToUse = theme\n }\n\n const classNameTheme =\n (currentThemeExists || defaultThemeExists) && themeToUse !== ''\n ? createTheme(themes[themeToUse])\n : ''\n\n return (\n <div data-theme-provider className={classNameTheme}>\n {children}\n </div>\n )\n}\n"],"names":["useTheme","createTheme","React"],"mappings":";;;;;;;;;;;;AAsBO,MAAM,gBAAgB,CAAyC;AAAA,EACpE,YAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AACF,CAAkE,KAAA;AAChE,EAAA,IAAI,UAAa,GAAA,EAAA,CAAA;AACjB,EAAM,MAAA,EAAE,KAAM,EAAA,GAAIA,6BAAS,EAAA,CAAA;AAE3B,EAAA,MAAM,kBACJ,GAAA,YAAA,KAAiB,KAAa,CAAA,IAAA,CAAA,MAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,MAAA,CAAS,YAAkB,CAAA,MAAA,KAAA,CAAA,CAAA;AAE3D,EAAA,MAAM,kBAAqB,GAAA,KAAA,IAAS,IAAQ,IAAA,CAAA,MAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,MAAA,CAAS,KAAW,CAAA,MAAA,KAAA,CAAA,CAAA;AAEhE,EAAI,IAAA,CAAC,sBAAsB,kBAAoB,EAAA;AAC7C,IAAA,OAAA,CAAQ,KAAK,iDAAiD,CAAA,CAAA;AAC9D,IAAA,UAAA,GAAa,aAAa,QAAS,EAAA,CAAA;AAAA,GACrC;AAEA,EAAI,IAAA,CAAC,kBAAsB,IAAA,KAAA,IAAS,IAAM,EAAA;AACxC,IAAQ,OAAA,CAAA,IAAA;AAAA,MACN,yEAAA;AAAA,KACF,CAAA;AAAA,GACF;AAEA,EAAA,IAAI,kBAAoB,EAAA;AACtB,IAAa,UAAA,GAAA,KAAA,CAAA;AAAA,GACf;AAEA,EAAM,MAAA,cAAA,GAAA,CACH,sBAAsB,kBAAuB,KAAA,UAAA,KAAe,KACzDC,gCAAY,CAAA,MAAA,CAAO,WAAW,CAC9B,GAAA,EAAA,CAAA;AAEN,EAAA,uBACGC,yBAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAA,IAAI,qBAAmB,EAAA,IAAA;AAAA,IAAC,SAAW,EAAA,cAAA;AAAA,GAAA,EACjC,QACH,CAAA,CAAA;AAEJ;;;;"}
package/dist/module.js ADDED
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { createTheme } from '@mirohq/design-system-stitches';
3
+ import { useTheme } from '@mirohq/design-system-use-theme';
4
+
5
+ const ThemeProvider = ({
6
+ defaultTheme,
7
+ themes,
8
+ children
9
+ }) => {
10
+ let themeToUse = "";
11
+ const { theme } = useTheme();
12
+ const defaultThemeExists = defaultTheme !== void 0 && (themes == null ? void 0 : themes[defaultTheme]) !== void 0;
13
+ const currentThemeExists = theme != null && (themes == null ? void 0 : themes[theme]) !== void 0;
14
+ if (!currentThemeExists && defaultThemeExists) {
15
+ console.warn("Set theme not found, setting the default theme.");
16
+ themeToUse = defaultTheme.toString();
17
+ }
18
+ if (!defaultThemeExists && theme == null) {
19
+ console.warn(
20
+ "Default theme not found, falling back to the Miro Design System basics."
21
+ );
22
+ }
23
+ if (currentThemeExists) {
24
+ themeToUse = theme;
25
+ }
26
+ const classNameTheme = (currentThemeExists || defaultThemeExists) && themeToUse !== "" ? createTheme(themes[themeToUse]) : "";
27
+ return /* @__PURE__ */ React.createElement("div", {
28
+ "data-theme-provider": true,
29
+ className: classNameTheme
30
+ }, children);
31
+ };
32
+
33
+ export { ThemeProvider };
34
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sources":["../src/theme-provider.tsx"],"sourcesContent":["import type { PropsWithChildren } from 'react'\nimport type * as themes from '@mirohq/design-system-themes'\nimport React from 'react'\nimport { createTheme } from '@mirohq/design-system-stitches'\nimport { useTheme } from '@mirohq/design-system-use-theme'\n\ninterface ThemesProp {\n [Key: string]: Partial<typeof themes.base>\n}\n\nexport interface ThemeProviderProps<Themes extends ThemesProp = ThemesProp> {\n /**\n * The default theme to use if no theme is provided.\n */\n defaultTheme?: keyof Themes\n\n /**\n * Theme config for all available themes.\n */\n themes?: Themes\n}\n\nexport const ThemeProvider = <Themes extends ThemesProp = ThemesProp>({\n defaultTheme,\n themes,\n children,\n}: PropsWithChildren<ThemeProviderProps<Themes>>): JSX.Element => {\n let themeToUse = ''\n const { theme } = useTheme()\n\n const defaultThemeExists =\n defaultTheme !== undefined && themes?.[defaultTheme] !== undefined\n\n const currentThemeExists = theme != null && themes?.[theme] !== undefined\n\n if (!currentThemeExists && defaultThemeExists) {\n console.warn('Set theme not found, setting the default theme.')\n themeToUse = defaultTheme.toString()\n }\n\n if (!defaultThemeExists && theme == null) {\n console.warn(\n 'Default theme not found, falling back to the Miro Design System basics.'\n )\n }\n\n if (currentThemeExists) {\n themeToUse = theme\n }\n\n const classNameTheme =\n (currentThemeExists || defaultThemeExists) && themeToUse !== ''\n ? createTheme(themes[themeToUse])\n : ''\n\n return (\n <div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AAA,CAAA;AAEJ;;;;"}
@@ -0,0 +1,19 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import * as themes from '@mirohq/design-system-themes';
3
+
4
+ interface ThemesProp {
5
+ [Key: string]: Partial<typeof themes.base>;
6
+ }
7
+ interface ThemeProviderProps<Themes extends ThemesProp = ThemesProp> {
8
+ /**
9
+ * The default theme to use if no theme is provided.
10
+ */
11
+ defaultTheme?: keyof Themes;
12
+ /**
13
+ * Theme config for all available themes.
14
+ */
15
+ themes?: Themes;
16
+ }
17
+ declare const ThemeProvider: <Themes extends ThemesProp = ThemesProp>({ defaultTheme, themes, children, }: PropsWithChildren<ThemeProviderProps<Themes>>) => JSX.Element;
18
+
19
+ export { ThemeProvider, ThemeProviderProps };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@mirohq/design-system-theme-provider",
3
+ "version": "0.1.8",
4
+ "author": "Miro",
5
+ "source": "src/index.ts",
6
+ "main": "dist/main.js",
7
+ "module": "dist/module.js",
8
+ "types": "dist/types.d.ts",
9
+ "sideEffects": false,
10
+ "exports": {
11
+ ".": {
12
+ "require": "./dist/main.js",
13
+ "import": "./dist/module.js",
14
+ "types": "./dist/types.d.ts"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "peerDependencies": {
24
+ "@stitches/react": "^1.2.8",
25
+ "react": "^16.14 || ^17"
26
+ },
27
+ "dependencies": {
28
+ "@mirohq/design-system-stitches": "^2.0.8",
29
+ "@mirohq/design-system-themes": "^0.1.5",
30
+ "@mirohq/design-system-use-theme": "^0.1.0",
31
+ "@mirohq/design-system-types": "^0.2.0"
32
+ },
33
+ "devDependencies": {
34
+ "@mirohq/design-system-button": "^2.0.11",
35
+ "@mirohq/design-system-box": "^2.0.9"
36
+ },
37
+ "scripts": {
38
+ "build": "rollup -c ../../../rollup.config.js",
39
+ "clean": "rm -rf dist",
40
+ "prebuild": "pnpm clean"
41
+ }
42
+ }