@energie360/ui-library 0.1.22 → 0.1.24
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/components/badge/u-badge.vue +2 -2
- package/components/card-amount/card-amount.scss +7 -0
- package/components/card-amount/u-card-amount.vue +21 -0
- package/components/card-amount-illustrated/card-amount-illustrated.scss +35 -0
- package/components/card-amount-illustrated/u-card-amount-illustrated.vue +80 -0
- package/components/card-contact/card-contact.scss +5 -3
- package/components/card-contact/u-card-contact.vue +15 -10
- package/components/card-footer/u-card-footer.vue +6 -2
- package/components/card-group/card-group.scss +25 -11
- package/components/card-group/u-card-group.vue +59 -4
- package/components/chip/chip.scss +31 -4
- package/components/chip/u-chip.vue +5 -2
- package/components/index.js +5 -0
- package/components/progress-bar/progress-bar.scss +5 -9
- package/components/progress-bar/u-progress-bar.vue +3 -6
- package/components/richtext/richtext.scss +2 -0
- package/components/skeleton-loader/u-skeleton-loader.vue +1 -1
- package/components/slider/slider.scss +249 -0
- package/components/slider/u-slider.vue +174 -0
- package/components/slider-progress-animation/slider-progress-animation.scss +25 -0
- package/components/slider-progress-animation/u-slider-progress-animation.vue +65 -0
- package/components/sprite-animation/sprite-animation.scss +7 -0
- package/components/sprite-animation/u-sprite-animation.vue +169 -0
- package/components/table/cell-progress-bar.scss +4 -0
- package/components/table/u-cell-icon-group.vue +12 -7
- package/components/table/u-cell-progress-bar.vue +5 -5
- package/components/text-block/text-block.scss +18 -14
- package/components/text-block/u-text-block.vue +17 -11
- package/components/tooltip/tooltip.scss +4 -2
- package/components/tooltip/u-tooltip.vue +20 -2
- package/elements/select-chip/select-chip.scss +1 -1
- package/elements/select-chip/u-select-chip.vue +7 -6
- package/modules/dialog/u-dialog.vue +2 -2
- package/package.json +3 -1
- package/utils/functions/animate.js +258 -0
- package/utils/math/scale-value.js +13 -0
- package/wizard/wizard-layout/u-wizard-layout-block.vue +2 -2
- package/wizard/wizard-top-bar/u-wizard-top-bar.vue +0 -8
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import UIcon from '../../elements/icon/u-icon.vue'
|
|
3
3
|
import UTooltip from '../tooltip/u-tooltip.vue'
|
|
4
|
+
import { UBadge } from '../'
|
|
5
|
+
import { Badge } from '../badge/u-badge.vue'
|
|
4
6
|
import { TableCellIconColor } from './table.type'
|
|
5
7
|
|
|
6
8
|
interface IconItem {
|
|
7
9
|
icon: string
|
|
8
10
|
title: string
|
|
9
11
|
color: TableCellIconColor
|
|
12
|
+
badge: Badge
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
interface Props {
|
|
@@ -22,13 +25,15 @@ const isColorKeyword = (str) => Object.values(TableCellIconColor).includes(str)
|
|
|
22
25
|
<div class="cell-icon-group">
|
|
23
26
|
<template v-for="(item, idx) in icons" :key="idx">
|
|
24
27
|
<UTooltip :title="item.title">
|
|
25
|
-
<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
<UBadge :show="!!item.badge" v-bind="item.badge">
|
|
29
|
+
<UIcon
|
|
30
|
+
:name="item.icon"
|
|
31
|
+
:class="{ [`icon-color-${item.color}`]: isColorKeyword(item.color) }"
|
|
32
|
+
:style="{
|
|
33
|
+
color: !isColorKeyword(item.color) ? item.color : false,
|
|
34
|
+
}"
|
|
35
|
+
></UIcon>
|
|
36
|
+
</UBadge>
|
|
32
37
|
</UTooltip>
|
|
33
38
|
</template>
|
|
34
39
|
</div>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import UProgressBar from '../
|
|
2
|
+
import { UProgressBar } from '../'
|
|
3
3
|
|
|
4
4
|
interface Props {
|
|
5
5
|
label?: string
|
|
@@ -13,10 +13,10 @@ const { label = '', labelPosition = 'top' } = defineProps<Props>()
|
|
|
13
13
|
<template>
|
|
14
14
|
<div :class="['cell-progress-bar', `label-position-${labelPosition}`]">
|
|
15
15
|
<p v-if="label" class="progress-bar-label">{{ label }}</p>
|
|
16
|
-
<
|
|
16
|
+
<div class="cell-progress-bar__progress-bar">
|
|
17
|
+
<UProgressBar :value="value"></UProgressBar>
|
|
18
|
+
</div>
|
|
17
19
|
</div>
|
|
18
20
|
</template>
|
|
19
21
|
|
|
20
|
-
<style scoped lang="scss">
|
|
21
|
-
@use './cell-progress-bar.scss';
|
|
22
|
-
</style>
|
|
22
|
+
<style scoped lang="scss" src="./cell-progress-bar.scss"></style>
|
|
@@ -1,58 +1,62 @@
|
|
|
1
1
|
@use '../../base/abstracts' as a;
|
|
2
2
|
|
|
3
|
-
.
|
|
4
|
-
.
|
|
3
|
+
.text-block {
|
|
4
|
+
.text-block__title {
|
|
5
5
|
@include a.type(800, strong);
|
|
6
6
|
|
|
7
|
-
+ .
|
|
7
|
+
+ .text-block__text {
|
|
8
8
|
margin-top: var(--e-space-4);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
.
|
|
12
|
+
.text-block__title--small {
|
|
13
13
|
@include a.type(500, strong);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
.
|
|
16
|
+
.text-block__text {
|
|
17
17
|
@include a.type(300);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
@include a.bp(lg) {
|
|
21
|
-
.
|
|
21
|
+
.text-block__title {
|
|
22
22
|
@include a.type(700, strong);
|
|
23
23
|
|
|
24
|
-
+ .
|
|
24
|
+
+ .text-block__text {
|
|
25
25
|
margin-top: var(--e-space-3);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// Modifiers
|
|
31
|
-
&.
|
|
32
|
-
.
|
|
31
|
+
&.text-block--sub {
|
|
32
|
+
.text-block__title {
|
|
33
33
|
@include a.type(300, strong);
|
|
34
34
|
|
|
35
|
-
+ .
|
|
35
|
+
+ .text-block__text {
|
|
36
36
|
margin-top: var(--e-space-2);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
.
|
|
40
|
+
.text-block__text {
|
|
41
41
|
@include a.type(300);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
@include a.bp(lg) {
|
|
45
|
-
.
|
|
45
|
+
.text-block__title {
|
|
46
46
|
@include a.type(200, strong);
|
|
47
47
|
|
|
48
|
-
+ .
|
|
48
|
+
+ .text-block__text {
|
|
49
49
|
margin-top: var(--e-space-2);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
.
|
|
53
|
+
.text-block__text {
|
|
54
54
|
@include a.type(200);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
+
|
|
59
|
+
&.centered {
|
|
60
|
+
text-align: center;
|
|
61
|
+
}
|
|
58
62
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { URichtext } from '../'
|
|
3
|
+
|
|
2
4
|
interface Props {
|
|
3
5
|
variant: 'lead' | 'sub'
|
|
4
6
|
title?: string
|
|
@@ -6,21 +8,25 @@ interface Props {
|
|
|
6
8
|
centered?: boolean
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
const { title = '', text = ''
|
|
11
|
+
const { title = '', text = '' } = defineProps<Props>()
|
|
10
12
|
</script>
|
|
11
13
|
|
|
12
14
|
<template>
|
|
13
|
-
<div :class="['
|
|
14
|
-
<h2 v-if="title" class="
|
|
15
|
+
<div :class="['text-block', `text-block--${variant}`, { centered }]">
|
|
16
|
+
<h2 v-if="$slots.title || title" class="text-block__title">
|
|
17
|
+
<slot name="title">
|
|
18
|
+
<span v-html="title"></span>
|
|
19
|
+
</slot>
|
|
20
|
+
</h2>
|
|
15
21
|
|
|
16
|
-
<div v-if="text" class="
|
|
22
|
+
<div v-if="$slots.text || text" class="text-block__text">
|
|
23
|
+
<URichtext>
|
|
24
|
+
<slot name="text">
|
|
25
|
+
<div v-html="text" />
|
|
26
|
+
</slot>
|
|
27
|
+
</URichtext>
|
|
28
|
+
</div>
|
|
17
29
|
</div>
|
|
18
30
|
</template>
|
|
19
31
|
|
|
20
|
-
<style scoped lang="scss">
|
|
21
|
-
@use './text-block.scss';
|
|
22
|
-
|
|
23
|
-
.centered {
|
|
24
|
-
text-align: center;
|
|
25
|
-
}
|
|
26
|
-
</style>
|
|
32
|
+
<style scoped lang="scss" src="./text-block.scss"></style>
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
@use '../../base/abstracts
|
|
1
|
+
@use '../../base/abstracts' as a;
|
|
2
2
|
|
|
3
3
|
.tooltip {
|
|
4
|
+
--tooltip-min-width: 84px;
|
|
5
|
+
|
|
4
6
|
pointer-events: none;
|
|
5
7
|
z-index: a.$layer-tooltip;
|
|
6
8
|
position: absolute;
|
|
7
9
|
top: 0;
|
|
8
10
|
left: 0;
|
|
9
11
|
max-width: a.rem(360);
|
|
10
|
-
min-width:
|
|
12
|
+
min-width: var(--tooltip-min-width);
|
|
11
13
|
opacity: 0;
|
|
12
14
|
transform: translateY(-5px);
|
|
13
15
|
transition:
|
|
@@ -5,9 +5,18 @@ import type { PopoverPositionParams } from './popover'
|
|
|
5
5
|
|
|
6
6
|
interface Props extends PopoverPositionParams {
|
|
7
7
|
title: string
|
|
8
|
+
disabled?: boolean
|
|
9
|
+
offsetX?: number
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
const {
|
|
12
|
+
const {
|
|
13
|
+
placement = 'top-center',
|
|
14
|
+
offset = 12,
|
|
15
|
+
viewportPadding = 20,
|
|
16
|
+
disabled = false,
|
|
17
|
+
// This optional prop is to potentially fix some slightly off calculations.
|
|
18
|
+
offsetX = 0,
|
|
19
|
+
} = defineProps<Props>()
|
|
11
20
|
|
|
12
21
|
const tooltip = ref<HTMLDivElement | null>(null)
|
|
13
22
|
const root = ref<HTMLSpanElement | null>(null)
|
|
@@ -18,10 +27,18 @@ const isTooltipVisible = ref<boolean>(false)
|
|
|
18
27
|
// For mobile and touch devices it's th opposite, pointer events will be fired first.
|
|
19
28
|
// This way we can detect on what device we are and handle the behaviour accordingly.
|
|
20
29
|
function hideTooltip() {
|
|
30
|
+
if (disabled) {
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
21
34
|
isTooltipVisible.value = false
|
|
22
35
|
}
|
|
23
36
|
|
|
24
37
|
function showTooltip() {
|
|
38
|
+
if (disabled) {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
25
42
|
updatePositions()
|
|
26
43
|
isTooltipVisible.value = true
|
|
27
44
|
}
|
|
@@ -40,7 +57,7 @@ function updatePositions(resetPositions = false) {
|
|
|
40
57
|
})
|
|
41
58
|
|
|
42
59
|
tooltip.value!.style.top = resetPositions ? '' : `${top}px`
|
|
43
|
-
tooltip.value!.style.left = resetPositions ? '' : `${left}px`
|
|
60
|
+
tooltip.value!.style.left = resetPositions ? '' : `${left + offsetX}px`
|
|
44
61
|
// Fix pointer position if necessary
|
|
45
62
|
pointer.value!.style.transform =
|
|
46
63
|
!resetPositions && leftCorrection ? `translateX(${leftCorrection * -1}px)` : ''
|
|
@@ -57,6 +74,7 @@ function updatePositions(resetPositions = false) {
|
|
|
57
74
|
ref="tooltip"
|
|
58
75
|
:class="['tooltip', { 'tooltip--open': isTooltipVisible }]"
|
|
59
76
|
:aria-hidden="!isTooltipVisible"
|
|
77
|
+
v-bind="$attrs"
|
|
60
78
|
@transitionend="onTransitionend"
|
|
61
79
|
>
|
|
62
80
|
<div class="tooltip__content">
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import UIcon from '../icon/u-icon.vue'
|
|
3
3
|
import { useRadio } from '../radio-group/radio-group-composables'
|
|
4
|
-
import { computed } from 'vue'
|
|
5
4
|
|
|
6
5
|
interface Props {
|
|
7
6
|
name: string
|
|
@@ -21,15 +20,17 @@ const {
|
|
|
21
20
|
const model = defineModel<string>()
|
|
22
21
|
|
|
23
22
|
const { onChange } = useRadio({ model, provideKey })
|
|
24
|
-
|
|
25
|
-
const classes = computed(() =>
|
|
26
|
-
disabled ? 'disabled' : model.value === value ? 'filled' : 'outlined',
|
|
27
|
-
)
|
|
28
23
|
</script>
|
|
29
24
|
|
|
30
25
|
<template>
|
|
31
26
|
<div class="select-chip">
|
|
32
|
-
<label
|
|
27
|
+
<label
|
|
28
|
+
:class="[
|
|
29
|
+
'select-chip__button',
|
|
30
|
+
'button',
|
|
31
|
+
{ filled: model === value && !disabled, outlined: model !== value || disabled, disabled },
|
|
32
|
+
]"
|
|
33
|
+
>
|
|
33
34
|
<UIcon v-if="model === value" name="mini-check" />
|
|
34
35
|
<slot name="label">
|
|
35
36
|
{{ label }}
|
|
@@ -88,7 +88,7 @@ watch(visible, (newV) => {
|
|
|
88
88
|
'dialog-container',
|
|
89
89
|
mobileDialogStyle,
|
|
90
90
|
{
|
|
91
|
-
'has-header-image': !!slots['header-image'] || headerImage,
|
|
91
|
+
'has-header-image': !!slots['header-image'] || (headerImage?.src && headerImage?.alt),
|
|
92
92
|
'has-content-image': !!slots['content-image'] || contentImage,
|
|
93
93
|
},
|
|
94
94
|
]"
|
|
@@ -128,7 +128,7 @@ watch(visible, (newV) => {
|
|
|
128
128
|
|
|
129
129
|
<div class="cta-container">
|
|
130
130
|
<slot name="cta"></slot>
|
|
131
|
-
<UButton @click="visible = false">{{ closeBtnLabel }}</UButton>
|
|
131
|
+
<UButton @click="visible = false">{{ closeBtnLabel || getTranslation('close') }}</UButton>
|
|
132
132
|
</div>
|
|
133
133
|
</div>
|
|
134
134
|
</dialog>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@energie360/ui-library",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
"typescript": "^5.8.3"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@lottiefiles/lottie-player": "^2.0.12",
|
|
38
|
+
"swiper": "^11.2.10",
|
|
37
39
|
"@energie360/design-tokens": "^1.3.0"
|
|
38
40
|
},
|
|
39
41
|
"peerDependencies": {
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/*
|
|
2
|
+
NOTE: This is old code, but it still works for very simple animation stuff.
|
|
3
|
+
Maybe refactor it (and use ts probably...).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { scaleValue } from '../math/scale-value.js'
|
|
7
|
+
|
|
8
|
+
// /**
|
|
9
|
+
// * Animate multiple props on an element
|
|
10
|
+
// * (Heavily inspired by GSAPs TweenLite.to method.)
|
|
11
|
+
// *
|
|
12
|
+
// * @param el
|
|
13
|
+
// * @param duration
|
|
14
|
+
// * @param props
|
|
15
|
+
// * @param easing
|
|
16
|
+
// * @param delay
|
|
17
|
+
// * @param settle
|
|
18
|
+
// * @param stagger
|
|
19
|
+
// * @param onAbort
|
|
20
|
+
// * @param onStart
|
|
21
|
+
// * @param onComplete
|
|
22
|
+
// * @param onUpdate
|
|
23
|
+
// */
|
|
24
|
+
// export const animateProps = ({
|
|
25
|
+
// el,
|
|
26
|
+
// duration,
|
|
27
|
+
// props,
|
|
28
|
+
// easing,
|
|
29
|
+
// delay,
|
|
30
|
+
// settle,
|
|
31
|
+
// stagger,
|
|
32
|
+
// onAbort,
|
|
33
|
+
// onStart,
|
|
34
|
+
// onComplete,
|
|
35
|
+
// onUpdate,
|
|
36
|
+
// }) => {
|
|
37
|
+
// if (el === undefined || duration === undefined || props === undefined) {
|
|
38
|
+
// throw new Error('Required arguments (el, props, duration) not set.')
|
|
39
|
+
// }
|
|
40
|
+
//
|
|
41
|
+
// if (el instanceof window.HTMLElement || el instanceof window.SVGElement) {
|
|
42
|
+
// el = [el]
|
|
43
|
+
// }
|
|
44
|
+
//
|
|
45
|
+
// let startTime
|
|
46
|
+
// let value
|
|
47
|
+
// let renderId
|
|
48
|
+
// let started = false
|
|
49
|
+
// let posTotal
|
|
50
|
+
// let pos
|
|
51
|
+
// let currentTimeDiff
|
|
52
|
+
// let paused = false
|
|
53
|
+
// let pauseTime
|
|
54
|
+
//
|
|
55
|
+
// onAbort = onAbort || function () {}
|
|
56
|
+
// onStart = onStart || function () {}
|
|
57
|
+
// onComplete = onComplete || function () {}
|
|
58
|
+
// onUpdate = onUpdate || function () {}
|
|
59
|
+
// easing =
|
|
60
|
+
// easing ||
|
|
61
|
+
// function (x) {
|
|
62
|
+
// return x
|
|
63
|
+
// }
|
|
64
|
+
// delay = delay || 0
|
|
65
|
+
// settle = settle || 0
|
|
66
|
+
// stagger = stagger || 0
|
|
67
|
+
//
|
|
68
|
+
// const additionalDuration = stagger * (el.length - 1)
|
|
69
|
+
//
|
|
70
|
+
// const set = ({ element, props, pos }) => {
|
|
71
|
+
// for (let i = 0; i < props.length; i++) {
|
|
72
|
+
// value =
|
|
73
|
+
// (props[i].prefix || '') +
|
|
74
|
+
// translateValue(easing(pos), 0, 1, props[i].start, props[i].end, 3) +
|
|
75
|
+
// (props[i].suffix || '')
|
|
76
|
+
//
|
|
77
|
+
// element.style[props[i].propName] = value
|
|
78
|
+
// }
|
|
79
|
+
// }
|
|
80
|
+
//
|
|
81
|
+
// const setProps = (ts) => {
|
|
82
|
+
// currentTimeDiff = ts - startTime
|
|
83
|
+
// posTotal = currentTimeDiff / (duration + additionalDuration)
|
|
84
|
+
//
|
|
85
|
+
// for (let i = 0; i < el.length; i++) {
|
|
86
|
+
// if (currentTimeDiff < i * stagger + duration && currentTimeDiff >= i * stagger) {
|
|
87
|
+
// pos = (currentTimeDiff - i * stagger) / duration
|
|
88
|
+
//
|
|
89
|
+
// set({ element: el[i], props, pos })
|
|
90
|
+
// } else if (currentTimeDiff >= i * stagger + duration) {
|
|
91
|
+
// set({ element: el[i], props, pos: 1 })
|
|
92
|
+
// }
|
|
93
|
+
// }
|
|
94
|
+
//
|
|
95
|
+
// onUpdate({
|
|
96
|
+
// progress: posTotal,
|
|
97
|
+
// time: currentTimeDiff,
|
|
98
|
+
// })
|
|
99
|
+
// }
|
|
100
|
+
//
|
|
101
|
+
// const anim = (ts) => {
|
|
102
|
+
// if (ts - startTime < 0) {
|
|
103
|
+
// // Don't animate when startTime is not reached (i.e. a delay has been set)
|
|
104
|
+
// renderId = window.requestAnimationFrame(anim)
|
|
105
|
+
// return
|
|
106
|
+
// }
|
|
107
|
+
//
|
|
108
|
+
// // Animation is finished.
|
|
109
|
+
// // Set all props to their defined end values.
|
|
110
|
+
// if (ts - startTime >= duration + additionalDuration) {
|
|
111
|
+
// setProps(startTime + duration + additionalDuration)
|
|
112
|
+
//
|
|
113
|
+
// // Fire callback
|
|
114
|
+
// setTimeout(function () {
|
|
115
|
+
// onComplete()
|
|
116
|
+
// }, settle)
|
|
117
|
+
//
|
|
118
|
+
// return
|
|
119
|
+
// }
|
|
120
|
+
//
|
|
121
|
+
// if (!started) {
|
|
122
|
+
// onStart()
|
|
123
|
+
//
|
|
124
|
+
// started = true
|
|
125
|
+
// }
|
|
126
|
+
//
|
|
127
|
+
// // animation
|
|
128
|
+
// setProps(ts)
|
|
129
|
+
// renderId = window.requestAnimationFrame(anim)
|
|
130
|
+
// }
|
|
131
|
+
//
|
|
132
|
+
// startTime = window.performance.now() + delay
|
|
133
|
+
// renderId = window.requestAnimationFrame(anim)
|
|
134
|
+
//
|
|
135
|
+
// return {
|
|
136
|
+
// pause: () => {
|
|
137
|
+
// window.cancelAnimationFrame(renderId)
|
|
138
|
+
// pauseTime = window.performance.now()
|
|
139
|
+
// paused = true
|
|
140
|
+
// },
|
|
141
|
+
// resume: () => {
|
|
142
|
+
// if (paused) {
|
|
143
|
+
// // start anim again
|
|
144
|
+
// startTime += window.performance.now() - pauseTime
|
|
145
|
+
// window.requestAnimationFrame(anim)
|
|
146
|
+
// paused = false
|
|
147
|
+
// }
|
|
148
|
+
// },
|
|
149
|
+
// abort: () => {
|
|
150
|
+
// window.cancelAnimationFrame(renderId)
|
|
151
|
+
//
|
|
152
|
+
// // Fire callback
|
|
153
|
+
// onAbort()
|
|
154
|
+
// },
|
|
155
|
+
// }
|
|
156
|
+
// }
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
*
|
|
160
|
+
* @param duration
|
|
161
|
+
* @param start
|
|
162
|
+
* @param end
|
|
163
|
+
* @param easing
|
|
164
|
+
* @param delay
|
|
165
|
+
* @param onAbort
|
|
166
|
+
* @param onStart
|
|
167
|
+
* @param onComplete
|
|
168
|
+
* @param onUpdate
|
|
169
|
+
* @returns {{abort: *}}
|
|
170
|
+
*/
|
|
171
|
+
export const animateValue = (
|
|
172
|
+
{ duration, start, end, easing, delay, onAbort, onStart, onComplete, onUpdate } = {
|
|
173
|
+
duration: 200,
|
|
174
|
+
start: 0,
|
|
175
|
+
end: 0,
|
|
176
|
+
delay: 0,
|
|
177
|
+
easing: (x) => x,
|
|
178
|
+
},
|
|
179
|
+
) => {
|
|
180
|
+
onAbort = onAbort || function () {}
|
|
181
|
+
onStart = onStart || function () {}
|
|
182
|
+
onComplete = onComplete || function () {}
|
|
183
|
+
onUpdate = onUpdate || function () {}
|
|
184
|
+
|
|
185
|
+
let startTime
|
|
186
|
+
let pos
|
|
187
|
+
let value
|
|
188
|
+
let renderId
|
|
189
|
+
|
|
190
|
+
delay = delay || 0
|
|
191
|
+
|
|
192
|
+
easing =
|
|
193
|
+
easing ||
|
|
194
|
+
function (x) {
|
|
195
|
+
return x
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const anim = (ts) => {
|
|
199
|
+
if (startTime === undefined) {
|
|
200
|
+
startTime = ts
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (ts - startTime >= duration) {
|
|
204
|
+
onUpdate.call(null, end)
|
|
205
|
+
onComplete.call(null, end)
|
|
206
|
+
return
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// animation
|
|
210
|
+
pos = (ts - startTime) / duration
|
|
211
|
+
|
|
212
|
+
value = scaleValue(easing(pos), 0, 1, start, end, 3)
|
|
213
|
+
onUpdate.call(null, value)
|
|
214
|
+
|
|
215
|
+
renderId = requestAnimationFrame(anim)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (delay) {
|
|
219
|
+
setTimeout(() => {
|
|
220
|
+
onStart()
|
|
221
|
+
renderId = requestAnimationFrame(anim)
|
|
222
|
+
}, delay)
|
|
223
|
+
} else {
|
|
224
|
+
onStart()
|
|
225
|
+
renderId = requestAnimationFrame(anim)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return {
|
|
229
|
+
abort: () => {
|
|
230
|
+
window.cancelAnimationFrame(renderId)
|
|
231
|
+
|
|
232
|
+
// Fire callback
|
|
233
|
+
onAbort.call(null, value)
|
|
234
|
+
},
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// export const timer = (cb, delay) => {
|
|
239
|
+
// let instance = {};
|
|
240
|
+
// let timerId;
|
|
241
|
+
// let startTime;
|
|
242
|
+
// let remaining = delay;
|
|
243
|
+
//
|
|
244
|
+
// instance.resume = () => {
|
|
245
|
+
// startTime = window.performance.now();
|
|
246
|
+
// clearTimeout(timerId);
|
|
247
|
+
// timerId = setTimeout(cb, remaining);
|
|
248
|
+
// };
|
|
249
|
+
//
|
|
250
|
+
// instance.pause = () => {
|
|
251
|
+
// clearTimeout(timerId);
|
|
252
|
+
// remaining -= window.performance.now() - startTime;
|
|
253
|
+
// };
|
|
254
|
+
//
|
|
255
|
+
// instance.resume();
|
|
256
|
+
//
|
|
257
|
+
// return instance;
|
|
258
|
+
// };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const scaleValue = (
|
|
2
|
+
srcValue,
|
|
3
|
+
srcRangeMin,
|
|
4
|
+
srcRangeMax,
|
|
5
|
+
targetRangeMin,
|
|
6
|
+
targetRangeMax,
|
|
7
|
+
round = 0,
|
|
8
|
+
) => {
|
|
9
|
+
const dec = Math.pow(10, round)
|
|
10
|
+
const scale = (targetRangeMax - targetRangeMin) / (srcRangeMax - srcRangeMin)
|
|
11
|
+
|
|
12
|
+
return Math.round((targetRangeMin + (srcValue - srcRangeMin) * scale) * dec) / dec
|
|
13
|
+
}
|