Skip to content

Commit be016be

Browse files
authored
Merge pull request #474 from devtron-labs/feat/deploy-button-animation
feat: add animated button for cd modal
2 parents bd6b48b + f0a6a9b commit be016be

File tree

10 files changed

+100
-3
lines changed

10 files changed

+100
-3
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.3.3",
3+
"version": "1.3.4",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Assets/Sounds/DeployAudio.mp3

37.6 KB
Binary file not shown.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { motion } from 'framer-motion'
2+
import { ReactComponent as ICDeploy } from '@Icons/ic-nav-rocket.svg'
3+
import { ComponentSizeType } from '@Shared/constants'
4+
import { SyntheticEvent, useEffect, useRef, useState } from 'react'
5+
import DeployAudio from '@Sounds/DeployAudio.mp3'
6+
import { Button } from '../Button'
7+
import './animatedDeployButton.scss'
8+
import { AnimatedDeployButtonProps } from './types'
9+
10+
const AnimatedDeployButton = ({ isVirtualEnvironment, onButtonClick }: AnimatedDeployButtonProps) => {
11+
const audioRef = useRef<HTMLAudioElement>(null)
12+
const timeoutRef = useRef<ReturnType<typeof setTimeout>>(null)
13+
const isAudioEnabled: boolean = window._env_.FEATURE_ACTION_AUDIOS_ENABLE
14+
const [clicked, setClicked] = useState<boolean>(false)
15+
const svgMotionVariants = {
16+
hover: {
17+
rotate: 45,
18+
},
19+
}
20+
21+
const handleButtonClick = async (e: SyntheticEvent) => {
22+
if (clicked) {
23+
return
24+
}
25+
if (isAudioEnabled && audioRef.current) {
26+
try {
27+
await audioRef.current.play()
28+
} catch {
29+
// do nothing
30+
}
31+
}
32+
setClicked(true)
33+
timeoutRef.current = setTimeout(() => {
34+
setClicked(false)
35+
onButtonClick(e, false)
36+
}, 700)
37+
}
38+
39+
useEffect(
40+
() => () => {
41+
clearTimeout(timeoutRef.current)
42+
},
43+
[],
44+
)
45+
46+
return (
47+
<motion.div whileHover="hover" className={`${clicked ? 'hide-button-text' : ''}`}>
48+
<Button
49+
dataTestId="cd-trigger-deploy-button"
50+
text={`Deploy${isVirtualEnvironment ? ' to isolated env' : ''}`}
51+
startIcon={
52+
<motion.div
53+
variants={svgMotionVariants}
54+
animate={
55+
clicked
56+
? {
57+
x: 200,
58+
rotate: 45,
59+
transition: {
60+
duration: 0.5,
61+
delay: 0.1,
62+
},
63+
}
64+
: {}
65+
}
66+
>
67+
<ICDeploy className="icon-dim-16" />
68+
</motion.div>
69+
}
70+
size={ComponentSizeType.large}
71+
onClick={handleButtonClick}
72+
/>
73+
{/* Disabling es-lint as captions are not required */}
74+
{/* eslint-disable-next-line jsx-a11y/media-has-caption */}
75+
<audio hidden ref={audioRef} src={DeployAudio} />
76+
</motion.div>
77+
)
78+
}
79+
80+
export default AnimatedDeployButton
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.hide-button-text {
2+
.button {
3+
:nth-child(2) {
4+
visibility: hidden;
5+
}
6+
}
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as AnimatedDeployButton } from './AnimatedDeployButton'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface AnimatedDeployButtonProps {
2+
isVirtualEnvironment: boolean
3+
onButtonClick: (e, disableDeployButton: boolean) => void
4+
}

src/Shared/Components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ export * from './DiffViewer'
6464
export * from './DynamicDataTable'
6565
export * from './TagsKeyValueTable'
6666
export * from './FileUpload'
67+
export * from './AnimatedDeployButton'

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export interface customEnv {
100100
FEATURE_DEFAULT_MERGE_STRATEGY?: OverrideMergeStrategyType
101101
FEATURE_DEFAULT_LANDING_RB_ENABLE?: boolean
102102
FEATURE_CLUSTER_MAP_ENABLE?: boolean
103+
FEATURE_ACTION_AUDIOS_ENABLE?: boolean
103104
}
104105
declare global {
105106
interface Window {

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"@Icons/*": [
66
"./src/Assets/Icon/*"
77
],
8+
"@Sounds/*": [
9+
"./src/Assets/Sounds/*"
10+
],
811
"@Images/*": [
912
"./src/Assets/Img/*"
1013
],

0 commit comments

Comments
 (0)