@tremolo-ui/react 0.0.5 → 0.0.6
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/dist/cjs/index.js +196 -93
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/AnimationCanvas/index.d.ts +3 -4
- package/dist/cjs/types/components/AnimationCanvas/index.d.ts.map +1 -1
- package/dist/cjs/types/components/Knob/index.d.ts +6 -7
- package/dist/cjs/types/components/Knob/index.d.ts.map +1 -1
- package/dist/cjs/types/components/NumberInput/index.d.ts +10 -7
- package/dist/cjs/types/components/NumberInput/index.d.ts.map +1 -1
- package/dist/cjs/types/components/Piano/BlackKey.d.ts +4 -0
- package/dist/cjs/types/components/Piano/BlackKey.d.ts.map +1 -0
- package/dist/cjs/types/components/Piano/KeyLabel.d.ts +20 -0
- package/dist/cjs/types/components/Piano/KeyLabel.d.ts.map +1 -0
- package/dist/cjs/types/components/Piano/WhiteKey.d.ts +4 -0
- package/dist/cjs/types/components/Piano/WhiteKey.d.ts.map +1 -0
- package/dist/cjs/types/components/Piano/index.d.ts +35 -0
- package/dist/cjs/types/components/Piano/index.d.ts.map +1 -0
- package/dist/cjs/types/components/Piano/key.d.ts +39 -0
- package/dist/cjs/types/components/Piano/key.d.ts.map +1 -0
- package/dist/cjs/types/components/Piano/keyboardShortcuts.d.ts +12 -0
- package/dist/cjs/types/components/Piano/keyboardShortcuts.d.ts.map +1 -0
- package/dist/cjs/types/components/Slider/Thumb.d.ts +17 -2
- package/dist/cjs/types/components/Slider/Thumb.d.ts.map +1 -1
- package/dist/cjs/types/components/Slider/Track.d.ts +21 -2
- package/dist/cjs/types/components/Slider/Track.d.ts.map +1 -1
- package/dist/cjs/types/components/Slider/index.d.ts +18 -10
- package/dist/cjs/types/components/Slider/index.d.ts.map +1 -1
- package/dist/cjs/types/components/_util/index.d.ts +4 -0
- package/dist/cjs/types/components/_util/index.d.ts.map +1 -0
- package/dist/esm/index.js +197 -94
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/AnimationCanvas/index.d.ts +3 -4
- package/dist/esm/types/components/AnimationCanvas/index.d.ts.map +1 -1
- package/dist/esm/types/components/Knob/index.d.ts +6 -7
- package/dist/esm/types/components/Knob/index.d.ts.map +1 -1
- package/dist/esm/types/components/NumberInput/index.d.ts +10 -7
- package/dist/esm/types/components/NumberInput/index.d.ts.map +1 -1
- package/dist/esm/types/components/Piano/BlackKey.d.ts +4 -0
- package/dist/esm/types/components/Piano/BlackKey.d.ts.map +1 -0
- package/dist/esm/types/components/Piano/KeyLabel.d.ts +20 -0
- package/dist/esm/types/components/Piano/KeyLabel.d.ts.map +1 -0
- package/dist/esm/types/components/Piano/WhiteKey.d.ts +4 -0
- package/dist/esm/types/components/Piano/WhiteKey.d.ts.map +1 -0
- package/dist/esm/types/components/Piano/index.d.ts +35 -0
- package/dist/esm/types/components/Piano/index.d.ts.map +1 -0
- package/dist/esm/types/components/Piano/key.d.ts +39 -0
- package/dist/esm/types/components/Piano/key.d.ts.map +1 -0
- package/dist/esm/types/components/Piano/keyboardShortcuts.d.ts +12 -0
- package/dist/esm/types/components/Piano/keyboardShortcuts.d.ts.map +1 -0
- package/dist/esm/types/components/Slider/Thumb.d.ts +17 -2
- package/dist/esm/types/components/Slider/Thumb.d.ts.map +1 -1
- package/dist/esm/types/components/Slider/Track.d.ts +21 -2
- package/dist/esm/types/components/Slider/Track.d.ts.map +1 -1
- package/dist/esm/types/components/Slider/index.d.ts +18 -10
- package/dist/esm/types/components/Slider/index.d.ts.map +1 -1
- package/dist/esm/types/components/_util/index.d.ts +4 -0
- package/dist/esm/types/components/_util/index.d.ts.map +1 -0
- package/dist/styles/{variables.css → index.css} +4 -0
- package/package.json +7 -7
- package/src/components/AnimationCanvas/index.tsx +3 -7
- package/src/components/Knob/index.tsx +15 -19
- package/src/components/NumberInput/index.tsx +18 -11
- package/src/components/Piano/BlackKey.tsx +108 -0
- package/src/components/Piano/KeyLabel.tsx +69 -0
- package/src/components/Piano/WhiteKey.tsx +109 -0
- package/src/components/Piano/index.tsx +222 -0
- package/src/components/Piano/key.ts +43 -0
- package/src/components/Piano/keyboardShortcuts.ts +12 -0
- package/src/components/Slider/Thumb.tsx +56 -15
- package/src/components/Slider/Track.tsx +62 -3
- package/src/components/Slider/index.tsx +125 -89
- package/src/components/_util/index.ts +11 -0
- package/src/styles/{variables.css → index.css} +4 -0
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import { CSSObject } from '@emotion/react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
interface SliderThumbProps {
|
|
4
|
+
size?: number | string;
|
|
5
|
+
width?: number | string;
|
|
6
|
+
height?: number | string;
|
|
4
7
|
color?: string;
|
|
8
|
+
hoverColor?: string;
|
|
9
|
+
disabledColor?: string;
|
|
10
|
+
disabledHoverColor?: string;
|
|
11
|
+
zIndex?: number;
|
|
12
|
+
className?: string;
|
|
5
13
|
style?: CSSObject;
|
|
6
|
-
__css?: CSSObject;
|
|
7
14
|
children?: ReactNode;
|
|
15
|
+
/** @internal */
|
|
16
|
+
__disabled?: boolean;
|
|
17
|
+
/** @internal */
|
|
18
|
+
__css?: CSSObject;
|
|
19
|
+
}
|
|
20
|
+
export interface SliderThumbMethods {
|
|
21
|
+
focus: () => void;
|
|
22
|
+
blur: () => void;
|
|
8
23
|
}
|
|
9
|
-
export declare
|
|
24
|
+
export declare const SliderThumb: import("react").ForwardRefExoticComponent<SliderThumbProps & import("react").RefAttributes<SliderThumbMethods>>;
|
|
10
25
|
export {};
|
|
11
26
|
//# sourceMappingURL=Thumb.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Thumb.d.ts","sourceRoot":"","sources":["../../../../../src/components/Slider/Thumb.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAO,MAAM,gBAAgB,CAAA;AAC/C,OAAO,
|
|
1
|
+
{"version":3,"file":"Thumb.d.ts","sourceRoot":"","sources":["../../../../../src/components/Slider/Thumb.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAO,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAc,SAAS,EAA+B,MAAM,OAAO,CAAA;AAG1E,UAAU,gBAAgB;IACxB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,QAAQ,CAAC,EAAE,SAAS,CAAA;IAEpB,gBAAgB;IAChB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,gBAAgB;IAChB,KAAK,CAAC,EAAE,SAAS,CAAA;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,IAAI,EAAE,MAAM,IAAI,CAAA;CACjB;AAEA,eAAO,MAAM,WAAW,iHAiEvB,CAAA"}
|
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
import { CSSObject } from '@emotion/react';
|
|
2
2
|
import { ReactElement } from 'react';
|
|
3
|
+
import { Direction } from './type';
|
|
3
4
|
interface SliderTrackProps {
|
|
5
|
+
length?: number | string;
|
|
6
|
+
thickness?: number | string;
|
|
7
|
+
activeBg?: string;
|
|
8
|
+
inactiveBg?: string;
|
|
9
|
+
activeHoverBg?: string;
|
|
10
|
+
inactiveHoverBg?: string;
|
|
11
|
+
disabledActiveBg?: string;
|
|
12
|
+
disabledInactiveBg?: string;
|
|
13
|
+
disabledActiveHoverBg?: string;
|
|
14
|
+
disabledInactiveHoverBg?: string;
|
|
15
|
+
className?: string;
|
|
4
16
|
style?: CSSObject;
|
|
5
17
|
children?: ReactElement;
|
|
6
|
-
|
|
18
|
+
/** inherit */
|
|
19
|
+
__thumb?: ReactElement;
|
|
20
|
+
/** inherit */
|
|
21
|
+
__direction?: Direction;
|
|
22
|
+
/** inherit */
|
|
23
|
+
__disabled?: boolean;
|
|
24
|
+
/** internal */
|
|
25
|
+
__percent?: number;
|
|
7
26
|
}
|
|
8
|
-
export declare function SliderTrack({ children, style,
|
|
27
|
+
export declare function SliderTrack({ length, thickness, activeBg, inactiveBg, activeHoverBg, inactiveHoverBg, disabledActiveBg, disabledInactiveBg, disabledActiveHoverBg, disabledInactiveHoverBg, children, className, style, __thumb, __direction, __disabled, __percent, }: SliderTrackProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
9
28
|
export {};
|
|
10
29
|
//# sourceMappingURL=Track.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Track.d.ts","sourceRoot":"","sources":["../../../../../src/components/Slider/Track.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAO,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"Track.d.ts","sourceRoot":"","sources":["../../../../../src/components/Slider/Track.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAO,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAKpC,OAAO,EAAE,SAAS,EAAqB,MAAM,QAAQ,CAAA;AAErD,UAAU,gBAAgB;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAE3B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAEhC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,QAAQ,CAAC,EAAE,YAAY,CAAA;IAEvB,cAAc;IACd,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB,cAAc;IACd,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB,cAAc;IACd,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,eAAe;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,WAAW,CAAC,EAC1B,MAAY,EACZ,SAAc,EACd,QAAoB,EACpB,UAAmB,EACnB,aAAyB,EACzB,eAA2B,EAC3B,gBAA4B,EAC5B,kBAA2B,EAC3B,qBAAwC,EACxC,uBAA4C,EAC5C,QAAQ,EACR,SAAS,EACT,KAAK,EACL,OAAO,EACP,WAAW,EACX,UAAU,EACV,SAAS,GACV,EAAE,gBAAgB,oDAwBlB"}
|
|
@@ -1,33 +1,41 @@
|
|
|
1
1
|
import { CSSObject } from '@emotion/react';
|
|
2
2
|
import { Direction, ScaleOrderList, ScaleType } from '@tremolo-ui/functions/Slider';
|
|
3
|
-
import {
|
|
4
|
-
import { ReactElement } from 'react';
|
|
5
|
-
import { UserActionPseudoProps } from '../../system/pseudo';
|
|
3
|
+
import { InputEventOption } from '@tremolo-ui/functions';
|
|
4
|
+
import React, { ReactElement } from 'react';
|
|
6
5
|
import { ScaleOption } from './type';
|
|
7
|
-
interface SliderProps {
|
|
6
|
+
export interface SliderProps {
|
|
8
7
|
value: number;
|
|
9
8
|
min: number;
|
|
10
9
|
max: number;
|
|
11
10
|
step?: number;
|
|
12
11
|
skew?: number;
|
|
13
|
-
length?: number | string;
|
|
14
|
-
thickness?: number | string;
|
|
15
12
|
direction?: Direction;
|
|
16
13
|
scale?: ['step', ScaleType] | [number, ScaleType] | ScaleOrderList[];
|
|
17
14
|
scaleOption?: ScaleOption;
|
|
18
|
-
color?: string;
|
|
19
|
-
bg?: string;
|
|
20
15
|
bodyNoSelect?: boolean;
|
|
21
|
-
|
|
16
|
+
/**
|
|
17
|
+
* wheel control option
|
|
18
|
+
*/
|
|
19
|
+
wheel?: InputEventOption;
|
|
20
|
+
/**
|
|
21
|
+
* keyboard control option
|
|
22
|
+
*/
|
|
23
|
+
keyboard?: InputEventOption;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
readonly?: boolean;
|
|
22
26
|
className?: string;
|
|
23
27
|
style?: CSSObject;
|
|
24
28
|
onChange?: (value: number) => void;
|
|
25
29
|
children?: ReactElement | ReactElement[];
|
|
26
30
|
}
|
|
31
|
+
export interface SliderMethods {
|
|
32
|
+
focus: () => void;
|
|
33
|
+
blur: () => void;
|
|
34
|
+
}
|
|
27
35
|
/**
|
|
28
36
|
* Customizable slider
|
|
29
37
|
*/
|
|
30
|
-
export declare
|
|
38
|
+
export declare const Slider: React.ForwardRefExoticComponent<SliderProps & React.RefAttributes<SliderMethods>>;
|
|
31
39
|
export * from './Thumb';
|
|
32
40
|
export * from './Track';
|
|
33
41
|
export * from './type';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/Slider/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAO,SAAS,EAAU,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/Slider/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAO,SAAS,EAAU,MAAM,gBAAgB,CAAA;AAEvD,OAAO,EACL,SAAS,EAKT,cAAc,EACd,SAAS,EACV,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAuD,gBAAgB,EAAe,MAAM,uBAAuB,CAAA;AAC1H,OAAO,KAAK,EAAE,EAAc,YAAY,EAA4C,MAAM,OAAO,CAAA;AASjG,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAEpC,MAAM,WAAW,WAAW;IAG1B,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IAGX,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,SAAS,CAAA;IAErB,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,cAAc,EAAE,CAAA;IACpE,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAA;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,QAAQ,CAAC,EAAE,YAAY,GAAG,YAAY,EAAE,CAAA;CAEzC;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,IAAI,EAAE,MAAM,IAAI,CAAA;CACjB;AAED;;GAEG;AACF,eAAO,MAAM,MAAM,mFAsSlB,CAAA;AAEF,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/_util/index.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,SAE1B;AAED,wBAAgB,cAAc,SAE7B;AAED,wBAAgB,cAAc,SAE7B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tremolo-ui/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "React component library for audio app",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
23
|
"require": {
|
|
24
|
-
"
|
|
25
|
-
"
|
|
24
|
+
"types": "./dist/cjs/types/index.d.ts",
|
|
25
|
+
"default": "./dist/cjs/index.js"
|
|
26
26
|
},
|
|
27
27
|
"import": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
28
|
+
"types": "./dist/esm/types/index.d.ts",
|
|
29
|
+
"default": "./dist/esm/index.js"
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"./styles": "./src/styles"
|
|
@@ -58,7 +58,6 @@
|
|
|
58
58
|
"emotion"
|
|
59
59
|
],
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@chromatic-com/storybook": "^1.6.1",
|
|
62
61
|
"@emotion/react": "^11.13.0",
|
|
63
62
|
"@storybook/addon-essentials": "^8.3.3",
|
|
64
63
|
"@storybook/addon-interactions": "^8.3.3",
|
|
@@ -72,7 +71,8 @@
|
|
|
72
71
|
"react": "^18.3.1",
|
|
73
72
|
"react-component-benchmark": "^2.0.0",
|
|
74
73
|
"react-dom": "^18.3.1",
|
|
75
|
-
"storybook": "^8.3.3"
|
|
74
|
+
"storybook": "^8.3.3",
|
|
75
|
+
"tone": "^15.0.4"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"@emotion/react": "11.x",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { css, CSSObject } from '@emotion/react'
|
|
2
|
-
import { MutableRefObject, useEffect, useRef } from 'react'
|
|
2
|
+
import { ComponentPropsWithRef, MutableRefObject, useEffect, useRef } from 'react'
|
|
3
3
|
import clsx from 'clsx'
|
|
4
4
|
|
|
5
5
|
import { DrawingContext, drawingState, DrawingStateValue } from './canvas'
|
|
@@ -25,7 +25,7 @@ export type DrawFunction = (
|
|
|
25
25
|
count: number,
|
|
26
26
|
) => void
|
|
27
27
|
|
|
28
|
-
interface AnimationCanvasProps {
|
|
28
|
+
export interface AnimationCanvasProps {
|
|
29
29
|
width?: number
|
|
30
30
|
height?: number
|
|
31
31
|
relativeSize?: boolean
|
|
@@ -52,11 +52,7 @@ export function AnimationCanvas({
|
|
|
52
52
|
className,
|
|
53
53
|
...props
|
|
54
54
|
}: AnimationCanvasProps &
|
|
55
|
-
Omit<
|
|
56
|
-
React.ClassAttributes<HTMLCanvasElement> &
|
|
57
|
-
React.CanvasHTMLAttributes<HTMLCanvasElement>,
|
|
58
|
-
'ref' | 'width' | 'height' | 'style'
|
|
59
|
-
>) {
|
|
55
|
+
Omit<ComponentPropsWithRef<'canvas'>, keyof AnimationCanvasProps>) {
|
|
60
56
|
const canvasRef = useRef<HTMLCanvasElement>(null)
|
|
61
57
|
const memoCanvasRef = useRef<HTMLCanvasElement>(null)
|
|
62
58
|
const reqIdRef = useRef<number>()
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { css, CSSObject, Global } from '@emotion/react'
|
|
2
|
-
import { clamp, normalizeValue, radian, rawValue, stepValue } from '@tremolo-ui/functions'
|
|
3
|
-
import {
|
|
4
|
-
import React, { useRef } from 'react'
|
|
2
|
+
import { clamp, normalizeValue, radian, rawValue, stepValue, InputEventOption } from '@tremolo-ui/functions'
|
|
3
|
+
import React, { ComponentPropsWithRef, useRef } from 'react'
|
|
5
4
|
import clsx from 'clsx'
|
|
6
5
|
|
|
7
6
|
import { useEventListener } from '../../hooks/useEventListener'
|
|
8
7
|
import { useRefCallbackEvent } from '../../hooks/useRefCallbackEvent'
|
|
9
8
|
import { UserActionPseudoProps } from '../../system/pseudo'
|
|
10
9
|
import { AnimationCanvas, DrawFunction } from '../AnimationCanvas'
|
|
10
|
+
import { addNoSelect, removeNoSelect } from '../_util'
|
|
11
11
|
|
|
12
|
-
interface KnobProps {
|
|
12
|
+
export interface KnobProps {
|
|
13
13
|
// required
|
|
14
14
|
value: number
|
|
15
15
|
min: number
|
|
@@ -46,13 +46,13 @@ interface KnobProps {
|
|
|
46
46
|
lineWeight?: number // line color
|
|
47
47
|
thumbWeight?: number // thumb weight
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
draw?: DrawFunction
|
|
51
51
|
|
|
52
|
-
/** Whether to apply {use-select: none} when dragging */
|
|
52
|
+
/** Whether to apply `{use-select: none}` when dragging */
|
|
53
53
|
bodyNoSelect?: boolean
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
wheel?: InputEventOption
|
|
56
56
|
enableDoubleClickDefault?: boolean
|
|
57
57
|
style?: CSSObject
|
|
58
58
|
onChange?: (value: number) => void
|
|
@@ -84,7 +84,7 @@ export function Knob({
|
|
|
84
84
|
options = defaultOptions,
|
|
85
85
|
draw,
|
|
86
86
|
bodyNoSelect = true,
|
|
87
|
-
|
|
87
|
+
wheel,
|
|
88
88
|
enableDoubleClickDefault = true,
|
|
89
89
|
style,
|
|
90
90
|
className,
|
|
@@ -95,11 +95,7 @@ export function Knob({
|
|
|
95
95
|
...props
|
|
96
96
|
}: KnobProps &
|
|
97
97
|
UserActionPseudoProps &
|
|
98
|
-
Omit<
|
|
99
|
-
React.ClassAttributes<HTMLDivElement> &
|
|
100
|
-
React.HTMLAttributes<HTMLDivElement>,
|
|
101
|
-
'onChange'
|
|
102
|
-
>) {
|
|
98
|
+
Omit<ComponentPropsWithRef<'div'>, keyof KnobProps>) {
|
|
103
99
|
// -- state and ref ---
|
|
104
100
|
// const [privateValue, setPrivateValue] = useState(value);
|
|
105
101
|
const dragOffsetY = useRef<number | undefined>(undefined)
|
|
@@ -126,7 +122,7 @@ export function Knob({
|
|
|
126
122
|
const isTouch = event instanceof TouchEvent
|
|
127
123
|
if (isTouch && event.cancelable) event.preventDefault()
|
|
128
124
|
if (dragOffsetY.current) {
|
|
129
|
-
if (bodyNoSelect)
|
|
125
|
+
if (bodyNoSelect) addNoSelect()
|
|
130
126
|
const screenY = isTouch ? event.touches[0].screenY : event.screenY
|
|
131
127
|
const delta = dragOffsetY.current - screenY
|
|
132
128
|
dragOffsetY.current = screenY
|
|
@@ -141,11 +137,11 @@ export function Knob({
|
|
|
141
137
|
const wheelRefCallback = useRefCallbackEvent(
|
|
142
138
|
'wheel',
|
|
143
139
|
(event) => {
|
|
144
|
-
if (!
|
|
140
|
+
if (!wheel) return
|
|
145
141
|
event.preventDefault()
|
|
146
|
-
const x = event.deltaY > 0 ? -
|
|
142
|
+
const x = event.deltaY > 0 ? -wheel[1] : wheel[1]
|
|
147
143
|
let v
|
|
148
|
-
if (
|
|
144
|
+
if (wheel[0] == 'normalized') {
|
|
149
145
|
const n = normalizeValue(value, min, max, skew)
|
|
150
146
|
v = rawValue(n + x, min, max, skew)
|
|
151
147
|
} else {
|
|
@@ -154,7 +150,7 @@ export function Knob({
|
|
|
154
150
|
if (onChange) onChange(clamp(stepValue(v, step), min, max))
|
|
155
151
|
},
|
|
156
152
|
{ passive: false },
|
|
157
|
-
[
|
|
153
|
+
[wheel, value, min, max, skew, step, onChange],
|
|
158
154
|
)
|
|
159
155
|
|
|
160
156
|
const touchMoveRefCallback = useRefCallbackEvent(
|
|
@@ -168,7 +164,7 @@ export function Knob({
|
|
|
168
164
|
|
|
169
165
|
useEventListener(window, 'pointerup', () => {
|
|
170
166
|
dragOffsetY.current = undefined
|
|
171
|
-
if (bodyNoSelect)
|
|
167
|
+
if (bodyNoSelect) removeNoSelect()
|
|
172
168
|
})
|
|
173
169
|
|
|
174
170
|
return (
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { css, CSSObject } from '@emotion/react'
|
|
2
2
|
import { clamp } from '@tremolo-ui/functions'
|
|
3
3
|
import { parseValue, Units } from '@tremolo-ui/functions/NumberInput'
|
|
4
|
-
import { ChangeEvent, useState } from 'react'
|
|
4
|
+
import { ChangeEvent, ComponentPropsWithoutRef, useState } from 'react'
|
|
5
5
|
import clsx from 'clsx'
|
|
6
6
|
|
|
7
7
|
import { InputPseudoProps, UserActionPseudoProps } from '../../system/pseudo'
|
|
8
8
|
|
|
9
|
-
interface NumberInputProps {
|
|
9
|
+
export interface NumberInputProps {
|
|
10
10
|
value: number | string
|
|
11
11
|
|
|
12
12
|
min?: number
|
|
@@ -31,12 +31,16 @@ interface NumberInputProps {
|
|
|
31
31
|
/**
|
|
32
32
|
* NOTE: If units is specified, it is forced to `false`
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
typeNumber?: boolean // TODO: rename typeNumber
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
+
* Digits for rounding numbers.
|
|
37
38
|
* @example
|
|
38
|
-
* with
|
|
39
|
-
*
|
|
39
|
+
* with:
|
|
40
|
+
* units={[['Hz', 1], ['kHz', 1000]]}
|
|
41
|
+
* digit={3}
|
|
42
|
+
* results:
|
|
43
|
+
* value=100 -> 100Hz, value=1600 -> 1.60Hz
|
|
40
44
|
*/
|
|
41
45
|
digit?: number
|
|
42
46
|
selectWithFocus?: 'all' | 'number' | 'none'
|
|
@@ -68,7 +72,7 @@ export function NumberInput({
|
|
|
68
72
|
placeholder,
|
|
69
73
|
readOnly,
|
|
70
74
|
tabIndex,
|
|
71
|
-
|
|
75
|
+
typeNumber = false,
|
|
72
76
|
digit,
|
|
73
77
|
selectWithFocus = 'none',
|
|
74
78
|
blurWithEnter = true,
|
|
@@ -77,13 +81,15 @@ export function NumberInput({
|
|
|
77
81
|
onChange,
|
|
78
82
|
onFocus,
|
|
79
83
|
onBlur,
|
|
80
|
-
...
|
|
81
|
-
}: NumberInputProps & UserActionPseudoProps & InputPseudoProps
|
|
84
|
+
...props
|
|
85
|
+
}: NumberInputProps & UserActionPseudoProps & InputPseudoProps &
|
|
86
|
+
Omit<ComponentPropsWithoutRef<'input'>, keyof NumberInputProps>
|
|
87
|
+
) {
|
|
82
88
|
const [showValue, setShowValue] = useState(
|
|
83
89
|
parseValue(String(value), units, digit, defaultValue).formatValue,
|
|
84
90
|
)
|
|
85
|
-
const
|
|
86
|
-
const { _active, _focus, _hover } =
|
|
91
|
+
const calculatedTypeNumber = units ? false : typeNumber
|
|
92
|
+
const { _active, _focus, _hover, ...rest } = props
|
|
87
93
|
|
|
88
94
|
return (
|
|
89
95
|
<input
|
|
@@ -92,7 +98,7 @@ export function NumberInput({
|
|
|
92
98
|
min={min}
|
|
93
99
|
max={max}
|
|
94
100
|
step={step}
|
|
95
|
-
type={
|
|
101
|
+
type={calculatedTypeNumber ? 'number' : 'text'}
|
|
96
102
|
spellCheck={'false'}
|
|
97
103
|
disabled={disabled}
|
|
98
104
|
placeholder={placeholder}
|
|
@@ -160,6 +166,7 @@ export function NumberInput({
|
|
|
160
166
|
event.currentTarget.blur()
|
|
161
167
|
}
|
|
162
168
|
}}
|
|
169
|
+
{...rest}
|
|
163
170
|
/>
|
|
164
171
|
)
|
|
165
172
|
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { css } from "@emotion/react"
|
|
2
|
+
import React, { forwardRef, useImperativeHandle, useRef, useState } from "react"
|
|
3
|
+
|
|
4
|
+
import { KeyLabel } from "./KeyLabel"
|
|
5
|
+
import { KeyMethods, KeyProps } from "./key"
|
|
6
|
+
|
|
7
|
+
export const BlackKey = forwardRef<KeyMethods, KeyProps>(({
|
|
8
|
+
width = 40 * 0.65,
|
|
9
|
+
height = '60%',
|
|
10
|
+
bg = '#333',
|
|
11
|
+
activeBg = '#666',
|
|
12
|
+
style,
|
|
13
|
+
children,
|
|
14
|
+
__glissando,
|
|
15
|
+
__position,
|
|
16
|
+
__note,
|
|
17
|
+
__disabled,
|
|
18
|
+
__index,
|
|
19
|
+
__fill,
|
|
20
|
+
__width,
|
|
21
|
+
__playNote,
|
|
22
|
+
__stopNote,
|
|
23
|
+
__label,
|
|
24
|
+
}: KeyProps, ref) => {
|
|
25
|
+
const [played, setPlayed] = useState(false)
|
|
26
|
+
|
|
27
|
+
useImperativeHandle(ref, () => {
|
|
28
|
+
return {
|
|
29
|
+
play() {
|
|
30
|
+
if (__disabled) return
|
|
31
|
+
setPlayed(true)
|
|
32
|
+
if (__playNote) __playNote(__note!)
|
|
33
|
+
},
|
|
34
|
+
stop() {
|
|
35
|
+
setPlayed(false)
|
|
36
|
+
if (__stopNote) __stopNote(__note!)
|
|
37
|
+
},
|
|
38
|
+
played() {
|
|
39
|
+
return played
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}, [])
|
|
43
|
+
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
let keyLabelProps: any
|
|
46
|
+
if (children != undefined) {
|
|
47
|
+
React.Children.forEach(children, (child) => {
|
|
48
|
+
if (React.isValidElement(child)) {
|
|
49
|
+
if (child.type == KeyLabel) {
|
|
50
|
+
keyLabelProps = child.props
|
|
51
|
+
} else {
|
|
52
|
+
throw new Error('only <KeyLabel>')
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
throw new Error('children is an invalid element.')
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<div
|
|
62
|
+
className={`tremolo-piano-black-key`}
|
|
63
|
+
aria-disabled={__disabled}
|
|
64
|
+
css={css({
|
|
65
|
+
position: 'absolute',
|
|
66
|
+
backgroundColor: played ? activeBg : bg,
|
|
67
|
+
color: 'white',
|
|
68
|
+
left: __position,
|
|
69
|
+
width: __fill ? __width : (width ?? __width),
|
|
70
|
+
height: height,
|
|
71
|
+
border: '1px solid #555',
|
|
72
|
+
borderRadius: '0 0 8px 8px',
|
|
73
|
+
cursor: __disabled ? 'not-allowed' : 'pointer',
|
|
74
|
+
zIndex: 2,
|
|
75
|
+
...style,
|
|
76
|
+
})}
|
|
77
|
+
onPointerDown={() => {
|
|
78
|
+
if (__disabled) return
|
|
79
|
+
setPlayed(true)
|
|
80
|
+
if (__playNote) __playNote(__note!)
|
|
81
|
+
}}
|
|
82
|
+
onPointerEnter={() => {
|
|
83
|
+
if (__disabled) return
|
|
84
|
+
if (__glissando) {
|
|
85
|
+
setPlayed(true)
|
|
86
|
+
if (__playNote) __playNote(__note!)
|
|
87
|
+
}
|
|
88
|
+
}}
|
|
89
|
+
onPointerUp={() => {
|
|
90
|
+
if (__disabled) return
|
|
91
|
+
setPlayed(false)
|
|
92
|
+
if (__stopNote) __stopNote(__note!)
|
|
93
|
+
}}
|
|
94
|
+
onPointerLeave={() => {
|
|
95
|
+
if (__disabled) return
|
|
96
|
+
setPlayed(false)
|
|
97
|
+
if (__stopNote) __stopNote(__note!)
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
<KeyLabel
|
|
101
|
+
__note={__note}
|
|
102
|
+
__label={__label}
|
|
103
|
+
__index={__index}
|
|
104
|
+
{...keyLabelProps}
|
|
105
|
+
/>
|
|
106
|
+
</div>
|
|
107
|
+
)
|
|
108
|
+
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { css, CSSObject } from "@emotion/react"
|
|
2
|
+
import clsx from "clsx"
|
|
3
|
+
import { ReactNode } from "react"
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
/**
|
|
7
|
+
* override Piano.label
|
|
8
|
+
*/
|
|
9
|
+
label?: (note: number, index: number) => ReactNode
|
|
10
|
+
|
|
11
|
+
className?: string
|
|
12
|
+
style?: CSSObject
|
|
13
|
+
wrapperStyle?: CSSObject
|
|
14
|
+
|
|
15
|
+
/** @internal */
|
|
16
|
+
__note?: number
|
|
17
|
+
/** @internal */
|
|
18
|
+
__index?: number
|
|
19
|
+
/** @internal */
|
|
20
|
+
__label?: (note: number, index: number) => ReactNode
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function KeyLabel({
|
|
24
|
+
label,
|
|
25
|
+
className,
|
|
26
|
+
style,
|
|
27
|
+
wrapperStyle,
|
|
28
|
+
__note,
|
|
29
|
+
__index,
|
|
30
|
+
__label,
|
|
31
|
+
}: Props) {
|
|
32
|
+
const content = label ? label(__note!, __index!) : __label && __label(__note!, __index!)
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
(content != undefined || content != null) &&
|
|
36
|
+
<div
|
|
37
|
+
className='tremolo-piano-key-label-wrapper'
|
|
38
|
+
css={css({
|
|
39
|
+
display: 'flex',
|
|
40
|
+
justifyContent: 'center',
|
|
41
|
+
alignItems: 'end',
|
|
42
|
+
height: '100%',
|
|
43
|
+
...wrapperStyle
|
|
44
|
+
})}
|
|
45
|
+
>
|
|
46
|
+
<div
|
|
47
|
+
className={clsx('tremolo-piano-key-label', className)}
|
|
48
|
+
css={css({
|
|
49
|
+
display: 'flex',
|
|
50
|
+
justifyContent: 'center',
|
|
51
|
+
alignItems: 'center',
|
|
52
|
+
fontSize: '0.6rem',
|
|
53
|
+
height: 10,
|
|
54
|
+
marginBottom: 10,
|
|
55
|
+
padding: 4,
|
|
56
|
+
borderRadius: 4,
|
|
57
|
+
borderStyle: 'solid',
|
|
58
|
+
borderWidth: 1,
|
|
59
|
+
borderColor: '#888',
|
|
60
|
+
aspectRatio: 1,
|
|
61
|
+
maxWidth: 'calc(100% - 16px)',
|
|
62
|
+
...style
|
|
63
|
+
})}
|
|
64
|
+
>
|
|
65
|
+
{content}
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
)
|
|
69
|
+
}
|