@applica-software-guru/react-admin 1.3.151 → 1.3.153
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/components/Layout/Header/Buttons/HeaderButton.d.ts +6 -0
- package/dist/components/Layout/Header/Buttons/HeaderButton.d.ts.map +1 -0
- package/dist/components/Layout/Header/Buttons/HeaderIconButton.d.ts +6 -0
- package/dist/components/Layout/Header/Buttons/HeaderIconButton.d.ts.map +1 -0
- package/dist/components/Layout/Header/Buttons/HeaderToggleButton.d.ts +6 -0
- package/dist/components/Layout/Header/Buttons/HeaderToggleButton.d.ts.map +1 -0
- package/dist/components/Layout/Header/Buttons/index.d.ts +4 -0
- package/dist/components/Layout/Header/Buttons/index.d.ts.map +1 -0
- package/dist/components/Layout/Header/DrawerToggle.d.ts.map +1 -1
- package/dist/components/Layout/Header/Notification/Notification.d.ts.map +1 -1
- package/dist/components/Layout/Header/Profile/Profile.d.ts +1 -1
- package/dist/components/Layout/Header/Profile/Profile.d.ts.map +1 -1
- package/dist/components/Layout/Header/ResponsiveSection.d.ts.map +1 -1
- package/dist/components/Layout/Header/index.d.ts +1 -0
- package/dist/components/Layout/Header/index.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +13 -12
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/mui.d.ts +4 -1
- package/dist/hooks/mui.d.ts.map +1 -1
- package/dist/hooks/useLocalizedValue.d.ts +9 -0
- package/dist/hooks/useLocalizedValue.d.ts.map +1 -0
- package/dist/hooks/usePopoverState.d.ts +10 -0
- package/dist/hooks/usePopoverState.d.ts.map +1 -0
- package/dist/react-admin.cjs.js +57 -57
- package/dist/react-admin.cjs.js.map +1 -1
- package/dist/react-admin.es.js +7315 -7304
- package/dist/react-admin.es.js.map +1 -1
- package/dist/react-admin.umd.js +58 -58
- package/dist/react-admin.umd.js.map +1 -1
- package/dist/utils/localizedValue.d.ts +12 -5
- package/dist/utils/localizedValue.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Layout/Header/Buttons/HeaderButton.tsx +13 -0
- package/src/components/Layout/Header/Buttons/HeaderIconButton.tsx +22 -0
- package/src/components/Layout/Header/Buttons/HeaderToggleButton.tsx +23 -0
- package/src/components/Layout/Header/Buttons/index.ts +3 -0
- package/src/components/Layout/Header/DrawerToggle.tsx +9 -18
- package/src/components/Layout/Header/Notification/Notification.tsx +31 -53
- package/src/components/Layout/Header/Profile/{Profile.jsx → Profile.tsx} +34 -92
- package/src/components/Layout/Header/ResponsiveSection.tsx +17 -34
- package/src/components/Layout/Header/index.ts +1 -0
- package/src/hooks/index.jsx +13 -22
- package/src/hooks/mui.ts +16 -6
- package/src/hooks/useLocalizedValue.tsx +34 -0
- package/src/hooks/usePopoverState.tsx +28 -0
- package/src/utils/localizedValue.ts +37 -2
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useLocaleState } from 'ra-core';
|
|
2
|
+
import { IGetLocalizedValueOptions, ILocalizedValue, getLocalizedValue } from '../utils';
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
|
|
5
|
+
function useLocale(locale?: string): string {
|
|
6
|
+
const [defaultLocale] = useLocaleState();
|
|
7
|
+
|
|
8
|
+
return locale !== undefined ? String(locale) : defaultLocale;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type IUseLocalizeValueOptions = IGetLocalizedValueOptions & {
|
|
12
|
+
locale?: string;
|
|
13
|
+
};
|
|
14
|
+
function useLocalizedValue<T>(value: ILocalizedValue<T>, options?: IUseLocalizeValueOptions): T | undefined {
|
|
15
|
+
const language = useLocale(options?.locale),
|
|
16
|
+
localizedValue = getLocalizedValue<T>(value, language, options);
|
|
17
|
+
|
|
18
|
+
return localizedValue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type IUseGetLocalizeValueOptions = IUseLocalizeValueOptions;
|
|
22
|
+
function useGetLocalizedValue<T>(options?: IUseGetLocalizeValueOptions): (v: ILocalizedValue<T>) => T | undefined {
|
|
23
|
+
const language = useLocale(options?.locale),
|
|
24
|
+
callback = useCallback(
|
|
25
|
+
(value: ILocalizedValue<T>) => {
|
|
26
|
+
return getLocalizedValue<T>(value, language, options);
|
|
27
|
+
},
|
|
28
|
+
[language, options]
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return callback;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { useLocalizedValue, useGetLocalizedValue };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { MouseEvent, useCallback, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
function usePopoverState() {
|
|
4
|
+
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null),
|
|
5
|
+
open = Boolean(anchorEl),
|
|
6
|
+
handleClick = useCallback((e: MouseEvent<HTMLElement>) => setAnchorEl(e?.currentTarget), [setAnchorEl]),
|
|
7
|
+
handleClose = useCallback(() => setAnchorEl(null), [setAnchorEl]),
|
|
8
|
+
handleToggle = useCallback(
|
|
9
|
+
(e: MouseEvent<HTMLElement>) => {
|
|
10
|
+
if (!open) {
|
|
11
|
+
handleClick(e);
|
|
12
|
+
} else {
|
|
13
|
+
handleClose();
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
[open, handleClick, handleClose]
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
anchorEl: anchorEl,
|
|
21
|
+
open: open,
|
|
22
|
+
handleClick: handleClick,
|
|
23
|
+
handleClose: handleClose,
|
|
24
|
+
handleToggle: handleToggle
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { usePopoverState };
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
+
type ILocale = {
|
|
3
|
+
name: string;
|
|
4
|
+
locale: string;
|
|
5
|
+
};
|
|
2
6
|
type ILocalizedValue<T> = { [key: string]: T };
|
|
3
7
|
|
|
4
8
|
function localizedValueHasAllLocales<T>(
|
|
5
9
|
value: ILocalizedValue<T> = {},
|
|
6
|
-
locales: Array<
|
|
10
|
+
locales: Array<ILocale> = [],
|
|
7
11
|
options: { isEmpty?: (v: T) => boolean } = {}
|
|
8
12
|
): boolean {
|
|
9
13
|
const { isEmpty = _.isEmpty } = options;
|
|
@@ -11,4 +15,35 @@ function localizedValueHasAllLocales<T>(
|
|
|
11
15
|
return !_.some(locales, (l) => isEmpty((value ?? {})[l.locale]));
|
|
12
16
|
}
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
type IGetLocalizedValueOptions = {
|
|
19
|
+
fallback?: boolean;
|
|
20
|
+
fallbackLocales?: Array<string>;
|
|
21
|
+
};
|
|
22
|
+
function getLocalizedValue<T>(value: ILocalizedValue<T>, locale: string, options?: IGetLocalizedValueOptions): T | undefined {
|
|
23
|
+
if (!_.isPlainObject(value) || locale === undefined) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const _options: IGetLocalizedValueOptions = _.isPlainObject(options) ? (options as IGetLocalizedValueOptions) : {},
|
|
28
|
+
fallback = Boolean(_options?.fallback ?? true);
|
|
29
|
+
|
|
30
|
+
let localizedValue: T | undefined = value[String(locale)];
|
|
31
|
+
|
|
32
|
+
if (localizedValue === undefined && fallback) {
|
|
33
|
+
const fallbackLocales = _.isArray(_options.fallbackLocales) && !_.isEmpty(_options.fallbackLocales) ? _options.fallbackLocales : ['en'];
|
|
34
|
+
localizedValue = _.chain(fallbackLocales)
|
|
35
|
+
.map((l) => value[String(l)])
|
|
36
|
+
.reject(_.isUndefined)
|
|
37
|
+
.first()
|
|
38
|
+
.value() as T | undefined;
|
|
39
|
+
|
|
40
|
+
if (localizedValue === undefined) {
|
|
41
|
+
localizedValue = _.chain(value).values().first().value() as T | undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return localizedValue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type { ILocalizedValue, IGetLocalizedValueOptions };
|
|
49
|
+
export { localizedValueHasAllLocales, getLocalizedValue };
|