@carbon/charts-react 0.58.1 → 0.59.0-beta.0

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 (162) hide show
  1. package/.babelrc +4 -0
  2. package/.prettierignore +1 -0
  3. package/.storybook/addons.js +2 -0
  4. package/.storybook/assets/logo.svg +1 -0
  5. package/.storybook/assets/share.png +0 -0
  6. package/.storybook/assets/welcome.png +0 -0
  7. package/.storybook/config.js +22 -0
  8. package/.storybook/main.js +24 -0
  9. package/.storybook/manager-head.html +42 -0
  10. package/.storybook/preview-head.html +10 -0
  11. package/build.sh +20 -0
  12. package/carbon.yml +275 -0
  13. package/carbon__charts-react-tests.tsx +83 -0
  14. package/demo/bundle/favicon.ico +0 -0
  15. package/demo/bundle/index.html +22 -0
  16. package/demo/bundle/logo.svg +1 -0
  17. package/demo/bundle/main.4a87b5852cddf04c8e9a.bundle.js +1 -0
  18. package/demo/bundle/runtime~main.6b70b35614cf83eab770.bundle.js +1 -0
  19. package/demo/bundle/sb_dll/storybook_ui-manifest.json +1 -0
  20. package/demo/bundle/sb_dll/storybook_ui_dll.LICENCE +113 -0
  21. package/demo/bundle/sb_dll/storybook_ui_dll.js +2 -0
  22. package/demo/bundle/share.png +0 -0
  23. package/demo/bundle/vendors~main.9ceec0efe2f3ef413ade.bundle.js +111 -0
  24. package/demo/bundle/welcome.png +0 -0
  25. package/dist/CHANGELOG.md +2150 -0
  26. package/dist/README.md +56 -0
  27. package/{alluvial-chart.d.ts → dist/alluvial-chart.d.ts} +0 -0
  28. package/{alluvial-chart.js → dist/alluvial-chart.js} +0 -0
  29. package/{area-chart-stacked.d.ts → dist/area-chart-stacked.d.ts} +0 -0
  30. package/{area-chart-stacked.js → dist/area-chart-stacked.js} +0 -0
  31. package/{area-chart.d.ts → dist/area-chart.d.ts} +0 -0
  32. package/{area-chart.js → dist/area-chart.js} +0 -0
  33. package/{bar-chart-grouped.d.ts → dist/bar-chart-grouped.d.ts} +0 -0
  34. package/{bar-chart-grouped.js → dist/bar-chart-grouped.js} +0 -0
  35. package/{bar-chart-simple.d.ts → dist/bar-chart-simple.d.ts} +0 -0
  36. package/{bar-chart-simple.js → dist/bar-chart-simple.js} +0 -0
  37. package/{bar-chart-stacked.d.ts → dist/bar-chart-stacked.d.ts} +0 -0
  38. package/{bar-chart-stacked.js → dist/bar-chart-stacked.js} +0 -0
  39. package/{base-chart.d.ts → dist/base-chart.d.ts} +0 -0
  40. package/{base-chart.js → dist/base-chart.js} +0 -0
  41. package/{boxplot-chart.d.ts → dist/boxplot-chart.d.ts} +0 -0
  42. package/{boxplot-chart.js → dist/boxplot-chart.js} +0 -0
  43. package/{bubble-chart.d.ts → dist/bubble-chart.d.ts} +0 -0
  44. package/{bubble-chart.js → dist/bubble-chart.js} +0 -0
  45. package/{bullet-chart.d.ts → dist/bullet-chart.d.ts} +0 -0
  46. package/{bullet-chart.js → dist/bullet-chart.js} +0 -0
  47. package/{bundle.js → dist/bundle.js} +0 -0
  48. package/{circle-pack-chart.d.ts → dist/circle-pack-chart.d.ts} +0 -0
  49. package/{circle-pack-chart.js → dist/circle-pack-chart.js} +0 -0
  50. package/{combo-chart.d.ts → dist/combo-chart.d.ts} +0 -0
  51. package/{combo-chart.js → dist/combo-chart.js} +0 -0
  52. package/{diagrams → dist/diagrams}/CardNode/CardNode.d.ts +0 -0
  53. package/{diagrams → dist/diagrams}/CardNode/CardNode.js +3 -4
  54. package/{diagrams → dist/diagrams}/CardNode/CardNodeColumn.d.ts +0 -0
  55. package/{diagrams → dist/diagrams}/CardNode/CardNodeColumn.js +3 -4
  56. package/{diagrams → dist/diagrams}/CardNode/CardNodeLabel.d.ts +0 -0
  57. package/{diagrams → dist/diagrams}/CardNode/CardNodeLabel.js +3 -4
  58. package/{diagrams → dist/diagrams}/CardNode/CardNodeSubtitle.d.ts +0 -0
  59. package/{diagrams → dist/diagrams}/CardNode/CardNodeSubtitle.js +3 -4
  60. package/{diagrams → dist/diagrams}/CardNode/CardNodeTitle.d.ts +0 -0
  61. package/{diagrams → dist/diagrams}/CardNode/CardNodeTitle.js +3 -4
  62. package/{diagrams → dist/diagrams}/CardNode/index.d.ts +0 -0
  63. package/{diagrams → dist/diagrams}/CardNode/index.js +0 -0
  64. package/{diagrams → dist/diagrams}/Edge/Edge.d.ts +0 -0
  65. package/{diagrams → dist/diagrams}/Edge/Edge.js +3 -4
  66. package/{diagrams → dist/diagrams}/Edge/index.d.ts +0 -0
  67. package/{diagrams → dist/diagrams}/Edge/index.js +0 -0
  68. package/{diagrams → dist/diagrams}/Marker/Marker.d.ts +0 -0
  69. package/{diagrams → dist/diagrams}/Marker/Marker.js +3 -4
  70. package/{diagrams → dist/diagrams}/Marker/index.d.ts +0 -0
  71. package/{diagrams → dist/diagrams}/Marker/index.js +0 -0
  72. package/{diagrams → dist/diagrams}/ShapeNode/ShapeNode.d.ts +0 -0
  73. package/{diagrams → dist/diagrams}/ShapeNode/ShapeNode.js +3 -4
  74. package/{diagrams → dist/diagrams}/ShapeNode/index.d.ts +0 -0
  75. package/{diagrams → dist/diagrams}/ShapeNode/index.js +0 -0
  76. package/dist/diagrams/configs.d.ts +1 -0
  77. package/dist/diagrams/configs.js +4 -0
  78. package/{donut-chart.d.ts → dist/donut-chart.d.ts} +0 -0
  79. package/{donut-chart.js → dist/donut-chart.js} +0 -0
  80. package/{gauge-chart.d.ts → dist/gauge-chart.d.ts} +0 -0
  81. package/{gauge-chart.js → dist/gauge-chart.js} +0 -0
  82. package/{heatmap-chart.d.ts → dist/heatmap-chart.d.ts} +0 -0
  83. package/{heatmap-chart.js → dist/heatmap-chart.js} +0 -0
  84. package/{histogram-chart.d.ts → dist/histogram-chart.d.ts} +0 -0
  85. package/{histogram-chart.js → dist/histogram-chart.js} +0 -0
  86. package/{index.d.ts → dist/index.d.ts} +0 -0
  87. package/{index.js → dist/index.js} +0 -0
  88. package/{line-chart.d.ts → dist/line-chart.d.ts} +0 -0
  89. package/{line-chart.js → dist/line-chart.js} +0 -0
  90. package/{lollipop-chart.d.ts → dist/lollipop-chart.d.ts} +0 -0
  91. package/{lollipop-chart.js → dist/lollipop-chart.js} +0 -0
  92. package/{meter-chart.d.ts → dist/meter-chart.d.ts} +0 -0
  93. package/{meter-chart.js → dist/meter-chart.js} +0 -0
  94. package/dist/package.json +107 -0
  95. package/{pie-chart.d.ts → dist/pie-chart.d.ts} +0 -0
  96. package/{pie-chart.js → dist/pie-chart.js} +0 -0
  97. package/{radar-chart.d.ts → dist/radar-chart.d.ts} +0 -0
  98. package/{radar-chart.js → dist/radar-chart.js} +0 -0
  99. package/{scatter-chart.d.ts → dist/scatter-chart.d.ts} +0 -0
  100. package/{scatter-chart.js → dist/scatter-chart.js} +0 -0
  101. package/{tree-chart.d.ts → dist/tree-chart.d.ts} +0 -0
  102. package/{tree-chart.js → dist/tree-chart.js} +0 -0
  103. package/{treemap-chart.d.ts → dist/treemap-chart.d.ts} +0 -0
  104. package/{treemap-chart.js → dist/treemap-chart.js} +0 -0
  105. package/{utils.d.ts → dist/utils.d.ts} +0 -0
  106. package/{utils.js → dist/utils.js} +0 -0
  107. package/{wordcloud-chart.d.ts → dist/wordcloud-chart.d.ts} +0 -0
  108. package/{wordcloud-chart.js → dist/wordcloud-chart.js} +0 -0
  109. package/helpers/commons.js +30 -0
  110. package/package.json +106 -106
  111. package/rollup.config.js +18 -0
  112. package/src/alluvial-chart.tsx +30 -0
  113. package/src/area-chart-stacked.tsx +33 -0
  114. package/src/area-chart.tsx +30 -0
  115. package/src/bar-chart-grouped.tsx +30 -0
  116. package/src/bar-chart-simple.tsx +30 -0
  117. package/src/bar-chart-stacked.tsx +30 -0
  118. package/src/base-chart.tsx +45 -0
  119. package/src/boxplot-chart.tsx +30 -0
  120. package/src/bubble-chart.tsx +30 -0
  121. package/src/bullet-chart.tsx +30 -0
  122. package/src/circle-pack-chart.tsx +30 -0
  123. package/src/combo-chart.tsx +30 -0
  124. package/src/diagrams/CardNode/CardNode.tsx +121 -0
  125. package/src/diagrams/CardNode/CardNodeColumn.tsx +38 -0
  126. package/src/diagrams/CardNode/CardNodeLabel.tsx +32 -0
  127. package/src/diagrams/CardNode/CardNodeSubtitle.tsx +32 -0
  128. package/src/diagrams/CardNode/CardNodeTitle.tsx +32 -0
  129. package/src/diagrams/CardNode/index.tsx +13 -0
  130. package/src/diagrams/Edge/Edge.tsx +137 -0
  131. package/src/diagrams/Edge/index.tsx +2 -0
  132. package/src/diagrams/Marker/Marker.tsx +121 -0
  133. package/src/diagrams/Marker/index.tsx +9 -0
  134. package/src/diagrams/ShapeNode/ShapeNode.tsx +153 -0
  135. package/src/diagrams/ShapeNode/index.tsx +2 -0
  136. package/src/diagrams/configs.ts +1 -0
  137. package/src/donut-chart.tsx +30 -0
  138. package/src/gauge-chart.tsx +30 -0
  139. package/src/heatmap-chart.tsx +30 -0
  140. package/src/histogram-chart.tsx +30 -0
  141. package/src/index.ts +51 -0
  142. package/src/line-chart.tsx +30 -0
  143. package/src/lollipop-chart.tsx +30 -0
  144. package/src/meter-chart.tsx +30 -0
  145. package/src/pie-chart.tsx +30 -0
  146. package/src/radar-chart.tsx +30 -0
  147. package/src/scatter-chart.tsx +30 -0
  148. package/src/tree-chart.tsx +30 -0
  149. package/src/treemap-chart.tsx +30 -0
  150. package/src/utils.ts +7 -0
  151. package/src/wordcloud-chart.tsx +30 -0
  152. package/stories/0_intro.stories.js +60 -0
  153. package/stories/1_gettingStarted.stories.js +74 -0
  154. package/stories/1_gettingStarted_content.js +121 -0
  155. package/stories/all.stories.js +110 -0
  156. package/stories/diagrams/0_Diagrams.stories.js +259 -0
  157. package/stories/diagrams/CardNode.stories.js +106 -0
  158. package/stories/diagrams/Edge.stories.js +94 -0
  159. package/stories/diagrams/Marker.stories.js +95 -0
  160. package/stories/diagrams/ShapeNode.stories.js +42 -0
  161. package/tsconfig.json +20 -0
  162. package/LICENSE.md +0 -201
