@j2inn/fin5-ui-utils 1.0.8-react-router.6 → 1.0.9

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 (65) hide show
  1. package/dist/fin5Top/useFin5AppURLHashParameter.d.ts +0 -3
  2. package/dist/fin5Top/useFin5AppURLHashParameter.js +9 -11
  3. package/dist/fin5Top/useFin5AppURLHashParameter.js.map +1 -1
  4. package/dist/index.d.ts +4 -6
  5. package/dist/index.js +4 -6
  6. package/dist/index.js.map +1 -1
  7. package/dist/react/components/navigation/BasicLayout.d.ts +10 -25
  8. package/dist/react/components/navigation/BasicLayout.js +36 -19
  9. package/dist/react/components/navigation/BasicLayout.js.map +1 -1
  10. package/dist/react/components/navigation/{customRouting/Router.d.ts → Router.d.ts} +1 -1
  11. package/dist/react/components/navigation/{customRouting/Router.js → Router.js} +2 -2
  12. package/dist/react/components/navigation/Router.js.map +1 -0
  13. package/dist_es/fin5Top/fin5FileUpload.d.ts +24 -0
  14. package/dist_es/fin5Top/fin5FileUpload.js +48 -0
  15. package/dist_es/fin5Top/fin5FileUpload.js.map +1 -0
  16. package/dist_es/fin5Top/finEdge2Cloud.d.ts +6 -0
  17. package/dist_es/fin5Top/finEdge2Cloud.js +12 -0
  18. package/dist_es/fin5Top/finEdge2Cloud.js.map +1 -0
  19. package/dist_es/fin5Top/useFin5AppURLHashParameter.d.ts +0 -3
  20. package/dist_es/fin5Top/useFin5AppURLHashParameter.js +6 -5
  21. package/dist_es/fin5Top/useFin5AppURLHashParameter.js.map +1 -1
  22. package/dist_es/index.d.ts +4 -6
  23. package/dist_es/index.js +4 -6
  24. package/dist_es/index.js.map +1 -1
  25. package/dist_es/jobs/jobUtils.d.ts +14 -0
  26. package/dist_es/jobs/jobUtils.js +10 -0
  27. package/dist_es/jobs/jobUtils.js.map +1 -0
  28. package/dist_es/react/components/RecordImage.d.ts +20 -0
  29. package/dist_es/react/components/RecordImage.js +25 -0
  30. package/dist_es/react/components/RecordImage.js.map +1 -0
  31. package/dist_es/react/components/charts/QRCode.d.ts +25 -0
  32. package/dist_es/react/components/charts/QRCode.js +54 -0
  33. package/dist_es/react/components/charts/QRCode.js.map +1 -0
  34. package/dist_es/react/components/charts/pie/PieChart.d.ts +93 -0
  35. package/dist_es/react/components/charts/pie/PieChart.js +176 -0
  36. package/dist_es/react/components/charts/pie/PieChart.js.map +1 -0
  37. package/dist_es/react/components/charts/pie/SimplePieChart.d.ts +20 -0
  38. package/dist_es/react/components/charts/pie/SimplePieChart.js +26 -0
  39. package/dist_es/react/components/charts/pie/SimplePieChart.js.map +1 -0
  40. package/dist_es/react/components/navigation/BasicLayout.d.ts +10 -25
  41. package/dist_es/react/components/navigation/BasicLayout.js +31 -13
  42. package/dist_es/react/components/navigation/BasicLayout.js.map +1 -1
  43. package/dist_es/react/components/navigation/HeaderSiderLayout.d.ts +13 -0
  44. package/dist_es/react/components/navigation/HeaderSiderLayout.js +81 -0
  45. package/dist_es/react/components/navigation/HeaderSiderLayout.js.map +1 -0
  46. package/dist_es/react/components/navigation/MenuTrigger.d.ts +9 -0
  47. package/dist_es/react/components/navigation/MenuTrigger.js +29 -0
  48. package/dist_es/react/components/navigation/MenuTrigger.js.map +1 -0
  49. package/dist_es/react/components/navigation/ReactRouterHeaderSiderLayout.d.ts +11 -0
  50. package/dist_es/react/components/navigation/ReactRouterHeaderSiderLayout.js +19 -0
  51. package/dist_es/react/components/navigation/ReactRouterHeaderSiderLayout.js.map +1 -0
  52. package/dist_es/react/components/navigation/ReactRouterLayout.d.ts +32 -2
  53. package/dist_es/react/components/navigation/ReactRouterLayout.js +66 -18
  54. package/dist_es/react/components/navigation/ReactRouterLayout.js.map +1 -1
  55. package/dist_es/react/hooks/useFin5BinUrl.d.ts +6 -0
  56. package/dist_es/react/hooks/useFin5BinUrl.js +12 -0
  57. package/dist_es/react/hooks/useFin5BinUrl.js.map +1 -0
  58. package/package.json +2 -4
  59. package/dist/react/components/navigation/ReactRouterLayout.d.ts +0 -16
  60. package/dist/react/components/navigation/ReactRouterLayout.js +0 -80
  61. package/dist/react/components/navigation/ReactRouterLayout.js.map +0 -1
  62. package/dist/react/components/navigation/customRouting/Router.js.map +0 -1
  63. package/dist/react/components/navigation/customRouting/RouterLayout.d.ts +0 -11
  64. package/dist/react/components/navigation/customRouting/RouterLayout.js +0 -62
  65. package/dist/react/components/navigation/customRouting/RouterLayout.js.map +0 -1
