dash-core-components 3.1.0 → 4.0.0-rc0
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/dash_core_components/async-datepicker.js +1 -1
- package/dash_core_components/async-datepicker.js.map +1 -1
- package/dash_core_components/async-dropdown.js +1 -1
- package/dash_core_components/async-dropdown.js.map +1 -1
- package/dash_core_components/async-graph.js +1 -1
- package/dash_core_components/async-graph.js.map +1 -1
- package/dash_core_components/async-highlight.js +1 -1
- package/dash_core_components/async-highlight.js.map +1 -1
- package/dash_core_components/async-markdown.js +1 -1
- package/dash_core_components/async-markdown.js.map +1 -1
- package/dash_core_components/async-slider.js +1 -1
- package/dash_core_components/async-slider.js.map +1 -1
- package/dash_core_components/dash_core_components-shared.js +1 -1
- package/dash_core_components/dash_core_components-shared.js.map +1 -1
- package/dash_core_components/dash_core_components.js +1 -1
- package/dash_core_components/dash_core_components.js.map +1 -1
- package/dash_core_components/plotly.min.js +8 -0
- package/dash_core_components/proptypes.js +81 -0
- package/lib/components/Dropdown.react.js.old +228 -0
- package/lib/components/Input.react.js.old +507 -0
- package/lib/components/Input.tsx +543 -0
- package/lib/components/RangeSlider.tsx +39 -0
- package/lib/components/Slider.react.js.old +214 -0
- package/lib/components/Slider.tsx +81 -0
- package/lib/components/css/dcc.css +13 -0
- package/lib/components/css/input.css +116 -2
- package/lib/components/css/react-select@1.0.0-rc.3.min.css +1 -1
- package/lib/components/css/sliders.css +198 -4
- package/lib/fragments/Graph.react.js +24 -4
- package/lib/fragments/RangeSlider.tsx +412 -0
- package/lib/fragments/Slider.tsx.old +364 -0
- package/lib/index.ts +58 -0
- package/lib/types.ts +331 -0
- package/lib/utils/LazyLoader/rangeSlider.ts +2 -0
- package/lib/utils/LazyLoader/slider.ts +2 -0
- package/lib/utils/_LoadingElement.tsx +36 -0
- package/lib/utils/computeSliderMarkers.ts +302 -0
- package/lib/utils/formatSliderTooltip.ts +20 -0
- package/lib/utils/sliderRendering.tsx +144 -0
- package/lib/utils/sliderSnapToMark.ts +17 -0
- package/lib/utils/sliderTooltip.tsx +65 -0
- package/package.json +27 -10
- package/lib/components/Input.react.js +0 -403
- package/lib/components/RangeSlider.react.js +0 -194
- package/lib/components/Slider.react.js +0 -179
- package/lib/fragments/RangeSlider.react.js +0 -143
- package/lib/fragments/Slider.react.js +0 -147
- package/lib/index.js +0 -183
- package/lib/utils/LazyLoader/rangeSlider.js +0 -8
- package/lib/utils/LazyLoader/slider.js +0 -8
- package/lib/utils/computeSliderMarkers.js +0 -153
- package/lib/utils/computeSliderStyle.js +0 -26
- package/lib/utils/formatSliderTooltip.js +0 -19
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {SliderMarks} from '../types';
|
|
3
|
+
|
|
4
|
+
// Replicate Radix UI's exact positioning logic for displaying marks
|
|
5
|
+
const convertValueToPercentage = (value: number, min: number, max: number) => {
|
|
6
|
+
const maxSteps = max - min;
|
|
7
|
+
const percentPerStep = 100 / maxSteps;
|
|
8
|
+
const percentage = percentPerStep * (value - min);
|
|
9
|
+
// Clamp to 0-100 range like Radix does
|
|
10
|
+
return Math.max(0, Math.min(100, percentage));
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const linearScale = (
|
|
14
|
+
input: readonly [number, number],
|
|
15
|
+
output: readonly [number, number]
|
|
16
|
+
) => {
|
|
17
|
+
return (value: number) => {
|
|
18
|
+
if (input[0] === input[1] || output[0] === output[1]) {
|
|
19
|
+
return output[0];
|
|
20
|
+
}
|
|
21
|
+
const ratio = (output[1] - output[0]) / (input[1] - input[0]);
|
|
22
|
+
return output[0] + ratio * (value - input[0]);
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const getThumbInBoundsOffset = (
|
|
27
|
+
width: number,
|
|
28
|
+
left: number,
|
|
29
|
+
direction: number
|
|
30
|
+
) => {
|
|
31
|
+
const halfWidth = width / 2;
|
|
32
|
+
const halfPercent = 50;
|
|
33
|
+
const offset = linearScale([0, halfPercent], [0, halfWidth]);
|
|
34
|
+
return (halfWidth - offset(left) * direction) * direction;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Calculate the exact position including pixel offset as Radix does
|
|
38
|
+
const getRadixThumbPosition = (
|
|
39
|
+
value: number,
|
|
40
|
+
minMaxValues: {min_mark: number; max_mark: number},
|
|
41
|
+
thumbWidth = 16
|
|
42
|
+
) => {
|
|
43
|
+
const percentage = convertValueToPercentage(
|
|
44
|
+
value,
|
|
45
|
+
minMaxValues.min_mark,
|
|
46
|
+
minMaxValues.max_mark
|
|
47
|
+
);
|
|
48
|
+
const direction = 1; // LTR direction
|
|
49
|
+
const thumbInBoundsOffset = getThumbInBoundsOffset(
|
|
50
|
+
thumbWidth,
|
|
51
|
+
percentage,
|
|
52
|
+
direction
|
|
53
|
+
);
|
|
54
|
+
return {percentage, offset: thumbInBoundsOffset};
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const renderSliderMarks = (
|
|
58
|
+
renderedMarks: SliderMarks,
|
|
59
|
+
vertical: boolean,
|
|
60
|
+
minMaxValues: {min_mark: number; max_mark: number},
|
|
61
|
+
dots: boolean
|
|
62
|
+
) => {
|
|
63
|
+
return Object.entries(renderedMarks).map(([position, mark]) => {
|
|
64
|
+
const pos = parseFloat(position);
|
|
65
|
+
const thumbPosition = getRadixThumbPosition(pos, minMaxValues);
|
|
66
|
+
const style = vertical
|
|
67
|
+
? {
|
|
68
|
+
bottom: `calc(${thumbPosition.percentage}% + ${thumbPosition.offset}px - 13px)`,
|
|
69
|
+
left: 'calc(100% + 8px)',
|
|
70
|
+
transform: 'translateY(-50%)',
|
|
71
|
+
}
|
|
72
|
+
: {
|
|
73
|
+
left: `calc(${thumbPosition.percentage}% + ${thumbPosition.offset}px)`,
|
|
74
|
+
bottom: 0,
|
|
75
|
+
transform: 'translateX(-50%)',
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div
|
|
80
|
+
key={position}
|
|
81
|
+
className={`dash-slider-mark ${dots ? 'with-dots' : ''}`}
|
|
82
|
+
style={{
|
|
83
|
+
...style,
|
|
84
|
+
...(typeof mark === 'object' && mark.style
|
|
85
|
+
? mark.style
|
|
86
|
+
: {}),
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
{typeof mark === 'string' ? mark : mark?.label || pos}
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const renderSliderDots = (
|
|
96
|
+
stepValue: number,
|
|
97
|
+
minMaxValues: {min_mark: number; max_mark: number},
|
|
98
|
+
vertical: boolean
|
|
99
|
+
) => {
|
|
100
|
+
if (stepValue <= 1) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const dotCount =
|
|
105
|
+
Math.floor(
|
|
106
|
+
(minMaxValues.max_mark - minMaxValues.min_mark) / stepValue
|
|
107
|
+
) + 1;
|
|
108
|
+
|
|
109
|
+
// Cap at 100 dots - if more, don't render any dots
|
|
110
|
+
if (dotCount > 100) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return Array.from(
|
|
115
|
+
{
|
|
116
|
+
length: dotCount,
|
|
117
|
+
},
|
|
118
|
+
(_, i) => {
|
|
119
|
+
const dotValue = minMaxValues.min_mark + i * stepValue;
|
|
120
|
+
const thumbPosition = getRadixThumbPosition(dotValue, minMaxValues);
|
|
121
|
+
const dotStyle = vertical
|
|
122
|
+
? {
|
|
123
|
+
bottom: `calc(${thumbPosition.percentage}% + ${thumbPosition.offset}px)`,
|
|
124
|
+
left: '2px',
|
|
125
|
+
transform: 'translate(50%, 50%)',
|
|
126
|
+
}
|
|
127
|
+
: {
|
|
128
|
+
left: `calc(${thumbPosition.percentage}% + ${thumbPosition.offset}px)`,
|
|
129
|
+
top: '0',
|
|
130
|
+
transform: 'translate(-50%, 50%)',
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<div
|
|
135
|
+
key={i}
|
|
136
|
+
className="dash-slider-dot"
|
|
137
|
+
style={{
|
|
138
|
+
...dotStyle,
|
|
139
|
+
}}
|
|
140
|
+
/>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {SliderMarks} from '../types';
|
|
2
|
+
|
|
3
|
+
export const snapToNearestMark = (
|
|
4
|
+
value: number,
|
|
5
|
+
marks: SliderMarks
|
|
6
|
+
): number => {
|
|
7
|
+
const markValues = Object.keys(marks).map(Number);
|
|
8
|
+
if (markValues.length === 0) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return markValues.reduce((closest, current) => {
|
|
13
|
+
return Math.abs(current - value) < Math.abs(closest - value)
|
|
14
|
+
? current
|
|
15
|
+
: closest;
|
|
16
|
+
});
|
|
17
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
formatSliderTooltip,
|
|
4
|
+
transformSliderTooltip,
|
|
5
|
+
} from '../utils/formatSliderTooltip';
|
|
6
|
+
import {SliderTooltip} from '../types';
|
|
7
|
+
|
|
8
|
+
type TooltipProps = {
|
|
9
|
+
id?: string;
|
|
10
|
+
index: number;
|
|
11
|
+
value: number;
|
|
12
|
+
tooltip: SliderTooltip;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const Tooltip = ({tooltip, value, index: key, id}: TooltipProps) => {
|
|
16
|
+
const formatTooltipContent = (value: number, index: number) => {
|
|
17
|
+
let displayValue: string | number = value;
|
|
18
|
+
if (tooltip?.transform) {
|
|
19
|
+
displayValue = transformSliderTooltip(tooltip.transform, value);
|
|
20
|
+
}
|
|
21
|
+
return (
|
|
22
|
+
<div
|
|
23
|
+
id={`${id}-tooltip-${index + 1}-content`}
|
|
24
|
+
style={tooltip?.style}
|
|
25
|
+
>
|
|
26
|
+
{formatSliderTooltip(
|
|
27
|
+
tooltip?.template || '{value}',
|
|
28
|
+
displayValue
|
|
29
|
+
)}
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const classNames = [
|
|
35
|
+
'dash-slider-tooltip',
|
|
36
|
+
tooltip.always_visible ? 'always-visible' : '',
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
const placement = (tooltip.placement ?? 'top').toLowerCase();
|
|
40
|
+
const position: React.CSSProperties = {transform: ''};
|
|
41
|
+
|
|
42
|
+
if (placement.includes('top')) {
|
|
43
|
+
position.bottom = 'calc(100% + var(--Dash-Spacing))';
|
|
44
|
+
} else if (placement.includes('bottom')) {
|
|
45
|
+
position.top = 'calc(100% + var(--Dash-Spacing))';
|
|
46
|
+
} else {
|
|
47
|
+
position.top = '50%';
|
|
48
|
+
position.transform += 'translateY(-50%)';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (placement.includes('left')) {
|
|
52
|
+
position.right = 'calc(100% + var(--Dash-Spacing))';
|
|
53
|
+
} else if (placement.includes('right')) {
|
|
54
|
+
position.left = 'calc(100% + var(--Dash-Spacing))';
|
|
55
|
+
} else {
|
|
56
|
+
position.left = '50%';
|
|
57
|
+
position.transform += 'translateX(-50%)';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<div className={classNames.join(' ')} style={position}>
|
|
62
|
+
{formatTooltipContent(value, key)}
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dash-core-components",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-rc0",
|
|
4
4
|
"description": "Core component suite for Dash",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"private::lint.flake8": "flake8 --exclude=dash_core_components,node_modules,venv",
|
|
21
21
|
"private::lint.prettier": "prettier --config .prettierrc src/**/*.js --list-different",
|
|
22
22
|
"prepublishOnly": "rimraf lib && babel src --out-dir lib --copy-files --config-file ./.lib.babelrc && rimraf --glob lib/jl/ lib/*.jl",
|
|
23
|
-
"test": "run-s -c lint test:intg test:pyimport",
|
|
23
|
+
"test": "run-s -c lint test:jest test:intg test:pyimport",
|
|
24
|
+
"test:jest": "jest",
|
|
24
25
|
"test:intg": "pytest --nopercyfinalize --headless tests/integration ",
|
|
25
26
|
"test:pyimport": "python -m unittest tests/test_dash_import.py",
|
|
26
27
|
"build:js": "webpack --mode production",
|
|
@@ -39,6 +40,8 @@
|
|
|
39
40
|
"@fortawesome/free-regular-svg-icons": "^5.15.4",
|
|
40
41
|
"@fortawesome/free-solid-svg-icons": "^5.15.4",
|
|
41
42
|
"@fortawesome/react-fontawesome": "^0.1.17",
|
|
43
|
+
"@radix-ui/react-slider": "^1.3.6",
|
|
44
|
+
"@radix-ui/react-tooltip": "^1.2.8",
|
|
42
45
|
"base64-js": "^1.5.1",
|
|
43
46
|
"color": "^4.2.3",
|
|
44
47
|
"d3-format": "^1.4.5",
|
|
@@ -50,7 +53,6 @@
|
|
|
50
53
|
"node-polyfill-webpack-plugin": "^2.0.1",
|
|
51
54
|
"prop-types": "^15.8.1",
|
|
52
55
|
"ramda": "^0.30.1",
|
|
53
|
-
"rc-slider": "^9.7.5",
|
|
54
56
|
"react-addons-shallow-compare": "^15.6.3",
|
|
55
57
|
"react-dates": "^21.8.0",
|
|
56
58
|
"react-docgen": "^5.4.3",
|
|
@@ -63,14 +65,24 @@
|
|
|
63
65
|
"uniqid": "^5.4.0"
|
|
64
66
|
},
|
|
65
67
|
"devDependencies": {
|
|
66
|
-
"@babel/cli": "^7.
|
|
67
|
-
"@babel/core": "^7.
|
|
68
|
-
"@babel/eslint-parser": "^7.
|
|
68
|
+
"@babel/cli": "^7.28.0",
|
|
69
|
+
"@babel/core": "^7.28.0",
|
|
70
|
+
"@babel/eslint-parser": "^7.28.0",
|
|
69
71
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
70
|
-
"@babel/preset-env": "^7.
|
|
72
|
+
"@babel/preset-env": "^7.28.0",
|
|
71
73
|
"@babel/preset-react": "^7.27.1",
|
|
74
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
72
75
|
"@plotly/dash-component-plugins": "^1.2.3",
|
|
73
76
|
"@plotly/webpack-dash-dynamic-import": "^1.3.0",
|
|
77
|
+
"@types/d3-format": "^3.0.4",
|
|
78
|
+
"@types/fast-isnumeric": "^1.1.2",
|
|
79
|
+
"@types/jest": "^29.5.0",
|
|
80
|
+
"@types/ramda": "^0.31.0",
|
|
81
|
+
"@types/react": "^16.14.8",
|
|
82
|
+
"@types/react-dom": "^16.9.13",
|
|
83
|
+
"@types/uniqid": "^5.3.4",
|
|
84
|
+
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
|
85
|
+
"@typescript-eslint/parser": "^5.59.7",
|
|
74
86
|
"babel-loader": "^9.2.1",
|
|
75
87
|
"copyfiles": "^2.4.1",
|
|
76
88
|
"css-loader": "^6.8.1",
|
|
@@ -80,13 +92,18 @@
|
|
|
80
92
|
"eslint-plugin-import": "^2.27.5",
|
|
81
93
|
"eslint-plugin-react": "^7.32.2",
|
|
82
94
|
"identity-obj-proxy": "^3.0.0",
|
|
95
|
+
"jest": "^29.5.0",
|
|
83
96
|
"npm-run-all": "^4.1.5",
|
|
84
97
|
"prettier": "^2.8.8",
|
|
98
|
+
"react": "^16.14.0",
|
|
99
|
+
"react-dom": "^16.14.0",
|
|
85
100
|
"react-jsx-parser": "1.21.0",
|
|
86
101
|
"rimraf": "^5.0.5",
|
|
87
102
|
"style-loader": "^3.3.3",
|
|
88
|
-
"styled-jsx": "^
|
|
89
|
-
"
|
|
103
|
+
"styled-jsx": "^5.1.7",
|
|
104
|
+
"ts-jest": "^29.1.0",
|
|
105
|
+
"typescript": "^5.8.3",
|
|
106
|
+
"webpack": "^5.101.0",
|
|
90
107
|
"webpack-cli": "^5.1.4"
|
|
91
108
|
},
|
|
92
109
|
"optionalDependencies": {
|
|
@@ -103,5 +120,5 @@
|
|
|
103
120
|
"browserslist": [
|
|
104
121
|
"last 9 years and not dead"
|
|
105
122
|
],
|
|
106
|
-
"gitHead": "
|
|
123
|
+
"gitHead": "45cfb0a0adc1ed7928fda39955e9586f48994a8a"
|
|
107
124
|
}
|