@tenancy.nz/feature-ui 1.4.11 → 1.5.1

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,120 @@
1
+ import { objectSpread2 as _objectSpread2 } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import React from 'react';
3
+ import { uid } from 'react-uid';
4
+ import Stack from '@mui/material/Stack';
5
+ import { Heading, Box } from '@tenancy.nz/ui';
6
+ import { Chart } from 'primereact/chart.js';
7
+ import ChartLegend from './ChartLegend.js';
8
+
9
+ function DoughnutChart(_ref) {
10
+ var data = _ref.data,
11
+ _ref$heading = _ref.heading,
12
+ heading = _ref$heading === void 0 ? void 0 : _ref$heading,
13
+ _ref$chartProps = _ref.chartProps,
14
+ chartProps = _ref$chartProps === void 0 ? {} : _ref$chartProps,
15
+ _ref$size = _ref.size,
16
+ size = _ref$size === void 0 ? "164px" : _ref$size;
17
+ if (!Array.isArray(data) || data.length === 0) {
18
+ return null;
19
+ }
20
+ var chartLabels = data.map(function (d) {
21
+ return d.title;
22
+ });
23
+ var chartValues = data.map(function (d) {
24
+ return d.count;
25
+ });
26
+ var chartColors = data.map(function (d) {
27
+ return d.color;
28
+ });
29
+ return /* @__PURE__ */React.createElement(Stack, {
30
+ sx: {
31
+ position: "relative"
32
+ },
33
+ alignItems: "center",
34
+ gap: 4
35
+ }, heading && /* @__PURE__ */React.createElement(Heading, {
36
+ as: "h4",
37
+ color: "primary"
38
+ }, heading), /* @__PURE__ */React.createElement(Stack, {
39
+ flexDirection: {
40
+ sm: "row"
41
+ },
42
+ gap: 12,
43
+ alignItems: "center"
44
+ }, /* @__PURE__ */React.createElement(Box, {
45
+ width: size,
46
+ height: size,
47
+ overflow: "hidden",
48
+ position: "relative",
49
+ maxWidth: "100%",
50
+ sx: {
51
+ "&& > canvas": {
52
+ width: "100%",
53
+ height: "100%"
54
+ }
55
+ }
56
+ }, /* @__PURE__ */React.createElement(Chart, _objectSpread2({
57
+ type: "doughnut",
58
+ data: {
59
+ labels: chartLabels,
60
+ datasets: [{
61
+ data: chartValues,
62
+ backgroundColor: chartColors,
63
+ hoverBackgroundColor: chartColors,
64
+ borderWidth: 0
65
+ }]
66
+ },
67
+ options: {
68
+ responsive: true,
69
+ maintainAspectRatio: false,
70
+ cutoutPercentage: 64,
71
+ legend: {
72
+ display: false
73
+ },
74
+ animation: {
75
+ duration: 0
76
+ },
77
+ tooltips: {
78
+ backgroundColor: "#0E0044",
79
+ titleFontColor: "#fff",
80
+ bodyFontColor: "#fff",
81
+ xPadding: 8,
82
+ yPadding: 8,
83
+ bodyFontFamily: "Montserrat, sans-serif",
84
+ bodyFontStyle: "semibold",
85
+ bodyFontSize: 14,
86
+ borderColor: "transparent",
87
+ callbacks: {
88
+ labelColor: function labelColor(tooltipItem, chart) {
89
+ var dataset = chart.config.data.datasets[tooltipItem.datasetIndex];
90
+ var color = dataset.backgroundColor[tooltipItem.index];
91
+ return {
92
+ borderColor: color,
93
+ backgroundColor: color,
94
+ borderWidth: 0,
95
+ borderRadius: 5
96
+ };
97
+ }
98
+ }
99
+ }
100
+ },
101
+ style: {
102
+ width: "100%",
103
+ height: "100%"
104
+ }
105
+ }, chartProps))), /* @__PURE__ */React.createElement(Stack, {
106
+ gap: 2
107
+ }, data.map(function (item) {
108
+ var color = item.color,
109
+ count = item.count,
110
+ title = item.title;
111
+ return /* @__PURE__ */React.createElement(ChartLegend, {
112
+ key: uid(item),
113
+ color: color,
114
+ count: count,
115
+ label: title
116
+ });
117
+ }))));
118
+ }
119
+
120
+ export { DoughnutChart as default };
package/dist/esm/index.js CHANGED
@@ -7,7 +7,8 @@ export { default as BookingTableRow } from './components/BookingTableRow.js';
7
7
  export { default as BookingTableRowHeader } from './components/BookingTableRowHeader.js';
