Skip to content

Commit 381d5c2

Browse files
committed
feat(index.html, gradient-text.ts): add functionality to pick colors in gradient text generator
fix #52
1 parent 53cddf1 commit 381d5c2

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ <h2>Gradient Border Generator</h2>
130130
id="gradient-text-text"
131131
placeholder="Enter the text"
132132
/>
133+
134+
<p>Pick Your Colors:</p>
135+
136+
<label for="colorPicker">
137+
<input type="color" value="#1DB8CE" id="gradient-text-color1" />
138+
<span>First Color</span>
139+
</label>
140+
141+
<label for="colorPicker">
142+
<input type="color" value="#1DB4CE" id="gradient-text-color2" />
143+
<span>Second Color</span>
144+
</label>
133145
<div class="btn" data-button="gradient-text">Get Text</div>
134146
</div>
135147
<div class="download-output">

src/general.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export const getColorInput1 = (attribute: string): HTMLInputElement =>
131131

132132
export const getColorInput2 = (attribute: string): HTMLInputElement =>
133133
<HTMLInputElement>document.getElementById(`${attribute}-color2`);
134-
134+
135135
export const getOutput = (attribute: string): HTMLElement =>
136136
<HTMLElement>document.querySelector(`[data-modal = ${attribute}] .output`);
137137

src/generators/gradient-text.ts

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

3+
type Colors = {
4+
firstColor: string;
5+
secondColor: string;
6+
};
7+
38
/**
49
* @function gradientTextGenerator
510
* @summary handles functionality of the gradient text generator
@@ -17,11 +22,23 @@ export function gradientTextGenerator(): void {
1722
getOutputElement.style.placeItems = 'center';
1823

1924
const getTextButtonElement = utils.getResultButton(attribute);
25+
const getFirstColor = utils.getColorInput1(attribute);
26+
const getSecondColor = utils.getColorInput2(attribute);
2027

2128
getTextButtonElement?.addEventListener('click', () => {
2229
if (getInputElement.value.length === 0) return;
2330

24-
getGradientTextResult(attribute, getInputElement.value, getOutputElement);
31+
const colors = {
32+
firstColor: getFirstColor.value,
33+
secondColor: getSecondColor.value,
34+
};
35+
36+
getGradientTextResult(
37+
attribute,
38+
getInputElement.value,
39+
colors,
40+
getOutputElement,
41+
);
2542
getInputElement.value = '';
2643
});
2744
}
@@ -36,14 +53,14 @@ export function gradientTextGenerator(): void {
3653
function getGradientTextResult(
3754
attribute: string,
3855
text: string,
56+
colors: Colors,
3957
outputElement: HTMLElement,
4058
): void {
4159
const createTextElement = () => {
4260
const wordElement = document.createElement('p');
4361
wordElement.innerText = text;
4462
wordElement.style.fontSize = '2rem';
45-
wordElement.style.background =
46-
'linear-gradient(to bottom, rgb(119, 118, 248) 50%, rgb(94, 238, 94))';
63+
wordElement.style.background = `linear-gradient(to bottom, ${colors.firstColor} 50%, ${colors.secondColor})`;
4764
wordElement.style.webkitBackgroundClip = 'text';
4865
wordElement.style.backgroundClip = 'text';
4966
wordElement.style.webkitTextFillColor = 'transparent';

src/style.css

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,11 @@ textarea:focus {
233233
width: var(--input-width);
234234
overflow-y: hidden;
235235
}
236-
237-
[data-modal='gradient-border'] .input p {
236+
.input p {
238237
margin-bottom: 0.5em;
239238
}
240239

241-
[data-modal='gradient-border'] .input label {
240+
.input label {
242241
background-color: #fff;
243242
display: flex;
244243
padding: 10px;

0 commit comments

Comments
 (0)