Skip to content

Commit aa8827d

Browse files
committed
feat(gradient-border.ts, gradient-text.ts): add option to pick your degree
1 parent 381d5c2 commit aa8827d

File tree

5 files changed

+50
-13
lines changed

5 files changed

+50
-13
lines changed

index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ <h2>Gradient Border Generator</h2>
142142
<input type="color" value="#1DB4CE" id="gradient-text-color2" />
143143
<span>Second Color</span>
144144
</label>
145+
<label id="degree">
146+
<span>Slide to change the degree</span>
147+
<input
148+
type="range"
149+
max="360"
150+
min="0"
151+
id="gradient-text-degree"
152+
/>
153+
</label>
145154
<div class="btn" data-button="gradient-text">Get Text</div>
146155
</div>
147156
<div class="download-output">
@@ -181,6 +190,16 @@ <h2>Gradient Border Generator</h2>
181190
<span>Second Color</span>
182191
</label>
183192

193+
<label id="degree">
194+
<span>Slide to change the degree</span>
195+
<input
196+
type="range"
197+
max="360"
198+
min="0"
199+
id="gradient-border-degree"
200+
/>
201+
</label>
202+
184203
<div class="btn" data-button="gradient-border">Get Result</div>
185204
</div>
186205
<div class="download-output">

src/general.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ export const getColorInput2 = (attribute: string): HTMLInputElement =>
135135
export const getOutput = (attribute: string): HTMLElement =>
136136
<HTMLElement>document.querySelector(`[data-modal = ${attribute}] .output`);
137137

138+
export const getRange = (attribute: string): HTMLInputElement =>
139+
<HTMLInputElement>document.getElementById(`${attribute}-degree`);
140+
138141
function createDownloadLink(fileName: string, url: string) {
139142
const link = document.createElement('a');
140143
link.download = fileName;

src/generators/gradient-border.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as utils from '../general';
22

3-
type Colors = {
3+
type Values = {
44
firstColor: string;
55
secondColor: string;
6+
degree: string;
67
};
78

89
export function gradientBorderGenerator(): void {
@@ -11,25 +12,27 @@ export function gradientBorderGenerator(): void {
1112
const color2 = utils.getColorInput2(attribute);
1213
const getResultButtonElement = utils.getResultButton(attribute);
1314
const getOutputElement = utils.getOutput(attribute);
15+
const getRangeElement = utils.getRange(attribute);
1416

1517
getResultButtonElement.addEventListener('click', () => {
16-
const colors = {
18+
const values = {
1719
firstColor: color1.value,
1820
secondColor: color2.value,
21+
degree: getRangeElement.value,
1922
};
20-
getGradientBorderResult(attribute, colors, getOutputElement);
23+
getGradientBorderResult(attribute, values, getOutputElement);
2124
});
2225
}
2326

2427
function getGradientBorderResult(
2528
attribute: string,
26-
colors: Colors,
29+
values: Values,
2730
outputElement: HTMLElement,
2831
): void {
2932
outputElement.style.border = 'solid';
3033
outputElement.style.borderWidth = '5px';
3134
outputElement.style.borderImageSlice = '1';
32-
outputElement.style.borderImageSource = `linear-gradient(100deg, ${colors.firstColor}, ${colors.secondColor})`;
35+
outputElement.style.borderImageSource = `linear-gradient(${values.degree}deg, ${values.firstColor}, ${values.secondColor})`;
3336

3437
const getCodeButtonElement = utils.getCopyCodeButton(attribute);
3538
getCodeButtonElement.addEventListener('click', () => {

src/generators/gradient-text.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import * as utils from '../general';
22

3-
type Colors = {
3+
type Values = {
44
firstColor: string;
55
secondColor: string;
6+
degree: string;
67
};
78

89
/**
910
* @function gradientTextGenerator
1011
* @summary handles functionality of the gradient text generator
11-
* @param attribute - The attribute name of the generator element
1212
* @return {void} Nothing
1313
*/
1414
export function gradientTextGenerator(): void {
@@ -24,22 +24,24 @@ export function gradientTextGenerator(): void {
2424
const getTextButtonElement = utils.getResultButton(attribute);
2525
const getFirstColor = utils.getColorInput1(attribute);
2626
const getSecondColor = utils.getColorInput2(attribute);
27+
const getRangeElement = utils.getRange(attribute);
2728

2829
getTextButtonElement?.addEventListener('click', () => {
2930
if (getInputElement.value.length === 0) return;
3031

31-
const colors = {
32+
const values = {
3233
firstColor: getFirstColor.value,
3334
secondColor: getSecondColor.value,
35+
degree: getRangeElement.value,
3436
};
3537

3638
getGradientTextResult(
3739
attribute,
3840
getInputElement.value,
39-
colors,
41+
values,
4042
getOutputElement,
4143
);
42-
getInputElement.value = '';
44+
// getInputElement.value = '';
4345
});
4446
}
4547

@@ -53,14 +55,14 @@ export function gradientTextGenerator(): void {
5355
function getGradientTextResult(
5456
attribute: string,
5557
text: string,
56-
colors: Colors,
58+
values: Values,
5759
outputElement: HTMLElement,
5860
): void {
5961
const createTextElement = () => {
6062
const wordElement = document.createElement('p');
6163
wordElement.innerText = text;
6264
wordElement.style.fontSize = '2rem';
63-
wordElement.style.background = `linear-gradient(to bottom, ${colors.firstColor} 50%, ${colors.secondColor})`;
65+
wordElement.style.background = `linear-gradient(${values.degree}deg, ${values.firstColor}, ${values.secondColor})`;
6466
wordElement.style.webkitBackgroundClip = 'text';
6567
wordElement.style.backgroundClip = 'text';
6668
wordElement.style.webkitTextFillColor = 'transparent';

src/style.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,15 @@ main {
212212
input[type='text'],
213213
textarea,
214214
textarea:focus {
215-
height: 30px;
215+
height: 40px;
216216
outline: none;
217217
padding: 5px;
218218
caret-color: var(--text-color);
219219
color: var(--text-color);
220220
background: transparent;
221221
border: 0.5px solid var(--text-color);
222222
border-radius: 3px;
223+
font-size: 1.3rem;
223224
}
224225

225226
::placeholder {
@@ -251,6 +252,7 @@ textarea:focus {
251252
height: 30px;
252253
border: none;
253254
margin-right: 10px;
255+
cursor: pointer;
254256
}
255257

256258
[type='color']::-webkit-color-swatch-wrapper {
@@ -261,6 +263,14 @@ textarea:focus {
261263
border: none;
262264
}
263265

266+
#degree {
267+
flex-direction: column;
268+
}
269+
270+
#degree > span {
271+
font-size: 0.7em;
272+
}
273+
264274
.count {
265275
position: absolute;
266276
right: 24px;

0 commit comments

Comments
 (0)