@oliasoft-open-source/charts-library 2.0.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.
- package/.eslintignore +2 -0
- package/.eslintrc.js +129 -0
- package/.gitlab-ci.yml +77 -0
- package/.husky/pre-commit +4 -0
- package/.prettierignore +3 -0
- package/.prettierrc +4 -0
- package/.storybook/main.js +40 -0
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/babel.config.js +29 -0
- package/index.js +9 -0
- package/jest.config.js +9 -0
- package/package.json +96 -0
- package/src/components/bar-chart/bar-chart-prop-types.js +181 -0
- package/src/components/bar-chart/bar-chart.interface.ts +83 -0
- package/src/components/bar-chart/bar-chart.jsx +247 -0
- package/src/components/bar-chart/bar-chart.module.less +56 -0
- package/src/components/bar-chart/basic.stories.jsx +752 -0
- package/src/components/bar-chart/charts.stories.jsx +119 -0
- package/src/components/bar-chart/get-bar-chart-data-labels.js +45 -0
- package/src/components/bar-chart/get-bar-chart-scales.js +147 -0
- package/src/components/bar-chart/get-bar-chart-tooltips.js +100 -0
- package/src/components/line-chart/Controls/Controls.jsx +59 -0
- package/src/components/line-chart/Controls/Controls.module.less +21 -0
- package/src/components/line-chart/Controls/Layer.jsx +169 -0
- package/src/components/line-chart/basic.stories.jsx +735 -0
- package/src/components/line-chart/charts.stories.jsx +264 -0
- package/src/components/line-chart/get-line-chart-data-labels.js +24 -0
- package/src/components/line-chart/get-line-chart-scales.js +131 -0
- package/src/components/line-chart/get-line-chart-tooltips.js +91 -0
- package/src/components/line-chart/line-chart-consts.js +6 -0
- package/src/components/line-chart/line-chart-prop-types.js +187 -0
- package/src/components/line-chart/line-chart-utils.js +163 -0
- package/src/components/line-chart/line-chart.interface.ts +103 -0
- package/src/components/line-chart/line-chart.jsx +423 -0
- package/src/components/line-chart/line-chart.minor-gridlines-plugin.js +78 -0
- package/src/components/line-chart/line-chart.minor-gridlines-plugin.test.js +34 -0
- package/src/components/line-chart/line-chart.module.less +56 -0
- package/src/components/line-chart/state/action-types.js +9 -0
- package/src/components/line-chart/state/initial-state.js +51 -0
- package/src/components/line-chart/state/line-chart-reducer.js +115 -0
- package/src/components/line-chart/stories/shapes/cubes.stories.jsx +326 -0
- package/src/components/line-chart/stories/shapes/pyramid.stories.jsx +189 -0
- package/src/components/line-chart/stories/shapes/round.stories.jsx +339 -0
- package/src/components/line-chart/stories/shapes/triangle.stories.jsx +166 -0
- package/src/components/pie-chart/basic.stories.jsx +390 -0
- package/src/components/pie-chart/charts.stories.jsx +66 -0
- package/src/components/pie-chart/pie-chart-prop-types.js +111 -0
- package/src/components/pie-chart/pie-chart-utils.js +55 -0
- package/src/components/pie-chart/pie-chart.interface.ts +61 -0
- package/src/components/pie-chart/pie-chart.jsx +477 -0
- package/src/components/pie-chart/pie-chart.module.less +56 -0
- package/src/components/scatter-chart/scatter-chart.intefrace.ts +32 -0
- package/src/components/scatter-chart/scatter-chart.jsx +13 -0
- package/src/components/scatter-chart/scatter.stories.jsx +196 -0
- package/src/helpers/chart-consts.js +82 -0
- package/src/helpers/chart-interface.ts +54 -0
- package/src/helpers/chart-utils.js +178 -0
- package/src/helpers/container.jsx +60 -0
- package/src/helpers/disabled-context.js +8 -0
- package/src/helpers/enums.js +84 -0
- package/src/helpers/get-chart-annotation.js +91 -0
- package/src/helpers/styles.js +68 -0
- package/src/helpers/text.js +6 -0
- package/src/style/external.less +4 -0
- package/src/style/fonts/lato/Lato-Bold.woff2 +0 -0
- package/src/style/fonts/lato/Lato-BoldItalic.woff2 +0 -0
- package/src/style/fonts/lato/Lato-Italic.woff2 +0 -0
- package/src/style/fonts/lato/Lato-Regular.woff2 +0 -0
- package/src/style/fonts.less +27 -0
- package/src/style/global.less +43 -0
- package/src/style/reset/reset.less +28 -0
- package/src/style/shared.less +24 -0
- package/src/style/variables.less +91 -0
- package/webpack/webpack.common.js +39 -0
- package/webpack/webpack.common.rules.js +107 -0
- package/webpack/webpack.dev.js +22 -0
- package/webpack/webpack.prod.js +23 -0
- package/webpack/webpack.resolve.js +22 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { AxisType, ChartType, CursorStyle, Position } from './enums';
|
|
2
|
+
import {
|
|
3
|
+
ANNOTATION_DASH,
|
|
4
|
+
BORDER_WIDTH,
|
|
5
|
+
COLORS,
|
|
6
|
+
DARK_MODE_COLORS,
|
|
7
|
+
} from './chart-consts';
|
|
8
|
+
|
|
9
|
+
const annotationEnter = ({ element }, { chart }) => {
|
|
10
|
+
if (element.options.scaleID?.includes(AxisType.X)) {
|
|
11
|
+
element.options.label.xAdjust = chart.chartArea.left;
|
|
12
|
+
}
|
|
13
|
+
element.options.borderWidth = BORDER_WIDTH.HOVERED;
|
|
14
|
+
element.options.label.enabled = true;
|
|
15
|
+
chart.draw();
|
|
16
|
+
chart.canvas.style.cursor = CursorStyle.Pointer;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const annotationLeave = ({ element }, { chart }) => {
|
|
20
|
+
element.options.borderWidth = BORDER_WIDTH.INITIAL;
|
|
21
|
+
element.options.label.enabled = false;
|
|
22
|
+
chart.draw();
|
|
23
|
+
chart.canvas.style.cursor = CursorStyle.Initial;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {import('../components/bar-chart/bar-chart.interface').IBarChartOptions |
|
|
28
|
+
* import('../components/line-chart/line-chart.interface').ILineChartOptions} options - chart options object
|
|
29
|
+
* @param {import('./chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
|
|
30
|
+
*/
|
|
31
|
+
const generateAnnotations = (options, state) => {
|
|
32
|
+
const { annotationsData } = options.annotations;
|
|
33
|
+
const isDarkModeOn = options.chartStyling.darkMode;
|
|
34
|
+
|
|
35
|
+
const annotations = annotationsData?.reduce((acc, curr, i) => {
|
|
36
|
+
if (!state?.showAnnotationLineIndex?.includes(i)) {
|
|
37
|
+
return { ...acc };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const getScaleId = () => {
|
|
41
|
+
const axisType = curr.annotationAxis;
|
|
42
|
+
return options.axes[axisType]?.length > 1 ? `${axisType}1` : axisType;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const color =
|
|
46
|
+
curr?.color || (isDarkModeOn ? DARK_MODE_COLORS[i] : COLORS[i]);
|
|
47
|
+
|
|
48
|
+
const annotation = {
|
|
49
|
+
...curr,
|
|
50
|
+
id: `${curr?.label}-${curr?.value}-${i}`,
|
|
51
|
+
scaleID: getScaleId(),
|
|
52
|
+
label: {
|
|
53
|
+
backgroundColor: color,
|
|
54
|
+
content: curr?.label,
|
|
55
|
+
enabled: false,
|
|
56
|
+
position: Position.Top,
|
|
57
|
+
},
|
|
58
|
+
borderColor: color,
|
|
59
|
+
borderWidth: BORDER_WIDTH.INITIAL,
|
|
60
|
+
borderDash: ANNOTATION_DASH,
|
|
61
|
+
type: ChartType.Line,
|
|
62
|
+
enter: (context, event) => {
|
|
63
|
+
annotationEnter(context, event);
|
|
64
|
+
},
|
|
65
|
+
leave: (context, event) => {
|
|
66
|
+
annotationLeave(context, event);
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
return { ...acc, [`annotation${i + 1}`]: annotation };
|
|
70
|
+
}, {});
|
|
71
|
+
return annotations;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {import('../components/bar-chart/bar-chart.interface').IBarChartOptions |
|
|
76
|
+
* import('../components/line-chart/line-chart.interface').ILineChartOptions} options - chart options object
|
|
77
|
+
* @param {import('./chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
|
|
78
|
+
* @return {{annotations: []}}
|
|
79
|
+
*/
|
|
80
|
+
const getAnnotation = (options, state) => {
|
|
81
|
+
const { annotations } = options;
|
|
82
|
+
const isAnnotationShown = annotations?.showAnnotations;
|
|
83
|
+
const isAnnotationDataProvided = annotations?.annotationsData?.length;
|
|
84
|
+
return {
|
|
85
|
+
annotations:
|
|
86
|
+
isAnnotationShown && isAnnotationDataProvided
|
|
87
|
+
? generateAnnotations(options, state)
|
|
88
|
+
: [],
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
export default getAnnotation;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
This helper allows us to export simple LESS variables as JavaScript objects.
|
|
3
|
+
The intention is for keeping code DRY by allowing primary colour palettes etc
|
|
4
|
+
to be defined in one place only (LESS).
|
|
5
|
+
|
|
6
|
+
These simple variables should be defined in a files called `shared.less` that
|
|
7
|
+
can exist in one of two place:
|
|
8
|
+
|
|
9
|
+
- in `override.less` in the root of the parent project
|
|
10
|
+
(to allow overriding of the default values set in this project)
|
|
11
|
+
- in `src/style/shared.less in this project (default values)
|
|
12
|
+
|
|
13
|
+
The parent and local definitions are merged, with the parent taking
|
|
14
|
+
precedence.
|
|
15
|
+
|
|
16
|
+
The implementation uses Webpack raw-loader to load the shared LESS variables
|
|
17
|
+
file, and a 3rd party package (less-vars-to-js) to parse it, so they can be
|
|
18
|
+
exported for use in JavaScript.
|
|
19
|
+
|
|
20
|
+
When we upgrade to Webpack 5, we'll have to refactor this to use asset modules
|
|
21
|
+
instead.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import lessToJs from 'less-vars-to-js';
|
|
25
|
+
|
|
26
|
+
// eslint-disable-next-line import/no-unresolved,import/no-webpack-loader-syntax
|
|
27
|
+
import lessVariables from '../style/shared.less?raw';
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
We need to import the `shared.less` file from the root of the parent project
|
|
31
|
+
conditionally (it may not exist). Would love to use ES6 imports here, but they
|
|
32
|
+
don't allow optional files without throwing an error when the file doesn't
|
|
33
|
+
exist. ES6 dynamic imports would require `async` when we use this helper
|
|
34
|
+
(prefer to avoid that). So falling back to CommonJS require here.
|
|
35
|
+
|
|
36
|
+
Hopefully this will get better once we have Webpack 5 asset modules.
|
|
37
|
+
*/
|
|
38
|
+
let lessParentVariables = '{}';
|
|
39
|
+
try {
|
|
40
|
+
const parentPath = '../../../../override.less?raw';
|
|
41
|
+
// eslint-disable-next-line import/no-unresolved,global-require,import/no-webpack-loader-syntax,import/no-dynamic-require
|
|
42
|
+
lessParentVariables = require(`${parentPath}`).default;
|
|
43
|
+
} catch (e) {
|
|
44
|
+
//do nothing (we fallback to the local definition anyway)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const load = () => {
|
|
48
|
+
/*
|
|
49
|
+
Merge the parent project shared.less with the local shared.less
|
|
50
|
+
(since less-vars-to-js doesn't handle import statements for us)
|
|
51
|
+
|
|
52
|
+
The parent definition takes precedence over the local definition
|
|
53
|
+
*/
|
|
54
|
+
const parent = lessToJs(lessParentVariables, {
|
|
55
|
+
resolveVariables: true,
|
|
56
|
+
stripPrefix: true,
|
|
57
|
+
});
|
|
58
|
+
const local = lessToJs(lessVariables, {
|
|
59
|
+
resolveVariables: true,
|
|
60
|
+
stripPrefix: true,
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
...local,
|
|
64
|
+
...parent,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const styleVariables = load();
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
@font-face {
|
|
2
|
+
font-family: 'Lato';
|
|
3
|
+
font-weight: normal;
|
|
4
|
+
font-style: normal;
|
|
5
|
+
src: url('./fonts/lato/Lato-Regular.woff2') format('woff2');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
@font-face {
|
|
9
|
+
font-family: 'Lato';
|
|
10
|
+
font-weight: bold;
|
|
11
|
+
font-style: normal;
|
|
12
|
+
src: url('./fonts/lato/Lato-Bold.woff2') format('woff2');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@font-face {
|
|
16
|
+
font-family: 'Lato';
|
|
17
|
+
font-weight: normal;
|
|
18
|
+
font-style: italic;
|
|
19
|
+
src: url('./fonts/lato/Lato-Italic.woff2') format('woff2');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@font-face {
|
|
23
|
+
font-family: 'Lato';
|
|
24
|
+
font-weight: bold;
|
|
25
|
+
font-style: italic;
|
|
26
|
+
src: url('./fonts/lato/Lato-BoldItalic.woff2') format('woff2');
|
|
27
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
@import './variables.less';
|
|
2
|
+
@import './fonts.less';
|
|
3
|
+
@import './reset/reset.less';
|
|
4
|
+
|
|
5
|
+
html {
|
|
6
|
+
font-size: 14px;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
body {
|
|
10
|
+
color: rgba(0, 0, 0, 0.87);
|
|
11
|
+
line-height: 1.4285em;
|
|
12
|
+
font-family: @default_font;
|
|
13
|
+
font-size: 14px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
h1,
|
|
17
|
+
h2,
|
|
18
|
+
h3,
|
|
19
|
+
h4,
|
|
20
|
+
h5 {
|
|
21
|
+
line-height: 1.285714em;
|
|
22
|
+
margin: 0 0 1rem;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
p,
|
|
26
|
+
ul,
|
|
27
|
+
ol {
|
|
28
|
+
margin: 0 0 1rem;
|
|
29
|
+
line-height: 1.4285em;
|
|
30
|
+
|
|
31
|
+
&:last-child {
|
|
32
|
+
margin-bottom: 0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
ul,
|
|
37
|
+
ol {
|
|
38
|
+
padding-left: 1.5em;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
a {
|
|
42
|
+
text-decoration: none;
|
|
43
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
@import '~normalize.css/normalize.css';
|
|
2
|
+
|
|
3
|
+
/* Border-Box */
|
|
4
|
+
*,
|
|
5
|
+
*:before,
|
|
6
|
+
*:after {
|
|
7
|
+
box-sizing: inherit;
|
|
8
|
+
}
|
|
9
|
+
html {
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/* iPad Input Shadows */
|
|
14
|
+
input[type='text'],
|
|
15
|
+
input[type='email'],
|
|
16
|
+
input[type='search'],
|
|
17
|
+
input[type='password'] {
|
|
18
|
+
-webkit-appearance: none;
|
|
19
|
+
-moz-appearance: none; /* mobile firefox too! */
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* FF dotted border outlines */
|
|
23
|
+
:focus {
|
|
24
|
+
outline: none !important;
|
|
25
|
+
}
|
|
26
|
+
::-moz-focus-inner {
|
|
27
|
+
border: 0 !important;
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
This file has shared variables that are re-used:
|
|
3
|
+
- in other LESS files/modules
|
|
4
|
+
- in JavaScript, via https://www.npmjs.com/package/less-vars-to-js
|
|
5
|
+
|
|
6
|
+
Only use simple variables in this file
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Brand guidelines
|
|
10
|
+
@colorPrimary: #eb6429;
|
|
11
|
+
@colorError: #e14c4c;
|
|
12
|
+
@colorWarning: #e2bd27;
|
|
13
|
+
@colorSuccess: #3bbb3b;
|
|
14
|
+
@colorInfo: #29a7eb;
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
Allow the parent project to optionally override the primary colour palette
|
|
18
|
+
by having an `override.less` file in its root directory
|
|
19
|
+
*/
|
|
20
|
+
@import (optional) '../../../../override.less';
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
Other shared variables
|
|
24
|
+
*/
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
@import './shared.less';
|
|
2
|
+
|
|
3
|
+
@default_font: 'Lato', sans-serif;
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
LAYOUT
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
@topbar_height: 60px;
|
|
10
|
+
@sidebar_width: 300px;
|
|
11
|
+
@sidebar_width_collapsed: 70px;
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
CARDS
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
@card_border_radius: 4px;
|
|
18
|
+
@card_border_color: #d5d7d9;
|
|
19
|
+
@card_header_bg_color: #f7f7f7;
|
|
20
|
+
@card_padding_x: 15px;
|
|
21
|
+
@card_padding_y: 10px;
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
INPUTS
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
@input_height: 38px;
|
|
28
|
+
@input_height_small: 24px;
|
|
29
|
+
@input_font_size_small: 12px;
|
|
30
|
+
@input_padding_x: 14px;
|
|
31
|
+
@input_padding_y: 9.5px;
|
|
32
|
+
@input_padding_small_x: 7px;
|
|
33
|
+
@input_padding_small_y: 3.5px;
|
|
34
|
+
@input_border_radius: 4px;
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
COLOR
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
// Text
|
|
41
|
+
@colorTextDefault: rgba(0, 0, 0, 0.87);
|
|
42
|
+
@colorTextMuted: #7d7b7a;
|
|
43
|
+
@colorTextFaint: #acabab;
|
|
44
|
+
@colorTextError: hsl(hue(@colorError), 40%, 50%);
|
|
45
|
+
@colorTextWarning: hsl(hue(@colorWarning), 40%, 50%);
|
|
46
|
+
@colorTextSuccess: hsl(hue(@colorSuccess), 40%, 50%);
|
|
47
|
+
@colorTextPrimary: @colorPrimary;
|
|
48
|
+
|
|
49
|
+
:root {
|
|
50
|
+
--color-text-default: @colorTextDefault;
|
|
51
|
+
--color-text-muted: @colorTextMuted;
|
|
52
|
+
--color-text-faint: @colorTextFaint;
|
|
53
|
+
--color-text-error: @colorTextError;
|
|
54
|
+
--color-text-warning: @colorTextWarning;
|
|
55
|
+
--color-text-success: @colorTextSuccess;
|
|
56
|
+
--color-text-primary: @colorTextPrimary;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Buttons
|
|
60
|
+
@col_btn_default: white;
|
|
61
|
+
@col_btn_primary: @colorPrimary;
|
|
62
|
+
@col_btn_danger: @colorError;
|
|
63
|
+
@col_btn_success: @colorSuccess;
|
|
64
|
+
|
|
65
|
+
// Inputs
|
|
66
|
+
@input_border_color: rgba(34, 36, 38, 0.15);
|
|
67
|
+
@input_border_color_hover: rgba(34, 36, 38, 0.35);
|
|
68
|
+
@input_border_color_focus: hsl(hue(@colorInfo), 40%, 60%);
|
|
69
|
+
@input_background_error: hsl(hue(@colorError), 40%, 97%);
|
|
70
|
+
@input_border_color_error: hsl(hue(@colorError), 40%, 70%);
|
|
71
|
+
@input_color_error: @colorTextError;
|
|
72
|
+
@input_background_warning: hsl(hue(@colorWarning), 40%, 97%);
|
|
73
|
+
@input_border_color_warning: hsl(hue(@colorWarning), 40%, 70%);
|
|
74
|
+
@input_color_warning: @colorTextWarning;
|
|
75
|
+
@input_color_placeholder: #c0c0c0;
|
|
76
|
+
@input_background_disabled: #ecedef;
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
Z-INDEX
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
@zindex_topbar_alert: 98;
|
|
83
|
+
@zindex_drawer: 99;
|
|
84
|
+
@zindex_topbar: 101;
|
|
85
|
+
@zindex_dimmer: 1000;
|
|
86
|
+
@zindex_modal: 2000;
|
|
87
|
+
//We need react-laag layers to appear above modals
|
|
88
|
+
//Tooltips need to be above dropdown layers
|
|
89
|
+
@zindex_popover: 2001;
|
|
90
|
+
@zindex_dropdown: 2002;
|
|
91
|
+
@zindex_tooltip: 2003;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
3
|
+
const HtmlWebPackPlugin = require('html-webpack-plugin');
|
|
4
|
+
const { resolve } = require('./webpack.resolve.js');
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
resolve,
|
|
8
|
+
entry: {
|
|
9
|
+
app: './src/docs/start.jsx',
|
|
10
|
+
},
|
|
11
|
+
output: {
|
|
12
|
+
path: path.resolve(__dirname, '../public'),
|
|
13
|
+
filename: '[name].[contenthash].js',
|
|
14
|
+
},
|
|
15
|
+
plugins: [
|
|
16
|
+
new HtmlWebPackPlugin({
|
|
17
|
+
template: 'src/docs/html/index.html',
|
|
18
|
+
filename: './index.html',
|
|
19
|
+
favicon: 'src/docs/html/favicon.png',
|
|
20
|
+
cache: true,
|
|
21
|
+
}),
|
|
22
|
+
new MiniCssExtractPlugin({
|
|
23
|
+
filename: '[name].[contenthash].css',
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
optimization: {
|
|
27
|
+
runtimeChunk: 'single', // single runtime bundle for all chunks
|
|
28
|
+
// put node_modules into separate bundles
|
|
29
|
+
splitChunks: {
|
|
30
|
+
cacheGroups: {
|
|
31
|
+
vendors: {
|
|
32
|
+
test: /[\\/]node_modules[\\/]/,
|
|
33
|
+
name: 'vendors',
|
|
34
|
+
chunks: 'all',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
3
|
+
|
|
4
|
+
module.exports = function getRules(env) {
|
|
5
|
+
const styleLoader = MiniCssExtractPlugin.loader;
|
|
6
|
+
|
|
7
|
+
return [
|
|
8
|
+
{
|
|
9
|
+
test: /\.jsx$|\.es6$|\.js$/,
|
|
10
|
+
exclude:
|
|
11
|
+
/node_modules(?![\\/]@oliasoft-open-source[\\/]react-ui-library)/,
|
|
12
|
+
use: {
|
|
13
|
+
loader: 'babel-loader',
|
|
14
|
+
options: {
|
|
15
|
+
cacheDirectory: false,
|
|
16
|
+
presets: ['@babel/react'],
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
test: /\.(ttf|eot|woff|woff2)$/,
|
|
22
|
+
type: 'asset/resource',
|
|
23
|
+
generator: {
|
|
24
|
+
filename: './fonts/[name].[contenthash][ext]',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
test: /\.(svg|gif|png|jpg)$/,
|
|
29
|
+
type: 'asset/resource',
|
|
30
|
+
generator: {
|
|
31
|
+
filename: './images/[name].[contenthash][ext]',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
test: /^(?!.*?(\.module)).*\.css$/, //all *.css except for *.module.css
|
|
36
|
+
use: [
|
|
37
|
+
styleLoader,
|
|
38
|
+
{
|
|
39
|
+
loader: 'css-loader',
|
|
40
|
+
options: {
|
|
41
|
+
sourceMap: env === 'development',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
test: /^(?!.*?(\.module)).*\.less$/, //all *.less except for *.module.less
|
|
48
|
+
use: [
|
|
49
|
+
styleLoader,
|
|
50
|
+
{
|
|
51
|
+
loader: 'css-loader',
|
|
52
|
+
options: {
|
|
53
|
+
sourceMap: env === 'development',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
'less-loader',
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
test: /\.module\.css$/, //*.module.css
|
|
61
|
+
use: [
|
|
62
|
+
styleLoader,
|
|
63
|
+
{
|
|
64
|
+
loader: 'css-loader',
|
|
65
|
+
options: {
|
|
66
|
+
sourceMap: env === 'development',
|
|
67
|
+
modules: {
|
|
68
|
+
mode: 'local',
|
|
69
|
+
localIdentName: '[name]-[local]-[hash:base64:5]', //friendly module classNames
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
test: /\.module\.less$/, //*.module.less
|
|
77
|
+
use: [
|
|
78
|
+
styleLoader,
|
|
79
|
+
{
|
|
80
|
+
loader: 'css-loader',
|
|
81
|
+
options: {
|
|
82
|
+
sourceMap: env === 'development',
|
|
83
|
+
modules: {
|
|
84
|
+
mode: 'local',
|
|
85
|
+
localIdentName: '[name]-[local]-[hash:base64:5]', //friendly module classNames
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
'less-loader',
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
test: /\.stories\.jsx?$/,
|
|
94
|
+
loader: require.resolve('@storybook/source-loader'),
|
|
95
|
+
include: [path.resolve(__dirname, '../src')],
|
|
96
|
+
enforce: 'pre',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
test: /\.mdx?$/,
|
|
100
|
+
use: ['babel-loader', '@mdx-js/loader'],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
resourceQuery: /raw/,
|
|
104
|
+
type: 'asset/source',
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const { merge } = require('webpack-merge');
|
|
2
|
+
const common = require('./webpack.common.js');
|
|
3
|
+
const getRules = require('./webpack.common.rules.js');
|
|
4
|
+
|
|
5
|
+
module.exports = merge(common, {
|
|
6
|
+
mode: 'development',
|
|
7
|
+
devtool: 'eval-cheap-module-source-map',
|
|
8
|
+
output: {
|
|
9
|
+
publicPath: '/',
|
|
10
|
+
},
|
|
11
|
+
devServer: {
|
|
12
|
+
port: 9001,
|
|
13
|
+
open: true,
|
|
14
|
+
historyApiFallback: true,
|
|
15
|
+
client: {
|
|
16
|
+
overlay: true,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
module: {
|
|
20
|
+
rules: getRules('development'),
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { merge } = require('webpack-merge');
|
|
2
|
+
const TerserPlugin = require('terser-webpack-plugin');
|
|
3
|
+
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
|
4
|
+
const common = require('./webpack.common.js');
|
|
5
|
+
const getRules = require('./webpack.common.rules.js');
|
|
6
|
+
|
|
7
|
+
module.exports = merge(common, {
|
|
8
|
+
mode: 'production',
|
|
9
|
+
output: {
|
|
10
|
+
publicPath: '/line-chart-library/',
|
|
11
|
+
},
|
|
12
|
+
optimization: {
|
|
13
|
+
minimizer: [
|
|
14
|
+
new TerserPlugin({
|
|
15
|
+
parallel: true,
|
|
16
|
+
}),
|
|
17
|
+
new CssMinimizerPlugin(),
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
module: {
|
|
21
|
+
rules: getRules('production'),
|
|
22
|
+
},
|
|
23
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
resolve: {
|
|
5
|
+
extensions: ['.js', '.jsx'],
|
|
6
|
+
alias: {
|
|
7
|
+
'~components': path.resolve(__dirname, '../src/components'),
|
|
8
|
+
'~docs': path.resolve(__dirname, '../src/docs'),
|
|
9
|
+
'~helpers': path.resolve(__dirname, '../src/helpers'),
|
|
10
|
+
'~style': path.resolve(__dirname, '../src/style'),
|
|
11
|
+
'~vendor': path.resolve(__dirname, '../src/vendor'),
|
|
12
|
+
},
|
|
13
|
+
fallback: {
|
|
14
|
+
fs: false,
|
|
15
|
+
net: false,
|
|
16
|
+
repl: false,
|
|
17
|
+
tls: false,
|
|
18
|
+
path: false,
|
|
19
|
+
crypto: false,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|