react-admin-base-bootstrap 0.5.1 → 0.5.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.
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare function useTheme(): any;
|
|
3
|
+
export declare function useAllThemes(): any;
|
|
4
|
+
export default function ThemeProvider({ themes, defaultTheme, children }: {
|
|
5
|
+
themes: any;
|
|
6
|
+
defaultTheme: any;
|
|
7
|
+
children: any;
|
|
8
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React, { createContext, useContext, useEffect, useMemo, useReducer } from "react";
|
|
2
|
+
import { useApp } from "react-admin-base";
|
|
3
|
+
const ThemeContext = createContext(null);
|
|
4
|
+
const AllThemesContext = createContext(null);
|
|
5
|
+
export function useTheme() {
|
|
6
|
+
return useContext(ThemeContext);
|
|
7
|
+
}
|
|
8
|
+
export function useAllThemes() {
|
|
9
|
+
return useContext(AllThemesContext);
|
|
10
|
+
}
|
|
11
|
+
function useLocalStorage(key) {
|
|
12
|
+
const app = useApp();
|
|
13
|
+
const _key = app.id + '_' + key;
|
|
14
|
+
const previousValue = useMemo(() => localStorage.getItem(_key), [_key]);
|
|
15
|
+
return useReducer((_, newValue) => {
|
|
16
|
+
localStorage.setItem(_key, newValue);
|
|
17
|
+
return newValue;
|
|
18
|
+
}, previousValue);
|
|
19
|
+
}
|
|
20
|
+
export default function ThemeProvider({ themes, defaultTheme, children }) {
|
|
21
|
+
const state = useLocalStorage('theme');
|
|
22
|
+
const [theme, setTheme] = state;
|
|
23
|
+
const rTheme = theme || defaultTheme || 'light';
|
|
24
|
+
useEffect(function () {
|
|
25
|
+
const promise = (themes[rTheme] || themes[defaultTheme]).css()
|
|
26
|
+
.then(css => {
|
|
27
|
+
css.default.use();
|
|
28
|
+
return css;
|
|
29
|
+
});
|
|
30
|
+
return function () {
|
|
31
|
+
promise.then(css => css.default.unuse());
|
|
32
|
+
};
|
|
33
|
+
}, [theme]);
|
|
34
|
+
const val = useMemo(() => [rTheme, setTheme], [rTheme, setTheme]);
|
|
35
|
+
return React.createElement(AllThemesContext.Provider, { value: themes },
|
|
36
|
+
React.createElement(ThemeContext.Provider, { value: val }, children));
|
|
37
|
+
}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -16,4 +16,5 @@ import CheckBox from './Components/CheckBox';
|
|
|
16
16
|
import ErrorBoundary from './Components/ErrorBoundary';
|
|
17
17
|
import { useMenuState, useIsMobile } from './Components/MenuState';
|
|
18
18
|
import TopProgressBar from './Components/TopProgressBar';
|
|
19
|
-
|
|
19
|
+
import ThemeProvider, { useTheme, useAllThemes } from './Components/ThemeProvider';
|
|
20
|
+
export { ThemeProvider, useTheme, useAllThemes, useIsMobile, useMenuState, TopProgressBar, CRUD, ModalEntityEditor, CRUDActions, Relative, ApiSelect, Preview, ExcelExportButton, ExternalLoginButton, SingleFilePicker, MultiFilePicker, ImagePicker, BootstrapTable, EntityEditor, GoToTop, Validator, ValueValidator, ValidationErrors, LoadingButton, BootstrapDataTable, IdColumn, Column, ActionsColumn, Actions, useDataTableContext, LanguageProvider, useLanguage, LanguageSwitcher, ErrorBoundary, CheckBox };
|
package/lib/esm/index.js
CHANGED
|
@@ -16,4 +16,5 @@ import CheckBox from './Components/CheckBox';
|
|
|
16
16
|
import ErrorBoundary from './Components/ErrorBoundary';
|
|
17
17
|
import { useMenuState, useIsMobile } from './Components/MenuState';
|
|
18
18
|
import TopProgressBar from './Components/TopProgressBar';
|
|
19
|
-
|
|
19
|
+
import ThemeProvider, { useTheme, useAllThemes } from './Components/ThemeProvider';
|
|
20
|
+
export { ThemeProvider, useTheme, useAllThemes, useIsMobile, useMenuState, TopProgressBar, CRUD, ModalEntityEditor, CRUDActions, Relative, ApiSelect, Preview, ExcelExportButton, ExternalLoginButton, SingleFilePicker, MultiFilePicker, ImagePicker, BootstrapTable, EntityEditor, GoToTop, Validator, ValueValidator, ValidationErrors, LoadingButton, BootstrapDataTable, IdColumn, Column, ActionsColumn, Actions, useDataTableContext, LanguageProvider, useLanguage, LanguageSwitcher, ErrorBoundary, CheckBox };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-admin-base-bootstrap",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": "^17.0.2",
|
|
29
29
|
"react-dom": "^17.0.2",
|
|
30
|
-
"react-
|
|
31
|
-
"react-
|
|
30
|
+
"react-intl": "^5.21.0",
|
|
31
|
+
"react-router-dom": "^5.3.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@emotion/react": "^11.5.0",
|
|
@@ -42,14 +42,15 @@
|
|
|
42
42
|
"react-responsive": "^8.2.0",
|
|
43
43
|
"react-select": "^5.2.1",
|
|
44
44
|
"reactstrap": "^9.0.0",
|
|
45
|
+
"rewire": "^6.0.0",
|
|
45
46
|
"sweetalert2": "^11.1.9"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@types/react": "^17.0.34",
|
|
49
50
|
"@types/react-router-dom": "^5.3.2",
|
|
50
|
-
"react-intl": "^5.21.0",
|
|
51
51
|
"cross-env": "^7.0.3",
|
|
52
52
|
"nodemon": "^2.0.14",
|
|
53
|
+
"react-intl": "^5.21.0",
|
|
53
54
|
"typescript": "^4.4.4"
|
|
54
55
|
}
|
|
55
56
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React, { createContext, Dispatch, useContext, useEffect, useMemo, useReducer, useRef } from "react";
|
|
2
|
+
import { useApp } from "react-admin-base";
|
|
3
|
+
|
|
4
|
+
const ThemeContext = createContext(null as any);
|
|
5
|
+
const AllThemesContext = createContext(null as any);
|
|
6
|
+
|
|
7
|
+
export function useTheme() {
|
|
8
|
+
return useContext(ThemeContext);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function useAllThemes() {
|
|
12
|
+
return useContext(AllThemesContext);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function useLocalStorage(key: string) : [string, Dispatch<string>] {
|
|
16
|
+
const app = useApp();
|
|
17
|
+
|
|
18
|
+
const _key = app.id + '_' + key;
|
|
19
|
+
|
|
20
|
+
const previousValue = useMemo(() => localStorage.getItem(_key), [_key]);
|
|
21
|
+
|
|
22
|
+
return useReducer((_: string, newValue) => {
|
|
23
|
+
localStorage.setItem(_key, newValue);
|
|
24
|
+
return newValue;
|
|
25
|
+
}, previousValue);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default function ThemeProvider({ themes, defaultTheme, children }) {
|
|
29
|
+
const state = useLocalStorage('theme');
|
|
30
|
+
const [ theme, setTheme ] = state;
|
|
31
|
+
|
|
32
|
+
const rTheme = theme || defaultTheme || 'light';
|
|
33
|
+
|
|
34
|
+
useEffect(function() {
|
|
35
|
+
const promise = (themes[rTheme] || themes[defaultTheme]).css()
|
|
36
|
+
.then(css => {
|
|
37
|
+
css.default.use();
|
|
38
|
+
return css;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return function() {
|
|
42
|
+
promise.then(css => css.default.unuse());
|
|
43
|
+
};
|
|
44
|
+
}, [ theme ]);
|
|
45
|
+
|
|
46
|
+
const val = useMemo(() => [rTheme, setTheme], [rTheme, setTheme]);
|
|
47
|
+
|
|
48
|
+
return <AllThemesContext.Provider value={themes}>
|
|
49
|
+
<ThemeContext.Provider value={val}>
|
|
50
|
+
{ children }
|
|
51
|
+
</ThemeContext.Provider>
|
|
52
|
+
</AllThemesContext.Provider>;
|
|
53
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -17,8 +17,10 @@ import CheckBox from './Components/CheckBox';
|
|
|
17
17
|
import ErrorBoundary from './Components/ErrorBoundary';
|
|
18
18
|
import { useMenuState, useIsMobile } from './Components/MenuState';
|
|
19
19
|
import TopProgressBar from './Components/TopProgressBar';
|
|
20
|
+
import ThemeProvider, { useTheme, useAllThemes } from './Components/ThemeProvider';
|
|
20
21
|
|
|
21
22
|
export {
|
|
23
|
+
ThemeProvider, useTheme, useAllThemes,
|
|
22
24
|
useIsMobile, useMenuState,
|
|
23
25
|
TopProgressBar,
|
|
24
26
|
CRUD, ModalEntityEditor, CRUDActions,
|
package/watch.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
const rewire = require('rewire');
|
|
3
|
+
const webpackConfig = rewire('react-scripts/scripts/start');
|
|
4
|
+
const oldConfigFactory = webpackConfig.__get__('configFactory');
|
|
5
|
+
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
|
|
9
|
+
webpackConfig.__set__('configFactory', function(env) {
|
|
10
|
+
const config = oldConfigFactory(env);
|
|
11
|
+
|
|
12
|
+
// disable use modules outside of src
|
|
13
|
+
config.resolve.plugins = config.resolve.plugins.filter(plugin => !(plugin instanceof ModuleScopePlugin));
|
|
14
|
+
|
|
15
|
+
// disable local node_modules/ path
|
|
16
|
+
config.resolve.modules.shift();
|
|
17
|
+
|
|
18
|
+
// add aliased packages from /opt/packages
|
|
19
|
+
for (const alias of find_custom_packages('/opt/packages')){
|
|
20
|
+
config.resolve.alias[alias.name] = alias.path;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
addLazyLoadingStyleLoader(config.module);
|
|
24
|
+
|
|
25
|
+
console.log(config);
|
|
26
|
+
//process.exit(0);
|
|
27
|
+
|
|
28
|
+
return config;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
function* find_custom_packages(location) {
|
|
32
|
+
const dir = fs.opendirSync(location, { withFileTypes: true });
|
|
33
|
+
let dirent;
|
|
34
|
+
while ((dirent = dir.readSync()) !== null) {
|
|
35
|
+
if (dirent.isSymbolicLink()) {
|
|
36
|
+
yield {name: dirent.name, path: fs.realpathSync(path.join(location, dirent.name))};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
dir.closeSync();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function addLazyLoadingStyleLoader(config) {
|
|
43
|
+
const cssLoader = config.rules[1].oneOf[5];
|
|
44
|
+
|
|
45
|
+
config.rules[1].oneOf.splice(5, 2, {
|
|
46
|
+
...cssLoader,
|
|
47
|
+
use: [
|
|
48
|
+
{
|
|
49
|
+
loader: cssLoader.use[0],
|
|
50
|
+
options: {
|
|
51
|
+
injectType: 'lazyStyleTag'
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
cssLoader.use[1],
|
|
55
|
+
cssLoader.use[2]
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
}
|