Skip to content

Commit 5bb0376

Browse files
committed
feat(preview): create slide in preview for shadow elements
1 parent 3e87632 commit 5bb0376

File tree

7 files changed

+79
-13
lines changed

7 files changed

+79
-13
lines changed

index.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,8 @@ <h2>
494494

495495
<!-- Box Shadow -->
496496
<div data-content="box-shadow">
497-
<div class="box-shadow-preview" id="box-shadow-preview"></div>
497+
<div class="preview-slider"></div>
498+
498499
<div class="colors">
499500
<label for="color" class="color">
500501
<input
@@ -578,6 +579,8 @@ <h2>
578579

579580
<!-- Text shadow generator -->
580581
<div data-content="text-shadow">
582+
<div class="preview-slider"></div>
583+
581584
<textarea
582585
id="text-shadow-text"
583586
placeholder="Enter the text"
@@ -668,10 +671,6 @@ <h2>Results</h2>
668671
<!-- Pic Text -->
669672
<div class="download-output" data-result="pic-text">
670673
<div class="output"></div>
671-
<p>
672-
Note: Downloading only works for firefox <br />
673-
but copying the code works for every browser
674-
</p>
675674
<div class="download-btn">
676675
<div class="image-download">
677676
<button class="btn" data-download="pic-text-PNG">

src/lib/general.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export const getResultPage = (): HTMLElement =>
159159
document.querySelector('.side-results') as HTMLElement;
160160

161161
export const getCopyCodeButton = (attribute: string): HTMLElement =>
162-
document.querySelector(`[data-download = ${attribute}-code]`) as HTMLElement;
162+
document.querySelector(`[data-download=${attribute}-code]`) as HTMLElement;
163163

164164
export const getPNGButton = (attribute: string): HTMLElement =>
165165
document.querySelector(`[data-download=${attribute}-PNG]`) as HTMLElement;
@@ -281,6 +281,24 @@ export const getShadowFields = (
281281
[]
282282
);
283283

