@react-cupertino-ui/volume-control 1.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/LICENSE +24 -0
- package/dist/index.css +73 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +58 -0
- package/dist/index.scss +75 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Anderson Lima
|
|
4
|
+
|
|
5
|
+
This project is inspired by Apple's design principles but is not affiliated with, endorsed, or sponsored by Apple Inc.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
.react-cupertino-ui-volume-control {
|
|
2
|
+
width: 100%;
|
|
3
|
+
display: flex;
|
|
4
|
+
align-items: center;
|
|
5
|
+
gap: 10px;
|
|
6
|
+
height: 32px;
|
|
7
|
+
}
|
|
8
|
+
.react-cupertino-ui-volume-control .icon {
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
color: #8e8e93;
|
|
13
|
+
pointer-events: none;
|
|
14
|
+
}
|
|
15
|
+
.react-cupertino-ui-volume-control .slider-container {
|
|
16
|
+
flex: 1;
|
|
17
|
+
height: 100%;
|
|
18
|
+
/* Larger hit area */
|
|
19
|
+
display: flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
position: relative;
|
|
23
|
+
}
|
|
24
|
+
.react-cupertino-ui-volume-control .slider-container:hover .track {
|
|
25
|
+
height: 6px;
|
|
26
|
+
}
|
|
27
|
+
.react-cupertino-ui-volume-control .track {
|
|
28
|
+
width: 100%;
|
|
29
|
+
height: 4px;
|
|
30
|
+
background-color: rgba(60, 60, 67, 0.18);
|
|
31
|
+
border-radius: 999px;
|
|
32
|
+
position: relative;
|
|
33
|
+
transition: height 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
|
|
34
|
+
overflow: hidden;
|
|
35
|
+
/* Contains the fill for neat edges */
|
|
36
|
+
}
|
|
37
|
+
@media (prefers-color-scheme: dark) {
|
|
38
|
+
.react-cupertino-ui-volume-control .track {
|
|
39
|
+
background-color: rgba(255, 255, 255, 0.18);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
.react-cupertino-ui-volume-control .fill {
|
|
43
|
+
position: absolute;
|
|
44
|
+
left: 0;
|
|
45
|
+
top: 0;
|
|
46
|
+
bottom: 0;
|
|
47
|
+
background-color: rgba(60, 60, 67, 0.6);
|
|
48
|
+
border-radius: 999px;
|
|
49
|
+
pointer-events: none;
|
|
50
|
+
}
|
|
51
|
+
@media (prefers-color-scheme: dark) {
|
|
52
|
+
.react-cupertino-ui-volume-control .fill {
|
|
53
|
+
background-color: rgba(255, 255, 255, 0.6);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
.react-cupertino-ui-volume-control {
|
|
57
|
+
/* Thumb is usually invisible in standard iOS volume slider until interacted,
|
|
58
|
+
but often just the expanding track serves as the handle.
|
|
59
|
+
We'll make it subtle or hidden for pure iOS aesthetic. */
|
|
60
|
+
}
|
|
61
|
+
.react-cupertino-ui-volume-control .thumb {
|
|
62
|
+
display: none;
|
|
63
|
+
/*
|
|
64
|
+
position: absolute;
|
|
65
|
+
top: 50%;
|
|
66
|
+
width: 20px;
|
|
67
|
+
height: 20px;
|
|
68
|
+
background: white;
|
|
69
|
+
border-radius: 50%;
|
|
70
|
+
transform: translate(-50%, -50%);
|
|
71
|
+
box-shadow: 0 1px 3px rgba(0,0,0,0.3);
|
|
72
|
+
*/
|
|
73
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { BaseProps } from "@react-cupertino-ui/shared/lib/interfaces/BaseProps";
|
|
3
|
+
import "./index.scss";
|
|
4
|
+
export interface VolumeControlProps extends Omit<BaseProps<HTMLDivElement>, "children"> {
|
|
5
|
+
volume: number;
|
|
6
|
+
onVolumeChange?: (volume: number) => void;
|
|
7
|
+
muted?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const VolumeControl: React.ForwardRefExoticComponent<VolumeControlProps & React.RefAttributes<HTMLDivElement>>;
|
|
10
|
+
export { VolumeControl };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "@react-cupertino-ui/shared/lib/utils";
|
|
4
|
+
import { Volume, Volume1, Volume2, VolumeX } from "lucide-react";
|
|
5
|
+
import "./index.scss";
|
|
6
|
+
const VolumeControl = React.forwardRef(({ className, volume, onVolumeChange, muted = false, ...props }, ref) => {
|
|
7
|
+
const [isDragging, setIsDragging] = React.useState(false);
|
|
8
|
+
const [dragVolume, setDragVolume] = React.useState(volume);
|
|
9
|
+
const sliderRef = React.useRef(null);
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
if (!isDragging) {
|
|
12
|
+
setDragVolume(volume);
|
|
13
|
+
}
|
|
14
|
+
}, [volume, isDragging]);
|
|
15
|
+
const handleMouseDown = (e) => {
|
|
16
|
+
setIsDragging(true);
|
|
17
|
+
updateVolumeFromClientX(e.clientX);
|
|
18
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
19
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
20
|
+
};
|
|
21
|
+
const handleMouseMove = (e) => {
|
|
22
|
+
updateVolumeFromClientX(e.clientX);
|
|
23
|
+
};
|
|
24
|
+
const handleMouseUp = (e) => {
|
|
25
|
+
setIsDragging(false);
|
|
26
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
|
27
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
28
|
+
// Final commit
|
|
29
|
+
if (sliderRef.current) {
|
|
30
|
+
const rect = sliderRef.current.getBoundingClientRect();
|
|
31
|
+
const percentage = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
|
|
32
|
+
onVolumeChange?.(percentage);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const updateVolumeFromClientX = (clientX) => {
|
|
36
|
+
if (sliderRef.current) {
|
|
37
|
+
const rect = sliderRef.current.getBoundingClientRect();
|
|
38
|
+
const percentage = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
|
|
39
|
+
setDragVolume(percentage);
|
|
40
|
+
// Optional: Real-time update
|
|
41
|
+
// onVolumeChange?.(percentage);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const displayVolume = muted ? 0 : (isDragging ? dragVolume : volume);
|
|
45
|
+
const percentage = displayVolume * 100;
|
|
46
|
+
const VolumeIcon = () => {
|
|
47
|
+
if (muted || displayVolume === 0)
|
|
48
|
+
return _jsx(VolumeX, { size: 18 });
|
|
49
|
+
if (displayVolume < 0.3)
|
|
50
|
+
return _jsx(Volume, { size: 18 });
|
|
51
|
+
if (displayVolume < 0.7)
|
|
52
|
+
return _jsx(Volume1, { size: 18 });
|
|
53
|
+
return _jsx(Volume2, { size: 18 });
|
|
54
|
+
};
|
|
55
|
+
return (_jsxs("div", { ref: ref, className: cn("react-cupertino-ui-volume-control", className), ...props, children: [_jsx("div", { className: "icon start", children: _jsx(VolumeIcon, {}) }), _jsx("div", { className: "slider-container", ref: sliderRef, onMouseDown: handleMouseDown, children: _jsxs("div", { className: "track", children: [_jsx("div", { className: "fill", style: { width: `${percentage}%` } }), _jsx("div", { className: "thumb", style: { left: `${percentage}%` } })] }) }), _jsx("div", { className: "icon end", children: _jsx(Volume2, { size: 16 }) })] }));
|
|
56
|
+
});
|
|
57
|
+
VolumeControl.displayName = "VolumeControl";
|
|
58
|
+
export { VolumeControl };
|
package/dist/index.scss
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
.react-cupertino-ui-volume-control {
|
|
2
|
+
width: 100%;
|
|
3
|
+
display: flex;
|
|
4
|
+
align-items: center;
|
|
5
|
+
gap: 10px;
|
|
6
|
+
height: 32px;
|
|
7
|
+
|
|
8
|
+
.icon {
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
color: #8e8e93;
|
|
13
|
+
pointer-events: none;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.slider-container {
|
|
17
|
+
flex: 1;
|
|
18
|
+
height: 100%;
|
|
19
|
+
/* Larger hit area */
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
position: relative;
|
|
24
|
+
|
|
25
|
+
&:hover .track {
|
|
26
|
+
height: 6px;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.track {
|
|
31
|
+
width: 100%;
|
|
32
|
+
height: 4px;
|
|
33
|
+
background-color: rgba(60, 60, 67, 0.18);
|
|
34
|
+
border-radius: 999px;
|
|
35
|
+
position: relative;
|
|
36
|
+
transition: height 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
|
|
37
|
+
overflow: hidden;
|
|
38
|
+
/* Contains the fill for neat edges */
|
|
39
|
+
|
|
40
|
+
@media (prefers-color-scheme: dark) {
|
|
41
|
+
background-color: rgba(255, 255, 255, 0.18);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.fill {
|
|
46
|
+
position: absolute;
|
|
47
|
+
left: 0;
|
|
48
|
+
top: 0;
|
|
49
|
+
bottom: 0;
|
|
50
|
+
background-color: rgba(60, 60, 67, 0.6);
|
|
51
|
+
border-radius: 999px;
|
|
52
|
+
pointer-events: none;
|
|
53
|
+
|
|
54
|
+
@media (prefers-color-scheme: dark) {
|
|
55
|
+
background-color: rgba(255, 255, 255, 0.6);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* Thumb is usually invisible in standard iOS volume slider until interacted,
|
|
60
|
+
but often just the expanding track serves as the handle.
|
|
61
|
+
We'll make it subtle or hidden for pure iOS aesthetic. */
|
|
62
|
+
.thumb {
|
|
63
|
+
display: none;
|
|
64
|
+
/*
|
|
65
|
+
position: absolute;
|
|
66
|
+
top: 50%;
|
|
67
|
+
width: 20px;
|
|
68
|
+
height: 20px;
|
|
69
|
+
background: white;
|
|
70
|
+
border-radius: 50%;
|
|
71
|
+
transform: translate(-50%, -50%);
|
|
72
|
+
box-shadow: 0 1px 3px rgba(0,0,0,0.3);
|
|
73
|
+
*/
|
|
74
|
+
}
|
|
75
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-cupertino-ui/volume-control",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "VolumeControl component from React Cupertino UI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"sideEffects": [
|
|
13
|
+
"./dist/**/*.css",
|
|
14
|
+
"./dist/**/*.scss"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.build.json && npm run build:styles",
|
|
18
|
+
"build:styles": "node ../../../scripts/build-styles.mjs"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"lucide-react": "^0.417.0",
|
|
22
|
+
"react": "^18.3.1",
|
|
23
|
+
"react-dom": "^18.3.1"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@react-cupertino-ui/shared": "workspace:*"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"typescript": "^5.2.2"
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "3f53987bdb936a331665691b517c2ba9984777f8",
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
}
|
|
35
|
+
}
|