8
8
  export { default as BookingTableRowSkeleton } from './components/BookingTableRowSkeleton.js';
9
9
  export { default as CheckedIcon } from './components/CheckedIcon.js';
10
- export { default as EnquiriesDoughnutChart } from './components/EnquiriesDoughnutChart.js';
10
+ export { default as DoughnutChart } from './components/doughnut-chart.js';
11
+ export { default as AnalyticsDoughnutChart } from './components/analytics-doughnut-chart.js';
11
12
  export { default as GridList } from './components/GridList.js';
12
13
  export { default as Hidden } from './components/Hidden.js';
13
14
  export { default as IconLabel } from './components/IconLabel.js';
@@ -0,0 +1,11 @@
1
+ var parseChartCount = function parseChartCount(value) {
2
+ if (Number.isNaN(Number.parseInt(String(value), 10))) {
3
+ return 0;
4
+ }
5
+ if (value === 0) {
6
+ return 0;
7
+ }
8
+ return Math.max(Number(value), 1e-3);
9
+ };
10
+
11
+ export { parseChartCount };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tenancy.nz/feature-ui",
3
3
  "description": "React UI feature components.",
4
- "version": "1.4.11",
4
+ "version": "1.5.1",
5
5
  "author": "TPS <https://www.tenancy.co.nz>",
6
6
  "type": "module",
7
7
  "main": "dist/cjs/index.cjs",
@@ -13,17 +13,21 @@
13
13
  "peerDependencies": {
14
14
  "@emotion/react": "^11.14.0",
15
15
  "@emotion/styled": "^11.14.1",
16
+ "@mui/icons-material": "^7.2.0",
17
+ "@mui/material": "^7.3.1",
16
18
  "chart.js": "2.7.3",
17
19
  "classnames": "^2.2.6",
18
20
  "primereact": "3.1.3",
19
21
  "react": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
20
22
  "react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
21
- "@tenancy.nz/icons": "1.4.11",
22
- "@tenancy.nz/ui": "1.4.11"
23
+ "@tenancy.nz/ui": "1.5.1"
23
24
  },
24
25
  "devDependencies": {
25
- "@tenancy.nz/icons": "1.4.11",
26
- "@tenancy.nz/ui": "1.4.11"
26
+ "@emotion/react": "^11.14.0",
27
+ "@emotion/styled": "^11.14.1",
28
+ "@mui/icons-material": "^7.2.0",
29
+ "@mui/material": "^7.3.1",
30
+ "@tenancy.nz/ui": "1.5.1"
27
31
  },
