fleetcor-lwc 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -375,6 +375,7 @@ Add / update `lwc.config.json` file in your project
375
375
  | change | event.detail | object | Return full data of component's state |
376
376
 
377
377
  ### Input Email
378
+
378
379
  This component fully extends from `Input Text`
379
380
 
380
381
  ```html
@@ -488,6 +489,10 @@ You can override them as you wish by global css variables as priority.
488
489
 
489
490
  ## Release Notes:
490
491
 
492
+ - v.3.4.0
493
+ - Added `Animation` util class
494
+ - Updated `Modal` view animation with `fadeIn` and `fadeOut`
495
+
491
496
  - v.3.3.0
492
497
  - Added components `flt-input-text`, `flt-input-email`, `flt-modal`
493
498
  - For modal added new interface `ModalViewer` for dynamically creation modals
@@ -24,7 +24,9 @@ describe('flt-modal', () => {
24
24
 
25
25
  const glassEl = modalElement.querySelector('.flt-modal__glass')
26
26
  glassEl.click()
27
- const removedModalElement = document.body.querySelector('flt-modal')
28
- expect(removedModalElement).toBeFalsy()
27
+ setTimeout(() => {
28
+ const removedModalElement = document.body.querySelector('flt-modal')
29
+ expect(removedModalElement).toBeFalsy()
30
+ }, 1000)
29
31
  })
30
32
  })
@@ -8,7 +8,6 @@
8
8
  display: flex;
9
9
  align-items: center;
10
10
  justify-content: center;
11
- animation: fadeIn 0.3s ease-in-out;
12
11
 
13
12
  &__glass {
14
13
  position: absolute;
@@ -23,12 +22,3 @@
23
22
  position: relative;
24
23
  }
25
24
  }
26
-
27
- @keyframes fadeIn {
28
- 0% {
29
- opacity: 0;
30
- }
31
- 100% {
32
- opacity: 1;
33
- }
34
- }
@@ -7,6 +7,7 @@ export { default as CheckboxElement } from './interface/CheckboxElement'
7
7
  export { default as SelectElement } from './interface/SelectElement'
8
8
  export { default as InputElement } from './interface/InputElement'
9
9
  export { default as ModalViewer } from './interface/ModalViewer'
10
+ export { default as Animation } from './interface/Animation'
10
11
 
11
12
  // ERROR
12
13
  export * from './error/errors'
@@ -0,0 +1,78 @@
1
+ export default class Animation {
2
+ static fadeIn = ({
3
+ el,
4
+ duration = 300,
5
+ beforeAction,
6
+ afterAction,
7
+ timing = (timeFraction) => timeFraction
8
+ }) => {
9
+ if (typeof beforeAction === 'function') {
10
+ beforeAction()
11
+ }
12
+ el.style.opacity = 0
13
+ document.body.style.overflow = 'hidden'
14
+
15
+ Animation.animate({
16
+ duration: duration,
17
+ timing: timing,
18
+ draw: (progress) => {
19
+ if (progress < 0) progress = 0
20
+ el.style.opacity = progress
21
+ },
22
+ complete: () => {
23
+ el.style.opacity = null
24
+ if (typeof afterAction === 'function') {
25
+ afterAction()
26
+ }
27
+ }
28
+ })
29
+ }
30
+
31
+ static fadeOut = ({
32
+ el,
33
+ duration = 300,
34
+ beforeAction,
35
+ afterAction,
36
+ timing = (timeFraction) => 1 - timeFraction
37
+ }) => {
38
+ if (typeof beforeAction === 'function') {
39
+ beforeAction()
40
+ }
41
+
42
+ Animation.animate({
43
+ duration: duration,
44
+ timing: timing,
45
+ draw: (progress) => {
46
+ if (progress > 1) progress = 1
47
+ el.style.opacity = progress
48
+ },
49
+ complete: () => {
50
+ el.style.opacity = null
51
+ if (typeof afterAction === 'function') {
52
+ afterAction()
53
+ }
54
+ }
55
+ })
56
+ }
57
+
58
+ static animate({ timing, duration, draw = () => {}, complete = () => {} }) {
59
+ let start = performance.now()
60
+
61
+ requestAnimationFrame(function animate(time) {
62
+ // timeFraction изменяется от 0 до 1
63
+ let timeFraction = (time - start) / duration
64
+ if (timeFraction > 1) timeFraction = 1
65
+
66
+ // вычисление текущего состояния анимации
67
+ let progress = timing(timeFraction)
68
+
69
+ draw(progress) // отрисовать её
70
+
71
+ if (timeFraction < 1) {
72
+ requestAnimationFrame(animate)
73
+ } else if (complete) {
74
+ complete()
75
+ }
76
+ })
77
+ }
78
+ }
@@ -1,4 +1,5 @@
1
1
  import { createElement } from 'lwc'
2
+ import { Animation } from 'fleetcor-lwc'
2
3
  import Modal from 'flt/modal'
3
4
 
4
5
  /**
@@ -7,20 +8,45 @@ import Modal from 'flt/modal'
7
8
  * @description This class is used to show and hide modal view
8
9
  */
9
10
  export default class ModalViewer {
10
- static showModalWithComponent(cmp) {
11
+ static showModalWithComponent(cmp, options = { duration: 300 }) {
11
12
  const appEl = createElement('flt-modal', { is: Modal })
12
13
  document.body.appendChild(appEl)
13
- document.body.style.overflow = 'hidden'
14
- if (cmp) {
15
- appEl.querySelector('.flt-modal__container').appendChild(cmp)
16
- }
14
+ appEl.querySelector('.flt-modal__container').appendChild(cmp)
15
+ Animation.fadeIn({
16
+ el: appEl,
17
+ duration: options?.duration || 300,
18
+ beforeAction: () => {
19
+ appEl.style.position = 'relative'
20
+ appEl.style.zIndex = 1000000
21
+ },
22
+ afterAction: () => {
23
+ appEl.style.position = null
24
+ appEl.style.zIndex = null
25
+ },
26
+ timing: (timeProgress) => {
27
+ return Math.pow(timeProgress, 2)
28
+ }
29
+ })
17
30
  }
18
31
 
19
- static hideModals() {
32
+ static hideModals(options = { duration: 300 }) {
20
33
  document.body.style.overflow = null
21
34
  const items = document.body.querySelectorAll('flt-modal')
22
35
  items.forEach((item) => {
23
- item.remove()
36
+ Animation.fadeOut({
37
+ el: item,
38
+ duration: options?.duration || 300,
39
+ beforeAction: () => {
40
+ item.style.position = 'relative'
41
+ item.style.zIndex = 1000000
42
+ },
43
+ afterAction: () => {
44
+ item.remove()
45
+ },
46
+ timing: (timeProgress) => {
47
+ return Math.pow(1 - timeProgress, 2)
48
+ }
49
+ })
24
50
  })
25
51
  }
26
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetcor-lwc",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "LWC framework by Fleetcor",
5
5
  "repository": {
6
6
  "type": "git",