@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.
Files changed (46) hide show
  1. package/dist/components/Layout/Header/Buttons/HeaderButton.d.ts +6 -0
  2. package/dist/components/Layout/Header/Buttons/HeaderButton.d.ts.map +1 -0
  3. package/dist/components/Layout/Header/Buttons/HeaderIconButton.d.ts +6 -0
  4. package/dist/components/Layout/Header/Buttons/HeaderIconButton.d.ts.map +1 -0
  5. package/dist/components/Layout/Header/Buttons/HeaderToggleButton.d.ts +6 -0
  6. package/dist/components/Layout/Header/Buttons/HeaderToggleButton.d.ts.map +1 -0
  7. package/dist/components/Layout/Header/Buttons/index.d.ts +4 -0
  8. package/dist/components/Layout/Header/Buttons/index.d.ts.map +1 -0
  9. package/dist/components/Layout/Header/DrawerToggle.d.ts.map +1 -1
  10. package/dist/components/Layout/Header/Notification/Notification.d.ts.map +1 -1
  11. package/dist/components/Layout/Header/Profile/Profile.d.ts +1 -1
  12. package/dist/components/Layout/Header/Profile/Profile.d.ts.map +1 -1
  13. package/dist/components/Layout/Header/ResponsiveSection.d.ts.map +1 -1
  14. package/dist/components/Layout/Header/index.d.ts +1 -0
  15. package/dist/components/Layout/Header/index.d.ts.map +1 -1
  16. package/dist/hooks/index.d.ts +13 -12
  17. package/dist/hooks/index.d.ts.map +1 -1
  18. package/dist/hooks/mui.d.ts +4 -1
  19. package/dist/hooks/mui.d.ts.map +1 -1
  20. package/dist/hooks/useLocalizedValue.d.ts +9 -0
  21. package/dist/hooks/useLocalizedValue.d.ts.map +1 -0
  22. package/dist/hooks/usePopoverState.d.ts +10 -0
  23. package/dist/hooks/usePopoverState.d.ts.map +1 -0
  24. package/dist/react-admin.cjs.js +57 -57
  25. package/dist/react-admin.cjs.js.map +1 -1
  26. package/dist/react-admin.es.js +7315 -7304
  27. package/dist/react-admin.es.js.map +1 -1
  28. package/dist/react-admin.umd.js +58 -58
  29. package/dist/react-admin.umd.js.map +1 -1
  30. package/dist/utils/localizedValue.d.ts +12 -5
  31. package/dist/utils/localizedValue.d.ts.map +1 -1
  32. package/package.json +1 -1
  33. package/src/components/Layout/Header/Buttons/HeaderButton.tsx +13 -0
  34. package/src/components/Layout/Header/Buttons/HeaderIconButton.tsx +22 -0
  35. package/src/components/Layout/Header/Buttons/HeaderToggleButton.tsx +23 -0
  36. package/src/components/Layout/Header/Buttons/index.ts +3 -0
  37. package/src/components/Layout/Header/DrawerToggle.tsx +9 -18
  38. package/src/components/Layout/Header/Notification/Notification.tsx +31 -53
  39. package/src/components/Layout/Header/Profile/{Profile.jsx → Profile.tsx} +34 -92
  40. package/src/components/Layout/Header/ResponsiveSection.tsx +17 -34
  41. package/src/components/Layout/Header/index.ts +1 -0
  42. package/src/hooks/index.jsx +13 -22
  43. package/src/hooks/mui.ts +16 -6
  44. package/src/hooks/useLocalizedValue.tsx +34 -0
  45. package/src/hooks/usePopoverState.tsx +28 -0
  46. 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<{ name: string; locale: string }> = [],
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
- export { localizedValueHasAllLocales };
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 };