-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React/radio controllers #378
Merged
kobakazu0429
merged 16 commits into
react/RadioCard-master
from
react/radio-controllers
Jul 13, 2019
+301
−53
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e692ddd
add useAudio
kobakazu0429 59ee597
add RadioCardPlayButtonProgress
kobakazu0429 a8ddbde
fix: isPlay ? white, progress : fill orange one
kobakazu0429 bf69055
fix
kobakazu0429 fc18aa3
add play_time
kobakazu0429 c1a1fd1
add sample seekbar
kobakazu0429 150c3d0
preload none
kobakazu0429 0ea164d
add duration
kobakazu0429 02f451b
seekable radio
kobakazu0429 d8c53ab
change method name
kobakazu0429 32857fa
remove RadioCardContent
kobakazu0429 5d844db
add interface
kobakazu0429 df6ef8c
change seekbar: to use input[range]
kobakazu0429 c4cf005
if played, button inner is replay
kobakazu0429 0b4bcec
init value in radios store
kobakazu0429 9dd9460
fix addEventListener -> removeEventListener
kobakazu0429 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
めちゃくちゃcircleを作っている...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あのデザインは難しかった