zds-pickers 4.0.5 → 4.0.7
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/.editorconfig +19 -0
- package/.github/workflows/codeql-analysis.yml +67 -0
- package/.nvmrc +1 -0
- package/.prettierignore +0 -0
- package/.prettierrc +13 -0
- package/.storybook/main.ts +42 -0
- package/.storybook/manager.ts +12 -0
- package/.storybook/preview.tsx +26 -0
- package/.vscode/extensions.json +32 -0
- package/.vscode/javascript.code-snippets +229 -0
- package/.vscode/settings.json +358 -0
- package/biome.jsonc +158 -0
- package/dist/index.cjs.js +13 -12
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.es.js +638 -644
- package/dist/index.es.js.map +1 -0
- package/dist/types/index.d.ts +34 -2
- package/dist/types/pickers/CCPicker.d.ts +2 -1
- package/dist/types/pickers/ChannelMappingPicker.d.ts +2 -1
- package/dist/types/pickers/ChannelPicker.d.ts +5 -3
- package/dist/types/pickers/LatchPicker.d.ts +5 -3
- package/dist/types/pickers/MappingPicker.d.ts +2 -1
- package/dist/types/pickers/NotePicker.d.ts +2 -1
- package/dist/types/pickers/PolarityPicker.d.ts +6 -4
- package/dist/types/pickers/ResponseCurve.d.ts +14 -5
- package/dist/types/pickers/ResponseCurvePicker.d.ts +6 -4
- package/dist/types/pickers/StatusPicker.d.ts +2 -1
- package/dist/types/pickers/ValuePicker.d.ts +2 -1
- package/lib/@types/nebiru-react-rotary-knob.d.ts +20 -0
- package/lib/@types/react-svgmt.d.ts +74 -0
- package/lib/@types/zds-mappings.d.ts +55 -0
- package/lib/@types/zds-react-piano.d.ts +17 -0
- package/lib/hooks/useComponentSize.ts +52 -0
- package/lib/hooks/useStateWithDynamicDefault.ts +13 -0
- package/lib/index.ts +51 -0
- package/lib/midi/ccValues.ts +139 -0
- package/lib/midi/export.ts +54 -0
- package/lib/other/DefaultTooltip.ts +14 -0
- package/lib/other/OctavePlayer.tsx +141 -0
- package/lib/other/SVGText.tsx +221 -0
- package/lib/other/SoundFontProvider.tsx +130 -0
- package/lib/pickers/CCPicker.tsx +28 -0
- package/lib/pickers/ChannelMappingPicker.tsx +135 -0
- package/lib/pickers/ChannelPicker.tsx +76 -0
- package/lib/pickers/Knob.tsx +93 -0
- package/lib/pickers/KnobPicker.tsx +93 -0
- package/lib/pickers/LatchPicker.tsx +33 -0
- package/lib/pickers/MappingPicker.tsx +68 -0
- package/lib/pickers/NotePicker.tsx +95 -0
- package/lib/pickers/PianoPicker.tsx +77 -0
- package/lib/pickers/PolarityPicker.tsx +39 -0
- package/lib/pickers/ResponseCurve.tsx +304 -0
- package/lib/pickers/ResponseCurvePicker.tsx +74 -0
- package/lib/pickers/Select.tsx +248 -0
- package/lib/pickers/StatusPicker.tsx +28 -0
- package/lib/pickers/ValuePicker.tsx +67 -0
- package/lib/pickers/knobSkin10.tsx +94 -0
- package/lib/rotaryKnob/InternalInput.tsx +43 -0
- package/lib/rotaryKnob/Types.ts +6 -0
- package/lib/rotaryKnob/helpers/DrawCircle.tsx +41 -0
- package/lib/rotaryKnob/helpers/DrawLine.tsx +32 -0
- package/lib/rotaryKnob/helpers/HelpersOverlay.tsx +43 -0
- package/lib/rotaryKnob/helpers/KnobVisualHelpers.tsx +138 -0
- package/lib/rotaryKnob/index.tsx +417 -0
- package/lib/rotaryKnob/knobdefaultskin.ts +56 -0
- package/lib/rotaryKnob/utils.ts +112 -0
- package/lib/temp/acoustic_grand_piano-mp3.js +94 -0
- package/lib/utils.ts +41 -0
- package/package.json +2 -6
- package/stories/assets/sampleStyles.css +349 -0
- package/stories/assets/utils.js +7 -0
- package/stories/picker.stories.tsx +313 -0
- package/tsconfig.json +34 -0
- package/vite.config.ts +48 -0
- package/dist/index.d.ts +0 -244
- package/dist/types/main.d.ts +0 -19
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const knobSkin10 = {
|
|
2
|
+
knobX: 71.44,
|
|
3
|
+
knobY: 71.44,
|
|
4
|
+
svg: `
|
|
5
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="207px" height="207px" viewBox="0 0 207 207" version="1.1">
|
|
6
|
+
<!-- Generator: Sketch 47.1 (45422) - http://www.bohemiancoding.com/sketch -->
|
|
7
|
+
<desc>Created with Sketch.</desc>
|
|
8
|
+
<defs>
|
|
9
|
+
<linearGradient x1="50%" y1="50%" x2="50%" y2="100%" id="27c61b0f-392f-962d-de12-cb9da898274b">
|
|
10
|
+
<stop stop-color="#444040" stop-opacity="0.51098279" offset="0%"/>
|
|
11
|
+
<stop stop-color="#131111" stop-opacity="0.893200861" offset="100%"/>
|
|
12
|
+
</linearGradient>
|
|
13
|
+
<circle id="e966567b-3869-4bcd-76b6-2cf084e45390" cx="100.497487" cy="100.497487" r="99.4974874"/>
|
|
14
|
+
<filter x="-3.3%" y="-3.3%" width="106.5%" height="106.5%" filterUnits="objectBoundingBox" id="e2e6829f-0086-96b2-e92a-6f3809b8ac61">
|
|
15
|
+
<feMorphology radius="0.5" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"/>
|
|
16
|
+
<feOffset dx="0" dy="0" in="shadowSpreadOuter1" result="shadowOffsetOuter1"/>
|
|
17
|
+
<feGaussianBlur stdDeviation="2" in="shadowOffsetOuter1" result="shadowBlurOuter1"/>
|
|
18
|
+
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"/>
|
|
19
|
+
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0" type="matrix" in="shadowBlurOuter1"/>
|
|
20
|
+
</filter>
|
|
21
|
+
<linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="0facd5c9-8e04-e83f-4842-8ba16f949942">
|
|
22
|
+
<stop stop-color="#FFFFFF" stop-opacity="0.5" offset="0%"/>
|
|
23
|
+
<stop stop-color="#000000" stop-opacity="0.5" offset="100%"/>
|
|
24
|
+
</linearGradient>
|
|
25
|
+
<circle id="c54189ed-7ea3-956c-f040-f0207548b268" cx="100.432161" cy="100.432161" r="86.4321608"/>
|
|
26
|
+
<filter x="-4.0%" y="-3.5%" width="108.1%" height="108.1%" filterUnits="objectBoundingBox" id="dedf2e7e-f008-c315-f682-e424d670f210">
|
|
27
|
+
<feMorphology radius="0.5" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"/>
|
|
28
|
+
<feOffset dx="0" dy="1" in="shadowSpreadOuter1" result="shadowOffsetOuter1"/>
|
|
29
|
+
<feGaussianBlur stdDeviation="2" in="shadowOffsetOuter1" result="shadowBlurOuter1"/>
|
|
30
|
+
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"/>
|
|
31
|
+
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0" type="matrix" in="shadowBlurOuter1"/>
|
|
32
|
+
</filter>
|
|
33
|
+
|
|
34
|
+
<filter x="-5.3%" y="-11.3%" width="110.7%" height="122.6%" filterUnits="objectBoundingBox" id="12f618f7-e258-b597-3ed6-242484ddad8f">
|
|
35
|
+
<feOffset dx="0" dy="0" in="SourceAlpha" result="shadowOffsetOuter1"/>
|
|
36
|
+
<feGaussianBlur stdDeviation="2" in="shadowOffsetOuter1" result="shadowBlurOuter1"/>
|
|
37
|
+
<feColorMatrix values="0 0 0 0 0.915577168 0 0 0 0 0.797591325 0 0 0 0 0.601479722 0 0 0 1 0" type="matrix" in="shadowBlurOuter1"/>
|
|
38
|
+
</filter>
|
|
39
|
+
<pattern id="3cc0e5b8-1f0a-886b-f635-8fcb19212870" width="8.04411765" height="8.04411765" x="21.9558824" y="21.9558824" patternUnits="userSpaceOnUse">
|
|
40
|
+
<use xlink:href="#2b8719c1-286b-ebf8-a488-ac66a6598fc5" transform="scale(0.167585784,0.167585784)"/>
|
|
41
|
+
</pattern>
|
|
42
|
+
<image id="2b8719c1-286b-ebf8-a488-ac66a6598fc5" width="48" height="48" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAEGWlDQ1BrQ0dDb2xvclNwYWNlR2VuZXJpY1JHQgAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia219thzg25abkRE/BpDc3pqvphHvRFys2weqvp+krbWKIX7nhDbzLOItiM8358pTwdirqpPFnMF2xLc1WvLyOwTAibpbmvHHcvttU57y5+XqNZrLe3lE/Pq8eUj2fXKfOe3pfOjzhJYtB/yll5SDFcSDiH+hRkH25+L+sdxKEAMZahrlSX8ukqMOWy/jXW2m6M9LDBc31B9LFuv6gVKg/0Szi3KAr1kGq1GMjU/aLbnq6/lRxc4XfJ98hTargX++DbMJBSiYMIe9Ck1YAxFkKEAG3xbYaKmDDgYyFK0UGYpfoWYXG+fAPPI6tJnNwb7ClP7IyF+D+bjOtCpkhz6CFrIa/I6sFtNl8auFXGMTP34sNwI/JhkgEtmDz14ySfaRcTIBInmKPE32kxyyE2Tv+thKbEVePDfW/byMM1Kmm0XdObS7oGD/MypMXFPXrCwOtoYjyyn7BV29/MZfsVzpLDdRtuIZnbpXzvlf+ev8MvYr/Gqk4H/kV/G3csdazLuyTMPsbFhzd1UabQbjFvDRmcWJxR3zcfHkVw9GfpbJmeev9F08WW8uDkaslwX6avlWGU6NRKz0g/SHtCy9J30o/ca9zX3Kfc19zn3BXQKRO8ud477hLnAfc1/G9mrzGlrfexZ5GLdn6ZZrrEohI2wVHhZywjbhUWEy8icMCGNCUdiBlq3r+xafL549HQ5jH+an+1y+LlYBifuxAvRN/lVVVOlwlCkdVm9NOL5BE4wkQ2SMlDZU97hX86EilU/lUmkQUztTE6mx1EEPh7OmdqBtAvv8HdWpbrJS6tJj3n0CWdM6busNzRV3S9KTYhqvNiqWmuroiKgYhshMjmhTh9ptWhsF7970j/SbMrsPE1suR5z7DMC+P/Hs+y7ijrQAlhyAgccjbhjPygfeBTjzhNqy28EdkUh8C+DU9+z2v/oyeH791OncxHOs5y2AtTc7nb/f73TWPkD/qwBnjX8BoJ98VQNcC+8AAAFFSURBVGgF7djbDYMwDAXQBjEMYqyqY1WMxTppLiJIQIA8ariWkp8IPuweO60am67r7MstY8wwjuPH7dMz3uUua63p+/7r9rePIRW/9QmQzCV9ub0YgSIgzhxvQkjFb1EZBAdEKolkfJTqtnb7bv/zOJm58moRE0AzYgFoRawAGhE7gDZEEKAJcQjQgjgFaEBcAtgRUQBmRDSAFZEEYEQkA9gQWQAmRDaABVEEYEAUAx5H4EaGOyw+SMl66mbXzNOD4k6gCPNUY/CFwF1YOn5zRxJJRINqaUbUuZA/79sd3wm3xIdbdS60rXzo2XVCbO60/HxKJgFKKv4CkEziuyKBWAE0InYAbYggQBPiEKAFcQrQgLgEsCOiAMyIaAArIgnAiEgGsCGyAEyIbAALogjAgCgGPI7AX9w6F3JtqHMhnMWLFSrSD9jOnakVHpZYAAAAAElFTkSuQmCC"/>
|
|
43
|
+
</defs>
|
|
44
|
+
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
45
|
+
<g id="s10" transform="translate(3.000000, 3.000000)">
|
|
46
|
+
<g id="container">
|
|
47
|
+
<g id="Oval-2">
|
|
48
|
+
<use fill="black" fill-opacity="1" filter="url(#e2e6829f-0086-96b2-e92a-6f3809b8ac61)" xlink:href="#e966567b-3869-4bcd-76b6-2cf084e45390"/>
|
|
49
|
+
<use stroke="#979797" stroke-width="1" fill="url(#27c61b0f-392f-962d-de12-cb9da898274b)" fill-rule="evenodd" xlink:href="#e966567b-3869-4bcd-76b6-2cf084e45390"/>
|
|
50
|
+
</g>
|
|
51
|
+
<g id="Oval-2">
|
|
52
|
+
<use fill="black" fill-opacity="1" filter="url(#dedf2e7e-f008-c315-f682-e424d670f210)" xlink:href="#c54189ed-7ea3-956c-f040-f0207548b268"/>
|
|
53
|
+
<use fill="" fill-rule="evenodd" xlink:href="#c54189ed-7ea3-956c-f040-f0207548b268"/>
|
|
54
|
+
<use stroke="#4A4A4A" stroke-width="1" fill="url(#0facd5c9-8e04-e83f-4842-8ba16f949942)" fill-rule="evenodd" xlink:href="#c54189ed-7ea3-956c-f040-f0207548b268"/>
|
|
55
|
+
</g>
|
|
56
|
+
<g id="knob" transform="translate(28.574244, 28.574244)">
|
|
57
|
+
<circle id="Oval-5" fill="#322E2E" cx="71.4356094" cy="71.4356094" r="71.4356094"/>
|
|
58
|
+
<path d="M72.4209282,3.63066376 L88.6786876,16.869789 C81.585496,18.1548295 76.1662428,18.7973498 72.4209282,18.7973498 C68.6756135,18.7973498 63.2563604,18.1548295 56.1631688,16.869789 L72.4209282,3.63066376 Z" id="Rectangle" fill="#E6D7D7" transform="translate(72.420928, 11.214007) scale(1, -1) translate(-72.420928, -11.214007) "/>
|
|
59
|
+
</g>
|
|
60
|
+
<g id="label">
|
|
61
|
+
<g id="labeltext" fill-opacity="1" fill="#E6D7D7">
|
|
62
|
+
<text id="534f4e02-5541-3607-0966-af0b025d80e0" font-family="Helvetica" font-size="44" font-weight="normal" fill="#E6D7D7" class="text-7" filter="url(#12f618f7-e258-b597-3ed6-242484ddad8f)">
|
|
63
|
+
<tspan x="45.3246625" y="117.884225">10.10</tspan>
|
|
64
|
+
</text>
|
|
65
|
+
<text id="92ebe866-c281-70c7-7b0e-a373cee013a9" font-family="Helvetica" font-size="44" font-weight="normal" fill="#E6D7D7" class="text-7">
|
|
66
|
+
<tspan x="45.3246625" y="117.884225">10.10</tspan>
|
|
67
|
+
</text>
|
|
68
|
+
</g>
|
|
69
|
+
<circle id="Oval-6" stroke="#979797" fill-opacity="0.730000019" fill="url(#3cc0e5b8-1f0a-886b-f635-8fcb19212870)" transform="translate(100.351759, 100.351759) rotate(-45.000000) translate(-100.351759, -100.351759) " cx="100.351759" cy="100.351759" r="70.3517588"/>
|
|
70
|
+
</g>
|
|
71
|
+
</g>
|
|
72
|
+
</g>
|
|
73
|
+
</g>
|
|
74
|
+
</svg>
|
|
75
|
+
`,
|
|
76
|
+
updateAttributes: [
|
|
77
|
+
{
|
|
78
|
+
element: '#labeltext text tspan',
|
|
79
|
+
content: (_props: React.CSSProperties, value: number) => value.toFixed(0),
|
|
80
|
+
attrs: [
|
|
81
|
+
{
|
|
82
|
+
name: 'text-anchor',
|
|
83
|
+
value: (/* props, value */) => 'middle',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: 'x',
|
|
87
|
+
value: (/* props, value */) => '100',
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export default knobSkin10
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
type InternalInputProps = {
|
|
4
|
+
disabled?: boolean
|
|
5
|
+
min: number
|
|
6
|
+
max: number
|
|
7
|
+
value: number
|
|
8
|
+
step?: number
|
|
9
|
+
inputRef: React.RefObject<HTMLInputElement>
|
|
10
|
+
onChange: (val: number) => void
|
|
11
|
+
style?: React.CSSProperties
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class InternalInput extends React.Component<InternalInputProps> {
|
|
15
|
+
static defaultProps = {
|
|
16
|
+
step: 1,
|
|
17
|
+
}
|
|
18
|
+
render() {
|
|
19
|
+
const props = this.props
|
|
20
|
+
const hideStyle = {}
|
|
21
|
+
|
|
22
|
+
function onValChange(event: React.ChangeEvent<HTMLInputElement>) {
|
|
23
|
+
props.onChange(Number(event.target.value))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const { value, min, max, step, onChange, inputRef, ...rest } = props
|
|
27
|
+
return (
|
|
28
|
+
<input
|
|
29
|
+
ref={inputRef}
|
|
30
|
+
value={value}
|
|
31
|
+
step={step}
|
|
32
|
+
onChange={onValChange}
|
|
33
|
+
style={hideStyle}
|
|
34
|
+
type="range"
|
|
35
|
+
min={min}
|
|
36
|
+
max={max}
|
|
37
|
+
{...rest}
|
|
38
|
+
/>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default InternalInput
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Draws a circle with radius = r
|
|
5
|
+
* position must be handled by parent
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
type DrawCircleProps = React.SVGProps<SVGCircleElement> & {
|
|
9
|
+
r: number
|
|
10
|
+
borderColor?: string
|
|
11
|
+
fillColor?: string
|
|
12
|
+
borderWidth?: number
|
|
13
|
+
fillOpacity: number
|
|
14
|
+
cx: number
|
|
15
|
+
cy: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class DrawCircle extends React.Component<DrawCircleProps> {
|
|
19
|
+
render() {
|
|
20
|
+
const {
|
|
21
|
+
r,
|
|
22
|
+
borderColor = 'black',
|
|
23
|
+
fillColor = 'transparent',
|
|
24
|
+
borderWidth = 2,
|
|
25
|
+
fillOpacity = 1,
|
|
26
|
+
...rest
|
|
27
|
+
} = this.props
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<circle
|
|
31
|
+
stroke={borderColor}
|
|
32
|
+
fill={fillColor}
|
|
33
|
+
fillOpacity={fillOpacity}
|
|
34
|
+
r={r}
|
|
35
|
+
{...rest}
|
|
36
|
+
/>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default DrawCircle
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import type { Point } from '../Types'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Draws a line from p1 to p2
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
type DrawLineProps = React.SVGProps<SVGLineElement> & {
|
|
9
|
+
width?: number
|
|
10
|
+
color?: string
|
|
11
|
+
p1: Point
|
|
12
|
+
p2: Point
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class DrawLine extends React.Component<DrawLineProps> {
|
|
16
|
+
render() {
|
|
17
|
+
const { width = 2, color = 'black', p1, p2, ...rest } = this.props
|
|
18
|
+
return (
|
|
19
|
+
<line
|
|
20
|
+
{...rest}
|
|
21
|
+
stroke={color}
|
|
22
|
+
strokeWidth={width}
|
|
23
|
+
x1={p1.x}
|
|
24
|
+
y1={p1.y}
|
|
25
|
+
x2={p2.x}
|
|
26
|
+
y2={p2.y}
|
|
27
|
+
/>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default DrawLine
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import ReactDOM from 'react-dom'
|
|
3
|
+
|
|
4
|
+
type HelpersOverlayProps = React.PropsWithChildren & {
|
|
5
|
+
overlayStyle?: React.CSSProperties
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Draws the overlay and the children
|
|
10
|
+
*/
|
|
11
|
+
class HelpersOverlay extends React.Component<HelpersOverlayProps> {
|
|
12
|
+
render() {
|
|
13
|
+
const { children, ...rest } = this.props
|
|
14
|
+
|
|
15
|
+
const styles = {
|
|
16
|
+
overlay: Object.assign(
|
|
17
|
+
{
|
|
18
|
+
width: '100%',
|
|
19
|
+
height: '100vh',
|
|
20
|
+
top: 0,
|
|
21
|
+
left: 0,
|
|
22
|
+
zIndex: 2147483647,
|
|
23
|
+
margin: '0',
|
|
24
|
+
padding: '0',
|
|
25
|
+
boxSizing: 'border-box',
|
|
26
|
+
position: 'fixed',
|
|
27
|
+
},
|
|
28
|
+
this.props.overlayStyle,
|
|
29
|
+
),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return ReactDOM.createPortal(
|
|
33
|
+
<div
|
|
34
|
+
style={styles.overlay}
|
|
35
|
+
{...rest}>
|
|
36
|
+
{children}
|
|
37
|
+
</div>,
|
|
38
|
+
document.body,
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default HelpersOverlay
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import type { Point } from '../Types'
|
|
3
|
+
import utils from '../utils'
|
|
4
|
+
import DrawCircle from './DrawCircle'
|
|
5
|
+
import DrawLine from './DrawLine'
|
|
6
|
+
import HelpersOverlay from './HelpersOverlay'
|
|
7
|
+
|
|
8
|
+
/** Precision visual helpers */
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Precision mode visual helpers
|
|
12
|
+
*/
|
|
13
|
+
type KnobVisualHelpersProps = {
|
|
14
|
+
svgRef?: SVGSVGElement
|
|
15
|
+
radius: number
|
|
16
|
+
minimumDragDistance: number
|
|
17
|
+
valueAngle: number
|
|
18
|
+
mousePos: Point
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type KnobVisualHelpersState = {
|
|
22
|
+
centerX: number
|
|
23
|
+
centerY: number
|
|
24
|
+
valueMarkerX: number
|
|
25
|
+
valueMarkerY: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
class KnobVisualHelpers extends React.Component<
|
|
29
|
+
KnobVisualHelpersProps,
|
|
30
|
+
KnobVisualHelpersState
|
|
31
|
+
> {
|
|
32
|
+
state = {
|
|
33
|
+
centerX: 0,
|
|
34
|
+
centerY: 0,
|
|
35
|
+
valueMarkerX: 0,
|
|
36
|
+
valueMarkerY: 0,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static getDerivedStateFromProps(
|
|
40
|
+
props: KnobVisualHelpersProps,
|
|
41
|
+
state: KnobVisualHelpersState,
|
|
42
|
+
) {
|
|
43
|
+
//Calculate position
|
|
44
|
+
if (!props.svgRef) return state
|
|
45
|
+
|
|
46
|
+
const vbox = props.svgRef.getBoundingClientRect()
|
|
47
|
+
const halfWidth = vbox.width / 2
|
|
48
|
+
|
|
49
|
+
//Calculate current angle segment end point
|
|
50
|
+
//Note: Not sure why we need to subtract 90 here
|
|
51
|
+
const valueMarkerX =
|
|
52
|
+
props.radius * Math.cos(utils.toRadians(props.valueAngle - 90))
|
|
53
|
+
const valueMarkerY =
|
|
54
|
+
props.radius * Math.sin(utils.toRadians(props.valueAngle - 90))
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
...state,
|
|
58
|
+
centerX: vbox.left + halfWidth,
|
|
59
|
+
centerY: vbox.top + halfWidth,
|
|
60
|
+
valueMarkerX,
|
|
61
|
+
valueMarkerY,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
render() {
|
|
66
|
+
const markCircleColor =
|
|
67
|
+
this.props.minimumDragDistance <= this.props.radius ? 'green' : 'grey'
|
|
68
|
+
const fillColor =
|
|
69
|
+
this.props.minimumDragDistance <= this.props.radius
|
|
70
|
+
? '#88E22D'
|
|
71
|
+
: '#D8D8D8'
|
|
72
|
+
const minDistanceCueVisible =
|
|
73
|
+
this.props.minimumDragDistance >= this.props.radius
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<HelpersOverlay>
|
|
77
|
+
<svg
|
|
78
|
+
style={{ position: 'absolute', top: '0', left: '0' }}
|
|
79
|
+
width="100%"
|
|
80
|
+
height="100%">
|
|
81
|
+
<defs>
|
|
82
|
+
<marker
|
|
83
|
+
id="Triangle"
|
|
84
|
+
viewBox="0 0 10 10"
|
|
85
|
+
refX="1"
|
|
86
|
+
refY="5"
|
|
87
|
+
markerWidth="6"
|
|
88
|
+
markerHeight="6"
|
|
89
|
+
orient="auto">
|
|
90
|
+
<path d="M 0 0 L 10 5 L 0 10 z" />
|
|
91
|
+
</marker>
|
|
92
|
+
</defs>
|
|
93
|
+
|
|
94
|
+
{/* Current drag distance */}
|
|
95
|
+
<DrawCircle
|
|
96
|
+
borderColor={markCircleColor}
|
|
97
|
+
fillColor={fillColor}
|
|
98
|
+
fillOpacity={0.02}
|
|
99
|
+
r={this.props.radius}
|
|
100
|
+
cx={this.state.centerX}
|
|
101
|
+
cy={this.state.centerY}
|
|
102
|
+
/>
|
|
103
|
+
{/* Minimum drag distance marker */}
|
|
104
|
+
{minDistanceCueVisible && (
|
|
105
|
+
<DrawCircle
|
|
106
|
+
borderColor={markCircleColor}
|
|
107
|
+
fillColor={fillColor}
|
|
108
|
+
fillOpacity={0}
|
|
109
|
+
r={this.props.minimumDragDistance}
|
|
110
|
+
cx={this.state.centerX}
|
|
111
|
+
cy={this.state.centerY}
|
|
112
|
+
//strokeDasharray="5, 5"
|
|
113
|
+
/>
|
|
114
|
+
)}
|
|
115
|
+
|
|
116
|
+
{/* Line to mouse position */}
|
|
117
|
+
{/* <DrawLine
|
|
118
|
+
p1={{ x: this.state.centerX, y: this.state.centerY }}
|
|
119
|
+
p2={{ x: this.props.mousePos.x, y: this.props.mousePos.y }}
|
|
120
|
+
opacity={0.4}
|
|
121
|
+
strokeDasharray="5, 5"
|
|
122
|
+
/> */}
|
|
123
|
+
{/* Line to current value */}
|
|
124
|
+
<DrawLine
|
|
125
|
+
p1={{ x: this.state.centerX, y: this.state.centerY }}
|
|
126
|
+
p2={{
|
|
127
|
+
x: this.state.valueMarkerX + this.state.centerX,
|
|
128
|
+
y: this.state.valueMarkerY + this.state.centerY,
|
|
129
|
+
}}
|
|
130
|
+
markerEnd="url(#Triangle)"
|
|
131
|
+
/>
|
|
132
|
+
</svg>
|
|
133
|
+
</HelpersOverlay>
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { KnobVisualHelpers }
|