sag_components 1.0.21 → 1.0.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sag_components",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -51,7 +51,8 @@
51
51
  "@mui/styled-engine-sc": "^5.12.0",
52
52
  "classnames": "^2.3.2",
53
53
  "hoopy": "^0.1.4",
54
- "react-scripts": "5.0.1"
54
+ "react-scripts": "5.0.1",
55
+ "recharts": "^2.6.2"
55
56
  },
56
57
  "browserslist": {
57
58
  "production": [
package/src/App.css CHANGED
@@ -1,6 +1,6 @@
1
1
  .App {
2
- display: block;
2
+ display: flex;
3
3
  width: 600px;
4
- padding-top: 5%;
5
- padding-left: 5%;
4
+ padding-top: 10%;
5
+ padding-left: 10%;
6
6
  }
package/src/App.js CHANGED
@@ -5,6 +5,8 @@ import { useState } from "react";
5
5
  import Button from "./stories/components/Button";
6
6
  import Dropdown from "./stories/components/Dropdown";
7
7
  import SegmentedButton from "./stories/components/SegmentedButton";
8
+ import TotalDoughnutChart from "./stories/components/TotalDoughnutChart";
9
+ import OneColumnContainer from "./stories/components/OneColumnContainer";
8
10
 
9
11
  const onChangehandler = (event, newValue) => {
10
12
  console.log("Dropdown onChange event returned:");
@@ -29,7 +31,7 @@ function App() {
29
31
  { id: "9", label: "South Eastern Grocers" },
30
32
  ];
31
33
 
32
- const segmentsArr1=[
34
+ const segmentsArr1 = [
33
35
  {
34
36
  label: "Complete",
35
37
  value: "complete",
@@ -44,7 +46,7 @@ function App() {
44
46
  },
45
47
  ];
46
48
 
47
- const segmentsArr2=[
49
+ const segmentsArr2 = [
48
50
  {
49
51
  label: "First",
50
52
  value: "first",
@@ -57,13 +59,44 @@ function App() {
57
59
  label: "Third",
58
60
  value: "third",
59
61
  },
60
- ]
62
+ ];
61
63
 
62
64
  const [selectedValue1, setSelectedValue1] = useState("complete");
63
65
  const [selectedValue2, setSelectedValue2] = useState("complete");
64
66
 
65
67
  return (
66
68
  <div className="App">
69
+ <OneColumnContainer
70
+ height="250px"
71
+ infoText="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"
72
+ width="250px"
73
+ />
74
+
75
+ <TotalDoughnutChart
76
+ currency
77
+ currencyType="USD"
78
+ dotCut
79
+ height={374}
80
+ legendData={[
81
+ {
82
+ color: "#85A1D2",
83
+ currency: "USD",
84
+ name: "Package Cost",
85
+ value: 30000,
86
+ },
87
+ {
88
+ color: "#9AE6FF",
89
+ currency: "USD",
90
+ name: "Redemption Cost",
91
+ value: 6500,
92
+ },
93
+ ]}
94
+ textColor="#212121"
95
+ title="Total Cost"
96
+ value={36500}
97
+ width={336}
98
+ />
99
+ {/*
67
100
  <Dropdown
68
101
  width="300"
69
102
  size="small"
@@ -84,24 +117,33 @@ function App() {
84
117
  onChange={onChangehandler}
85
118
  onInputChange={onInputChangeHandler}
86
119
  />
87
-
88
- <SegmentedButton
89
- name="group1"
90
- onClick={(val) => setSelectedValue1(val)}
91
- segments={segmentsArr1}
92
- />
93
- <p className="selected-item">Selected: {selectedValue1}</p>
94
120
  <SegmentedButton
95
- name="group2"
96
- onClick={(val) => setSelectedValue2(val)}
97
- defaultIndex={1}
98
- segments={segmentsArr2}
99
- />
100
- <p className="selected-item">Selected: {selectedValue2}</p>
101
-
121
+ backgroundColor="#ECF0FF"
122
+ controlRadius={8}
123
+ defaultIndex={0}
124
+ fontSize={14}
125
+ name="segmentedFilter"
126
+ onClick={() => {}}
127
+ options={[
128
+ {
129
+ value: "Total",
130
+ },
131
+ {
132
+ value: "Ecommerce",
133
+ },
134
+ {
135
+ value: "In Store",
136
+ },
137
+ ]}
138
+ segmentHeigth={40}
139
+ segmentRadius={8}
140
+ segmentWidth={120}
141
+ selectedSegmentColor="#fcfcfc"
142
+ selectedTextColor="#000000"
143
+ unselectedTextColor="#000000"
144
+ /> */}
102
145
  </div>
103
146
  );
104
147
  }
105
148
 
106
-
107
149
  export default App;
@@ -0,0 +1,112 @@
1
+ import React from "react";
2
+ import { TotalDoughnutChart } from "./components/TotalDoughnutChart";
3
+
4
+ const arrLegendData = [
5
+ { name: "Package Cost", value: 30000, color: "#85A1D2"},
6
+ { name: "Redemption Cost", value: 6500, color: "#9AE6FF"},
7
+ ];
8
+
9
+ const arrLegendDat3rows = [
10
+ { name: "Package Cost", value: 30000, color: "#85A1D2"},
11
+ { name: "Redemption Cost", value: 6500,color: "#9AE6FF"},
12
+ { name: "Others", value: 20000, color: "#FD5959"},
13
+ // { name: "My test 2", value: 35000, color: "#79DB95"},
14
+ ];
15
+
16
+
17
+ export default {
18
+ title: "SAG/TotalDoughnutChart",
19
+ component: TotalDoughnutChart,
20
+ tags: ["autodocs"],
21
+
22
+ argTypes: {
23
+
24
+ title: {
25
+ name: "title",
26
+ control: { type: "text" },
27
+ description: "title on top of the component",
28
+ },
29
+
30
+ value: {
31
+ name: "value",
32
+ control: { type: "number", min: 0, max: 100000000000000 },
33
+ description: "value (total) ",
34
+ },
35
+
36
+ dotCut: {
37
+ name: "dotCut",
38
+ control: { type: "boolean" },
39
+ description: "true/false - format total value with dot cut",
40
+ },
41
+
42
+ currency: {
43
+ name: "currency",
44
+ control: { type: "boolean" },
45
+ description: "true/false - show/hide currency before total value",
46
+ },
47
+
48
+
49
+ currencyType: {
50
+ name: "currencyType",
51
+ options: ["USD", "EUR", "ILS", "GBP", "JPY"],
52
+ control: { type: "select" },
53
+ },
54
+
55
+
56
+ width: {
57
+ name: "width",
58
+ control: { type: "number", min: 0, max: 600 },
59
+ description: "width of the control (in px)",
60
+ },
61
+
62
+ height: {
63
+ name: "height",
64
+ control: { type: "number", min: 0, max: 600 },
65
+ description: "height of the control (in px)",
66
+ },
67
+
68
+
69
+ textColor: {
70
+ name: "textColor",
71
+ description: "Sets the text color",
72
+ control: {
73
+ type: "color",
74
+ presetColors: ["#ffffff", "#ff0000", "#00ff00", "#0000ff"],
75
+ },
76
+ },
77
+
78
+ legendData: {
79
+ description:
80
+ "array [] of objects: {displayName: string, value:number} to fill the pie chart ",
81
+ },
82
+ },
83
+ };
84
+
85
+ const Template = (args) => <TotalDoughnutChart {...args} />;
86
+
87
+ export const TotalCost = Template.bind({});
88
+ TotalCost.args = {
89
+ title: "Total Cost",
90
+ value: 36500,
91
+ dotCut: true,
92
+ currency: true,
93
+ currencyType: "USD",
94
+ legendData: arrLegendData,
95
+ width: 336,
96
+ height: 374,
97
+ textColor: "#212121",
98
+ };
99
+
100
+
101
+ export const TotalCost3rows = Template.bind({});
102
+ TotalCost3rows.args = {
103
+ title: "Total Cost",
104
+ value: 56500,
105
+ dotCut: true,
106
+ currency: true,
107
+ currencyType: "USD",
108
+ legendData: arrLegendDat3rows,
109
+ width: 336,
110
+ height: 374,
111
+ textColor: "#212121",
112
+ };
@@ -0,0 +1,135 @@
1
+ import styled from "styled-components";
2
+
3
+ export const ControlsContainer = styled.div`
4
+ display: flex;
5
+ position: relative;
6
+ margin: 0px 0 0px;
7
+ font-family: "Lato", sans-serif;
8
+ font-style: normal;
9
+ color: ${(props) => {
10
+ return props.textColor;
11
+ }};
12
+ width: ${(props) => {
13
+ return props.width.toString().concat("", "px");
14
+ }};
15
+ height: ${(props) => {
16
+ return props.height.toString().concat("", "px");
17
+ }};
18
+ //box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
19
+ border-radius: 12px;
20
+ //border: 1px solid red;
21
+ `;
22
+
23
+ export const Controls = styled.div`
24
+ position: relative;
25
+ border-radius: 12px;
26
+ width: ${(props) => {
27
+ return props.width.toString().concat("", "px");
28
+ }};
29
+ height: ${(props) => {
30
+ return props.height.toString().concat("", "px");
31
+ }};
32
+ background: #ffffff;
33
+ //border: 1px solid blue;
34
+ `;
35
+
36
+ export const Title = styled.div`
37
+ position: absolute;
38
+ width: 150px;
39
+ height: 22px;
40
+ left: 40px;
41
+ top: 81px;
42
+ font-weight: 600;
43
+ font-size: 18px;
44
+ line-height: 22px;
45
+ //border: 1px solid red;
46
+ `;
47
+
48
+ export const CurrencySign = styled.div`
49
+ position: absolute;
50
+ width: 11px;
51
+ height: 22px;
52
+ left: 42px;
53
+ top: 135px;
54
+ font-weight: 500;
55
+ font-size: 18px;
56
+ line-height: 22px;
57
+ //border: 1px solid red;
58
+ `;
59
+
60
+ export const FormattedValue = styled.div`
61
+ position: absolute;
62
+ width: 200px;
63
+ height: 48px;
64
+ left: 57px;
65
+ top: 115px;
66
+ font-weight: 500;
67
+ font-size: 40px;
68
+ line-height: 48px;
69
+ //border: 1px solid red;
70
+ `;
71
+
72
+ export const DoughnutChart = styled.div`
73
+ position: absolute;
74
+ width: 95px;
75
+ height: 95px;
76
+ left: 40px;
77
+ top: 221px;
78
+ //border: 1px solid red;
79
+ `;
80
+
81
+ export const LegendControls = styled.div`
82
+ position: relative;
83
+ border-radius: 12px;
84
+ width: 180px;
85
+ height: 47px;
86
+ left: 150px;
87
+ top: 221px;
88
+ background: #ffffff;
89
+ //border: 1px solid blue;
90
+ `;
91
+
92
+ export const LegendColorRectangle = styled.div`
93
+ position: absolute;
94
+ width: 16px;
95
+ height: 16px;
96
+ left: 14px;
97
+ top: 14px;
98
+ background: ${(props) => props.color};
99
+ `;
100
+
101
+ export const LegendTitle = styled.div`
102
+ position: absolute;
103
+ width: 120px;
104
+ height: 18px;
105
+ left: 40px;
106
+ top: 1px;
107
+ font-weight: 400;
108
+ font-size: 14px;
109
+ line-height: 17px;
110
+ //border: 1px solid red;
111
+ `;
112
+
113
+ export const LegendCurrencySign = styled.div`
114
+ position: absolute;
115
+ width: 11px;
116
+ height: 19px;
117
+ left: 42px;
118
+ top: 21px;
119
+ font-weight: 600;
120
+ font-size: 16px;
121
+ line-height: 19px;
122
+ //border: 1px solid red;
123
+ `;
124
+
125
+ export const LegendFormattedValue = styled.div`
126
+ position: absolute;
127
+ width: 100px;
128
+ height: 19px;
129
+ left: 52px;
130
+ top: 21px;
131
+ font-weight: 600;
132
+ font-size: 16px;
133
+ line-height: 19px;
134
+ //border: 1px solid red;
135
+ `;
@@ -9,9 +9,6 @@ import classNames from "classnames";
9
9
  */
10
10
  export const OneColumnContainer = ({ children,nodeRef,itemClass,overStyle,draggingStyle,droppedStyle,refId,width,height,infoText,...props }) => {
11
11
  const [clicked, setClicked] = useState(false);
12
- const { over,isOver, setNodeRef } = useDroppable({
13
- refId,
14
- });
15
12
  const onInfoClick = ()=>{
16
13
  setClicked(!clicked)
17
14
  }
@@ -22,11 +19,14 @@ export const OneColumnContainer = ({ children,nodeRef,itemClass,overStyle,draggi
22
19
  itemClass,
23
20
  overStyle,
24
21
  draggingStyle,
25
- droppedStyle
22
+ children && droppedStyle
26
23
  )} width={width} height={height}>
27
24
  <div ref={nodeRef} style={{
25
+
28
26
  width: "100%",
29
- height: "100%"
27
+ height: "100%",
28
+ display: "grid",
29
+ gridTemplateColumns: "repeat(2, 1fr)"
30
30
  }}>
31
31
  {children}
32
32
  <InfoTextContainer clicked={clicked} width={width} height={height}>
@@ -0,0 +1,135 @@
1
+ import React from "react";
2
+
3
+ import { PieChart as SourcePieChart, Pie, Cell, Tooltip } from "recharts";
4
+
5
+ import {
6
+ ControlsContainer,
7
+ Title,
8
+ CurrencySign,
9
+ FormattedValue,
10
+ Controls,
11
+ DoughnutChart,
12
+ LegendControls,
13
+ LegendColorRectangle,
14
+ LegendTitle,
15
+ LegendCurrencySign,
16
+ LegendFormattedValue,
17
+ } from "../TotalDoughnutChart.style.js";
18
+
19
+ /*TotalDoughnutChart*/
20
+ export const TotalDoughnutChart = ({
21
+ title = "Total Cost",
22
+ value = 0,
23
+ dotCut = true,
24
+ currency = true,
25
+ currencyType = "USD",
26
+ legendData,
27
+ width = 336,
28
+ height = 374,
29
+ textColor = "black",
30
+ ...props
31
+ }) => {
32
+ const getCurrencySign = (currencyTypeToConvert) => {
33
+ if (!currencyTypeToConvert) return "";
34
+ let currencySign = "";
35
+ const currencyFormatter = new Intl.NumberFormat("en-US", {
36
+ style: "currency",
37
+ currency: currencyTypeToConvert,
38
+ });
39
+ currencySign = currencyFormatter.format(value).substring(0, 1);
40
+ return currencySign;
41
+ };
42
+
43
+ const getFormattedUnits = (num) => {
44
+ if (Math.abs(num) >= 1000000000) {
45
+ return "B";
46
+ }
47
+ if (Math.abs(num) >= 1000000) {
48
+ return "M";
49
+ }
50
+ if (Math.abs(num) >= 1000) {
51
+ return "K";
52
+ }
53
+ return "";
54
+ };
55
+
56
+ const getFormattedValue = (num) => {
57
+ if (Math.abs(num) >= 1000000000) {
58
+ return (num / 1000000000).toFixed(1).replace(/\.0$/, "");
59
+ }
60
+ if (Math.abs(num) >= 1000000) {
61
+ return (num / 1000000).toFixed(1).replace(/\.0$/, "");
62
+ }
63
+ if (Math.abs(num) >= 1000) {
64
+ return (num / 1000).toFixed(1).replace(/\.0$/, "");
65
+ }
66
+ return num;
67
+ };
68
+
69
+ const getNumberWithCommas = (x) => {
70
+ x = x.toString();
71
+ var pattern = /(-?\d+)(\d{3})/;
72
+ while (pattern.test(x)) x = x.replace(pattern, "$1,$2");
73
+ return x;
74
+ };
75
+
76
+ const onPieEnterHandler = () => {};
77
+
78
+ return (
79
+ <ControlsContainer height={height} width={width} textColor={textColor}>
80
+ <Controls height={height} width={width}>
81
+ <Title>{title}</Title>
82
+
83
+ <CurrencySign>
84
+ {`${currency ? getCurrencySign(currencyType) : ""}`}
85
+ </CurrencySign>
86
+ <FormattedValue>
87
+ {`${dotCut ? getFormattedValue(value) : getNumberWithCommas(value)}`}
88
+ {`${dotCut ? getFormattedUnits(value) : ""}`}
89
+ </FormattedValue>
90
+
91
+ {legendData.map((row, index) => (
92
+ <LegendControls>
93
+ <LegendColorRectangle color={row.color}></LegendColorRectangle>
94
+ <LegendTitle>{row.name}</LegendTitle>
95
+ <LegendCurrencySign>
96
+ {`${currency ? getCurrencySign(currencyType) : ""}`}
97
+ </LegendCurrencySign>
98
+ <LegendFormattedValue>
99
+ {`${
100
+ dotCut
101
+ ? getFormattedValue(row.value)
102
+ : getNumberWithCommas(row.value)
103
+ }`}
104
+ {`${dotCut ? getFormattedUnits(row.value) : ""}`}
105
+ </LegendFormattedValue>
106
+ </LegendControls>
107
+ ))}
108
+
109
+ <DoughnutChart>
110
+ <SourcePieChart
111
+ width={93}
112
+ height={93}
113
+ onMouseEnter={onPieEnterHandler}
114
+ >
115
+ <Pie
116
+ data={legendData}
117
+ innerRadius={32}
118
+ outerRadius={47}
119
+ fill="#8884d8"
120
+ dataKey="value"
121
+ >
122
+ {legendData.map((row, index) => (
123
+ <Cell key={`cell-${index}`} fill={row.color} />
124
+ ))}
125
+ </Pie>
126
+
127
+ <Tooltip/>
128
+ </SourcePieChart>
129
+ </DoughnutChart>
130
+ </Controls>
131
+ </ControlsContainer>
132
+ );
133
+ };
134
+
135
+ export default TotalDoughnutChart;