Skip to content

Commit cdbe01a

Browse files
committed
add preview bar
1 parent 9494bb4 commit cdbe01a

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ <h1 class="text-xl font-bold mb-5">Trackmania Username Generator</h1>
1616
name="username"
1717
class="relative bg-gray-50 ring-0 outline-none border border-neutral-500 text-neutral-900 placeholder-violet-700 text-sm rounded-lg focus:ring-violet-500 focus:border-violet-500 block w-64 p-2.5 checked:bg-emerald-500"
1818
/>
19+
<p class="text-sm text-gray-500 mt-0.5" id="minLetters">min. 2 letters</p>
1920
</div>
2021
<!-- colors input (start and end) -->
2122
<div id="colorsDiv">
@@ -88,6 +89,16 @@ <h3 class="font-bold">Code:</h3>
8889
<p class="text-sm text-gray-400 italic">
8990
Made by <a href="https://steveblox.github.io">SteveBlox</a>
9091
</p>
92+
<!-- gradient bar at the bottom of the card -->
93+
<div id="gradientBar" class="mt-5">
94+
<div id="gradient" class="h-2"></div>
95+
</div>
96+
<button
97+
id="expandGradient"
98+
class="py-2.5 px-5 me-2 mb-2 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded-lg border border-gray-200 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700"
99+
>
100+
Expand
101+
</button>
91102
</div>
92103

93104
<script src="main.js"></script>

main.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ const result = document.querySelector(".result");
7878
const tmResult = document.querySelector("#tmResult");
7979
const copy = document.querySelector("#copy");
8080
const middleColorCheckbox = document.querySelector("#middleColorCheckbox");
81+
const gradientPreview = document.querySelector("#gradient");
82+
let gradientExpanded = false;
83+
const expandGradientButton = document.querySelector("#expandGradient");
84+
const minLetters = document.querySelector("#minLetters");
8185
function generateUsername() {
8286
const startColor = startInput.value;
8387
const middleColor = middleColorCheckbox.checked ? middleInput.value : null;
@@ -87,6 +91,16 @@ function generateUsername() {
8791
`startColor: ${startColor}, middleColor: ${middleColor}, endColor: ${endColor}, name: ${name}`
8892
);
8993
const minNameLength = middleColorCheckbox.checked ? 4 : 2;
94+
if (startColor && endColor) {
95+
gradientPreview.style.background = `linear-gradient(to right, ${startColor}, ${
96+
middleColor || endColor
97+
}${middleColor ? `, ${endColor}` : ""}`;
98+
}
99+
if (middleColorCheckbox.checked) {
100+
minLetters.textContent = "min. 4 letters";
101+
} else {
102+
minLetters.textContent = "min. 2 letters";
103+
}
90104
if (!startColor || !endColor || !name || name.length < minNameLength) return;
91105
const gradient = generateGradient(
92106
startColor,
@@ -111,7 +125,19 @@ middleInput.addEventListener("input", () => {
111125
});
112126
endInput.addEventListener("input", generateUsername);
113127
middleColorCheckbox.addEventListener("change", generateUsername);
114-
128+
document.body.onload = generateUsername;
115129
copy.addEventListener("click", function () {
116130
navigator.clipboard.writeText(tmResult.value);
117131
});
132+
expandGradientButton.addEventListener("click", () => {
133+
gradientExpanded = !gradientExpanded;
134+
if (gradientExpanded) {
135+
gradientPreview.style.height = "8rem";
136+
expandGradientButton.style.bottom = "8.2rem";
137+
expandGradientButton.innerText = "Collapse";
138+
} else {
139+
gradientPreview.style.height = "0.5rem";
140+
expandGradientButton.style.bottom = "0.4rem";
141+
expandGradientButton.innerText = "Expand";
142+
}
143+
});

styles.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,21 @@ body {
1818
padding: 2em;
1919
background: #fff;
2020
box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
21+
}
2122

23+
#gradient {
24+
position: fixed;
25+
bottom: 0;
26+
left: 0;
27+
width: 100%;
28+
transition: .5s all;
29+
}
30+
#gradient:hover{
31+
height: 8rem;
32+
}
33+
#expandGradient {
34+
position: fixed;
35+
bottom: .4rem;
36+
right: 0;
37+
transition: .5s all;
2238
}

0 commit comments

Comments
 (0)