-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #378 from kure-kosen/react/radio-controllers
React/radio controllers
- Loading branch information
Showing
8 changed files
with
301 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
frontend/src/components/atoms/RadioCard/RadioCardContent.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
frontend/src/components/atoms/RadioCard/RadioCardPlayButtonProgress.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
|
||
import { color } from "@/constants/styles"; | ||
|
||
const calcParams = ({ | ||
radius, | ||
strokeWidth | ||
}: { | ||
radius: number; | ||
strokeWidth: number; | ||
}) => { | ||
return { | ||
width: radius * 2 + strokeWidth, | ||
height: radius * 2 + strokeWidth, | ||
radius, | ||
strokeWidth, | ||
circumference: 2 * Math.PI * (radius - 2) | ||
}; | ||
}; | ||
|
||
interface IProps { | ||
progress?: number; | ||
currentTime: number; | ||
} | ||
|
||
export default ({ progress = 100, currentTime }: IProps) => { | ||
const params = calcParams({ radius: 16, strokeWidth: 4 }); | ||
|
||
return ( | ||
<Wrapper width={params.width} height={params.height}> | ||
<Progress | ||
width={params.width} | ||
height={params.height} | ||
progress={progress} | ||
circumference={params.circumference} | ||
strokeWidth={params.strokeWidth} | ||
currentTime={currentTime} | ||
> | ||
<circle | ||
className="back" | ||
cx={params.width / 2} | ||
cy={params.height / 2} | ||
r={params.radius} | ||
/> | ||
<circle | ||
className="white-bar" | ||
x={1} | ||
y={1} | ||
cx={params.width / 2} | ||
cy={params.height / 2} | ||
r={params.radius - 2.5} | ||
/> | ||
<circle | ||
className="progress" | ||
cx={params.width / 2} | ||
cy={params.height / 2} | ||
r={params.radius - 2} | ||
/> | ||
</Progress> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
const Wrapper = styled.div<{ width: number; height: number }>` | ||
margin: 0 auto; | ||
width: ${props => props.width}px; | ||
height: ${props => props.height}px; | ||
`; | ||
|
||
interface IProgress { | ||
currentTime: number; | ||
progress: number; | ||
circumference: number; | ||
strokeWidth: number; | ||
} | ||
|
||
const Progress = styled.svg<IProgress>` | ||
transform: rotate(-90deg); | ||
& .progress { | ||
fill: transparent; | ||
stroke: ${props => | ||
props.currentTime > 0 ? color.VIVID_ORANGE : color.ORANGE}; | ||
stroke-width: ${props => props.strokeWidth}; | ||
stroke-dasharray: ${props => | ||
`${(props.progress / 100) * props.circumference} ${props.circumference}`}; | ||
} | ||
& .white-bar { | ||
fill: transparent; | ||
stroke: ${color.WHITE}; | ||
stroke-width: ${props => (props.currentTime > 0 ? 3 : 0)}; | ||
} | ||
& .back { | ||
fill: ${color.ORANGE}; | ||
} | ||
`; |
74 changes: 74 additions & 0 deletions
74
frontend/src/components/atoms/RadioCard/RadioCardSeekBar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
|
||
import { color } from "@/constants/styles"; | ||
import { IRadio } from "@/api/RadioApi"; | ||
import { IUseAudio } from "@/utils/hooks/useAudio"; | ||
|
||
interface IProps extends Pick<IRadio, "duration">, Pick<IUseAudio, "jump"> { | ||
currentTime: number; | ||
} | ||
|
||
export default (props: IProps) => { | ||
const { currentTime, duration, jump } = props; | ||
|
||
const [value, setValue] = React.useState(0); | ||
|
||
React.useEffect(() => { | ||
setValue(currentTime); | ||
}, [currentTime]); | ||
|
||
const handleChange = React.useCallback( | ||
(e: React.ChangeEvent<HTMLInputElement>) => { | ||
const data = Number(e.target.value); | ||
jump(data); | ||
setValue(data); | ||
}, | ||
[] | ||
); | ||
|
||
return ( | ||
<Wrapper> | ||
<SeekBar | ||
type="range" | ||
value={value} | ||
min={0} | ||
max={duration} | ||
onChange={handleChange} | ||
/> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
const Wrapper = styled.div` | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
`; | ||
|
||
const SeekBar = styled.input` | ||
width: 100%; | ||
height: 4px; | ||
border-radius: 6px; | ||
background-color: #eaeaea; | ||
&:focus, | ||
&:active { | ||
outline: none; | ||
} | ||
&::-webkit-slider-thumb, | ||
-moz-range-thumb { | ||
appearance: none; | ||
cursor: pointer; | ||
position: relative; | ||
width: 13px; | ||
height: 13px; | ||
display: block; | ||
background-color: ${color.ORANGE}; | ||
border-radius: 50%; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.