Skip to content

Commit 546e5ac

Browse files
authored
feat: add animation preview (#388)
* feat: Add animation preview * fix: Fix position of animation preview slider * fix: Fixed formatting
1 parent de52cb4 commit 546e5ac

File tree

4 files changed

+82
-18
lines changed

4 files changed

+82
-18
lines changed

index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,8 @@ <h2>
623623

624624
<!-- Animation -->
625625
<div data-content="animation">
626+
<div class="preview-slider"></div>
627+
626628
<div class="animation-type">
627629
<p>Animation Type</p>
628630
<div class="radio-group">
@@ -830,7 +832,7 @@ <h2>
830832

831833
<div class="btn" data-button="box-shadow">Get Results</div>
832834
</div>
833-
<!-- End of Box Shadown -->
835+
<!-- End of Box Shadow -->
834836

835837
<!-- Text Shadow Generator -->
836838
<div data-content="text-shadow">

src/main.ts

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
// Generator Modules
2-
import {picTextGenerator} from './pages/pic-text';
32
import {
4-
addGradientTextListener,
5-
gradientTextGenerator,
6-
} from './pages/gradient-text';
3+
addAnimationListener,
4+
animationGenerator,
5+
displayAnimationPreview,
6+
} from './pages/animation';
77
import {
8-
gradientBorderGenerator,
9-
addGradientBorderListener,
10-
} from './pages/gradient-border';
8+
addBorderRadiusListener,
9+
borderRadiusGenerator,
10+
} from './pages/border-radius';
11+
import {addBoxShadowListener, boxShadowGenerator} from './pages/box-shadow';
1112
import {
1213
addGradientBackgroundListener,
1314
gradientBackgroundGenerator,
1415
} from './pages/gradient-background';
15-
import {addAnimationListener, animationGenerator} from './pages/animation';
1616
import {
17-
addBorderRadiusListener,
18-
borderRadiusGenerator,
19-
} from './pages/border-radius';
20-
import {boxShadowGenerator, addBoxShadowListener} from './pages/box-shadow';
21-
import {addTextShadowListener, textShadowGenerator} from './pages/text-shadow';
17+
addGradientBorderListener,
18+
gradientBorderGenerator,
19+
} from './pages/gradient-border';
20+
import {
21+
addGradientTextListener,
22+
gradientTextGenerator,
23+
} from './pages/gradient-text';
2224
import {rangeGenerator} from './pages/input-range';
25+
import {picTextGenerator} from './pages/pic-text';
26+
import {addTextShadowListener, textShadowGenerator} from './pages/text-shadow';
2327

2428
// Packages
2529
import * as FilePond from 'filepond';
@@ -33,7 +37,10 @@ import FilePondPluginImageTransform from 'filepond-plugin-image-transform';
3337
import 'filepond-plugin-image-preview/dist/filepond-plugin-image-preview.css';
3438
import {
3539
getGeneratorsElement,
40+
getInputSpinner,
3641
getOpenSideBarButton,
42+
getRadioButtonSet,
43+
getRange,
3744
getResultPage,
3845
} from './lib/getElements';
3946

@@ -110,6 +117,9 @@ const downloadButtons = document.querySelectorAll(
110117
'.image-download'
111118
) as NodeListOf<HTMLElement>;
112119
const dropDownElements = document.querySelectorAll('.dropdown');
120+
const getDegreeElement = getRange('animation');
121+
const getRadioButtonSetElement = getRadioButtonSet('animation');
122+
const getDurationElement = getInputSpinner('animation');
113123
if (openSidePanelButton) {
114124
openSidePanelButton.style.display = 'none';
115125
}
@@ -377,6 +387,17 @@ getResultsButton.forEach((getResult) => {
377387
});
378388
});
379389

390+
getDegreeElement?.addEventListener('change', () => displayAnimationPreview());
391+
getRadioButtonSetElement.forEach((radioButton: HTMLInputElement) => {
392+
radioButton.onclick = () => {
393+
displayAnimationPreview();
394+
};
395+
});
396+
getDurationElement?.addEventListener('change', () => {
397+
displayAnimationPreview();
398+
});
399+
400+
// configuring dropdown menu
380401
dropDownElements.forEach((dropDown) => {
381402
const listElement = dropDown.lastElementChild as HTMLElement;
382403

src/pages/animation.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import copy from 'copy-to-clipboard';
22
import {
33
getCopyCodeButton,
4+
getInputSpinner,
45
getOutput,
6+
getPreviewSlider,
7+
getRadioButtonSet,
58
getRange,
6-
getInputSpinner,
7-
getStyleSheet,
89
getResultPage,
9-
getRadioButtonSet,
10+
getStyleSheet,
1011
} from '../lib/getElements';
11-
import {showPopup, setGradientDegreeValue} from '../lib/packages';
12+
import {setGradientDegreeValue, showPopup, slideIn} from '../lib/packages';
1213

1314
let initial_length = 0;
1415
// let rule_added = false;
16+
let isAnimationSliderOpen = false;
1517
let css = '';
1618

1719
type Values = {
@@ -27,6 +29,8 @@ const getOutputElement = getOutput(attribute);
2729
const getDegreeElement = getRange(attribute);
2830
const getRadioButtonSetElement = getRadioButtonSet(attribute);
2931

32+
const preview = getPreviewSlider(attribute);
33+
3034
initialConfiguration(
3135
getRadioButtonSetElement,
3236
getDegreeElement,
@@ -69,6 +73,39 @@ export function animationGenerator(type: 'newResults' | 'oldResults' | null) {
6973
manageAnimation(values, getOutputElement, Stylesheet);
7074
}
7175

76+
// configuring animation preview
77+
export function displayAnimationPreview() {
78+
slideIn(preview, isAnimationSliderOpen);
79+
isAnimationSliderOpen = true;
80+
81+
if (preview.getAttribute('data-running') !== 'true') {
82+
const duration = getInputSpinner(attribute);
83+
84+
const Stylesheet = getStyleSheet();
85+
86+
let i = 0;
87+
88+
for (i = 0; i < getRadioButtonSetElement.length; i++)
89+
if (getRadioButtonSetElement[i].checked) break;
90+
91+
const values: Values = {
92+
type: getRadioButtonSetElement[i].value,
93+
degree: getDegreeElement.value,
94+
duration: duration.value,
95+
};
96+
97+
// only updating preview animation if no current animation is running
98+
preview.onanimationend = () => {
99+
preview.setAttribute('data-running', 'false');
100+
preview.style.animation = '';
101+
Stylesheet.deleteRule(initial_length + 1);
102+
};
103+
104+
preview.setAttribute('data-running', 'true');
105+
manageAnimation(values, preview, Stylesheet);
106+
}
107+
}
108+
72109
/**
73110
* sets the animation to the output element
74111
*

src/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ main > section:last-of-type {
296296
align-items: center;
297297
}
298298

299+
[data-content='animation'] .preview-slider {
300+
top: -50%;
301+
}
302+
299303
[data-content='pic-text'] {
300304
display: flex;
301305
}

0 commit comments

Comments
 (0)