@draftbit/theme 49.5.1-312cdf.2

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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/lib/commonjs/DefaultTheme.js +1 -0
  4. package/lib/commonjs/Provider.js +1 -0
  5. package/lib/commonjs/createTheme.js +1 -0
  6. package/lib/commonjs/createThemeValuesProxy.js +1 -0
  7. package/lib/commonjs/index.js +1 -0
  8. package/lib/commonjs/types.js +0 -0
  9. package/lib/commonjs/validators.js +1 -0
  10. package/lib/typescript/src/DefaultTheme.d.ts +2 -0
  11. package/lib/typescript/src/DefaultTheme.js +146 -0
  12. package/lib/typescript/src/DefaultTheme.js.map +1 -0
  13. package/lib/typescript/src/Provider.d.ts +14 -0
  14. package/lib/typescript/src/Provider.js +55 -0
  15. package/lib/typescript/src/Provider.js.map +1 -0
  16. package/lib/typescript/src/createTheme.d.ts +7 -0
  17. package/lib/typescript/src/createTheme.js +17 -0
  18. package/lib/typescript/src/createTheme.js.map +1 -0
  19. package/lib/typescript/src/createThemeValuesProxy.d.ts +10 -0
  20. package/lib/typescript/src/createThemeValuesProxy.js +96 -0
  21. package/lib/typescript/src/createThemeValuesProxy.js.map +1 -0
  22. package/lib/typescript/src/index.d.ts +4 -0
  23. package/lib/typescript/src/index.js +4 -0
  24. package/lib/typescript/src/index.js.map +1 -0
  25. package/lib/typescript/src/types.d.ts +37 -0
  26. package/lib/typescript/src/types.js +2 -0
  27. package/lib/typescript/src/types.js.map +1 -0
  28. package/lib/typescript/src/validators.d.ts +4 -0
  29. package/lib/typescript/src/validators.js +52 -0
  30. package/lib/typescript/src/validators.js.map +1 -0
  31. package/lib/typescript/tsconfig.tsbuildinfo +1 -0
  32. package/package.json +67 -0
  33. package/src/DefaultTheme.js +146 -0
  34. package/src/DefaultTheme.js.map +1 -0
  35. package/src/DefaultTheme.ts +149 -0
  36. package/src/Provider.js +55 -0
  37. package/src/Provider.js.map +1 -0
  38. package/src/Provider.tsx +124 -0
  39. package/src/createTheme.js +17 -0
  40. package/src/createTheme.js.map +1 -0
  41. package/src/createTheme.ts +40 -0
  42. package/src/createThemeValuesProxy.js +96 -0
  43. package/src/createThemeValuesProxy.js.map +1 -0
  44. package/src/createThemeValuesProxy.ts +156 -0
  45. package/src/index.js +4 -0
  46. package/src/index.js.map +1 -0
  47. package/src/index.ts +15 -0
  48. package/src/types.js +2 -0
  49. package/src/types.js.map +1 -0
  50. package/src/types.ts +41 -0
  51. package/src/validators.js +52 -0
  52. package/src/validators.js.map +1 -0
  53. package/src/validators.ts +59 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Draftbit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @draftbit/theme
