@m4l/graphics 0.1.18 → 0.1.19
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/.eslintignore +2 -0
- package/.eslintrc.cjs +118 -0
- package/.gitignore +24 -0
- package/.gitlab-ci.yml +15 -0
- package/.prettierignore +3 -0
- package/.prettierrc.json +26 -0
- package/.vscode/settings.json +50 -0
- package/{contexts/LocalesContext/index.3fcfbe02.js → dist/contexts/LocalesContext/index.5b555637.js} +22 -22
- package/{contexts/index.84089632.js → dist/contexts/index.2f4a4040.js} +1 -1
- package/{hooks/index.a0cce694.js → dist/hooks/index.c13bc37e.js} +1 -1
- package/{hooks/useLocales/index.8154a401.js → dist/hooks/useLocales/index.f676279e.js} +1 -1
- package/{index.d.ts → dist/index.d.ts} +1 -0
- package/dist/index.js +55 -0
- package/dist/package.json +34 -0
- package/dist/theme/breakpoints.d.ts +10 -0
- package/{theme/defaultThemeOptions.9b9e7503.js → dist/theme/defaultThemeOptions.b2cdbe59.js} +11 -9
- package/{theme/typography.f5eadf47.js → dist/theme/typography.63fff3ec.js} +1 -1
- package/dist/utils/anchorEl.d.ts +13 -0
- package/dist/utils/index.7ab4fc54.js +159 -0
- package/dist/vendor.3b4b3674.js +27 -0
- package/package.json +49 -7
- package/src/components/ProgressBarStyle/index.tsx +39 -0
- package/src/components/index.ts +3 -0
- package/src/contexts/FormatterContext/index.tsx +131 -0
- package/src/contexts/FormatterContext/types.ts +73 -0
- package/src/contexts/HostThemeContext/index.tsx +85 -0
- package/src/contexts/HostThemeContext/types.ts +16 -0
- package/src/contexts/LocalesContext/helper.ts +67 -0
- package/src/contexts/LocalesContext/index.tsx +152 -0
- package/src/contexts/LocalesContext/types.ts +37 -0
- package/src/contexts/index.ts +15 -0
- package/src/hooks/index.ts +8 -0
- package/src/hooks/useFirstRender/index.ts +17 -0
- package/src/hooks/useFormatter/index.ts +10 -0
- package/src/hooks/useHostTheme/index.ts +10 -0
- package/src/hooks/useIsMountedRef/index.ts +16 -0
- package/src/hooks/useLocales/index.ts +10 -0
- package/src/hooks/useOffSetTop.ts +26 -0
- package/src/hooks/useResponsive/index.ts +44 -0
- package/src/index.ts +25 -0
- package/src/theme/breakpoints.ts +13 -0
- package/src/theme/defaultThemeOptions.ts +42 -0
- package/src/theme/overrides/Accordion.ts +85 -0
- package/src/theme/overrides/Alert.tsx +74 -0
- package/src/theme/overrides/Autocomplete.ts +31 -0
- package/src/theme/overrides/Avatar.ts +29 -0
- package/src/theme/overrides/Backdrop.ts +26 -0
- package/src/theme/overrides/Badge.ts +17 -0
- package/src/theme/overrides/Breadcrumbs.ts +16 -0
- package/src/theme/overrides/Button.ts +62 -0
- package/src/theme/overrides/ButtonGroup.ts +51 -0
- package/src/theme/overrides/Card.ts +36 -0
- package/src/theme/overrides/Checkbox.tsx +54 -0
- package/src/theme/overrides/Chip.tsx +49 -0
- package/src/theme/overrides/ControlLabel.ts +29 -0
- package/src/theme/overrides/CssBaseline.ts +46 -0
- package/src/theme/overrides/CustomIcons.tsx +122 -0
- package/src/theme/overrides/DataGrid.ts +101 -0
- package/src/theme/overrides/Dialog.ts +60 -0
- package/src/theme/overrides/Drawer.ts +30 -0
- package/src/theme/overrides/Fab.ts +40 -0
- package/src/theme/overrides/IconButton.ts +35 -0
- package/src/theme/overrides/Input.ts +94 -0
- package/src/theme/overrides/InputLabel.ts +17 -0
- package/src/theme/overrides/Link.ts +20 -0
- package/src/theme/overrides/List.ts +37 -0
- package/src/theme/overrides/LoadingButton.ts +28 -0
- package/src/theme/overrides/Menu.ts +20 -0
- package/src/theme/overrides/Pagination.ts +38 -0
- package/src/theme/overrides/Paper.ts +27 -0
- package/src/theme/overrides/Popover.ts +16 -0
- package/src/theme/overrides/Progress.ts +27 -0
- package/src/theme/overrides/Radio.ts +21 -0
- package/src/theme/overrides/Rating.tsx +30 -0
- package/src/theme/overrides/Select.tsx +14 -0
- package/src/theme/overrides/Skeleton.ts +19 -0
- package/src/theme/overrides/Slider.ts +31 -0
- package/src/theme/overrides/Stepper.ts +15 -0
- package/src/theme/overrides/SvgIcon.ts +21 -0
- package/src/theme/overrides/Switch.ts +35 -0
- package/src/theme/overrides/Table.ts +95 -0
- package/src/theme/overrides/Tabs.ts +61 -0
- package/src/theme/overrides/Timeline.ts +23 -0
- package/src/theme/overrides/ToggleButton.ts +54 -0
- package/src/theme/overrides/Tooltip.ts +20 -0
- package/src/theme/overrides/TreeView.tsx +25 -0
- package/src/theme/overrides/Typography.ts +18 -0
- package/src/theme/overrides/index.ts +102 -0
- package/src/theme/palette.ts +216 -0
- package/src/theme/shadows.ts +110 -0
- package/src/theme/stretch.ts +10 -0
- package/src/theme/typography.ts +91 -0
- package/src/types/index.ts +9 -0
- package/src/utils/anchorEl.ts +146 -0
- package/src/utils/getColorPresets.ts +91 -0
- package/src/utils/getFontValue.ts +73 -0
- package/src/utils/strings.ts +1 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +29 -0
- package/tsconfig.node.json +8 -0
- package/vite.config.ts +234 -0
- package/index.js +0 -53
- package/utils/index.d8b24456.js +0 -107
- /package/{components → dist/components}/ProgressBarStyle/index.d.ts +0 -0
- /package/{components → dist/components}/ProgressBarStyle/index.fb6fd9ed.js +0 -0
- /package/{components → dist/components}/index.80514d59.js +0 -0
- /package/{components → dist/components}/index.d.ts +0 -0
- /package/{contexts → dist/contexts}/FormatterContext/index.92336f4c.js +0 -0
- /package/{contexts → dist/contexts}/FormatterContext/index.d.ts +0 -0
- /package/{contexts → dist/contexts}/FormatterContext/types.d.ts +0 -0
- /package/{contexts → dist/contexts}/HostThemeContext/index.a6a62c70.js +0 -0
- /package/{contexts → dist/contexts}/HostThemeContext/index.d.ts +0 -0
- /package/{contexts → dist/contexts}/HostThemeContext/types.d.ts +0 -0
- /package/{contexts → dist/contexts}/LocalesContext/helper.d.ts +0 -0
- /package/{contexts → dist/contexts}/LocalesContext/index.d.ts +0 -0
- /package/{contexts → dist/contexts}/LocalesContext/types.d.ts +0 -0
- /package/{contexts → dist/contexts}/index.d.ts +0 -0
- /package/{hooks → dist/hooks}/index.d.ts +0 -0
- /package/{hooks → dist/hooks}/useFirstRender/index.1e9b02fb.js +0 -0
- /package/{hooks → dist/hooks}/useFirstRender/index.d.ts +0 -0
- /package/{hooks → dist/hooks}/useFormatter/index.57ac8cca.js +0 -0
- /package/{hooks → dist/hooks}/useFormatter/index.d.ts +0 -0
- /package/{hooks → dist/hooks}/useHostTheme/index.1c8e4ad7.js +0 -0
- /package/{hooks → dist/hooks}/useHostTheme/index.d.ts +0 -0
- /package/{hooks → dist/hooks}/useIsMountedRef/index.d.ts +0 -0
- /package/{hooks → dist/hooks}/useLocales/index.d.ts +0 -0
- /package/{hooks → dist/hooks}/useOffSetTop.d.ts +0 -0
- /package/{hooks → dist/hooks}/useResponsive/index.d.ts +0 -0
- /package/{hooks → dist/hooks}/useResponsive/index.fc5e1b4f.js +0 -0
- /package/{theme → dist/theme}/defaultThemeOptions.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Accordion.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Autocomplete.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Avatar.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Backdrop.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Badge.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Breadcrumbs.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Button.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/ButtonGroup.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Card.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Checkbox.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/ControlLabel.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/CssBaseline.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/DataGrid.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Dialog.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Drawer.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Fab.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/IconButton.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Input.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/InputLabel.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Link.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/List.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/LoadingButton.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Menu.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Pagination.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Paper.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Popover.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Progress.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Radio.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Skeleton.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Slider.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Stepper.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/SvgIcon.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Switch.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Table.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Tabs.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Timeline.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/ToggleButton.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Tooltip.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/Typography.d.ts +0 -0
- /package/{theme → dist/theme}/overrides/index.d.ts +0 -0
- /package/{theme → dist/theme}/overrides.7958c0ab.js +0 -0
- /package/{theme → dist/theme}/palette.2baf72f5.js +0 -0
- /package/{theme → dist/theme}/palette.d.ts +0 -0
- /package/{theme → dist/theme}/shadows.bf8dc290.js +0 -0
- /package/{theme → dist/theme}/shadows.d.ts +0 -0
- /package/{theme → dist/theme}/stretch.d.ts +0 -0
- /package/{theme → dist/theme}/typography.d.ts +0 -0
- /package/{types → dist/types}/index.d.ts +0 -0
- /package/{utils → dist/utils}/getColorPresets.d.ts +0 -0
- /package/{utils → dist/utils}/getFontValue.d.ts +0 -0
- /package/{utils → dist/utils}/strings.d.ts +0 -0
- /package/{vite-env.d.ts → dist/vite-env.d.ts} +0 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/* eslint-disable import/no-duplicates */
|
|
2
|
+
import { createContext, useState, useEffect, useCallback } from 'react';
|
|
3
|
+
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
|
|
4
|
+
import { LocalizationProvider as MUILocalizationProvider } from '@mui/x-date-pickers';
|
|
5
|
+
|
|
6
|
+
// import esLocale from 'date-fns/localeHost/es';
|
|
7
|
+
//import frLocale from 'date-fns/localeHost/fr';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
EmitEvents,
|
|
11
|
+
useEnvironment,
|
|
12
|
+
useHostTools,
|
|
13
|
+
useLocalStorageWithListener,
|
|
14
|
+
useNetwork,
|
|
15
|
+
} from '@m4l/core';
|
|
16
|
+
import { BaseLocale, LocalesProviderProps, LocaleType, LocalesContextProps } from './types';
|
|
17
|
+
import { joinLocale, splitLocale } from './helper';
|
|
18
|
+
|
|
19
|
+
// ----------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
const LocalesContext = createContext<LocalesContextProps | null>(null);
|
|
22
|
+
|
|
23
|
+
function LocalesProvider(props: LocalesProviderProps) {
|
|
24
|
+
const { children, isMicroFrontEnd, localeHost, getLocaleFromNetwork } = props;
|
|
25
|
+
|
|
26
|
+
if (isMicroFrontEnd && !localeHost) {
|
|
27
|
+
throw Error('Must set localeHost in microfrontend');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!isMicroFrontEnd && !getLocaleFromNetwork) {
|
|
31
|
+
throw Error('Must set getLocaleFromNetwork in host');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const { domain_token, host_static_assets, environment_assets } = useEnvironment();
|
|
35
|
+
const { networkOperation } = useNetwork();
|
|
36
|
+
|
|
37
|
+
const { events_add_listener, events_remove_listener, events_emit } = useHostTools();
|
|
38
|
+
|
|
39
|
+
const [currentLocale, setCurrentLocale] = useState<LocaleType | undefined>(() => {
|
|
40
|
+
if (isMicroFrontEnd) {
|
|
41
|
+
return localeHost;
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const [nextLocaleString, setNextLocalString] = useLocalStorageWithListener<string>(
|
|
47
|
+
'localeHost',
|
|
48
|
+
navigator.language,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const [currentLocaleString, setCurrentLocalString] = useState<string>('');
|
|
52
|
+
|
|
53
|
+
const onUpdateLocale = useCallback((newLocale: LocaleType) => {
|
|
54
|
+
setCurrentLocale(newLocale);
|
|
55
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
//Matricular el cambio de localee si es microfrontend
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (isMicroFrontEnd) {
|
|
61
|
+
events_add_listener(EmitEvents.EMMIT_EVENT_HOST_LOCALE_CHANGE, onUpdateLocale);
|
|
62
|
+
}
|
|
63
|
+
console.log('useEffect LocalesProvider');
|
|
64
|
+
return () => {
|
|
65
|
+
if (isMicroFrontEnd) {
|
|
66
|
+
events_remove_listener(EmitEvents.EMMIT_EVENT_HOST_LOCALE_CHANGE, onUpdateLocale);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}, []);
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
let mounted = true;
|
|
73
|
+
|
|
74
|
+
if (isMicroFrontEnd) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (!getLocaleFromNetwork) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (nextLocaleString === currentLocaleString && nextLocaleString !== '') {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
networkOperation({
|
|
86
|
+
method: 'POST',
|
|
87
|
+
endPoint: `na/locales`,
|
|
88
|
+
data: { ...splitLocale(nextLocaleString), domain_token },
|
|
89
|
+
})
|
|
90
|
+
.then((response: any) => {
|
|
91
|
+
if (mounted) {
|
|
92
|
+
//getLocale(response.data, host_static_assets, environment_assets).then(
|
|
93
|
+
getLocaleFromNetwork(
|
|
94
|
+
response.data,
|
|
95
|
+
host_static_assets,
|
|
96
|
+
environment_assets,
|
|
97
|
+
).then(newLocale => {
|
|
98
|
+
setCurrentLocale(newLocale);
|
|
99
|
+
setCurrentLocalString(newLocale.localeString);
|
|
100
|
+
|
|
101
|
+
if (nextLocaleString !== newLocale.localeString) {
|
|
102
|
+
//Solo si cambia
|
|
103
|
+
setNextLocalString(newLocale.localeString);
|
|
104
|
+
}
|
|
105
|
+
//Notificar a los microfrontends, que ha cambiado el locale
|
|
106
|
+
events_emit(EmitEvents.EMMIT_EVENT_HOST_LOCALE_CHANGE, newLocale);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
.finally(() => {});
|
|
111
|
+
|
|
112
|
+
return function cleanUp() {
|
|
113
|
+
mounted = false;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
117
|
+
}, [nextLocaleString]);
|
|
118
|
+
|
|
119
|
+
if (!currentLocale) {
|
|
120
|
+
return <div></div>;
|
|
121
|
+
}
|
|
122
|
+
// const [locales];
|
|
123
|
+
|
|
124
|
+
const onChangeLocale = (newLocale: BaseLocale) => {
|
|
125
|
+
if (
|
|
126
|
+
newLocale.lang !== currentLocale.lang ||
|
|
127
|
+
newLocale.script !== currentLocale.script ||
|
|
128
|
+
newLocale.region !== currentLocale.region
|
|
129
|
+
) {
|
|
130
|
+
setNextLocalString(joinLocale(newLocale));
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<LocalesContext.Provider
|
|
136
|
+
value={{
|
|
137
|
+
currentLocale,
|
|
138
|
+
onChangeLocale,
|
|
139
|
+
}}
|
|
140
|
+
>
|
|
141
|
+
<MUILocalizationProvider
|
|
142
|
+
dateAdapter={AdapterDateFns}
|
|
143
|
+
adapterLocale={currentLocale.module}
|
|
144
|
+
dateFormats={{ hours24h: '23' }}
|
|
145
|
+
>
|
|
146
|
+
{children}
|
|
147
|
+
</MUILocalizationProvider>
|
|
148
|
+
</LocalesContext.Provider>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export { LocalesProvider, LocalesContext };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import type { Locale } from 'date-fns';
|
|
3
|
+
|
|
4
|
+
export type SupportedLocales = 'en-US' | 'es' | 'fr';
|
|
5
|
+
|
|
6
|
+
export interface BaseLocale {
|
|
7
|
+
lang: string;
|
|
8
|
+
script?: string;
|
|
9
|
+
region?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface NetworkLocaleType extends BaseLocale {
|
|
13
|
+
name: string;
|
|
14
|
+
url_icon: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface LocaleType extends NetworkLocaleType {
|
|
18
|
+
module: Locale;
|
|
19
|
+
localeString: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type LocalesProviderProps = {
|
|
23
|
+
isMicroFrontEnd: boolean;
|
|
24
|
+
localeHost?: LocaleType; //undefined en host
|
|
25
|
+
getLocaleFromNetwork?: (
|
|
26
|
+
locale: NetworkLocaleType,
|
|
27
|
+
host_static_assets: string,
|
|
28
|
+
environment_assets: string,
|
|
29
|
+
) => Promise<LocaleType>;
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type LocalesContextProps = {
|
|
34
|
+
currentLocale?: LocaleType;
|
|
35
|
+
// currentLocaleString: string;
|
|
36
|
+
onChangeLocale: (newLocaleString: BaseLocale) => void;
|
|
37
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './FormatterContext';
|
|
2
|
+
export type {
|
|
3
|
+
Formatters,
|
|
4
|
+
DateFormatter,
|
|
5
|
+
NumberFormatter,
|
|
6
|
+
CurrencyFormatter,
|
|
7
|
+
} from './FormatterContext/types';
|
|
8
|
+
|
|
9
|
+
export * from './LocalesContext';
|
|
10
|
+
export type { NetworkLocaleType, LocaleType } from './LocalesContext/types';
|
|
11
|
+
export { getLocaleFromNetwork } from './LocalesContext/helper';
|
|
12
|
+
|
|
13
|
+
export * from './HostThemeContext';
|
|
14
|
+
|
|
15
|
+
// export { HelmetProvider } from 'react-helmet-async';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { useFirstRender } from './useFirstRender';
|
|
2
|
+
export { useFormatter } from './useFormatter';
|
|
3
|
+
export { useHostTheme } from './useHostTheme';
|
|
4
|
+
export { useIsMountedRef } from './useIsMountedRef';
|
|
5
|
+
export { useLocales } from './useLocales';
|
|
6
|
+
export { useOffSetTop } from './useOffSetTop';
|
|
7
|
+
|
|
8
|
+
export { useResponsive, useResponsiveDesktop } from './useResponsive';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useRef, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
// ----------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
export function useFirstRender(dependencies: Array<any> = []) {
|
|
6
|
+
const isMounted = useRef(true);
|
|
7
|
+
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
isMounted.current = false;
|
|
10
|
+
|
|
11
|
+
return () => {
|
|
12
|
+
isMounted.current = true;
|
|
13
|
+
};
|
|
14
|
+
}, dependencies);
|
|
15
|
+
|
|
16
|
+
return isMounted.current;
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { FormatterContext } from '../../contexts/FormatterContext';
|
|
3
|
+
|
|
4
|
+
// ----------------------------------------------------------------------
|
|
5
|
+
export const useFormatter = () => {
|
|
6
|
+
const context = useContext(FormatterContext);
|
|
7
|
+
if (!context) throw new Error('useFormatter context must be use inside FormatterProvider');
|
|
8
|
+
|
|
9
|
+
return context;
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { HostThemeContext } from '../../contexts/HostThemeContext';
|
|
3
|
+
|
|
4
|
+
// ----------------------------------------------------------------------
|
|
5
|
+
export const useHostTheme = () => {
|
|
6
|
+
const context = useContext(HostThemeContext);
|
|
7
|
+
if (!context) throw new Error('useHostTheme context must be use inside HostThemeProvider');
|
|
8
|
+
|
|
9
|
+
return context;
|
|
10
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useRef, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
// ----------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
export function useIsMountedRef() {
|
|
6
|
+
const isMounted = useRef(true);
|
|
7
|
+
|
|
8
|
+
useEffect(
|
|
9
|
+
() => () => {
|
|
10
|
+
isMounted.current = false;
|
|
11
|
+
},
|
|
12
|
+
[],
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
return isMounted;
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { LocalesContext } from '../../contexts/LocalesContext';
|
|
3
|
+
|
|
4
|
+
// ----------------------------------------------------------------------
|
|
5
|
+
export const useLocales = () => {
|
|
6
|
+
const context = useContext(LocalesContext);
|
|
7
|
+
if (!context) throw new Error('useLocales context must be use inside LocalesProvider');
|
|
8
|
+
|
|
9
|
+
return context;
|
|
10
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
// ----------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
export function useOffSetTop(top: number) {
|
|
6
|
+
const [offsetTop, setOffSetTop] = useState(false);
|
|
7
|
+
const isTop = top || 100;
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
window.onscroll = () => {
|
|
11
|
+
if (window.pageYOffset > isTop) {
|
|
12
|
+
setOffSetTop(true);
|
|
13
|
+
} else {
|
|
14
|
+
setOffSetTop(false);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
return () => {
|
|
18
|
+
window.onscroll = null;
|
|
19
|
+
};
|
|
20
|
+
}, [isTop]);
|
|
21
|
+
|
|
22
|
+
return offsetTop;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Usage
|
|
26
|
+
// const offset = useOffSetTop(100);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// @mui
|
|
2
|
+
import { Breakpoint } from '@mui/material';
|
|
3
|
+
import { useTheme } from '@mui/material/styles';
|
|
4
|
+
import useMediaQuery from '@mui/material/useMediaQuery';
|
|
5
|
+
|
|
6
|
+
// ----------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
type Query = 'up' | 'down' | 'between' | 'only';
|
|
9
|
+
type Key = Breakpoint | number;
|
|
10
|
+
type Start = Breakpoint | number;
|
|
11
|
+
type End = Breakpoint | number;
|
|
12
|
+
|
|
13
|
+
export function useResponsive(query: Query, key?: Key, start?: Start, end?: End) {
|
|
14
|
+
const theme = useTheme();
|
|
15
|
+
|
|
16
|
+
const mediaUp = useMediaQuery(theme.breakpoints.up(key as Key));
|
|
17
|
+
|
|
18
|
+
const mediaDown = useMediaQuery(theme.breakpoints.down(key as Key));
|
|
19
|
+
|
|
20
|
+
const mediaBetween = useMediaQuery(theme.breakpoints.between(start as Start, end as End));
|
|
21
|
+
|
|
22
|
+
const mediaOnly = useMediaQuery(theme.breakpoints.only(key as Breakpoint));
|
|
23
|
+
|
|
24
|
+
if (query === 'up') {
|
|
25
|
+
return mediaUp;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (query === 'down') {
|
|
29
|
+
return mediaDown;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (query === 'between') {
|
|
33
|
+
return mediaBetween;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (query === 'only') {
|
|
37
|
+
return mediaOnly;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function useResponsiveDesktop() {
|
|
42
|
+
const isDesktop = useResponsive('up', 'sm');
|
|
43
|
+
return isDesktop;
|
|
44
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from './components';
|
|
2
|
+
export * from './contexts';
|
|
3
|
+
export * from './hooks';
|
|
4
|
+
|
|
5
|
+
export type { CustomShadowOptions } from './theme/shadows';
|
|
6
|
+
export type { GradientsPaletteOptions } from './theme/palette';
|
|
7
|
+
export type { ChartPaletteOptions } from './theme/palette';
|
|
8
|
+
export type { GridPaletteOptions } from './theme/palette';
|
|
9
|
+
|
|
10
|
+
export { defaultThemeOptions } from './theme/defaultThemeOptions';
|
|
11
|
+
export { shadows, customShadows } from './theme/shadows';
|
|
12
|
+
export * from './theme/stretch';
|
|
13
|
+
export { palette, type ColorSchema } from './theme/palette';
|
|
14
|
+
export { getColorPresets, colorPresets, defaultPreset } from './utils/getColorPresets';
|
|
15
|
+
export { getFontValue as GetFontValue } from './utils/getFontValue';
|
|
16
|
+
export * from './utils/strings';
|
|
17
|
+
|
|
18
|
+
export { default as fnComponentsOverrides } from './theme/overrides';
|
|
19
|
+
|
|
20
|
+
//types
|
|
21
|
+
export type { HostThemeType } from './types';
|
|
22
|
+
|
|
23
|
+
//anchoEl
|
|
24
|
+
|
|
25
|
+
export * from './utils/anchorEl';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { alpha, ThemeOptions } from '@mui/material/styles';
|
|
2
|
+
import { typography } from './typography';
|
|
3
|
+
import { palette, GREY } from './palette';
|
|
4
|
+
import shadows, { customShadows } from './shadows';
|
|
5
|
+
|
|
6
|
+
import getColorPresets from '../utils/getColorPresets';
|
|
7
|
+
import { breakpoints } from './breakpoints';
|
|
8
|
+
|
|
9
|
+
export const defaultThemeOptions: ThemeOptions = {
|
|
10
|
+
typography,
|
|
11
|
+
breakpoints: breakpoints,
|
|
12
|
+
shadows: shadows.light,
|
|
13
|
+
customShadows: {
|
|
14
|
+
...customShadows.light,
|
|
15
|
+
primary: `0 8px 16px 0 ${alpha(getColorPresets('default').main, 0.24)}`,
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
palette: {
|
|
19
|
+
...palette.light,
|
|
20
|
+
primary: {
|
|
21
|
+
lighter: '#283829',
|
|
22
|
+
light: '#26372b',
|
|
23
|
+
main: '#00AB55',
|
|
24
|
+
dark: '#007B55',
|
|
25
|
+
darker: '#005249',
|
|
26
|
+
LightSelected: '#EBF9F1',
|
|
27
|
+
LightSelectedHover: '#D6F2E3',
|
|
28
|
+
DarkSelected: '#142827',
|
|
29
|
+
DarkSelectedHover: '#12342B',
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
text: { primary: GREY[800], secondary: GREY[700], disabled: GREY[500] },
|
|
33
|
+
secondary: {
|
|
34
|
+
main: '#34ac4e',
|
|
35
|
+
},
|
|
36
|
+
// background: {
|
|
37
|
+
// header: '#cfd7e0'
|
|
38
|
+
// },
|
|
39
|
+
|
|
40
|
+
// grid: { sectionHeader: '#F6F7F9', divider: '#EDEFF2', rowHover: '#F6F7F9' }
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Theme } from '@mui/material/styles';
|
|
2
|
+
|
|
3
|
+
// ----------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
export default function Accordion(theme: Theme) {
|
|
6
|
+
return {
|
|
7
|
+
MuiAccordion: {
|
|
8
|
+
styleOverrides: {
|
|
9
|
+
root: {
|
|
10
|
+
backgroundColor: theme.palette.background.default,
|
|
11
|
+
width: '100%',
|
|
12
|
+
marginTop: '0px',
|
|
13
|
+
marginBottom: theme.spacing(1.5),
|
|
14
|
+
'&.Mui-expanded': {
|
|
15
|
+
marginTop: '0px',
|
|
16
|
+
marginBottom: theme.spacing(1.5),
|
|
17
|
+
},
|
|
18
|
+
border: '0px solid transparent',
|
|
19
|
+
|
|
20
|
+
'&.Mui-disabled': {
|
|
21
|
+
backgroundColor: 'transparent',
|
|
22
|
+
},
|
|
23
|
+
'&::before': {
|
|
24
|
+
content: 'none',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
MuiAccordionDetails: {
|
|
30
|
+
styleOverrides: {
|
|
31
|
+
root: {
|
|
32
|
+
padding: `0px ${theme.spacing(0)}`,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
MuiAccordionSummary: {
|
|
37
|
+
styleOverrides: {
|
|
38
|
+
root: {
|
|
39
|
+
borderRadius: theme.spacing(0.5),
|
|
40
|
+
|
|
41
|
+
height: theme.spacing(4.5),
|
|
42
|
+
minHeight: theme.spacing(4.5),
|
|
43
|
+
backgroundColor: theme.palette.background.header,
|
|
44
|
+
paddingLeft: theme.spacing(2),
|
|
45
|
+
paddingRight: theme.spacing(2),
|
|
46
|
+
marginBottom: '0px',
|
|
47
|
+
|
|
48
|
+
'&.Mui-expanded': {
|
|
49
|
+
height: theme.spacing(4.5),
|
|
50
|
+
minHeight: theme.spacing(4.5),
|
|
51
|
+
borderRadius: `${theme.spacing(0.5)} ${theme.spacing(0.5)} 0px 0px`,
|
|
52
|
+
},
|
|
53
|
+
'&.Mui-disabled': {
|
|
54
|
+
opacity: 1,
|
|
55
|
+
color: theme.palette.action.disabled,
|
|
56
|
+
'& .MuiTypography-root': {
|
|
57
|
+
color: 'inherit',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
expandIconWrapper: {
|
|
62
|
+
color: theme.palette.action.active,
|
|
63
|
+
height: 20,
|
|
64
|
+
width: 20,
|
|
65
|
+
alignItems: 'center',
|
|
66
|
+
justifyContent: 'center',
|
|
67
|
+
'& > svg': {
|
|
68
|
+
height: 12,
|
|
69
|
+
width: 12,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
content: {
|
|
73
|
+
...theme.typography.subtitle2,
|
|
74
|
+
margin: '0px',
|
|
75
|
+
// '& .MuiTypography-root': {
|
|
76
|
+
|
|
77
|
+
// },
|
|
78
|
+
'&.Mui-expanded': {
|
|
79
|
+
margin: '0px',
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// @mui
|
|
2
|
+
import { Theme } from '@mui/material/styles';
|
|
3
|
+
// theme
|
|
4
|
+
import { ColorSchema } from '../palette';
|
|
5
|
+
//
|
|
6
|
+
import { ErrorIcon, InfoIcon, SuccessIcon, WarningIcon } from './CustomIcons';
|
|
7
|
+
|
|
8
|
+
// ----------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
export default function Alert(theme: Theme) {
|
|
11
|
+
const isLight = theme.palette.mode === 'light';
|
|
12
|
+
|
|
13
|
+
const standardStyle = (color: ColorSchema) => ({
|
|
14
|
+
color: theme.palette[color][isLight ? 'darker' : 'lighter'],
|
|
15
|
+
backgroundColor: theme.palette[color][isLight ? 'lighter' : 'darker'],
|
|
16
|
+
'& .MuiAlert-icon': {
|
|
17
|
+
color: theme.palette[color][isLight ? 'main' : 'light'],
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const filledStyle = (color: ColorSchema) => ({
|
|
22
|
+
color: theme.palette[color].contrastText,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const outlinedStyle = (color: ColorSchema) => ({
|
|
26
|
+
color: theme.palette[color][isLight ? 'darker' : 'lighter'],
|
|
27
|
+
border: `solid 1px ${theme.palette[color][isLight ? 'light' : 'dark']}`,
|
|
28
|
+
backgroundColor: theme.palette[color][isLight ? 'lighter' : 'darker'],
|
|
29
|
+
'& .MuiAlert-icon': {
|
|
30
|
+
color: theme.palette[color][isLight ? 'main' : 'light'],
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
MuiAlert: {
|
|
36
|
+
defaultProps: {
|
|
37
|
+
iconMapping: {
|
|
38
|
+
info: <InfoIcon />,
|
|
39
|
+
success: <SuccessIcon />,
|
|
40
|
+
warning: <WarningIcon />,
|
|
41
|
+
error: <ErrorIcon />,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
styleOverrides: {
|
|
46
|
+
message: {
|
|
47
|
+
'& .MuiAlertTitle-root': {
|
|
48
|
+
marginBottom: theme.spacing(0.5),
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
action: {
|
|
52
|
+
'& button:not(:first-of-type)': {
|
|
53
|
+
marginLeft: theme.spacing(1),
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
standardInfo: standardStyle('info'),
|
|
58
|
+
standardSuccess: standardStyle('success'),
|
|
59
|
+
standardWarning: standardStyle('warning'),
|
|
60
|
+
standardError: standardStyle('error'),
|
|
61
|
+
|
|
62
|
+
filledInfo: filledStyle('info'),
|
|
63
|
+
filledSuccess: filledStyle('success'),
|
|
64
|
+
filledWarning: filledStyle('warning'),
|
|
65
|
+
filledError: filledStyle('error'),
|
|
66
|
+
|
|
67
|
+
outlinedInfo: outlinedStyle('info'),
|
|
68
|
+
outlinedSuccess: outlinedStyle('success'),
|
|
69
|
+
outlinedWarning: outlinedStyle('warning'),
|
|
70
|
+
outlinedError: outlinedStyle('error'),
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Theme } from '@mui/material/styles';
|
|
2
|
+
|
|
3
|
+
// ----------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
export default function Autocomplete(theme: Theme) {
|
|
6
|
+
return {
|
|
7
|
+
MuiAutocomplete: {
|
|
8
|
+
styleOverrides: {
|
|
9
|
+
root: {
|
|
10
|
+
'& .MuiInputBase-root': {
|
|
11
|
+
padding: '0 39px 0px 0',
|
|
12
|
+
},
|
|
13
|
+
input: {
|
|
14
|
+
padding: `${theme.spacing(1.5, 1.5)}!important`,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
paper: {
|
|
18
|
+
boxShadow: theme.customShadows.dropdown,
|
|
19
|
+
},
|
|
20
|
+
listbox: {
|
|
21
|
+
padding: theme.spacing(0, 1),
|
|
22
|
+
'& .MuiAutocomplete-option': {
|
|
23
|
+
padding: theme.spacing(1),
|
|
24
|
+
margin: theme.spacing(1, 0),
|
|
25
|
+
borderRadius: theme.shape.borderRadius,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Theme } from '@mui/material/styles';
|
|
2
|
+
|
|
3
|
+
// ----------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
export default function Avatar(theme: Theme) {
|
|
6
|
+
return {
|
|
7
|
+
MuiAvatar: {
|
|
8
|
+
styleOverrides: {
|
|
9
|
+
colorDefault: {
|
|
10
|
+
color: theme.palette.text.secondary,
|
|
11
|
+
backgroundColor: theme.palette.grey[400],
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
MuiAvatarGroup: {
|
|
16
|
+
styleOverrides: {
|
|
17
|
+
avatar: {
|
|
18
|
+
fontSize: 16,
|
|
19
|
+
fontWeight: theme.typography.fontWeightMedium,
|
|
20
|
+
'&:first-of-type': {
|
|
21
|
+
fontSize: 14,
|
|
22
|
+
color: theme.palette.primary.main,
|
|
23
|
+
backgroundColor: theme.palette.primary.lighter,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|