Skip to content

Commit 506f88d

Browse files
feat: Avoid gradient background results without input. (#439)
1 parent 68c1005 commit 506f88d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,11 @@ <h2>
639639

640640
<div class="btn-container">
641641
<div class="reset" data-reset="gradient-background">Reset</div>
642-
<div class="btn" data-button="gradient-background">
642+
<div
643+
class="btn"
644+
data-button="gradient-background"
645+
id="getResultBtn"
646+
>
643647
Get Result
644648
</div>
645649
</div>

src/pages/gradient-background.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
getCssOrTailwindButton,
1515
} from '../lib/getElements';
1616
import {
17+
triggerEmptyAnimation,
1718
copyCSSCodeToClipboard,
1819
showPopup,
1920
whatColorButtonShouldShow,
@@ -34,7 +35,7 @@ const attribute = 'gradient-background';
3435

3536
const getNewColorButtonElement = getNewColorButton(attribute);
3637
const getRemoveColorButtonElement = getRemoveNewColorButton(attribute);
37-
38+
const getResultBtn = document.getElementById('getResultBtn');
3839
let gradientBackgroundInputs = getAllInputElements('gradient-background');
3940

4041
const getDegreeElement = getRange(attribute);
@@ -46,6 +47,22 @@ export function gradientBackgroundGenerator(
4647
type: 'newResults' | 'oldResults' | null
4748
) {
4849
if (type === null) return;
50+
// Show error when the colors are not entered.
51+
var element = gradientBackgroundInputs[0];
52+
var value = element.value;
53+
if (value.length < 3) {
54+
gradientBackgroundInputs.forEach((ele) => {
55+
if (getResultBtn) {
56+
getResultBtn.style.backgroundColor = 'grey';
57+
}
58+
triggerEmptyAnimation(ele);
59+
});
60+
return;
61+
} else {
62+
if (getResultBtn) {
63+
getResultBtn.style.backgroundColor = 'blue';
64+
}
65+
}
4966

5067
const getOutputElement = getOutput(attribute);
5168
const resultPage = getResultPage();

0 commit comments

Comments
 (0)