Skip to content

Commit

Permalink
feat(gradient-background.ts): add gradient background generator
Browse files Browse the repository at this point in the history
fix #29
  • Loading branch information
Dun-sin committed Aug 8, 2022
1 parent e35541f commit 14dc29e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 9 deletions.
13 changes: 12 additions & 1 deletion src/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function copyCodeToClipboard(

function actOnGenerator() {
let codeToCopy: string = '';
let element;
switch (attribute) {
case 'pic-text':
codeToCopy = `
Expand All @@ -43,14 +44,24 @@ export function copyCodeToClipboard(

break;
case 'gradient-border':
const element = outputElement.style;
element = outputElement.style;
codeToCopy = `
div {
border: ${element.border},
border-width: ${element.borderWidth},
border-image-slice: ${element.borderImageSlice},
border-image-source: ${element.borderImageSource},
}
`;
break;
case 'gradient-background':
element = outputElement.style;
codeToCopy = `
div {
height: 100px;
width: 100px;
background: ${element.backgroundImage};
}
`;
}
copy(codeToCopy);
Expand Down
44 changes: 44 additions & 0 deletions src/generators/gradient-background.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as utils from '../general';

type Values = {
firstColor: string;
secondColor: string;
degree: string;
};

export function gradientBackgroundGenerator() {
const attribute = 'gradient-background';
// Inputs
const color1 = utils.getColorInput1(attribute);
const color2 = utils.getColorInput2(attribute);
const getDegreeElement = utils.getRange(attribute);

const getResultElement = utils.getResultButton(attribute);
const getOutputElement = utils.getOutput(attribute);

getResultElement.addEventListener('click', () => {
onClickButton();
});

function onClickButton() {
const values: Values = {
firstColor: color1.value,
secondColor: color2.value,
degree: getDegreeElement.value,
};
getGradientBackgroundResult(attribute, values, getOutputElement);
}
}

function getGradientBackgroundResult(
attribute: string,
values: Values,
outputElement: HTMLElement,
): void {
outputElement.style.background = `linear-gradient(${values.degree}deg, ${values.firstColor}, ${values.secondColor})`;

const getCodeButtonElement = utils.getCopyCodeButton(attribute);
getCodeButtonElement.addEventListener('click', () => {
utils.copyCodeToClipboard(attribute, outputElement);
});
}
19 changes: 11 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Generator Modules
import { picTextGenerator } from './generators/pic-text';
import { gradientTextGenerator } from './generators/gradient-text';
import { gradientBorderGenerator } from './generators/gradient-border';
import { gradientBackgroundGenerator } from './generators/gradient-background';

import * as FilePond from 'filepond';
import { gradientBorderGenerator } from './generators/gradient-border';

/**
* All Variables
Expand Down Expand Up @@ -81,6 +82,9 @@ function generatorsFunction(attribute: string): void {
case 'gradient-border':
gradientBorderGenerator();
break;
case 'gradient-background':
gradientBackgroundGenerator();
break;
}
}

Expand Down Expand Up @@ -142,11 +146,10 @@ generators.forEach((generator) => {
});

// closing modal when user clicks outside
document.addEventListener("click", function (event) {
if (event.target === null) return;
const element = <HTMLElement>event.target;
if (element.matches(".modal-container")) {
closeModalFunction();
}
document.addEventListener('click', function (event) {
if (event.target === null) return;
const element = <HTMLElement>event.target;
if (element.matches('.modal-container')) {
closeModalFunction();
}
});

1 comment on commit 14dc29e

@vercel
Copy link

@vercel vercel bot commented on 14dc29e Aug 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

trick-generator – ./

trick-generator-dun-sin.vercel.app
trick-generator-git-main-dun-sin.vercel.app
trick-generator.vercel.app

Please sign in to comment.