Skip to content

Commit 77bfb37

Browse files
committed
feat(general.ts): add shake animation for when a user doesn't input a text
1 parent aa8827d commit 77bfb37

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/general.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ export function downloadSVG(attribute: string, outputImage: HTMLElement): void {
9696
});
9797
}
9898

99+
export function triggerEmptyAnimation(inputElement: HTMLInputElement): void {
100+
inputElement.style.borderColor = 'red';
101+
inputElement.animate(
102+
[
103+
{ transform: 'translate(10px, 0)' },
104+
{ transform: 'translate(-10px, 0)' },
105+
{ transform: 'translate(0, 0)' },
106+
],
107+
{ duration: 300 },
108+
);
109+
110+
setTimeout(() => {
111+
inputElement.style.borderColor = 'white';
112+
}, 1000);
113+
}
114+
99115
/**
100116
* @function getCopyCodeButton
101117
* @summary Get the button element for copying code to clipboard
@@ -138,6 +154,9 @@ export const getOutput = (attribute: string): HTMLElement =>
138154
export const getRange = (attribute: string): HTMLInputElement =>
139155
<HTMLInputElement>document.getElementById(`${attribute}-degree`);
140156

157+
export const getInputText = (attribute: string) =>
158+
<HTMLInputElement>document.getElementById(`${attribute}-text`);
159+
141160
function createDownloadLink(fileName: string, url: string) {
142161
const link = document.createElement('a');
143162
link.download = fileName;

src/generators/gradient-text.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ type Values = {
1313
*/
1414
export function gradientTextGenerator(): void {
1515
const attribute = 'gradient-text';
16-
const getInputElement = <HTMLInputElement>(
17-
document.getElementById(`${attribute}-text`)
18-
);
16+
const getInputElement = utils.getInputText(attribute);
1917
const getOutputElement = utils.getOutput(attribute);
2018
getOutputElement.style.display = 'grid';
2119
getOutputElement.style.height = 'fit-content';
@@ -27,7 +25,10 @@ export function gradientTextGenerator(): void {
2725
const getRangeElement = utils.getRange(attribute);
2826

2927
getTextButtonElement?.addEventListener('click', () => {
30-
if (getInputElement.value.length === 0) return;
28+
if (getInputElement.value.length === 0) {
29+
utils.triggerEmptyAnimation(getInputElement);
30+
return;
31+
}
3132

3233
const values = {
3334
firstColor: getFirstColor.value,

src/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ textarea:focus {
221221
border: 0.5px solid var(--text-color);
222222
border-radius: 3px;
223223
font-size: 1.3rem;
224+
position: relative;
224225
}
225226

226227
::placeholder {

0 commit comments

Comments
 (0)