@@ -0,0 +1,121 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ // @ts-ignore
5
+ import classnames from 'classnames';
6
+
7
+ // Carbon Prefix
8
+ import { carbonPrefix } from '../configs';
9
+
10
+ const namespace = `${carbonPrefix}--cc--card-node`;
11
+
12
+ const CardNode = ({
13
+ as = 'div',
14
+ children,
15
+ className,
16
+ color,
17
+ href = null,
18
+ onMouseEnter = null,
19
+ onMouseOver = null,
20
+ onMouseOut = null,
21
+ onMouseLeave = null,
22
+ onMouseMove = null,
23
+ onClick = null,
24
+ position = 'static',
25
+ stacked,
26
+ }: any) => {
27
+ let Component = 'div';
28
+
29
+ if (as !== 'div') {
30
+ Component = as;
31
+ } else if (href) {
32
+ Component = 'a';
33
+ } else if (onClick) {
34
+ Component = 'button';
35
+ }
36
+
37
+ const cardClasses = classnames(namespace, {
38
+ [`${namespace}--stacked`]: stacked,
39
+ [`${namespace}--${Component}`]: Component,
40
+ [className]: className,
41
+ });
42
+
43
+ return (
44
+ // @ts-ignore
45
+ <Component
46
+ className={cardClasses}
47
+ onClick={onClick}
48
+ onMouseEnter={onMouseEnter}
49
+ onMouseOver={onMouseOver}
50
+ onMouseOut={onMouseOut}
51
+ onMouseLeave={onMouseLeave}
52
+ onMouseMove={onMouseMove}
53
+ style={{ borderColor: color, position }}
54
+ tabIndex={0}>
55
+ {children}
56
+ </Component>
57
+ );
58
+ };
59
+
60
+ export default CardNode;
61
+
62
+ CardNode.propTypes = {
63
+ /** Provide a custom element to be rendered instead of the default */
64
+ as: PropTypes.elementType,
65
+
66
+ /**
67
+ * Pass in the children that will be rendered within the CardNode
68
+ */
69
+ children: PropTypes.node,
70
+
71
+ /**
72
+ * Provide an optional class to be applied on the outer element
73
+ */
74
+ className: PropTypes.string,
75
+
76
+ /**
77
+ * Specify the node's border color
78
+ */
79
+ color: PropTypes.string,
80
+
81
+ /**
82
+ * Optionally specify an href for the CardNode to become an `<a>` element
83
+ */
84
+ href: PropTypes.string,
85
+
86
+ /**
87
+ * Provide an optional function to be called when the CardNode
88
+ * is clicked, turning the CardNode into a `<button>` element
89
+ */
90
+ onClick: PropTypes.func,
91
+
92
+ /**
93
+ * Provide an optional function to be called for the onMouseEnter event
94
+ */
95
+ onMouseEnter: PropTypes.func,
96
+
97
+ /**
98
+ * Provide an optional function to be called for the onMouseOver event
99
+ */
100
+ onMouseOver: PropTypes.func,
101
+
102
+ /**
103
+ * Provide an optional function to be called for the onMouseOut event
104
+ */
105
+ onMouseOut: PropTypes.func,
106
+
107
+ /**
108
+ * Provide an optional function to be called for the onMouseLeave event
109
+ */
110
+ onMouseLeave: PropTypes.func,
111
+
112
+ /**
113
+ * Provide an optional function to be called for the onMouseMove event
114
+ */
115
+ onMouseMove: PropTypes.func,
116
+
117
+ /**
118
+ * Specify whether the node displays a stacked effect
119
+ */
120
+ stacked: PropTypes.bool,
121
+ };
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ // @ts-ignore
5
+ import classnames from 'classnames';
6
+
7
+ // Carbon Prefix
8
+ import { carbonPrefix } from '../configs';
9
+
10
+ const namespace = `${carbonPrefix}--cc--card-node`;
11
+
12
+ const CardNodeColumn = ({ children, className, farsideColumn }: any) => {
13
+ const classes = classnames(`${namespace}__column`, {
14
+ [`${namespace}__column--farside`]: farsideColumn,
15
+ [className]: className,
16
+ });
17
+
18
+ return <div className={classes}>{children}</div>;
19
+ };
20
+
21
+ export { CardNodeColumn };
22
+
23
+ CardNodeColumn.propTypes = {
24
+ /**
25
+ * Pass in the children that will be rendered within the CardNodeColumn
26
+ */
27
+ children: PropTypes.node,
28
+
29
+ /**
30
+ * Provide an optional class to be applied on the outer element
31
+ */
32
+ className: PropTypes.string,
33
+
34
+ /**
35
+ * Specify whether this is the last column
36
+ */
37
+ farsideColumn: PropTypes.bool,
38
+ };
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ // @ts-ignore
5
+ import classnames from 'classnames';
6
+
7
+ // Carbon Prefix
8
+ import { carbonPrefix } from '../configs';
9
+
10
+ const namespace = `${carbonPrefix}--cc--card-node`;
11
+
12
+ const CardNodeLabel = ({ children, className }: any) => {
13
+ const classes = classnames(`${namespace}__label`, {
14
+ [className]: className,
15
+ });
16
+
17
+ return <label className={classes}>{children}</label>;
18
+ };
19
+
20
+ export { CardNodeLabel };
21
+
22
+ CardNodeLabel.propTypes = {
23
+ /**
24
+ * Pass in the children that will be rendered within the CardNodeLabel
25
+ */
26
+ children: PropTypes.node,
27
+
28
+ /**
29
+ * Provide an optional class to be applied on the outer element
30
+ */
31
+ className: PropTypes.string,
32
+ };
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ // @ts-ignore
5
+ import classnames from 'classnames';
6
+
7
+ // Carbon Prefix
8
+ import { carbonPrefix } from '../configs';
9
+
10
+ const namespace = `${carbonPrefix}--cc--card-node`;
11
+
12
+ const CardNodeSubtitle = ({ children, className }: any) => {
13
+ const classes = classnames(`${namespace}__subtitle`, {
14
+ [className]: className,
15
+ });
16
+
17
+ return <div className={classes}>{children}</div>;
18
+ };
19
+
20
+ export { CardNodeSubtitle };
21
+
22
+ CardNodeSubtitle.propTypes = {
23
+ /**
24
+ * Pass in the children that will be rendered within the CardNodeSubtitle
25
+ */
26
+ children: PropTypes.node,
27
+
28
+ /**
29
+ * Provide an optional class to be applied on the outer element
30
+ */
31
+ className: PropTypes.string,
32
+ };
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ // @ts-ignore
5
+ import classnames from 'classnames';
6
+
7
+ // Carbon Prefix
8
+ import { carbonPrefix } from '../configs';
9
+
10
+ const namespace = `${carbonPrefix}--cc--card-node`;
11
+
12
+ const CardNodeTitle = ({ children, className }: any) => {
13
+ const classes = classnames(`${namespace}__title`, {
14
+ [className]: className,
15
+ });
16
+
17
+ return <div className={classes}>{children}</div>;
18
+ };
19
+
20
+ export { CardNodeTitle };
21
+
22
+ CardNodeTitle.propTypes = {
23
+ /**
24
+ * Pass in the children that will be rendered within the CardNodeTitle
25
+ */
26
+ children: PropTypes.node,
27
+
28
+ /**
29
+ * Provide an optional class to be applied on the outer element
30
+ */
31
+ className: PropTypes.string,
32
+ };
@@ -0,0 +1,13 @@
1
+ import CardNode from './CardNode';
2
+ import { CardNodeColumn } from './CardNodeColumn';
3
+ import { CardNodeLabel } from './CardNodeLabel';
4
+ import { CardNodeSubtitle } from './CardNodeSubtitle';
5
+ import { CardNodeTitle } from './CardNodeTitle';
6
+
7
+ export {
8
+ CardNode as default,
9
+ CardNodeColumn,
10
+ CardNodeSubtitle,
11
+ CardNodeTitle,
12
+ CardNodeLabel,
13
+ };
@@ -0,0 +1,137 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ // Carbon Prefix
5
+ import { carbonPrefix } from '../configs';
6
+
7
+ // @ts-ignore
8
+ import classnames from 'classnames';
9
+
10
+ import { buildStraightPathString } from '@carbon/charts/components/diagrams/buildPaths';
11
+
12
+ const Edge = ({
13
+ className,
14
+ color,
15
+ markerEnd,
16
+ markerStart,
17
+ onMouseEnter = null,
18
+ onMouseOver = null,
19
+ onMouseOut = null,
20
+ onMouseLeave = null,
21
+ onMouseMove = null,
22
+ path,
23
+ source,
24
+ target,
25
+ variant = null,
26
+ }: any) => {
27
+ const namespace = `${carbonPrefix}--cc--edge`;
28
+
29
+ const pathClasses = classnames(namespace, {
30
+ [`${namespace}--${variant}`]: variant,
31
+ [className]: className,
32
+ });
33
+
34
+ const d = path || buildStraightPathString(source, target);
35
+
36
+ return (
37
+ <g
38
+ className={pathClasses}
39
+ onMouseEnter={onMouseEnter}
40
+ onMouseOver={onMouseOver}
41
+ onMouseOut={onMouseOut}
42
+ onMouseLeave={onMouseLeave}
43
+ onMouseMove={onMouseMove}>
44
+ <path d={d} className={`${namespace}__container`} />
45
+ <path d={d} className={`${namespace}__outer`} />
46
+ <path
47
+ d={d}
48
+ className={`${namespace}__inner`}
49
+ markerEnd={`url(#${markerEnd})`}
50
+ markerStart={`url(#${markerStart})`}
51
+ style={{ stroke: color }}
52
+ />
53
+ </g>
54
+ );
55
+ };
56
+
57
+ export default Edge;
58
+
59
+ Edge.propTypes = {
60
+ /**
61
+ * Provide an optional class to be applied on the outer element
62
+ */
63
+ className: PropTypes.string,
64
+
65
+ /**
66
+ * Specify the edge's color
67
+ */
68
+ color: PropTypes.string,
69
+
70
+ /**
71
+ * Specify an ID for a corresponding end marker
72
+ */
73
+ markerEnd: PropTypes.string,
74
+
75
+ /**
76
+ * Specify an ID for a corresponding start marker
77
+ */
78
+ markerStart: PropTypes.string,
79
+
80
+ /**
81
+ * Provide an optional function to be called for the onMouseEnter event
82
+ */
83
+ onMouseEnter: PropTypes.func,
84
+
85
+ /**
86
+ * Provide an optional function to be called for the onMouseOver event
87
+ */
88
+ onMouseOver: PropTypes.func,
89
+
90
+ /**
91
+ * Provide an optional function to be called for the onMouseOut event
92
+ */
93
+ onMouseOut: PropTypes.func,
94
+
95
+ /**
96
+ * Provide an optional function to be called for the onMouseLeave event
97
+ */
98
+ onMouseLeave: PropTypes.func,
99
+
100
+ /**
101
+ * Provide an optional function to be called for the onMouseMove event
102
+ */
103
+ onMouseMove: PropTypes.func,
104
+
105
+ /**
106
+ * Specify a path string
107
+ */
108
+ path: PropTypes.string,
109
+
110
+ /**
111
+ * Coordinates for the source element
112
+ */
113
+ source: PropTypes.shape({
114
+ x: PropTypes.number,
115
+ y: PropTypes.number,
116
+ }),
117
+
118
+ /**
119
+ * Coordinates for the target element
120
+ */
121
+ target: PropTypes.shape({
122
+ x: PropTypes.number,
123
+ y: PropTypes.number,
124
+ }),
125
+
126
+ /**
127
+ * Specify the variant of the edge
128
+ */
129
+ variant: PropTypes.oneOf([
130
+ 'dash-sm',
131
+ 'dash-md',
132
+ 'dash-lg',
133
+ 'dash-xl',
134
+ 'double',
135
+ 'tunnel',
136
+ ]),
137
+ };
@@ -0,0 +1,2 @@
1
+ import Edge from './Edge';
2
+ export default Edge;
@@ -0,0 +1,121 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ // @ts-ignore
5
+ import classnames from 'classnames';
6
+
7
+ // Carbon Prefix
8
+ import { carbonPrefix } from '../configs';
9
+
10
+ import {
11
+ arrowLeft,
12
+ arrowRight,
13
+ circle,
14
+ diamond,
15
+ square,
16
+ tee,
17
+ } from '@carbon/charts/components/diagrams/markerDefinitions';
18
+
19
+ const Marker = ({
20
+ className,
21
+ color,
22
+ d,
23
+ id,
24
+ orient = 'auto',
25
+ height,
26
+ width,
27
+ position = 'end',
28
+ refX,
29
+ refY,
30
+ }: any) => {
31
+ const namespace = `${carbonPrefix}--cc--marker`;
32
+ const classes = classnames(namespace, {
33
+ [className]: className,
34
+ });
35
+
36
+ const xPos = position === 'end' ? width / 2 + 0.5 : 0.5;
37
+ const yPos = height / 2;
38
+
39
+ return (
40
+ <marker
41
+ className={classes}
42
+ markerHeight={height}
43
+ markerWidth={width}
44
+ orient={orient}
45
+ id={id}
46
+ refX={refX || xPos}
47
+ refY={refY || yPos}
48
+ markerUnits="userSpaceOnUse">
49
+ <path d={d} style={{ fill: color }} />
50
+ </marker>
51
+ );
52
+ };
53
+
54
+ const ArrowLeftMarker = ({ ...rest }) => <Marker {...arrowLeft} {...rest} />;
55
+ const ArrowRightMarker = ({ ...rest }) => <Marker {...arrowRight} {...rest} />;
56
+ const CircleMarker = ({ ...rest }) => <Marker {...circle} {...rest} />;
57
+ const DiamondMarker = ({ ...rest }) => <Marker {...diamond} {...rest} />;
58
+ const SquareMarker = ({ ...rest }) => <Marker {...square} {...rest} />;
59
+ const TeeMarker = ({ ...rest }) => <Marker {...tee} {...rest} />;
60
+
61
+ export {
62
+ Marker as default,
63
+ ArrowLeftMarker,
64
+ ArrowRightMarker,
65
+ CircleMarker,
66
+ DiamondMarker,
67
+ SquareMarker,
68
+ TeeMarker,
69
+ };
70
+
71
+ Marker.propTypes = {
72
+ /**
73
+ * Provide an optional class to be applied on the outer element
74
+ */
75
+ className: PropTypes.string,
76
+
77
+ /**
78
+ * Specify the marker's color
79
+ */
80
+ color: PropTypes.string,
81
+
82
+ /**
83
+ * Specify a path string
84
+ */
85
+ d: PropTypes.string,
86
+
87
+ /**
88
+ * Specify an ID for the marker
89
+ */
90
+ id: PropTypes.string,
91
+
92
+ /**
93
+ * Specify the orient attribute for the marker
94
+ */
95
+ orient: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
96
+
97
+ /**
98
+ * Specify the height attribute for the marker
99
+ */
100
+ height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
101
+
102
+ /**
103
+ * Specify the width attribute for the marker
104
+ */
105
+ width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
106
+
107
+ /**
108
+ * Specify whether this marker appears at the start or end of a line
109
+ */
110
+ position: PropTypes.oneOf(['end', 'start']),
111
+
112
+ /**
113
+ * Specify the refX attribute for the marker
114
+ */
115
+ refX: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
116
+
117
+ /**
118
+ * Specify the refY attribute for the marker
119
+ */
120
+ refY: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
121
+ };
@@ -0,0 +1,9 @@
1
+ export {
2
+ default,
3
+ ArrowLeftMarker,
4
+ ArrowRightMarker,
5
+ CircleMarker,
6
+ DiamondMarker,
7
+ SquareMarker,
8
+ TeeMarker,
9
+ } from './Marker';
@@ -0,0 +1,153 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ // Carbon Prefix
5
+ import { carbonPrefix } from '../configs';
6
+
7
+ // @ts-ignore
8
+ import classnames from 'classnames';
9
+
10
+ const ShapeNode = ({
11
+ as = 'div',
12
+ className,
13
+ href = null,
14
+ onClick = null,
15
+ onMouseEnter = null,
16
+ onMouseOver = null,
17
+ onMouseOut = null,
18
+ onMouseLeave = null,
19
+ onMouseMove = null,
20
+ position = 'fixed',
21
+ bodyPosition = 'absolute',
22
+ renderIcon,
23
+ size = 48,
24
+ stacked,
25
+ shape = 'circle',
26
+ subtitle,
27
+ title,
28
+ }: any) => {
29
+ const namespace = `${carbonPrefix}--cc--shape-node`;
30
+
31
+ let Component = 'div';
32
+
33
+ if (href) {
34
+ Component = 'a';
35
+ } else if (onClick) {
36
+ Component = 'button';
37
+ }
38
+
39
+ const circleClasses = classnames(namespace, {
40
+ [`${namespace}--stacked`]: stacked,
41
+ [`${namespace}--${shape}`]: shape,
42
+ [`${namespace}--${Component}`]: Component,
43
+ [className]: className,
44
+ });
45
+
46
+ const titleElement = title ? (
47
+ <div className={`${namespace}__title`}>{title}</div>
48
+ ) : null;
49
+ const subtitleElement = subtitle ? (
50
+ <div className={`${namespace}__subtitle`}>{subtitle}</div>
51
+ ) : null;
52
+
53
+ return (
54
+ // @ts-ignore
55
+ <Component
56
+ className={circleClasses}
57
+ onClick={onClick}
58
+ onMouseEnter={onMouseEnter}
59
+ onMouseOver={onMouseOver}
60
+ onMouseOut={onMouseOut}
61
+ onMouseLeave={onMouseLeave}
62
+ onMouseMove={onMouseMove}
63
+ style={{ height: size, width: size, position }}
64
+ tabIndex={0}>
65
+ <div className={`${namespace}__icon`}>{renderIcon}</div>
66
+ <div
67
+ className={`${namespace}__body`}
68
+ style={{ position: bodyPosition }}>
69
+ {titleElement}
70
+ {subtitleElement}
71
+ </div>
72
+ </Component>
73
+ );
74
+ };
75
+
76
+ ShapeNode.propTypes = {
77
+ /** Provide a custom element to be rendered instead of the default */
78
+ as: PropTypes.oneOf(['div', 'a', 'button']),
79
+
80
+ /**
81
+ * Provide an optional class to be applied on the outer element
82
+ */
83
+ className: PropTypes.string,
84
+
85
+ /**
86
+ * Optionally specify an href for the CardNode to become an `<a>` element
87
+ */
88
+ href: PropTypes.string,
89
+
90
+ /**
91
+ * Provide an optional function to be called when the CardNode
92
+ * is clicked, turning the CardNode into a `<button>` element
93
+ */
94
+ onClick: PropTypes.func,
95
+
96
+ /**
97
+ * Provide an optional function to be called for the onMouseEnter event
98
+ */
99
+ onMouseEnter: PropTypes.func,
100
+
101
+ /**
102
+ * Provide an optional function to be called for the onMouseOver event
103
+ */
104
+ onMouseOver: PropTypes.func,
105
+
106
+ /**
107
+ * Provide an optional function to be called for the onMouseOut event
108
+ */
109
+ onMouseOut: PropTypes.func,
110
+
111
+ /**
112
+ * Provide an optional function to be called for the onMouseLeave event
113
+ */
114
+ onMouseLeave: PropTypes.func,
115
+
116
+ /**
117
+ * Provide an optional function to be called for the onMouseMove event
118
+ */
119
+ onMouseMove: PropTypes.func,
120
+
121
+ /**
122
+ * Function to render your own icon in the underlying button
123
+ */
124
+ renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
125
+
126
+ /**
127
+ * Specify the height and width of the shape
128
+ * Can be defined using any CSS length unit (px, %, rem)
129
+ */
130
+ size: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
131
+
132
+ /**
133
+ * Specify whether the node displays a stacked effect
134
+ */
135
+ stacked: PropTypes.bool,
136
+
137
+ /**
138
+ * Specify the shape of the node
139
+ */
140
+ shape: PropTypes.oneOf(['circle', 'square', 'rounded-square']),
141
+
142
+ /**
143
+ * Specify the node's subtitle
144
+ */
145
+ subtitle: PropTypes.string,
146
+
147
+ /**
148
+ * Specify the node's title
149
+ */
150
+ title: PropTypes.string,
151
+ };
152
+
153
+ export default ShapeNode;
@@ -0,0 +1,2 @@
1
+ import ShapeNode from './ShapeNode';
2
+ export default ShapeNode;
@@ -0,0 +1 @@
1
+ export const carbonPrefix = 'cds';