@@ -0,0 +1 @@
1
+ import{systemWeights}from"react-native-typography";import createTheme from"./createTheme";var palettes={draftbit:{primary:"rgb(90, 69, 255)",secondary:"rgb(59, 201, 234)",tertiary:"rgb(90,69,255)",background:"rgba(251, 252, 253, 1)",error:"rgba(255, 69, 100, 1)",divider:"rgba(200, 200, 200, 1)",strong:"rgba(18, 20, 44, 1)",medium:"rgba(70, 78, 88, 1)",light:"rgba(165, 173, 183, 1)",text:"#000",success:"#22bb33",warning:"#f0ad4e",info:"#aaaaaa"}};var DraftbitTheme=createTheme({breakpoints:{},palettes:palettes,theme:{name:"Draftbit",colors:{branding:{primary:palettes.draftbit.primary,secondary:palettes.draftbit.secondary,tertiary:palettes.draftbit.tertiary,accent:palettes.draftbit.accent},text:{strong:palettes.draftbit.strong,medium:palettes.draftbit.medium,normal:palettes.draftbit.text,light:palettes.draftbit.light,success:palettes.draftbit.success,warning:palettes.draftbit.warning,danger:palettes.draftbit.error},background:{brand:palettes.draftbit.background,info:palettes.draftbit.info,success:palettes.draftbit.success,warning:palettes.draftbit.warning,danger:palettes.draftbit.error},foreground:{brand:palettes.draftbit.light,info:palettes.draftbit.strong,success:palettes.draftbit.light,warning:palettes.draftbit.light,danger:palettes.draftbit.light},border:{brand:palettes.draftbit.divider,info:palettes.draftbit.divider,success:palettes.draftbit.divider,warning:palettes.draftbit.divider,danger:palettes.draftbit.divider}},typography:{headline1:Object.assign({},systemWeights.regular,{fontSize:60,letterSpacing:0,lineHeight:71}),headline2:Object.assign({},systemWeights.regular,{fontSize:48,letterSpacing:0,lineHeight:58}),headline3:Object.assign({},systemWeights.regular,{fontSize:34,letterSpacing:0,lineHeight:40}),headline4:Object.assign({},systemWeights.regular,{fontSize:24,letterSpacing:0,lineHeight:34}),headline5:Object.assign({},systemWeights.regular,{fontSize:20,letterSpacing:0,lineHeight:26}),subtitle1:Object.assign({},systemWeights.regular,{fontSize:16,letterSpacing:0,lineHeight:26}),subtitle2:Object.assign({},systemWeights.regular,{fontSize:14,letterSpacing:0,lineHeight:22}),body1:Object.assign({},systemWeights.regular,{fontSize:16,letterSpacing:0,lineHeight:26}),body2:Object.assign({},systemWeights.regular,{fontSize:14,letterSpacing:0,lineHeight:22}),button:Object.assign({},systemWeights.regular,{fontSize:14,letterSpacing:0,lineHeight:16}),caption:Object.assign({},systemWeights.regular,{fontSize:12,letterSpacing:0,lineHeight:16}),overline:Object.assign({},systemWeights.regular,{fontSize:12,letterSpacing:2,lineHeight:16}),headline6:Object.assign({},systemWeights.regular,{fontSize:16,letterSpacing:0,lineHeight:24})}}});export default DraftbitTheme;
@@ -0,0 +1 @@
1
+ import _slicedToArray from"@babel/runtime/helpers/slicedToArray";var _this=this,_jsxFileName="/home/runner/work/react-native-jigsaw/react-native-jigsaw/packages/theme/src/Provider.tsx";import React from"react";import{Dimensions,Platform}from"react-native";import createThemeValuesProxy from"./createThemeValuesProxy";import DefaultTheme from"./DefaultTheme";import{jsx as _jsx}from"react/jsx-runtime";var ThemeContext=React.createContext({theme:DefaultTheme,changeTheme:function changeTheme(){}});var Provider=function Provider(_ref){var _themes$find;var themes=_ref.themes,breakpoints=_ref.breakpoints,initialThemeName=_ref.initialThemeName,children=_ref.children;var initialTheme=(_themes$find=themes.find(function(theme){return theme.name===initialThemeName;}))!=null?_themes$find:DefaultTheme;var _React$useState=React.useState(initialTheme),_React$useState2=_slicedToArray(_React$useState,2),currentTheme=_React$useState2[0],setCurrentTheme=_React$useState2[1];var _React$useState3=React.useState(Dimensions.get("window").width),_React$useState4=_slicedToArray(_React$useState3,2),deviceWidth=_React$useState4[0],setDeviceWidth=_React$useState4[1];React.useEffect(function(){var listener=Dimensions.addEventListener("change",function(_ref2){var window=_ref2.window;return setDeviceWidth(window.width);});return function(){listener.remove();};});var changeTheme=function changeTheme(themeName){var theme=themes.find(function(theme){return theme.name===themeName;});if(!theme){console.warn("Theme with name",themeName,"not found. Make sure it's passed into the top level ThemeProvider");return;}setCurrentTheme(theme);};var proxiedTheme=React.useMemo(function(){return Object.assign({},currentTheme,{colors:{branding:createThemeValuesProxy(currentTheme.colors.branding,breakpoints,deviceWidth,Platform.OS),text:createThemeValuesProxy(currentTheme.colors.text,breakpoints,deviceWidth,Platform.OS),background:createThemeValuesProxy(currentTheme.colors.background,breakpoints,deviceWidth,Platform.OS),foreground:createThemeValuesProxy(currentTheme.colors.foreground,breakpoints,deviceWidth,Platform.OS),border:createThemeValuesProxy(currentTheme.colors.border,breakpoints,deviceWidth,Platform.OS)}});},[currentTheme,deviceWidth,breakpoints]);return _jsx(ThemeContext.Provider,{value:{theme:proxiedTheme,changeTheme:changeTheme},children:children});};var useTheme=function useTheme(){var _React$useContext=React.useContext(ThemeContext),theme=_React$useContext.theme;return theme;};var useChangeTheme=function useChangeTheme(){var _React$useContext2=React.useContext(ThemeContext),changeTheme=_React$useContext2.changeTheme;return changeTheme;};var withTheme=function withTheme(Component){return function(props){var _React$useContext3=React.useContext(ThemeContext),theme=_React$useContext3.theme;return _jsx(Component,Object.assign({},props,{theme:theme}));};};export{Provider,useTheme,useChangeTheme,withTheme};
@@ -0,0 +1 @@
1
+ import merge from"deepmerge";import{validateBreakpoints,validatePalettes,validateTheme}from"./validators";export default function createTheme(_ref){var breakpoints=_ref.breakpoints,palettes=_ref.palettes,theme=_ref.theme,baseTheme=_ref.baseTheme;validateBreakpoints(breakpoints);validatePalettes(palettes);validateTheme(theme);var resultTheme=theme;if(baseTheme){validateTheme(baseTheme);resultTheme=merge(baseTheme,theme);}return Object.assign({},resultTheme,{validated:true});}
@@ -0,0 +1 @@
1
+ import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import{isObject}from"lodash";export default function createThemeValuesProxy(value,breakpoints,deviceWidth,devicePlatform){if(value===undefined||value===null){return undefined;}return new Proxy(value,{get:function get(target,key){var currentValue=target[key];if(!isObject(currentValue)){return currentValue;}else{var platformKeys=["ios","android","web","macos","windows"];var breakpointKeys=Object.keys(breakpoints);var keysType=getKeysType(currentValue,platformKeys,breakpointKeys);if(keysType==="default"){return createThemeValuesProxy(currentValue,breakpoints,deviceWidth,devicePlatform);}else if(keysType==="platform"){return getPlatformValue(currentValue,breakpoints,deviceWidth,devicePlatform);}else if(keysType==="breakpoint"){return getBreakpointValue(currentValue,breakpoints,deviceWidth,devicePlatform);}else{return undefined;}}},set:function set(){throw new Error("Theme is read only, cannot be modified at runtime");}});}function getKeysType(value,platformKeys,breakpointKeys){var hasPlatformKeys=platformKeys.some(function(key){return value[key]!==undefined;});var hasBreakpointKeys=breakpointKeys.some(function(key){return value[key]!==undefined;});var hasUserDefinedKeys=Object.keys(value).some(function(key){return!platformKeys.includes(key)&&!breakpointKeys.includes(key)&&key!=="default";});if(!onlyOneTrue(hasPlatformKeys,hasBreakpointKeys,hasUserDefinedKeys)&&!allFalse(hasPlatformKeys,hasBreakpointKeys,hasUserDefinedKeys)){throw new Error("Cannot mix usage of platform keys, breakpoint keys, and custom defined keys on the same level");}else if(hasPlatformKeys){return"platform";}else if(hasBreakpointKeys){return"breakpoint";}else{return"default";}}function onlyOneTrue(a,b,c){return[a,b,c].filter(function(x){return x;}).length===1;}function allFalse(a,b,c){return[a,b,c].filter(function(x){return x;}).length===0;}function getPlatformValue(value,breakpoints,deviceWidth,devicePlatform){var _value$devicePlatform;var currentPlatformValue=(_value$devicePlatform=value[devicePlatform])!=null?_value$devicePlatform:value.default;if(!isObject(currentPlatformValue)){return currentPlatformValue;}else{return createThemeValuesProxy(currentPlatformValue,breakpoints,deviceWidth,devicePlatform);}}function getBreakpointValue(value,breakpoints,deviceWidth,devicePlatform){var _value$currentBreakpo;var keysToBreakpointValue=Object.keys(value).map(function(key){return[key,breakpoints[key]];});var orderedBreakpoints=keysToBreakpointValue.sort(function(_ref){var _ref2=_slicedToArray(_ref,2),_=_ref2[0],val=_ref2[1];return val;});var currentBreakpointKey="";for(var _ref3 of orderedBreakpoints){var _ref4=_slicedToArray(_ref3,2);var breakpointKey=_ref4[0];var breakpointValue=_ref4[1];if(deviceWidth>=breakpointValue){currentBreakpointKey=breakpointKey;}}var currentBreakpointValue=(_value$currentBreakpo=value[currentBreakpointKey])!=null?_value$currentBreakpo:value.default;if(!isObject(currentBreakpointValue)){return currentBreakpointValue;}else{return createThemeValuesProxy(currentBreakpointValue,breakpoints,deviceWidth,devicePlatform);}}
@@ -0,0 +1 @@
1
+ export{default as DefaultTheme}from"./DefaultTheme";export{default as createTheme}from"./createTheme";export{Provider as ThemeProvider,useChangeTheme,useTheme,withTheme}from"./Provider";
File without changes
@@ -0,0 +1 @@
1
+ import _slicedToArray from"@babel/runtime/helpers/slicedToArray";export function validatePalettes(palettes){for(var key of Object.keys(palettes)){if(typeof key!=="string"){throw new Error(`Invalid palettes object, ${key} is not a string`);}for(var _ref of Object.entries(palettes[key])){var _ref2=_slicedToArray(_ref,2);var innerKey=_ref2[0];var value=_ref2[1];if(typeof innerKey!=="string"){throw new Error(`Invalid palette color key, ${innerKey} is not a string`);}if(typeof value!=="string"){throw new Error(`Invalid palette color value, ${value} is not a string`);}}}}export function validateBreakpoints(breakpoints){for(var _ref3 of Object.entries(breakpoints)){var _ref4=_slicedToArray(_ref3,2);var key=_ref4[0];var value=_ref4[1];if(typeof key!=="string"){throw new Error(`Invalid breakpoint key, ${key} is not a string`);}if(typeof value!=="number"){throw new Error(`Invalid breakpoint value, ${value} is not a number`);}}}export function validateTheme(theme){function validateThemeValues(themeValue){if(themeValue===undefined||themeValue===null){return;}for(var _ref5 of Object.entries(themeValue)){var _ref6=_slicedToArray(_ref5,2);var key=_ref6[0];var value=_ref6[1];if(typeof key!=="string"){throw new Error(`Invalid theme key, ${key} is not a string`);}if(value===undefined||value===null){continue;}else if(typeof value==="object"){validateThemeValues(value);}else if(typeof value!=="string"&&typeof value!=="number"){throw new Error(`Invalid theme value, ${value} is not a string, number, or object`);}}}validateThemeValues(theme.colors.branding);validateThemeValues(theme.colors.text);validateThemeValues(theme.colors.foreground);validateThemeValues(theme.colors.background);validateThemeValues(theme.colors.border);}
@@ -0,0 +1,2 @@
1
+ declare const DraftbitTheme: import("./types").ValidatedTheme;
2
+ export default DraftbitTheme;
@@ -0,0 +1,146 @@
1
+ import { systemWeights } from "react-native-typography";
2
+ import createTheme from "./createTheme";
3
+ const palettes = {
4
+ draftbit: {
5
+ primary: "rgb(90, 69, 255)",
6
+ secondary: "rgb(59, 201, 234)",
7
+ tertiary: "rgb(90,69,255)",
8
+ background: "rgba(251, 252, 253, 1)",
9
+ error: "rgba(255, 69, 100, 1)",
10
+ divider: "rgba(200, 200, 200, 1)",
11
+ strong: "rgba(18, 20, 44, 1)",
12
+ medium: "rgba(70, 78, 88, 1)",
13
+ light: "rgba(165, 173, 183, 1)",
14
+ text: "#000",
15
+ success: "#22bb33",
16
+ warning: "#f0ad4e",
17
+ info: "#aaaaaa",
18
+ },
19
+ };
20
+ const DraftbitTheme = createTheme({
21
+ breakpoints: {},
22
+ palettes,
23
+ theme: {
24
+ name: "Draftbit",
25
+ colors: {
26
+ branding: {
27
+ primary: palettes.draftbit.primary,
28
+ secondary: palettes.draftbit.secondary,
29
+ tertiary: palettes.draftbit.tertiary,
30
+ accent: palettes.draftbit.accent,
31
+ },
32
+ text: {
33
+ strong: palettes.draftbit.strong,
34
+ medium: palettes.draftbit.medium,
35
+ normal: palettes.draftbit.text,
36
+ light: palettes.draftbit.light,
37
+ success: palettes.draftbit.success,
38
+ warning: palettes.draftbit.warning,
39
+ danger: palettes.draftbit.error,
40
+ },
41
+ background: {
42
+ brand: palettes.draftbit.background,
43
+ info: palettes.draftbit.info,
44
+ success: palettes.draftbit.success,
45
+ warning: palettes.draftbit.warning,
46
+ danger: palettes.draftbit.error,
47
+ },
48
+ foreground: {
49
+ brand: palettes.draftbit.light,
50
+ info: palettes.draftbit.strong,
51
+ success: palettes.draftbit.light,
52
+ warning: palettes.draftbit.light,
53
+ danger: palettes.draftbit.light,
54
+ },
55
+ border: {
56
+ brand: palettes.draftbit.divider,
57
+ info: palettes.draftbit.divider,
58
+ success: palettes.draftbit.divider,
59
+ warning: palettes.draftbit.divider,
60
+ danger: palettes.draftbit.divider,
61
+ },
62
+ },
63
+ typography: {
64
+ headline1: {
65
+ ...systemWeights.regular,
66
+ fontSize: 60,
67
+ letterSpacing: 0,
68
+ lineHeight: 71,
69
+ },
70
+ headline2: {
71
+ ...systemWeights.regular,
72
+ fontSize: 48,
73
+ letterSpacing: 0,
74
+ lineHeight: 58,
75
+ },
76
+ headline3: {
77
+ ...systemWeights.regular,
78
+ fontSize: 34,
79
+ letterSpacing: 0,
80
+ lineHeight: 40,
81
+ },
82
+ headline4: {
83
+ ...systemWeights.regular,
84
+ fontSize: 24,
85
+ letterSpacing: 0,
86
+ lineHeight: 34,
87
+ },
88
+ headline5: {
89
+ ...systemWeights.regular,
90
+ fontSize: 20,
91
+ letterSpacing: 0,
92
+ lineHeight: 26,
93
+ },
94
+ subtitle1: {
95
+ ...systemWeights.regular,
96
+ fontSize: 16,
97
+ letterSpacing: 0,
98
+ lineHeight: 26,
99
+ },
100
+ subtitle2: {
101
+ ...systemWeights.regular,
102
+ fontSize: 14,
103
+ letterSpacing: 0,
104
+ lineHeight: 22,
105
+ },
106
+ body1: {
107
+ ...systemWeights.regular,
108
+ fontSize: 16,
109
+ letterSpacing: 0,
110
+ lineHeight: 26,
111
+ },
112
+ body2: {
113
+ ...systemWeights.regular,
114
+ fontSize: 14,
115
+ letterSpacing: 0,
116
+ lineHeight: 22,
117
+ },
118
+ button: {
119
+ ...systemWeights.regular,
120
+ fontSize: 14,
121
+ letterSpacing: 0,
122
+ lineHeight: 16,
123
+ },
124
+ caption: {
125
+ ...systemWeights.regular,
126
+ fontSize: 12,
127
+ letterSpacing: 0,
128
+ lineHeight: 16,
129
+ },
130
+ overline: {
131
+ ...systemWeights.regular,
132
+ fontSize: 12,
133
+ letterSpacing: 2,
134
+ lineHeight: 16,
135
+ },
136
+ headline6: {
137
+ ...systemWeights.regular,
138
+ fontSize: 16,
139
+ letterSpacing: 0,
140
+ lineHeight: 24,
141
+ },
142
+ },
143
+ },
144
+ });
145
+ export default DraftbitTheme;
146
+ //# sourceMappingURL=DefaultTheme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,EAAE;gBACZ,aAAa,EAAE,CAAC;gBAChB,UAAU,EAAE,EAAE;aACf;YACD,SAAS,EAAE;gBACT,GAAG,aAAa,CAAC,OAAO;gBACxB,QAAQ,EAAE,EAAE;gBACZ,aAAa,EAAE,CAAC;gBAChB,UAAU,EAAE,EAAE;aACf;SACF;KACF;CACF,CAAC,CAAC;AAEH,eAAe,aAAa,CAAC"}
@@ -0,0 +1,14 @@
1
+ import React from "react";
2
+ import { Breakpoints, ReadTheme, ValidatedTheme } from "./types";
3
+ declare type ProviderProps = {
4
+ themes: ValidatedTheme[];
5
+ breakpoints: Breakpoints;
6
+ initialThemeName: string;
7
+ };
8
+ declare const Provider: React.FC<React.PropsWithChildren<ProviderProps>>;
9
+ declare const useTheme: () => ReadTheme;
10
+ declare const useChangeTheme: () => (themeName: string) => void;
11
+ declare const withTheme: <Props extends {
12
+ theme: ReadTheme;
13
+ }>(Component: React.ComponentType<Props>) => React.ComponentType<Omit<Props, "theme">>;
14
+ export { Provider, useTheme, useChangeTheme, withTheme };
@@ -0,0 +1,55 @@
1
+ import React from "react";
2
+ import { Dimensions, Platform } from "react-native";
3
+ import createThemeValuesProxy from "./createThemeValuesProxy";
4
+ import DefaultTheme from "./DefaultTheme";
5
+ const ThemeContext = React.createContext({
6
+ theme: DefaultTheme,
7
+ changeTheme: () => { },
8
+ });
9
+ const Provider = ({ themes, breakpoints, initialThemeName, children, }) => {
10
+ var _a;
11
+ const initialTheme = (_a = themes.find((theme) => theme.name === initialThemeName)) !== null && _a !== void 0 ? _a : DefaultTheme;
12
+ const [currentTheme, setCurrentTheme] = React.useState(initialTheme);
13
+ const [deviceWidth, setDeviceWidth] = React.useState(Dimensions.get("window").width);
14
+ React.useEffect(() => {
15
+ const listener = Dimensions.addEventListener("change", ({ window }) => setDeviceWidth(window.width));
16
+ return () => {
17
+ listener.remove();
18
+ };
19
+ });
20
+ const changeTheme = (themeName) => {
21
+ const theme = themes.find((theme) => theme.name === themeName);
22
+ if (!theme) {
23
+ console.warn("Theme with name", themeName, "not found. Make sure it's passed into the top level ThemeProvider");
24
+ return;
25
+ }
26
+ setCurrentTheme(theme);
27
+ };
28
+ const proxiedTheme = React.useMemo(() => ({
29
+ ...currentTheme,
30
+ colors: {
31
+ branding: createThemeValuesProxy(currentTheme.colors.branding, breakpoints, deviceWidth, Platform.OS),
32
+ text: createThemeValuesProxy(currentTheme.colors.text, breakpoints, deviceWidth, Platform.OS),
33
+ background: createThemeValuesProxy(currentTheme.colors.background, breakpoints, deviceWidth, Platform.OS),
34
+ foreground: createThemeValuesProxy(currentTheme.colors.foreground, breakpoints, deviceWidth, Platform.OS),
35
+ border: createThemeValuesProxy(currentTheme.colors.border, breakpoints, deviceWidth, Platform.OS),
36
+ },
37
+ }), [currentTheme, deviceWidth, breakpoints]);
38
+ return (React.createElement(ThemeContext.Provider, { value: { theme: proxiedTheme, changeTheme } }, children));
39
+ };
40
+ const useTheme = () => {
41
+ const { theme } = React.useContext(ThemeContext);
42
+ return theme;
43
+ };
44
+ const useChangeTheme = () => {
45
+ const { changeTheme } = React.useContext(ThemeContext);
46
+ return changeTheme;
47
+ };
48
+ const withTheme = (Component) => {
49
+ return (props) => {
50
+ const { theme } = React.useContext(ThemeContext);
51
+ return React.createElement(Component, { ...props, theme: theme });
52
+ };
53
+ };
54
+ export { Provider, useTheme, useChangeTheme, withTheme };
55
+ //# sourceMappingURL=Provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../src/Provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,sBAAsB,MAAM,0BAA0B,CAAC;AAC9D,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAQ1C,MAAM,YAAY,GAAG,KAAK,CAAC,aAAa,CAAmB;IACzD,KAAK,EAAE,YAAY;IACnB,WAAW,EAAE,GAA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AAE;QACrC,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;QACjD,OAAO,oBAAC,SAAS,OAAM,KAAe,EAAE,KAAK,EAAE,KAAK,GAAI,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Breakpoints, Theme, ValidatedTheme, ColorPalettes } from "./types";
2
+ export default function createTheme({ breakpoints, palettes, theme, baseTheme, }: {
3
+ breakpoints: Breakpoints;
4
+ palettes: ColorPalettes;
5
+ theme: Theme;
6
+ baseTheme?: Theme;
7
+ }): ValidatedTheme;
@@ -0,0 +1,17 @@
1
+ import merge from "deepmerge";
2
+ import { validateBreakpoints, validatePalettes, validateTheme, } from "./validators";
3
+ export default function createTheme({ breakpoints, palettes, theme, baseTheme, }) {
4
+ validateBreakpoints(breakpoints);
5
+ validatePalettes(palettes);
6
+ validateTheme(theme);
7
+ let resultTheme = theme;
8
+ if (baseTheme) {
9
+ validateTheme(baseTheme);
10
+ resultTheme = merge(baseTheme, theme);
11
+ }
12
+ return {
13
+ ...resultTheme,
14
+ validated: true,
15
+ };
16
+ }
17
+ //# sourceMappingURL=createTheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTheme.js","sourceRoot":"","sources":["../../../src/createTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,WAAW,CAAC;AAO9B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,WAAW,EACX,QAAQ,EACR,KAAK,EACL,SAAS,GAMV;IACC,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACjC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC3B,aAAa,CAAC,KAAK,CAAC,CAAC;IAErB,IAAI,WAAW,GAAG,KAAK,CAAC;IAExB,IAAI,SAAS,EAAE;QACb,aAAa,CAAC,SAAS,CAAC,CAAC;QACzB,WAAW,GAAG,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;KACvC;IAED,OAAO;QACL,GAAG,WAAW;QACd,SAAS,EAAE,IAAI;KAChB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { ThemeValues, Breakpoints } from "./types";
2
+ import { Platform } from "react-native";
3
+ /**
4
+ * Creates a proxy for theme value objects to select a value whenever
5
+ * multiple values are provided for different platforms and/or breakpoints
6
+ *
7
+ * Ex: {color: {ios: "blue", android: "red"}}
8
+ * -> theme.color returns "blue" when the platform is ios and "red" when android
9
+ */
10
+ export default function createThemeValuesProxy(value: ThemeValues | undefined, breakpoints: Breakpoints, deviceWidth: number, devicePlatform: typeof Platform.OS): any;
@@ -0,0 +1,96 @@
1
+ import { isObject } from "lodash";
2
+ /**
3
+ * Creates a proxy for theme value objects to select a value whenever
4
+ * multiple values are provided for different platforms and/or breakpoints
5
+ *
6
+ * Ex: {color: {ios: "blue", android: "red"}}
7
+ * -> theme.color returns "blue" when the platform is ios and "red" when android
8
+ */
9
+ export default function createThemeValuesProxy(value, breakpoints, deviceWidth, devicePlatform) {
10
+ if (value === undefined || value === null) {
11
+ return undefined;
12
+ }
13
+ return new Proxy(value, {
14
+ get: (target, key) => {
15
+ const currentValue = target[key];
16
+ if (!isObject(currentValue)) {
17
+ return currentValue;
18
+ }
19
+ else {
20
+ const platformKeys = ["ios", "android", "web", "macos", "windows"];
21
+ const breakpointKeys = Object.keys(breakpoints);
22
+ const keysType = getKeysType(currentValue, platformKeys, breakpointKeys);
23
+ if (keysType === "default") {
24
+ return createThemeValuesProxy(currentValue, breakpoints, deviceWidth, devicePlatform);
25
+ }
26
+ else if (keysType === "platform") {
27
+ return getPlatformValue(currentValue, breakpoints, deviceWidth, devicePlatform);
28
+ }
29
+ else if (keysType === "breakpoint") {
30
+ return getBreakpointValue(currentValue, breakpoints, deviceWidth, devicePlatform);
31
+ }
32
+ else {
33
+ return undefined;
34
+ }
35
+ }
36
+ },
37
+ set: () => {
38
+ throw new Error("Theme is read only, cannot be modified at runtime");
39
+ },
40
+ });
41
+ }
42
+ function getKeysType(value, platformKeys, breakpointKeys) {
43
+ const hasPlatformKeys = platformKeys.some((key) => value[key] !== undefined);
44
+ const hasBreakpointKeys = breakpointKeys.some((key) => value[key] !== undefined);
45
+ const hasUserDefinedKeys = Object.keys(value).some((key) => !platformKeys.includes(key) &&
46
+ !breakpointKeys.includes(key) &&
47
+ key !== "default");
48
+ if (!onlyOneTrue(hasPlatformKeys, hasBreakpointKeys, hasUserDefinedKeys) &&
49
+ !allFalse(hasPlatformKeys, hasBreakpointKeys, hasUserDefinedKeys)) {
50
+ throw new Error("Cannot mix usage of platform keys, breakpoint keys, and custom defined keys on the same level");
51
+ }
52
+ else if (hasPlatformKeys) {
53
+ return "platform";
54
+ }
55
+ else if (hasBreakpointKeys) {
56
+ return "breakpoint";
57
+ }
58
+ else {
59
+ return "default";
60
+ }
61
+ }
62
+ function onlyOneTrue(a, b, c) {
63
+ return [a, b, c].filter((x) => x).length === 1;
64
+ }
65
+ function allFalse(a, b, c) {
66
+ return [a, b, c].filter((x) => x).length === 0;
67
+ }
68
+ function getPlatformValue(value, breakpoints, deviceWidth, devicePlatform) {
69
+ var _a;
70
+ const currentPlatformValue = (_a = value[devicePlatform]) !== null && _a !== void 0 ? _a : value.default;
71
+ if (!isObject(currentPlatformValue)) {
72
+ return currentPlatformValue;
73
+ }
74
+ else {
75
+ return createThemeValuesProxy(currentPlatformValue, breakpoints, deviceWidth, devicePlatform);
76
+ }
77
+ }
78
+ function getBreakpointValue(value, breakpoints, deviceWidth, devicePlatform) {
79
+ var _a;
80
+ const keysToBreakpointValue = Object.keys(value).map((key) => [key, breakpoints[key]]);
81
+ const orderedBreakpoints = keysToBreakpointValue.sort(([_, val]) => val);
82
+ let currentBreakpointKey = "";
83
+ for (const [breakpointKey, breakpointValue] of orderedBreakpoints) {
84
+ if (deviceWidth >= breakpointValue) {
85
+ currentBreakpointKey = breakpointKey;
86
+ }
87
+ }
88
+ const currentBreakpointValue = (_a = value[currentBreakpointKey]) !== null && _a !== void 0 ? _a : value.default;
89
+ if (!isObject(currentBreakpointValue)) {
90
+ return currentBreakpointValue;
91
+ }
92
+ else {
93
+ return createThemeValuesProxy(currentBreakpointValue, breakpoints, deviceWidth, devicePlatform);
94
+ }
95
+ }
96
+ //# sourceMappingURL=createThemeValuesProxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createThemeValuesProxy.js","sourceRoot":"","sources":["../../../src/createThemeValuesProxy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,KAA8B,EAC9B,WAAwB,EACxB,WAAmB,EACnB,cAAkC;IAElC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE;QACzC,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE;QACtB,GAAG,EAAE,CACH,MAAmB,EACnB,GAAW,EACgC,EAAE;YAC7C,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YACjC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;gBAC3B,OAAO,YAAY,CAAC;aACrB;iBAAM;gBACL,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;gBACnE,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBAChD,MAAM,QAAQ,GAAG,WAAW,CAC1B,YAAY,EACZ,YAAY,EACZ,cAAc,CACf,CAAC;gBAEF,IAAI,QAAQ,KAAK,SAAS,E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AAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;IACzE,IAAI,oBAAoB,GAAG,EAAE,CAAC;IAC9B,KAAK,MAAM,CAAC,aAAa,EAAE,eAAe,CAAC,IAAI,kBAAkB,EAAE;QACjE,IAAI,WAAW,IAAI,eAAe,EAAE;YAClC,oBAAoB,GAAG,aAAa,CAAC;SACtC;KACF;IACD,MAAM,sBAAsB,GAAG,MAAA,KAAK,CAAC,oBAAoB,CAAC,mCAAI,KAAK,CAAC,OAAO,CAAC;IAC5E,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE;QACrC,OAAO,sBAAsB,CAAC;KAC/B;SAAM;QACL,OAAO,sBAAsB,CAC3B,sBAAsB,EACtB,WAAW,EACX,WAAW,EACX,cAAc,CACf,CAAC;KACH;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { default as DefaultTheme } from "./DefaultTheme";
2
+ export type { Theme, ReadTheme, ValidatedTheme, Breakpoints, ColorPalettes, } from "./types";
3
+ export { default as createTheme } from "./createTheme";
4
+ export { Provider as ThemeProvider, useChangeTheme, useTheme, withTheme, } from "./Provider";
@@ -0,0 +1,4 @@
1
+ export { default as DefaultTheme } from "./DefaultTheme";
2
+ export { default as createTheme } from "./createTheme";
3
+ export { Provider as ThemeProvider, useChangeTheme, useTheme, withTheme, } from "./Provider";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAQzD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EACL,QAAQ,IAAI,aAAa,EACzB,cAAc,EACd,QAAQ,EACR,SAAS,GACV,MAAM,YAAY,CAAC"}
@@ -0,0 +1,37 @@
1
+ export declare type ThemeValues = {
2
+ [key: string]: string | number | ThemeValues;
3
+ };
4
+ export declare type Theme = {
5
+ name: string;
6
+ colors: {
7
+ branding?: ThemeValues;
8
+ text?: ThemeValues;
9
+ background?: ThemeValues;
10
+ foreground?: ThemeValues;
11
+ border?: ThemeValues;
12
+ };
13
+ typography: {
14
+ [key: string]: any;
15
+ };
16
+ };
17
+ export declare type ValidatedTheme = Theme & {
18
+ validated: true;
19
+ };
20
+ export declare type ReadTheme = Theme & {
21
+ colors: {
22
+ branding?: any;
23
+ text?: any;
24
+ background?: any;
25
+ foreground?: any;
26
+ border?: any;
27
+ };
28
+ };
29
+ export declare type ColorPaletteValues = {
30
+ [key: string]: string;
31
+ };
32
+ export declare type ColorPalettes = {
33
+ [key: string]: ColorPaletteValues;
34
+ };
35
+ export declare type Breakpoints = {
36
+ [key: string]: number;
37
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { ColorPalettes, Breakpoints, Theme } from "./types";
2
+ export declare function validatePalettes(palettes: ColorPalettes): void;
3
+ export declare function validateBreakpoints(breakpoints: Breakpoints): void;
4
+ export declare function validateTheme(theme: Theme): void;
@@ -0,0 +1,52 @@
1
+ export function validatePalettes(palettes) {
2
+ for (const key of Object.keys(palettes)) {
3
+ if (typeof key !== "string") {
4
+ throw new Error(`Invalid palettes object, ${key} is not a string`);
5
+ }
6
+ for (const [innerKey, value] of Object.entries(palettes[key])) {
7
+ if (typeof innerKey !== "string") {
8
+ throw new Error(`Invalid palette color key, ${innerKey} is not a string`);
9
+ }
10
+ if (typeof value !== "string") {
11
+ throw new Error(`Invalid palette color value, ${value} is not a string`);
12
+ }
13
+ }
14
+ }
15
+ }
16
+ export function validateBreakpoints(breakpoints) {
17
+ for (const [key, value] of Object.entries(breakpoints)) {
18
+ if (typeof key !== "string") {
19
+ throw new Error(`Invalid breakpoint key, ${key} is not a string`);
20
+ }
21
+ if (typeof value !== "number") {
22
+ throw new Error(`Invalid breakpoint value, ${value} is not a number`);
23
+ }
24
+ }
25
+ }
26
+ export function validateTheme(theme) {
27
+ function validateThemeValues(themeValue) {
28
+ if (themeValue === undefined || themeValue === null) {
29
+ return;
30
+ }
31
+ for (const [key, value] of Object.entries(themeValue)) {
32
+ if (typeof key !== "string") {
33
+ throw new Error(`Invalid theme key, ${key} is not a string`);
34
+ }
35
+ if (value === undefined || value === null) {
36
+ continue;
37
+ }
38
+ else if (typeof value === "object") {
39
+ validateThemeValues(value);
40
+ }
41
+ else if (typeof value !== "string" && typeof value !== "number") {
42
+ throw new Error(`Invalid theme value, ${value} is not a string, number, or object`);
43
+ }
44
+ }
45
+ }
46
+ validateThemeValues(theme.colors.branding);
47
+ validateThemeValues(theme.colors.text);
48
+ validateThemeValues(theme.colors.foreground);
49
+ validateThemeValues(theme.colors.background);
50
+ validateThemeValues(theme.colors.border);
51
+ }
52
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/validators.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB,CAAC,QAAuB;IACtD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;QACvC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,kBAAkB,CAAC,CAAC;SACpE;QACD,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE;YAC7D,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;gBAChC,MAAM,IAAI,KAAK,CACb,8BAA8B,QAAQ,kBAAkB,CACzD,CAAC;aACH;YACD,IAAI,OAAO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