|
| 1 | +import * as utils from '../general'; |
| 2 | + |
| 3 | +type Values = { |
| 4 | + firstColor: string; |
| 5 | + secondColor: string; |
| 6 | + degree: string; |
| 7 | +}; |
| 8 | + |
| 9 | +export function gradientBackgroundGenerator() { |
| 10 | + const attribute = 'gradient-background'; |
| 11 | + // Inputs |
| 12 | + const color1 = utils.getColorInput1(attribute); |
| 13 | + const color2 = utils.getColorInput2(attribute); |
| 14 | + const getDegreeElement = utils.getRange(attribute); |
| 15 | + |
| 16 | + const getResultElement = utils.getResultButton(attribute); |
| 17 | + const getOutputElement = utils.getOutput(attribute); |
| 18 | + |
| 19 | + getResultElement.addEventListener('click', () => { |
| 20 | + onClickButton(); |
| 21 | + }); |
| 22 | + |
| 23 | + function onClickButton() { |
| 24 | + const values: Values = { |
| 25 | + firstColor: color1.value, |
| 26 | + secondColor: color2.value, |
| 27 | + degree: getDegreeElement.value, |
| 28 | + }; |
| 29 | + getGradientBackgroundResult(attribute, values, getOutputElement); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +function getGradientBackgroundResult( |
| 34 | + attribute: string, |
| 35 | + values: Values, |
| 36 | + outputElement: HTMLElement, |
| 37 | +): void { |
| 38 | + outputElement.style.background = `linear-gradient(${values.degree}deg, ${values.firstColor}, ${values.secondColor})`; |
| 39 | + |
| 40 | + const getCodeButtonElement = utils.getCopyCodeButton(attribute); |
| 41 | + getCodeButtonElement.addEventListener('click', () => { |
| 42 | + utils.copyCodeToClipboard(attribute, outputElement); |
| 43 | + }); |
| 44 | +} |
0 commit comments