284+
export const getPreviewSlider = (attribute: string): HTMLElement =>
285+
document.querySelector(
286+
`[data-content=${attribute}] .preview-slider`
287+
) as HTMLElement;
288+
289+
export function slideIn(slider: HTMLElement, isOpen: boolean) {
290+
if (isOpen) return;
291+
292+
const slideIn = [{left: '-300px'}, {left: '-10px'}];
293+
const slideInTiming = {
294+
duration: 500,
295+
iterations: 1,
296+
fill: 'both' as FillMode,
297+
};
298+
299+
slider.animate(slideIn, slideInTiming);
300+
}
301+
284302
function createDownloadLink(fileName: string, url: string) {
285303
const link = document.createElement('a');
286304
link.download = fileName;

src/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ const borderRadiusPreview = document.querySelector(
155155
const menu = document.querySelector('.menu') as HTMLElement;
156156
const body = document.querySelector('body') as HTMLElement;
157157

158+
const gradientGenerator = document.querySelectorAll('[data-gen]');
159+
const getResultButtons = document.querySelectorAll('[data-button]');
160+
158161
// get the element with data-button="open-side-panel" attribute and make it hidden
159162
const openSidePanelButton = document.getElementsByClassName(
160163
'open-sidebar'
@@ -389,7 +392,6 @@ const displayGradientValue = (gradientElement: HTMLInputElement) => {
389392
});
390393
};
391394

392-
const gradientGenerator = document.querySelectorAll('[data-gen]');
393395
gradientGenerator.forEach((item) => {
394396
item.addEventListener('click', () => {
395397
if (openSidePanelButton) {
@@ -398,7 +400,6 @@ gradientGenerator.forEach((item) => {
398400
});
399401
});
400402

401-
const getResultButtons = document.querySelectorAll('[data-button]');
402403
getResultButtons.forEach((item) => {
403404
item.addEventListener('click', () => {
404405
if (openSidePanelButton) {

src/pages/box-shadow.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type Values = {
99
};
1010

1111
const attribute = 'box-shadow';
12+
let isSliderOpen = false;
1213

1314
function copyHandler() {
1415
const outputElement = utils.getOutput(attribute);
@@ -77,7 +78,7 @@ export function addBoxShadowListener(): void {
7778
const spread = utils.getShadowSpread(attribute);
7879
const color = utils.getShadowColor(attribute);
7980

80-
const preview = utils.getShadowPreview(attribute);
81+
const preview = utils.getPreviewSlider(attribute);
8182

8283
const allBoxShadowInputs = [
8384
horizontalOffset,
@@ -103,6 +104,9 @@ export function addBoxShadowListener(): void {
103104
allBoxShadowInputsFields[idx].textContent = `${input.value}px`;
104105
}
105106
input.addEventListener('input', () => {
107+
utils.slideIn(preview, isSliderOpen);
108+
109+
isSliderOpen = true;
106110
if (idx < 4) {
107111
allBoxShadowInputsFields[idx].textContent = `${input.value}px`;
108112
}

src/pages/gradient-text.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ function getGradientTextResult(
8989
wordElement.style.backgroundClip = 'text';
9090
wordElement.style.webkitBackgroundClip = 'text';
9191
wordElement.style.webkitTextFillColor = 'transparent';
92-
outputElement.appendChild(wordElement);
92+
93+
return wordElement;
9394
};
9495

9596
const getCodeButtonElement = utils.getCopyCodeButton(attribute);
@@ -98,9 +99,9 @@ function getGradientTextResult(
9899

99100
if (outputElement.childElementCount >= 1) {
100101
outputElement.innerHTML = '';
101-
createTextElement();
102+
outputElement.appendChild(createTextElement());
102103
} else {
103-
createTextElement();
104+
outputElement.appendChild(createTextElement());
104105
}
105106

106107
getPNGButtonElement.addEventListener('click', pngDownloadHandler);

src/pages/text-shadow.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type Values = {
88
text: string;
99
};
1010

11+
let isSliderOpen = false;
1112
const attribute = 'text-shadow';
1213

1314
function copyHandler() {
@@ -78,22 +79,41 @@ export function addTextShadowListener(): void {
7879
const blur = utils.getShadowBlur(attribute);
7980
const color = utils.getShadowColor(attribute);
8081

82+
const getInputElement = utils.getInputText(attribute);
83+
const preview = utils.getPreviewSlider(attribute);
84+
8185
const allTextShadowInputs = [horizontalOffset, verticalOffset, blur, color];
8286
const allTextShadowInputsFields = utils.getShadowFields(attribute, [
8387
'h-offset',
8488
'v-offset',
8589
'blur',
90+
'text',
8691
]);
8792

93+
const getShadowValue = () =>
94+
`${horizontalOffset.value}px ${verticalOffset.value}px ${blur.value}px ${color.value}`;
95+
96+
preview.innerText = getInputElement.value;
97+
preview.style.textShadow = getShadowValue();
98+
8899
allTextShadowInputs.forEach((input, idx) => {
89100
// default
90101
if (idx < 3) {
91102
allTextShadowInputsFields[idx].textContent = `${input.value}px`;
92103
}
104+
getInputElement.addEventListener('input', () => {
105+
preview.innerText = getInputElement.value;
106+
preview.style.textShadow = getShadowValue();
107+
});
93108
input.addEventListener('input', () => {
109+
utils.slideIn(preview, isSliderOpen);
110+
111+
isSliderOpen = true;
112+
94113
if (idx < 3) {
95114
allTextShadowInputsFields[idx].textContent = `${input.value}px`;
96115
}
116+
preview.style.textShadow = getShadowValue();
97117
});
98118
});
99119
}

src/style.css

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ main > section:last-of-type {
194194
flex-direction: column;
195195
align-items: center;
196196
justify-content: center;
197+
position: relative;
197198
}
198199

199200
/* inputs */
200-
201201
.generators > div {
202202
display: none;
203203
width: var(--generator-width);
@@ -206,6 +206,29 @@ main > section:last-of-type {
206206
align-items: center;
207207
}
208208

209+
.preview-slider {
210+
height: 80px;
211+
width: 200px;
212+
213+
position: absolute;
214+
left: -300px;
215+
border: 1px solid #fff;
216+
background: transparent;
217+
}
218+
219+
[data-content='box-shadow'] .preview-slider {
220+
top: -79%;
221+
}
222+
223+
[data-content='text-shadow'] .preview-slider {
224+
top: -30%;
225+
word-wrap: break-word;
226+
font-size: 0.8rem;
227+
display: flex;
228+
justify-content: center;
229+
align-items: center;
230+
}
231+
209232
[data-content='pic-text'] {
210233
display: flex;
211234
}

0 commit comments

Comments
 (0)