@@ -0,0 +1,20 @@
1
+ import { HRef } from 'haystack-core';
2
+ import React from 'react';
3
+ export interface RecordImageProps {
4
+ /**
5
+ * Ref of the image bin record.
6
+ */
7
+ imageRef?: HRef;
8
+ /**
9
+ * Fallback component to be displayed if the imageRef is not valid or the image is not found.
10
+ */
11
+ fallbackComponent?: React.ReactElement;
12
+ /**
13
+ * Props for img customization
14
+ */
15
+ imgProps?: Omit<React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, 'src'>;
16
+ }
17
+ /**
18
+ * Displays an image from a bin record or a fallback if the given imageRef is not valid or if the image can't be found.
19
+ */
20
+ export declare const RecordImage: ({ imageRef, fallbackComponent, imgProps, }: RecordImageProps) => JSX.Element;
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright (c) 2023, J2 Innovations. All Rights Reserved
3
+ */
4
+ import React, { useState } from 'react';
5
+ import { useFin5BinUrl } from '../hooks/useFin5BinUrl';
6
+ /**
7
+ * Displays an image from a bin record or a fallback if the given imageRef is not valid or if the image can't be found.
8
+ */
9
+ export const RecordImage = ({ imageRef, fallbackComponent, imgProps, }) => {
10
+ const imgUrl = useFin5BinUrl(imageRef);
11
+ // State used to identify whether there is an error in loading the image, to display the fallback component if necessary
12
+ const [hasImage, setHasImage] = useState(true);
13
+ const shouldDisplayFallback = !!fallbackComponent && (!hasImage || !imgUrl);
14
+ if (shouldDisplayFallback) {
15
+ return fallbackComponent;
16
+ }
17
+ else {
18
+ return (React.createElement("img", { ...imgProps, onError: (event) => {
19
+ // This will happen if the resource is not found for some reason
20
+ setHasImage(false);
21
+ imgProps?.onError?.(event);
22
+ }, src: imgUrl }));
23
+ }
24
+ };
25
+ //# sourceMappingURL=RecordImage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecordImage.js","sourceRoot":"","sources":["../../../src/react/components/RecordImage.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAuBtD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAC3B,QAAQ,EACR,iBAAiB,EACjB,QAAQ,GACU,EAAE,EAAE;IACtB,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;IACtC,wHAAwH;IACxH,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC9C,MAAM,qBAAqB,GAAG,CAAC,CAAC,iBAAiB,IAAI,CAAC,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,CAAA;IAE3E,IAAI,qBAAqB,EAAE;QAC1B,OAAO,iBAAiB,CAAA;KACxB;SAAM;QACN,OAAO,CACN,gCACK,QAAQ,EACZ,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;gBAClB,gEAAgE;gBAChE,WAAW,CAAC,KAAK,CAAC,CAAA;gBAClB,QAAQ,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,CAAA;YAC3B,CAAC,EACD,GAAG,EAAE,MAAM,GACV,CACF,CAAA;KACD;AACF,CAAC,CAAA"}
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ interface QRCodeProps {
3
+ /**
4
+ * The value the QR code holds (can be an URI or a plain string)
5
+ */
6
+ value: string;
7
+ /**
8
+ * True to show a link to copy QR code to clipboard, false otherwise.
9
+ * @default true
10
+ */
11
+ copyable?: boolean;
12
+ /**
13
+ * The text of the link to copy the QR code to clipboard.
14
+ * @default 'Copy QR code to clipboard'
15
+ */
16
+ copyText?: string;
17
+ /**
18
+ * The size of the QR code in pixels.
19
+ * @default 350
20
+ */
21
+ size?: number;
22
+ className?: string;
23
+ }
24
+ declare const QRCode: React.FC<QRCodeProps>;
25
+ export default QRCode;
@@ -0,0 +1,54 @@
1
+ import { Typography, ant_prefix } from '@j2inn/ui';
2
+ import cn from 'classnames';
3
+ import QRious from 'qrious';
4
+ import React, { useCallback, useEffect, useLayoutEffect, useRef, useState, } from 'react';
5
+ import { createUseStyles } from 'react-jss';
6
+ const useStyles = createUseStyles({
7
+ qrCode: {
8
+ display: 'flex',
9
+ flexDirection: 'column',
10
+ [`& .${ant_prefix}-typography`]: {
11
+ textAlign: 'center',
12
+ paddingBottom: '0.5em',
13
+ },
14
+ },
15
+ });
16
+ const QRCode = ({ value, size = 350, copyable = true, copyText = 'Copy QR code to clipboard', className, }) => {
17
+ const classes = useStyles();
18
+ const canvasRef = useRef(null);
19
+ const [qrCode, setQrCode] = useState();
20
+ useLayoutEffect(() => {
21
+ if (canvasRef.current) {
22
+ setQrCode(new QRious({
23
+ element: canvasRef.current,
24
+ value,
25
+ size,
26
+ }));
27
+ }
28
+ }, [value, canvasRef.current]);
29
+ useEffect(() => {
30
+ if (qrCode && qrCode.size !== size) {
31
+ qrCode.size = size;
32
+ }
33
+ }, [size]);
34
+ const copyQrCodeToClipboard = useCallback(async () => {
35
+ if (canvasRef.current) {
36
+ await canvasRef.current.toBlob((blob) => {
37
+ if (blob) {
38
+ navigator.clipboard.write([
39
+ new ClipboardItem({
40
+ 'image/png': blob,
41
+ }),
42
+ ]);
43
+ }
44
+ });
45
+ }
46
+ }, [canvasRef.current]);
47
+ return (React.createElement("div", { className: cn(className, classes.qrCode) },
48
+ copyable && (React.createElement(Typography.Text, { copyable: {
49
+ onCopy: () => copyQrCodeToClipboard(),
50
+ } }, copyText)),
51
+ React.createElement("canvas", { ref: canvasRef })));
52
+ };
53
+ export default QRCode;
54
+ //# sourceMappingURL=QRCode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QRCode.js","sourceRoot":"","sources":["../../../../src/react/components/charts/QRCode.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,MAAM,YAAY,CAAA;AAC3B,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,KAAK,EAAE,EACb,WAAW,EACX,SAAS,EACT,eAAe,EACf,MAAM,EACN,QAAQ,GACR,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAE3C,MAAM,SAAS,GAAG,eAAe,CAAC;IACjC,MAAM,EAAE;QACP,OAAO,EAAE,MAAM;QACf,aAAa,EAAE,QAAQ;QACvB,CAAC,MAAM,UAAU,aAAa,CAAC,EAAE;YAChC,SAAS,EAAE,QAAQ;YACnB,aAAa,EAAE,OAAO;SACtB;KACD;CACD,CAAC,CAAA;AAyBF,MAAM,MAAM,GAA0B,CAAC,EACtC,KAAK,EACL,IAAI,GAAG,GAAG,EACV,QAAQ,GAAG,IAAI,EACf,QAAQ,GAAG,2BAA2B,EACtC,SAAS,GACT,EAAE,EAAE;IACJ,MAAM,OAAO,GAAG,SAAS,EAAE,CAAA;IAC3B,MAAM,SAAS,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAA;IACjD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,EAAiB,CAAA;IAErD,eAAe,CAAC,GAAG,EAAE;QACpB,IAAI,SAAS,CAAC,OAAO,EAAE;YACtB,SAAS,CACR,IAAI,MAAM,CAAC;gBACV,OAAO,EAAE,SAAS,CAAC,OAAO;gBAC1B,KAAK;gBACL,IAAI;aACJ,CAAC,CACF,CAAA;SACD;IACF,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;IAE9B,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,EAAE;YACnC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAA;SAClB;IACF,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;IAEV,MAAM,qBAAqB,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QACpD,IAAI,SAAS,CAAC,OAAO,EAAE;YACtB,MAAM,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;gBACvC,IAAI,IAAI,EAAE;oBACT,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC;wBACzB,IAAI,aAAa,CAAC;4BACjB,WAAW,EAAE,IAAI;yBACjB,CAAC;qBACF,CAAC,CAAA;iBACF;YACF,CAAC,CAAC,CAAA;SACF;IACF,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;IAEvB,OAAO,CACN,6BAAK,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC;QAC3C,QAAQ,IAAI,CACZ,oBAAC,UAAU,CAAC,IAAI,IACf,QAAQ,EAAE;gBACT,MAAM,EAAE,GAAG,EAAE,CAAC,qBAAqB,EAAE;aACrC,IACA,QAAQ,CACQ,CAClB;QACD,gCAAQ,GAAG,EAAE,SAAS,GAAW,CAC5B,CACN,CAAA;AACF,CAAC,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -0,0 +1,93 @@
1
+ import * as am5 from '@amcharts/amcharts5';
2
+ import * as am5percent from '@amcharts/amcharts5/percent';
3
+ import React from 'react';
4
+ export declare type PieChartInterfaceColors = {
5
+ [Property in keyof am5.IInterfaceColorsSettings]: string;
6
+ };
7
+ export interface PieChartColorPalette {
8
+ interfaceColors?: Partial<PieChartInterfaceColors>;
9
+ series?: string[];
10
+ }
11
+ export interface PieChartSliceData {
12
+ value: number;
13
+ category: string;
14
+ }
15
+ export interface PieChartProps {
16
+ /**
17
+ * Data used to populate the chart
18
+ */
19
+ data: PieChartSliceData[];
20
+ /**
21
+ * Color palette for the chart slices and interface colors @see https://www.amcharts.com/docs/v5/concepts/colors-gradients-and-patterns/#Interface_colors
22
+ */
23
+ colorPalette?: Partial<PieChartColorPalette>;
24
+ /**
25
+ * Number formatting options @see https://www.amcharts.com/docs/v5/tutorials/formatting-date-time-and-numbers-using-intl-object/#Formatting_numbers
26
+ */
27
+ numberFormat?: Intl.NumberFormatOptions;
28
+ /**
29
+ * amcharts5 theme classes to be used by the chart @see https://www.amcharts.com/docs/v5/concepts/themes/
30
+ */
31
+ chartThemes?: typeof am5.Theme[];
32
+ /**
33
+ * Settings for chart customization @see https://www.amcharts.com/docs/v5/reference/piechart/#Settings
34
+ * The function accepts the chart root as a parameter to allow layout configuration.
35
+ */
36
+ chartSettingsProvider?: (root: am5.Root) => am5percent.IPieChartSettings;
37
+ /**
38
+ * Function to get settings for legend customization @see https://www.amcharts.com/docs/v5/reference/legend/#Settings
39
+ * The function accepts the chart root as a parameter to allow layout configuration.
40
+ */
41
+ legendSettingsProvider?: (root: am5.Root) => am5.ILegendSettings;
42
+ /**
43
+ * Settings for legend labels customization @see https://www.amcharts.com/docs/v5/reference/label/#Settings
44
+ */
45
+ legendLabelsSettings?: Partial<am5.ILabelSettings>;
46
+ /**
47
+ * Settings for legend value labels customization @see https://www.amcharts.com/docs/v5/reference/label/#Settings
48
+ */
49
+ legendValueLabelsSettings?: Partial<am5.ILabelSettings>;
50
+ /**
51
+ * Settings for legend markers customization @see https://www.amcharts.com/docs/v5/reference/label/#Settings
52
+ */
53
+ legendMarkersSettings?: Partial<am5.ILabelSettings>;
54
+ /**
55
+ * Settings for chart series customization @see https://www.amcharts.com/docs/v5/reference/pieseries/#Settings
56
+ */
57
+ seriesSettings?: am5percent.IPieSeriesSettings;
58
+ /**
59
+ * Settings for series labels customization @see https://www.amcharts.com/docs/v5/reference/pieseries/#Settings
60
+ */
61
+ seriesLabelsSettings?: Partial<am5.IRadialLabelSettings>;
62
+ /**
63
+ * Settings for central label customization, useful for donut charts, if not specified no center label will be shown @see https://www.amcharts.com/docs/v5/reference/radiallabel/#Settings
64
+ */
65
+ centerLabelSettings?: am5.ILabelSettings;
66
+ /**
67
+ * Settings for pie slices customization @see https://www.amcharts.com/docs/v5/reference/slice/#Settings
68
+ */
69
+ slicesSettings?: Partial<am5.ISliceSettings>;
70
+ /**
71
+ * List of adapters to be applied to the slices @see https://www.amcharts.com/docs/v5/concepts/settings/adapters
72
+ */
73
+ sliceAdapters?: SliceAdapter[];
74
+ /**
75
+ * Optional DOM id for the chart container, if not specified it will be automatically generated
76
+ */
77
+ DOMtargetId?: string;
78
+ }
79
+ export declare type SliceAdapter<T extends keyof am5.ISliceSettings = keyof am5.ISliceSettings> = [
80
+ T,
81
+ (context: {
82
+ root: am5.Root;
83
+ chart: am5percent.PieChart;
84
+ series: am5percent.PieSeries;
85
+ }) => (value: am5.ISliceSettings[T], target: am5.Slice, key: T) => am5.ISliceSettings[T]
86
+ ];
87
+ /**
88
+ * Highly customizable pie chart component based on amcharts5
89
+ * @see https://www.amcharts.com/docs/v5/charts/percent-charts/pie-chart/
90
+ *
91
+ * This component wraps some of the chart configuration trying to make it more react-friendly
92
+ */
93
+ export declare const PieChart: React.FC<PieChartProps>;
@@ -0,0 +1,176 @@
1
+ /*
2
+ * Copyright (c) 2023, J2 Innovations. All Rights Reserved
3
+ */
4
+ import * as am5 from '@amcharts/amcharts5';
5
+ import * as am5percent from '@amcharts/amcharts5/percent';
6
+ import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
7
+ import { createUseStyles, useTheme } from 'react-jss';
8
+ const useStyles = createUseStyles({
9
+ root: {
10
+ width: '100%',
11
+ height: '100%',
12
+ },
13
+ });
14
+ /**
15
+ * Returns a color palette selecting some colors from the theme.
16
+ * @param theme The theme
17
+ * @returns An array of colors
18
+ */
19
+ const getDefaultChartColors = (theme) => {
20
+ return {
21
+ interfaceColors: {
22
+ text: theme.textColor,
23
+ },
24
+ series: [
25
+ theme.palette.lime,
26
+ theme.palette.cyan,
27
+ theme.palette.red,
28
+ theme.palette.volcano,
29
+ theme.palette.orange,
30
+ theme.palette.gold,
31
+ theme.palette.yellow,
32
+ theme.palette.green,
33
+ theme.palette.purple,
34
+ theme.palette.magenta,
35
+ theme.palette.blue,
36
+ theme.palette.grey,
37
+ ],
38
+ };
39
+ };
40
+ /**
41
+ * Highly customizable pie chart component based on amcharts5
42
+ * @see https://www.amcharts.com/docs/v5/charts/percent-charts/pie-chart/
43
+ *
44
+ * This component wraps some of the chart configuration trying to make it more react-friendly
45
+ */
46
+ export const PieChart = ({ DOMtargetId, data, colorPalette, numberFormat, chartThemes, chartSettingsProvider, legendSettingsProvider, legendLabelsSettings, legendValueLabelsSettings, legendMarkersSettings, seriesSettings, seriesLabelsSettings, centerLabelSettings, slicesSettings, sliceAdapters, }) => {
47
+ // Colors configuration
48
+ const theme = useTheme();
49
+ const colors = { ...getDefaultChartColors(theme), ...colorPalette };
50
+ // Chart lifecycle
51
+ const [id, setId] = useState(DOMtargetId ?? `amchart-${Math.random()}`);
52
+ const rootRef = useRef(null);
53
+ const chartRef = useRef(null);
54
+ const legendRef = useRef(null);
55
+ useEffect(() => {
56
+ if (DOMtargetId && DOMtargetId !== id) {
57
+ setId(DOMtargetId);
58
+ }
59
+ }, [DOMtargetId]);
60
+ // Chart setup
61
+ useLayoutEffect(() => {
62
+ const root = am5.Root.new(id);
63
+ // Setup amcharts theme
64
+ if (chartThemes) {
65
+ root.setThemes(chartThemes.map((t) => t.new(root)));
66
+ }
67
+ // Setup interface colors, see https://www.amcharts.com/docs/v5/concepts/colors-gradients-and-patterns/#Interface_colors
68
+ if (colors.interfaceColors) {
69
+ // Remap settings to use amcharts Color objects
70
+ for (const setting in colors.interfaceColors) {
71
+ const color = colors.interfaceColors[setting];
72
+ // Apply defined interfaceColor on the chart
73
+ root.interfaceColors.set(setting, am5.color(color));
74
+ }
75
+ }
76
+ // Setup chart settings
77
+ const chart = root.container.children.push(am5percent.PieChart.new(root, {
78
+ layout: root.verticalLayout,
79
+ ...chartSettingsProvider?.(root),
80
+ }));
81
+ // Setup legend
82
+ const legend = chart.children.push(am5.Legend.new(root, {
83
+ layout: root.horizontalLayout,
84
+ ...legendSettingsProvider?.(root),
85
+ }));
86
+ if (legendLabelsSettings) {
87
+ legend.labels.template.setAll(legendLabelsSettings);
88
+ }
89
+ if (legendValueLabelsSettings) {
90
+ legend.valueLabels.template.setAll(legendValueLabelsSettings);
91
+ }
92
+ if (legendMarkersSettings) {
93
+ legend.markers.template.setAll(legendMarkersSettings);
94
+ }
95
+ rootRef.current = root;
96
+ chartRef.current = chart;
97
+ legendRef.current = legend;
98
+ // clean up before component removal from the DOM
99
+ return () => {
100
+ legendRef.current?.dispose();
101
+ legendRef.current = null;
102
+ chartRef.current?.dispose();
103
+ chartRef.current = null;
104
+ root?.dispose();
105
+ rootRef.current = null;
106
+ };
107
+ }, [
108
+ id,
109
+ colors,
110
+ chartThemes,
111
+ chartSettingsProvider,
112
+ legendSettingsProvider,
113
+ legendValueLabelsSettings,
114
+ legendMarkersSettings,
115
+ ]);
116
+ // Set data
117
+ useEffect(() => {
118
+ const root = rootRef.current;
119
+ const chart = chartRef.current;
120
+ if (chart && root) {
121
+ chart.series.clear();
122
+ if (data?.length) {
123
+ // Setup series
124
+ const series = chart.series.push(am5percent.PieSeries.new(root, {
125
+ valueField: 'value',
126
+ categoryField: 'category',
127
+ ...seriesSettings,
128
+ }));
129
+ // Setup series labels
130
+ if (seriesLabelsSettings) {
131
+ series.labels.template.setAll(seriesLabelsSettings);
132
+ }
133
+ // Setup center label
134
+ if (centerLabelSettings) {
135
+ series.children.push(am5.Label.new(root, {
136
+ ...centerLabelSettings,
137
+ }));
138
+ }
139
+ // Setup series slices
140
+ if (slicesSettings) {
141
+ series.slices.template.setAll(slicesSettings);
142
+ }
143
+ // Setup slice adapters
144
+ if (sliceAdapters) {
145
+ sliceAdapters.forEach(([key, callbackMaker]) => series.slices.template.adapters.add(key, callbackMaker({
146
+ root: root,
147
+ chart: chart,
148
+ series,
149
+ })));
150
+ }
151
+ // Setup series colors
152
+ if (colors?.series) {
153
+ series.get('colors')?.set('colors', colors.series.map((c) => am5.color(c)));
154
+ }
155
+ series.data.setAll(data);
156
+ legendRef.current?.data.setAll(series.dataItems);
157
+ }
158
+ }
159
+ }, [
160
+ data,
161
+ chartRef.current,
162
+ colors?.series,
163
+ seriesSettings,
164
+ slicesSettings,
165
+ seriesLabelsSettings,
166
+ sliceAdapters,
167
+ ]);
168
+ useEffect(() => {
169
+ if (numberFormat) {
170
+ rootRef.current?.numberFormatter.set('numberFormat', numberFormat);
171
+ }
172
+ }, [rootRef.current, numberFormat]);
173
+ const classes = useStyles();
174
+ return React.createElement("div", { id: id, className: classes.root });
175
+ };
176
+ //# sourceMappingURL=PieChart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PieChart.js","sourceRoot":"","sources":["../../../../../src/react/components/charts/pie/PieChart.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAA;AAC1C,OAAO,KAAK,UAAU,MAAM,6BAA6B,CAAA;AAEzD,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC3E,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAErD,MAAM,SAAS,GAAG,eAAe,CAAC;IACjC,IAAI,EAAE;QACL,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,MAAM;KACd;CACD,CAAC,CAAA;AAWF;;;;GAIG;AACH,MAAM,qBAAqB,GAAG,CAAC,KAAe,EAAwB,EAAE;IACvE,OAAO;QACN,eAAe,EAAE;YAChB,IAAI,EAAE,KAAK,CAAC,SAAS;SACrB;QACD,MAAM,EAAE;YACP,KAAK,CAAC,OAAO,CAAC,IAAI;YAClB,KAAK,CAA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IACF,CAAC,EAAE;QACF,IAAI;QACJ,QAAQ,CAAC,OAAO;QAChB,MAAM,EAAE,MAAM;QACd,cAAc;QACd,cAAc;QACd,oBAAoB;QACpB,aAAa;KACb,CAAC,CAAA;IAEF,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,YAAY,EAAE;YACjB,OAAO,CAAC,OAAO,EAAE,eAAe,CAAC,GAAG,CAAC,cAAc,EAAE,YAAY,CAAC,CAAA;SAClE;IACF,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAA;IAEnC,MAAM,OAAO,GAAG,SAAS,EAAE,CAAA;IAC3B,OAAO,6BAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,IAAI,GAAQ,CAAA;AACpD,CAAC,CAAA"}
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { PieChartColorPalette, PieChartSliceData } from './PieChart';
3
+ export interface SimplePieChartProps {
4
+ data: PieChartSliceData[];
5
+ donut?: boolean;
6
+ animated?: boolean;
7
+ colorPalette?: Partial<PieChartColorPalette>;
8
+ tooltipFormat?: string;
9
+ numberFormat?: Intl.NumberFormatOptions;
10
+ hideLabels?: boolean;
11
+ /**
12
+ * Optional DOM id for the chart container, if not specified it will be automatically generated
13
+ */
14
+ DOMtargetId?: string;
15
+ }
16
+ /**
17
+ * Simplified version of the pie chart for quick usage and easy configuration.
18
+ * Serves also as an example of how to use the underlying PieChart component.
19
+ */
20
+ export declare const SimplePieChart: React.FC<SimplePieChartProps>;
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright (c) 2023, J2 Innovations. All Rights Reserved
3
+ */
4
+ import * as am5 from '@amcharts/amcharts5';
5
+ import am5themes_Animated from '@amcharts/amcharts5/themes/Animated';
6
+ import React from 'react';
7
+ import { PieChart } from './PieChart';
8
+ /**
9
+ * Simplified version of the pie chart for quick usage and easy configuration.
10
+ * Serves also as an example of how to use the underlying PieChart component.
11
+ */
12
+ export const SimplePieChart = ({ data, donut, animated, colorPalette, tooltipFormat, numberFormat = {
13
+ style: 'decimal',
14
+ minimumFractionDigits: 0,
15
+ maximumFractionDigits: 1,
16
+ }, hideLabels, DOMtargetId, }) => {
17
+ return (React.createElement(PieChart, { DOMtargetId: DOMtargetId, colorPalette: colorPalette, data: data, chartThemes: animated ? [am5themes_Animated] : undefined, chartSettingsProvider: () => ({
18
+ innerRadius: donut ? am5.percent(55) : undefined,
19
+ }), numberFormat: numberFormat, legendSettingsProvider: () => ({
20
+ centerX: am5.percent(50),
21
+ x: am5.percent(50),
22
+ }), seriesLabelsSettings: { forceHidden: hideLabels }, seriesSettings: { alignLabels: false }, slicesSettings: {
23
+ tooltipText: tooltipFormat,
24
+ } }));
25
+ };
26
+ //# sourceMappingURL=SimplePieChart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SimplePieChart.js","sourceRoot":"","sources":["../../../../../src/react/components/charts/pie/SimplePieChart.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAA;AAC1C,OAAO,kBAAkB,MAAM,qCAAqC,CAAA;AACpE,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,QAAQ,EAA2C,MAAM,YAAY,CAAA;AAgB9E;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAkC,CAAC,EAC7D,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,YAAY,GAAG;IACd,KAAK,EAAE,SAAS;IAChB,qBAAqB,EAAE,CAAC;IACxB,qBAAqB,EAAE,CAAC;CACxB,EACD,UAAU,EACV,WAAW,GACX,EAAe,EAAE;IACjB,OAAO,CACN,oBAAC,QAAQ,IACR,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,YAAY,EAC1B,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS,EACxD,qBAAqB,EAAE,GAAG,EAAE,CAAC,CAAC;YAC7B,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS;SAChD,CAAC,EACF,YAAY,EAAE,YAAY,EAC1B,sBAAsB,EAAE,GAAG,EAAE,CAAC,CAAC;YAC9B,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YACxB,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;SAClB,CAAC,EACF,oBAAoB,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,EACjD,cAAc,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,EACtC,cAAc,EAAE;YACf,WAAW,EAAE,aAAa;SAC1B,GACA,CACF,CAAA;AACF,CAAC,CAAA"}
@@ -1,21 +1,14 @@
1
- import { ThemeDef } from '@j2inn/ui';
2
1
  import { LayoutProps, MenuProps, SiderProps } from 'antd';
