-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-board): add estimation component
- Loading branch information
Showing
10 changed files
with
328 additions
and
14 deletions.
There are no files selected for viewing
153 changes: 153 additions & 0 deletions
153
packages/game-app/src/_shared/components/EstimationEditor/EstimationEditor.styled.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,153 @@ | ||
import Box from '../Box'; | ||
import { Input } from '../TextInput/TextInput.styled'; | ||
import styled from 'styled-components'; | ||
/* | ||
const estimationWrapperDefinition = keyframes` | ||
0% { | ||
top: -50px; | ||
left: 0; | ||
right: 0; | ||
} | ||
50% { | ||
left: 0; | ||
right: 0; | ||
height: 40px; | ||
width: 40px; | ||
border-radius: 50% | ||
} | ||
75% { | ||
left: 0; | ||
top: -40px; | ||
height: 40px; | ||
width: 40px; | ||
border-radius: 50% | ||
} | ||
100% { | ||
left: 0; | ||
top: -40px; | ||
height: 32px; | ||
width: 80px; | ||
border-radius: 10px 20px 20px 10px; | ||
} | ||
`; | ||
animation: ${estimationWrapperDefinition} linear 1s; | ||
animation-delay: 3s; | ||
animation-fill-mode: forwards; | ||
*/ | ||
|
||
export const EstimationWrapper = styled(Box)` | ||
position: absolute; | ||
top: -50px; | ||
left: 0; | ||
right: 0; | ||
`; | ||
|
||
EstimationWrapper.displayName = 'EstimationWrapper'; | ||
/* | ||
const estimationDefinition = keyframes` | ||
0% { | ||
} | ||
5% { | ||
right: 0; | ||
top: 0; | ||
bottom: 0; | ||
height: 40px; | ||
width: 40px; | ||
} | ||
50% { | ||
right: 0; | ||
top: 0; | ||
bottom: 0; | ||
height: 40px; | ||
width: 40px; | ||
border-radius: 50% | ||
} | ||
50% { | ||
right: 0; | ||
top: 0; | ||
bottom: 0; | ||
height: 40px; | ||
width: 100%; | ||
border-radius: 15px 0 0 15px; | ||
} | ||
75% { | ||
right: 0; | ||
top: 0; | ||
bottom: 0; | ||
height: 40px; | ||
width: 100%; | ||
border-radius: 20px; | ||
} | ||
100% { | ||
right: 0; | ||
top: 0; | ||
bottom: 0; | ||
height: 40px; | ||
width: 100%; | ||
border-radius: 20px; | ||
} | ||
animation: ${estimationDefinition} linear 3s; | ||
animation-fill-mode: forwards; | ||
`; | ||
*/ | ||
export const ConfirmButton = styled.button` | ||
border: none; | ||
background: #96d5d2; | ||
position: absolute; | ||
top: 8px; | ||
right: 8px; | ||
width: 24px; | ||
height: 24px; | ||
z-index: 1; | ||
border-radius: 50%; | ||
transition: all 0.3s; | ||
cursor: pointer; | ||
:hover { | ||
width: 40px; | ||
height: 40px; | ||
right: 0; | ||
top: 0; | ||
} | ||
:active, | ||
:focus { | ||
outline: none; | ||
} | ||
`; | ||
|
||
ConfirmButton.displayName = 'ConfirmButton'; | ||
|
||
export const EstimationInput = styled(Input)` | ||
background: #ffffff 0% 0% no-repeat padding-box; | ||
box-shadow: 0px 3px 3px #d7d2cb80; | ||
border-radius: 20px; | ||
opacity: 1; | ||
padding-left: 16px; | ||
font-family: Montserrat; | ||
:focus { | ||
border: none; | ||
} | ||
::placeholder { | ||
color: #d7d2cb; | ||
opacity: 1; /* Firefox */ | ||
} | ||
:focus + ${ConfirmButton} { | ||
background: #096762; | ||
} | ||
`; | ||
|
||
EstimationInput.displayName = 'EstimationInput'; | ||
|
||
export const EstimationInputContainer = styled.div` | ||
border-radius: 20px; | ||
position: relative; | ||
overflow: hidden; | ||
`; | ||
|
||
EstimationInputContainer.displayName = 'EstimationInputContainer'; |
35 changes: 35 additions & 0 deletions
35
packages/game-app/src/_shared/components/EstimationEditor/EstimationEditor.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,35 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
import { ConfirmButton, EstimationInput, EstimationInputContainer, EstimationWrapper } from './EstimationEditor.styled'; | ||
|
||
type Props = { | ||
saveEstimation: (estimation: string) => void; | ||
initialEstimation?: string; | ||
}; | ||
|
||
/** | ||
* Input that appears at the top of the card to edit time estimation | ||
*/ | ||
const EstimationEditor: React.FC<Props> = ({ saveEstimation, initialEstimation }) => { | ||
const [estimation, setEstimation] = useState(initialEstimation || ''); | ||
|
||
const onChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => { | ||
setEstimation(e.target.value); | ||
}, []); | ||
|
||
const onClick = useCallback(() => { | ||
saveEstimation(estimation); | ||
}, [estimation, saveEstimation]); | ||
|
||
return ( | ||
<EstimationWrapper mb={2}> | ||
<EstimationInputContainer> | ||
<EstimationInput value={estimation} onChange={onChange} placeholder={'Write time estimation'} variant="clear" /> | ||
<ConfirmButton onClick={onClick} /> | ||
</EstimationInputContainer> | ||
</EstimationWrapper> | ||
); | ||
}; | ||
|
||
EstimationEditor.displayName = 'EstimationEditor'; | ||
|
||
export default EstimationEditor; |
3 changes: 3 additions & 0 deletions
3
packages/game-app/src/_shared/components/EstimationEditor/index.ts
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,3 @@ | ||
import EstimationEditor from './EstimationEditor'; | ||
|
||
export default EstimationEditor; |
18 changes: 18 additions & 0 deletions
18
packages/game-app/src/_shared/components/EstimationInCard/EstimationInCard.styled.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,18 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const EstimationCardContent = styled.div` | ||
width: 80px; | ||
height: 32px; | ||
background: #096762; | ||
border-radius: 10px 20px 20px 10px; | ||
opacity: 1; | ||
position: absolute; | ||
top: 12px; | ||
left: -4px; | ||
line-height: 32px; | ||
color: white; | ||
padding-left: 16px; | ||
z-index: 10001; | ||
`; | ||
|
||
EstimationCardContent.displayName = 'EstimationCardContent'; |
17 changes: 17 additions & 0 deletions
17
packages/game-app/src/_shared/components/EstimationInCard/EstimationInCard.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,17 @@ | ||
import React from 'react'; | ||
import { EstimationCardContent } from './EstimationInCard.styled'; | ||
|
||
type Props = { | ||
estimation: string; | ||
}; | ||
|
||
/** | ||
* Component to show estimation inside the card | ||
*/ | ||
const EstimationInCard: React.FC<Props> = ({ estimation }) => { | ||
return <EstimationCardContent>{estimation}</EstimationCardContent>; | ||
}; | ||
|
||
EstimationInCard.displayName = 'EstimationInCard'; | ||
|
||
export default EstimationInCard; |
3 changes: 3 additions & 0 deletions
3
packages/game-app/src/_shared/components/EstimationInCard/index.ts
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,3 @@ | ||
import EstimationInCard from './EstimationInCard'; | ||
|
||
export default EstimationInCard; |
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
27 changes: 27 additions & 0 deletions
27
packages/game-app/src/gameView/components/DraggableCard/useDoubleClick.ts
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,27 @@ | ||
import { useCallback, useEffect, useRef } from 'react'; | ||
|
||
export default function useDoubleClick(handler: () => void) { | ||
const intervalRef = useRef(0); | ||
const counterRef = useRef(0); | ||
const handlerRef = useRef(handler); | ||
|
||
useEffect(() => { | ||
handlerRef.current = handler; | ||
}, [handler]); | ||
|
||
const fire = useCallback(() => { | ||
clearTimeout(intervalRef.current); | ||
if (counterRef.current === 0) { | ||
counterRef.current = intervalRef.current + 1; | ||
|
||
intervalRef.current = setTimeout(() => { | ||
counterRef.current = 0; | ||
}, 200) as any; | ||
} else { | ||
counterRef.current = 0; | ||
handlerRef.current(); | ||
} | ||
}, []); | ||
|
||
return fire; | ||
} |
Oops, something went wrong.