-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gradient-background.ts): add gradient background generator
fix #29
- Loading branch information
Showing
3 changed files
with
67 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14dc29e
There was a problem hiding this comment.
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