3
- import { PropsWithChildren, ReactElement } from 'react';
2
+ import React from 'react';
4
3
  import { MenuPage } from './MenuPage';
5
- export declare const HEADER_HEIGHT = 45;
6
- interface StyleVariables {
7
- isMobile?: boolean;
8
- compactSider?: boolean;
9
- siderWidth?: number | string;
10
- }
11
- export declare const useStyles: (data?: (StyleVariables & {
12
- theme?: ThemeDef | undefined;
13
- }) | undefined) => import("jss").Classes<"content" | "header" | "sider" | "menuTrigger">;
14
- export interface BasicLayoutProps<T extends MenuPage> extends PropsWithChildren {
15
- pages?: T[];
4
+ export interface BasicLayoutProps {
5
+ /**
6
+ * List of pages for the menu and the routing
7
+ */
8
+ page?: string;
9
+ pages?: MenuPage[];
16
10
  defaultPage?: string;
17
- selectedPages?: string[];
18
- onSelect?: (key: string) => void;
11
+ onPageChange?: (page: string) => void;
19
12
  compactSider?: boolean;
20
13
  layoutProps?: LayoutProps;
21
14
  mobileHeaderProps?: LayoutProps;
@@ -24,14 +17,6 @@ export interface BasicLayoutProps<T extends MenuPage> extends PropsWithChildren
24
17
  menuProps?: Omit<MenuProps, 'items' | 'selectedKeys' | 'onSelect'>;
25
18
  }
26
19
  /**
27
- * Copy the array and recursively remove pages having the `showInMenu` flag set to false.
28
- * @param pages
29
- * @returns
30
- */
31
- export declare const getMenuPages: (pages: MenuPage[]) => MenuPage<Record<string, unknown>>[];
32
- /**
33
- * Basic layout with sider and mobile navigation management.
34
- * Routing management can be plugged in, for examples @see ReactRouterLayout @see RouterLayout
20
+ * Basic layout that combines menu and routing into one.
35
21
  */
36
- export declare function BasicLayout<T extends MenuPage>({ pages, defaultPage, selectedPages, onSelect, compactSider, layoutProps, mobileHeaderProps, siderProps, contentProps, menuProps, children, }: BasicLayoutProps<T>): ReactElement;
37
- export {};
22
+ export declare const BasicLayout: React.FC<BasicLayoutProps>;
@@ -1,13 +1,16 @@
1
1
  /*
2
- * Copyright (c) 2023, J2 Innovations. All Rights Reserved
2
+ * Copyright (c) 2022, J2 Innovations. All Rights Reserved
3
3
  */
4
4
  import { MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons';
5
- import { Layout, Menu } from '@j2inn/ui';
5
+ import { Button, Layout, Menu } from '@j2inn/ui';
6
6
  import classNames from 'classnames';
7
- import React, { useMemo, useState, } from 'react';
7
+ import React, { useEffect, useMemo, useState } from 'react';
8
8
  import { createUseStyles } from 'react-jss';
9
- export const HEADER_HEIGHT = 45;
10
- export const useStyles = createUseStyles((theme) => {
9
+ import { ErrorDisplayer } from '../ErrorDisplayer';
10
+ import { findPageByName } from './MenuPage';
11
+ import { Router } from './Router';
12
+ const HEADER_HEIGHT = 45;
13
+ const useStyles = createUseStyles((theme) => {
11
14
  return {
12
15
  header: {
13
16
  position: 'fixed',
@@ -55,7 +58,7 @@ const Content = Layout.Content;
55
58
  * @param pages
56
59
  * @returns
57
60
  */
58
- export const getMenuPages = (pages) => {
61
+ const getMenuPages = (pages) => {
59
62
  const menuPages = [];
60
63
  pages.forEach((page) => {
61
64
  const show = page.showInMenu == null || page.showInMenu;
@@ -73,10 +76,19 @@ export const getMenuPages = (pages) => {
73
76
  return menuPages;
74
77
  };
75
78
  /**
76
- * Basic layout with sider and mobile navigation management.
77
- * Routing management can be plugged in, for examples @see ReactRouterLayout @see RouterLayout
79
+ * Basic layout that combines menu and routing into one.
78
80
  */
79
- export function BasicLayout({ pages = [], defaultPage, selectedPages = [], onSelect, compactSider, layoutProps, mobileHeaderProps, siderProps, contentProps, menuProps, children, }) {
81
+ export const BasicLayout = ({ pages = [], defaultPage = pages?.[0].key ?? '', onPageChange, compactSider, layoutProps, mobileHeaderProps, siderProps, contentProps, menuProps, page, }) => {
82
+ const [currentPage, setCurrentPage] = useState(page ?? defaultPage);
83
+ useEffect(() => {
84
+ if (page) {
85
+ setCurrentPage(page);
86
+ }
87
+ }, [page]);
88
+ // Fire onChange
89
+ useEffect(() => {
90
+ onPageChange?.(currentPage);
91
+ }, [currentPage]);
80
92
  // manage mobile navigation
81
93
  const [isMobile, setIsMobile] = useState(false);
82
94
  const [hiddenSider, setHiddenSider] = useState(false);
@@ -97,12 +109,18 @@ export function BasicLayout({ pages = [], defaultPage, selectedPages = [], onSel
97
109
  : compactSider
98
110
  ? HEADER_HEIGHT
99
111
  : 0, trigger: null },
100
- React.createElement(Menu, { ...menuProps, defaultSelectedKeys: defaultPage ? [defaultPage] : undefined, items: menuPages, selectedKeys: selectedPages, onSelect: ({ key }) => {
112
+ React.createElement(Menu, { ...menuProps, items: menuPages, selectedKeys: [currentPage], onSelect: ({ key }) => {
101
113
  if (!hiddenSider) {
102
114
  setHiddenSider(true);
103
115
  }
104
- onSelect?.(key);
116
+ const page = findPageByName(pages, key);
117
+ if (page?.component) {
118
+ setCurrentPage(key);
119
+ }
105
120
  } })),
106
- React.createElement(Content, { ...contentProps, className: classNames(classes.content, contentProps?.className) }, children)));
107
- }
121
+ React.createElement(Content, { ...contentProps, className: classNames(classes.content, contentProps?.className) },
122
+ React.createElement(Router, { pages: pages, currentPage: currentPage, fallbackComponent: React.createElement(ErrorDisplayer, { error: new Error('Page Not Found'), extra: [
123
+ React.createElement(Button, { type: 'primary', key: 'refresh', onClick: () => setCurrentPage(defaultPage) }, "Go Home"),
124
+ ] }) }))));
125
+ };
108
126
  //# sourceMappingURL=BasicLayout.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BasicLayout.js","sourceRoot":"","sources":["../../../../src/react/components/navigation/BasicLayout.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAY,MAAM,WAAW,CAAA;AAElD,OAAO,UAAU,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,EAAE,EAGb,OAAO,EACP,QAAQ,GACR,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAG3C,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAA;AAQ/B,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,CAAC,CAAC,KAAe,EAAE,EAAE;IAC5D,OAAO;QACN,MAAM,EAAE;YACP,QAAQ,EAAE,OAAO;YACjB,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,CAAC;YACV,MAAM,EAAE,aAAa;YACrB,UAAU,EAAE,MAAM;SAClB;QACD,KAAK,EAAE;YACN,QAAQ,EAAE,MAAM;YAChB,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,OAAO;YACjB,IAAI,EAAE,CAAC;YACP,GAAG,EAAE,CAAC;YACN,MAAM,EAAE,CAAC;YACT,MAAM,EAAE,GAAG;YACX,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAkB,EAAE,EAAE,CAC5C,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;SAC7B;QACD,WAAW,EAAE;YACZ,KAAK,EAAE,EAAE;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,CACH,oBAAC,gBAAgB,IAChB,SAAS,EAAE,OAAO,CAAC,WAAW,EAC9B,OAAO,EAAE,GAAG,EAAE;gBACb,cAAc,CAAC,CAAC,WAAW,CAAC,CAAA;YAC7B,CAAC,GACA,CACF,CACO,CACT;QACD,oBAAC,KAAK,OACD,UAAU,EACd,SAAS,EAAE,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,EAC3D,UAAU,EAAC,IAAI,EACf,YAAY,EAAE,CAAC,MAAe,EAAE,EAAE;gBACjC,WAAW,CAAC,MAAM,CAAC,CAAA;gBACnB,cAAc,CAAC,IAAI,CAAC,CAAA;YACrB,CAAC,EACD,SAAS,EAAE,CAAC,QAAQ,IAAI,WAAW,CAAC,IAAI,YAAY,EACpD,cAAc,EACb,QAAQ,IAAI,WAAW;gBACtB,CAAC,CAAC,CAAC;gBACH,CAAC,CAAC,YAAY;oBACd,CAAC,CAAC,aAAa;oBACf,CAAC,CAAC,CAAC,EAEL,OAAO,EAAE,IAAI;YACb,oBAAC,IAAI,OACA,SAAS,EACb,mBAAmB,EAClB,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,EAExC,KAAK,EAAE,SAAS,EAChB,YAAY,EAAE,aAAa,EAC3B,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;oBACrB,IAAI,CAAC,WAAW,EAAE;wBACjB,cAAc,CAAC,IAAI,CAAC,CAAA;qBACpB;oBACD,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAA;gBAChB,CAAC,GACA,CACK;QACR,oBAAC,OAAO,OACH,YAAY,EAChB,SAAS,EAAE,UAAU,CACpB,OAAO,CAAC,OAAO,EACf,YAAY,EAAE,SAAS,CACvB,IACA,QAAQ,CACA,CACF,CACT,CAAA;AACF,CAAC"}
1
+ {"version":3,"file":"BasicLayout.js","sourceRoot":"","sources":["../../../../src/react/components/navigation/BasicLayout.tsx"],"names":[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AI,EAAE,SAAS,EAAE;wBACpB,cAAc,CAAC,GAAG,CAAC,CAAA;qBACnB;gBACF,CAAC,GACA,CACK;QACR,oBAAC,OAAO,OACH,YAAY,EAChB,SAAS,EAAE,UAAU,CACpB,OAAO,CAAC,OAAO,EACf,YAAY,EAAE,SAAS,CACvB;YACD,oBAAC,MAAM,IACN,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAChB,oBAAC,cAAc,IACd,KAAK,EAAE,IAAI,KAAK,CAAC,gBAAgB,CAAC,EAClC,KAAK,EAAE;wBACN,oBAAC,MAAM,IACN,IAAI,EAAC,SAAS,EACd,GAAG,EAAC,SAAS,EACb,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,WAAW,CAAC,cAElC;qBACT,GACA,GAEF,CACO,CACF,CACT,CAAA;AACF,CAAC,CAAA"}
@@ -0,0 +1,13 @@
1
+ import { LayoutProps } from 'antd';
2
+ import React, { ReactElement } from 'react';
3
+ import { BasicLayoutProps } from './BasicLayout';
4
+ import { MenuPage } from './MenuPage';
5
+ export declare type HeaderSiderLayoutProps<T extends MenuPage> = Omit<BasicLayoutProps<T>, 'mobileHeaderProps'> & {
6
+ header?: React.ReactNode;
7
+ headerProps?: LayoutProps;
8
+ };
9
+ /**
10
+ * Layout with header and sider. Sider is collapsed on mobile.
11
+ * Routing management can be plugged in, for examples @see ReactRouterLayout @see RouterLayout
12
+ */
13
+ export declare function HeaderSiderLayout<T extends MenuPage>({ pages, defaultPage, selectedPages, onSelect, compactSider, layoutProps, header, headerProps, siderProps, contentProps, menuProps, menuBefore, menuAfter, menuTriggerClassName, headerHeight, children, }: HeaderSiderLayoutProps<T>): ReactElement;