28
32
  "dependencies": {
29
33
  "react-uid": "^2.4.0"
@@ -1,143 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var React = require('react');
6
- var ui = require('@tenancy.nz/ui');
7
- var chart_js = require('primereact/chart.js');
8
-
9
- function EnquiriesDoughnutChart(_ref) {
10
- var _ref$tradeMeEnquiries = _ref.tradeMeEnquiriesCount,
11
- tradeMeEnquiriesCount = _ref$tradeMeEnquiries === void 0 ? 0 : _ref$tradeMeEnquiries,
12
- _ref$bookMeEnquiriesC = _ref.bookMeEnquiriesCount,
13
- bookMeEnquiriesCount = _ref$bookMeEnquiriesC === void 0 ? 0 : _ref$bookMeEnquiriesC,
14
- _ref$manualEnquiryCou = _ref.manualEnquiryCount,
15
- manualEnquiryCount = _ref$manualEnquiryCou === void 0 ? 0 : _ref$manualEnquiryCou;
16
- var colors = {
17
- tradeMe: "#6FD3C0",
18
- bookMe: "#00C0F3",
19
- manual: "#394869"
20
- };
21
- var chartColors = [colors.tradeMe, colors.bookMe, colors.manual];
22
- return /* @__PURE__ */React.createElement(ui.Box, {
23
- position: "relative",
24
- display: "flex",
25
- height: "100%",
26
- align: "center"
27
- }, /* @__PURE__ */React.createElement(ui.Text, {
28
- transform: "uppercase",
29
- sx: {
30
- position: "absolute",
31
- left: 20,
32
- top: -10
33
- },
34
- fontSize: 13,
35
- color: "textPrimary",
36
- weight: "700"
37
- }, "Number of enquiries"), /* @__PURE__ */React.createElement(ui.Box, {
38
- width: "100%",
39
- overflow: "hidden"
40
- }, /* @__PURE__ */React.createElement(chart_js.Chart, {
41
- type: "doughnut",
42
- data: {
43
- labels: ["TradeMe", "BookMe", "Manual"],
44
- datasets: [{
45
- data: [Math.max(tradeMeEnquiriesCount, 1e-3), Math.max(bookMeEnquiriesCount, 1e-3), Math.max(manualEnquiryCount, 1e-3)],
46
- backgroundColor: chartColors,
47
- hoverBackgroundColor: chartColors
48
- }]
49
- },
50
- options: {
51
- legend: {
52
- display: false
53
- },
54
- animation: {
55
- duration: 0
56
- }
57
- },
58
- style: {
59
- width: "100%",
60
- position: "absolute",
61
- top: "18%",
62
- left: "-75px"
63
- }
64
- })), /* @__PURE__ */React.createElement(ui.Box, {
65
- maxWidth: {
66
- xs: "160px",
67
- xl: "180px"
68
- },
69
- width: "100%",
70
- padding: "10px 20px",
71
- mt: -4
72
- }, /* @__PURE__ */React.createElement(ui.Box, {
73
- width: "100%"
74
- }, /* @__PURE__ */React.createElement(ui.Box, {
75
- height: "10px",
76
- backgroundColor: colors.tradeMe,
77
- width: "100%"
78
- }), /* @__PURE__ */React.createElement(ui.Box, {
79
- display: "flex",
80
- justify: "space-between",
81
- width: "100%",
82
- align: "flex-start",
83
- mt: 2
84
- }, /* @__PURE__ */React.createElement(ui.Text, {
85
- transform: "uppercase",
86
- fontSize: 12,
87
- weight: "600"
88
- }, "TradeMe"), /* @__PURE__ */React.createElement(ui.Text, {
89
- transform: "uppercase",
90
- fontSize: 32,
91
- weight: "700",
92
- mt: -3,
93
- color: "textPrimary"
94
- }, tradeMeEnquiriesCount))), /* @__PURE__ */React.createElement(ui.Box, {
95
- width: "100%",
96
- mt: "30px"
97
- }, /* @__PURE__ */React.createElement(ui.Box, {
98
- height: "10px",
99
- backgroundColor: colors.bookMe,
100
- width: "100%"
101
- }), /* @__PURE__ */React.createElement(ui.Box, {
102
- display: "flex",
103
- justify: "space-between",
104
- width: "100%",
105
- align: "flex-start",
106
- mt: 2
107
- }, /* @__PURE__ */React.createElement(ui.Text, {
108
- transform: "uppercase",
109
- fontSize: 12,
110
- weight: "600"
111
- }, "Bookme"), /* @__PURE__ */React.createElement(ui.Text, {
112
- transform: "uppercase",
113
- fontSize: 32,
114
- weight: "700",
115
- mt: -3,
116
- color: "textPrimary"
117
- }, bookMeEnquiriesCount))), /* @__PURE__ */React.createElement(ui.Box, {
118
- width: "100%",
119
- mt: "30px"
120
- }, /* @__PURE__ */React.createElement(ui.Box, {
121
- height: "10px",
122
- backgroundColor: colors.manual,
123
- width: "100%"
124
- }), /* @__PURE__ */React.createElement(ui.Box, {
125
- display: "flex",
126
- justify: "space-between",
127
- width: "100%",
128
- align: "flex-start",
129
- mt: 2
130
- }, /* @__PURE__ */React.createElement(ui.Text, {
131
- transform: "uppercase",
132
- fontSize: 12,
133
- weight: "600"
134
- }, "Manually", /* @__PURE__ */React.createElement("br", null), "Generated"), /* @__PURE__ */React.createElement(ui.Text, {
135
- transform: "uppercase",
136
- fontSize: 32,
137
- weight: "700",
138
- color: "textPrimary",
139
- mt: -3
140
- }, manualEnquiryCount)))));
141
- }
142
-
143
- exports.default = EnquiriesDoughnutChart;
@@ -1,139 +0,0 @@
1
- import React from 'react';
2
- import { Box, Text } from '@tenancy.nz/ui';
3
- import { Chart } from 'primereact/chart.js';
4
-
5
- function EnquiriesDoughnutChart(_ref) {
6
- var _ref$tradeMeEnquiries = _ref.tradeMeEnquiriesCount,
7
- tradeMeEnquiriesCount = _ref$tradeMeEnquiries === void 0 ? 0 : _ref$tradeMeEnquiries,
8
- _ref$bookMeEnquiriesC = _ref.bookMeEnquiriesCount,
9
- bookMeEnquiriesCount = _ref$bookMeEnquiriesC === void 0 ? 0 : _ref$bookMeEnquiriesC,
10
- _ref$manualEnquiryCou = _ref.manualEnquiryCount,
11
- manualEnquiryCount = _ref$manualEnquiryCou === void 0 ? 0 : _ref$manualEnquiryCou;
12
- var colors = {
13
- tradeMe: "#6FD3C0",
14
- bookMe: "#00C0F3",
15
- manual: "#394869"
16
- };
17
- var chartColors = [colors.tradeMe, colors.bookMe, colors.manual];
18
- return /* @__PURE__ */React.createElement(Box, {
19
- position: "relative",
20
- display: "flex",
21
- height: "100%",
22
- align: "center"
23
- }, /* @__PURE__ */React.createElement(Text, {
24
- transform: "uppercase",
25
- sx: {
26
- position: "absolute",
27
- left: 20,
28
- top: -10
29
- },
30
- fontSize: 13,
31
- color: "textPrimary",
32
- weight: "700"
33
- }, "Number of enquiries"), /* @__PURE__ */React.createElement(Box, {
34
- width: "100%",
35
- overflow: "hidden"
36
- }, /* @__PURE__ */React.createElement(Chart, {
37
- type: "doughnut",
38
- data: {
39
- labels: ["TradeMe", "BookMe", "Manual"],
40
- datasets: [{
41
- data: [Math.max(tradeMeEnquiriesCount, 1e-3), Math.max(bookMeEnquiriesCount, 1e-3), Math.max(manualEnquiryCount, 1e-3)],
42
- backgroundColor: chartColors,
43
- hoverBackgroundColor: chartColors
44
- }]
45
- },
46
- options: {
47
- legend: {
48
- display: false
49
- },
50
- animation: {
51
- duration: 0
52
- }
53
- },
54
- style: {
55
- width: "100%",
56
- position: "absolute",
57
- top: "18%",
58
- left: "-75px"
59
- }
60
- })), /* @__PURE__ */React.createElement(Box, {
61
- maxWidth: {
62
- xs: "160px",
63
- xl: "180px"
64
- },
65
- width: "100%",
66
- padding: "10px 20px",
67
- mt: -4
68
- }, /* @__PURE__ */React.createElement(Box, {
69
- width: "100%"
70
- }, /* @__PURE__ */React.createElement(Box, {
71
- height: "10px",
72
- backgroundColor: colors.tradeMe,
73
- width: "100%"
74
- }), /* @__PURE__ */React.createElement(Box, {
75
- display: "flex",
76
- justify: "space-between",
77
- width: "100%",
78
- align: "flex-start",
79
- mt: 2
80
- }, /* @__PURE__ */React.createElement(Text, {
81
- transform: "uppercase",
82
- fontSize: 12,
83
- weight: "600"
84
- }, "TradeMe"), /* @__PURE__ */React.createElement(Text, {
85
- transform: "uppercase",
86
- fontSize: 32,
87
- weight: "700",
88
- mt: -3,
89
- color: "textPrimary"
90
- }, tradeMeEnquiriesCount))), /* @__PURE__ */React.createElement(Box, {
91
- width: "100%",
92
- mt: "30px"
93
- }, /* @__PURE__ */React.createElement(Box, {
94
- height: "10px",
95
- backgroundColor: colors.bookMe,
96
- width: "100%"
97
- }), /* @__PURE__ */React.createElement(Box, {
98
- display: "flex",
99
- justify: "space-between",
100
- width: "100%",
101
- align: "flex-start",
102
- mt: 2
103
- }, /* @__PURE__ */React.createElement(Text, {
104
- transform: "uppercase",
105
- fontSize: 12,
106
- weight: "600"
107
- }, "Bookme"), /* @__PURE__ */React.createElement(Text, {
108
- transform: "uppercase",
109
- fontSize: 32,
110
- weight: "700",
111
- mt: -3,
112
- color: "textPrimary"
113
- }, bookMeEnquiriesCount))), /* @__PURE__ */React.createElement(Box, {
114
- width: "100%",
115
- mt: "30px"
116
- }, /* @__PURE__ */React.createElement(Box, {
117
- height: "10px",
118
- backgroundColor: colors.manual,
119
- width: "100%"
120
- }), /* @__PURE__ */React.createElement(Box, {
121
- display: "flex",
122
- justify: "space-between",
123
- width: "100%",
124
- align: "flex-start",
125
- mt: 2
126
- }, /* @__PURE__ */React.createElement(Text, {
127
- transform: "uppercase",
128
- fontSize: 12,
129
- weight: "600"
130
- }, "Manually", /* @__PURE__ */React.createElement("br", null), "Generated"), /* @__PURE__ */React.createElement(Text, {
131
- transform: "uppercase",
132
- fontSize: 32,
133
- weight: "700",
134
- color: "textPrimary",
135
- mt: -3
136
- }, manualEnquiryCount)))));
137
- }
138
-
139
- export { EnquiriesDoughnutChart as default };