@alfalab/core-components-page-indicator 1.0.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/Component.d.ts +5 -0
- package/Component.js +15 -0
- package/components/bullet/Component.d.ts +4 -0
- package/components/bullet/Component.js +64 -0
- package/components/bullet/default.css +41 -0
- package/components/bullet/index.css +64 -0
- package/components/bullet/index.d.ts +1 -0
- package/components/bullet/index.js +9 -0
- package/components/bullet/inverted.css +41 -0
- package/components/bullet/static-inverted.css +41 -0
- package/components/bullet/static.css +41 -0
- package/components/bullet/utils/index.d.ts +1 -0
- package/components/bullet/utils/index.js +9 -0
- package/components/bullet/utils/utils.d.ts +9 -0
- package/components/bullet/utils/utils.js +120 -0
- package/components/dynamic/Component.d.ts +5 -0
- package/components/dynamic/Component.js +93 -0
- package/components/dynamic/default.css +43 -0
- package/components/dynamic/index.css +53 -0
- package/components/dynamic/index.d.ts +1 -0
- package/components/dynamic/index.js +9 -0
- package/components/dynamic/inverted.css +43 -0
- package/components/dynamic/static-inverted.css +43 -0
- package/components/dynamic/static.css +43 -0
- package/components/runner/Component.d.ts +5 -0
- package/components/runner/Component.js +45 -0
- package/components/runner/default.css +41 -0
- package/components/runner/index.css +37 -0
- package/components/runner/index.d.ts +1 -0
- package/components/runner/index.js +9 -0
- package/components/runner/inverted.css +41 -0
- package/components/runner/static-inverted.css +41 -0
- package/components/runner/static.css +41 -0
- package/components/step/Component.d.ts +5 -0
- package/components/step/Component.js +44 -0
- package/components/step/default.css +41 -0
- package/components/step/index.css +44 -0
- package/components/step/index.d.ts +1 -0
- package/components/step/index.js +9 -0
- package/components/step/inverted.css +41 -0
- package/components/step/static-inverted.css +41 -0
- package/components/step/static.css +41 -0
- package/cssm/Component.d.ts +5 -0
- package/cssm/Component.js +15 -0
- package/cssm/components/bullet/Component.d.ts +4 -0
- package/cssm/components/bullet/Component.js +59 -0
- package/cssm/components/bullet/default.module.css +40 -0
- package/cssm/components/bullet/index.d.ts +1 -0
- package/cssm/components/bullet/index.js +9 -0
- package/cssm/components/bullet/index.module.css +63 -0
- package/cssm/components/bullet/inverted.module.css +40 -0
- package/cssm/components/bullet/static-inverted.module.css +40 -0
- package/cssm/components/bullet/static.module.css +40 -0
- package/cssm/components/bullet/utils/index.d.ts +1 -0
- package/cssm/components/bullet/utils/index.js +9 -0
- package/cssm/components/bullet/utils/utils.d.ts +9 -0
- package/cssm/components/bullet/utils/utils.js +120 -0
- package/cssm/components/dynamic/Component.d.ts +5 -0
- package/cssm/components/dynamic/Component.js +88 -0
- package/cssm/components/dynamic/default.module.css +42 -0
- package/cssm/components/dynamic/index.d.ts +1 -0
- package/cssm/components/dynamic/index.js +9 -0
- package/cssm/components/dynamic/index.module.css +52 -0
- package/cssm/components/dynamic/inverted.module.css +42 -0
- package/cssm/components/dynamic/static-inverted.module.css +42 -0
- package/cssm/components/dynamic/static.module.css +42 -0
- package/cssm/components/runner/Component.d.ts +5 -0
- package/cssm/components/runner/Component.js +40 -0
- package/cssm/components/runner/default.module.css +40 -0
- package/cssm/components/runner/index.d.ts +1 -0
- package/cssm/components/runner/index.js +9 -0
- package/cssm/components/runner/index.module.css +36 -0
- package/cssm/components/runner/inverted.module.css +40 -0
- package/cssm/components/runner/static-inverted.module.css +40 -0
- package/cssm/components/runner/static.module.css +40 -0
- package/cssm/components/step/Component.d.ts +5 -0
- package/cssm/components/step/Component.js +39 -0
- package/cssm/components/step/default.module.css +40 -0
- package/cssm/components/step/index.d.ts +1 -0
- package/cssm/components/step/index.js +9 -0
- package/cssm/components/step/index.module.css +43 -0
- package/cssm/components/step/inverted.module.css +40 -0
- package/cssm/components/step/static-inverted.module.css +40 -0
- package/cssm/components/step/static.module.css +40 -0
- package/cssm/index.d.ts +1 -0
- package/cssm/index.js +15 -0
- package/cssm/types.d.ts +129 -0
- package/cssm/types.js +2 -0
- package/cssm/vars.css +32 -0
- package/esm/Component.d.ts +5 -0
- package/esm/Component.js +4 -0
- package/esm/components/bullet/Component.d.ts +4 -0
- package/esm/components/bullet/Component.js +55 -0
- package/esm/components/bullet/default.css +41 -0
- package/esm/components/bullet/index.css +64 -0
- package/esm/components/bullet/index.d.ts +1 -0
- package/esm/components/bullet/index.js +1 -0
- package/esm/components/bullet/inverted.css +41 -0
- package/esm/components/bullet/static-inverted.css +41 -0
- package/esm/components/bullet/static.css +41 -0
- package/esm/components/bullet/utils/index.d.ts +1 -0
- package/esm/components/bullet/utils/index.js +1 -0
- package/esm/components/bullet/utils/utils.d.ts +9 -0
- package/esm/components/bullet/utils/utils.js +116 -0
- package/esm/components/dynamic/Component.d.ts +5 -0
- package/esm/components/dynamic/Component.js +84 -0
- package/esm/components/dynamic/default.css +43 -0
- package/esm/components/dynamic/index.css +53 -0
- package/esm/components/dynamic/index.d.ts +1 -0
- package/esm/components/dynamic/index.js +1 -0
- package/esm/components/dynamic/inverted.css +43 -0
- package/esm/components/dynamic/static-inverted.css +43 -0
- package/esm/components/dynamic/static.css +43 -0
- package/esm/components/runner/Component.d.ts +5 -0
- package/esm/components/runner/Component.js +36 -0
- package/esm/components/runner/default.css +41 -0
- package/esm/components/runner/index.css +37 -0
- package/esm/components/runner/index.d.ts +1 -0
- package/esm/components/runner/index.js +1 -0
- package/esm/components/runner/inverted.css +41 -0
- package/esm/components/runner/static-inverted.css +41 -0
- package/esm/components/runner/static.css +41 -0
- package/esm/components/step/Component.d.ts +5 -0
- package/esm/components/step/Component.js +35 -0
- package/esm/components/step/default.css +41 -0
- package/esm/components/step/index.css +44 -0
- package/esm/components/step/index.d.ts +1 -0
- package/esm/components/step/index.js +1 -0
- package/esm/components/step/inverted.css +41 -0
- package/esm/components/step/static-inverted.css +41 -0
- package/esm/components/step/static.css +41 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +4 -0
- package/esm/types.d.ts +129 -0
- package/esm/types.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +15 -0
- package/modern/Component.d.ts +5 -0
- package/modern/Component.js +4 -0
- package/modern/components/bullet/Component.d.ts +4 -0
- package/modern/components/bullet/Component.js +50 -0
- package/modern/components/bullet/default.css +41 -0
- package/modern/components/bullet/index.css +64 -0
- package/modern/components/bullet/index.d.ts +1 -0
- package/modern/components/bullet/index.js +1 -0
- package/modern/components/bullet/inverted.css +41 -0
- package/modern/components/bullet/static-inverted.css +41 -0
- package/modern/components/bullet/static.css +41 -0
- package/modern/components/bullet/utils/index.d.ts +1 -0
- package/modern/components/bullet/utils/index.js +1 -0
- package/modern/components/bullet/utils/utils.d.ts +9 -0
- package/modern/components/bullet/utils/utils.js +114 -0
- package/modern/components/dynamic/Component.d.ts +5 -0
- package/modern/components/dynamic/Component.js +83 -0
- package/modern/components/dynamic/default.css +43 -0
- package/modern/components/dynamic/index.css +53 -0
- package/modern/components/dynamic/index.d.ts +1 -0
- package/modern/components/dynamic/index.js +1 -0
- package/modern/components/dynamic/inverted.css +43 -0
- package/modern/components/dynamic/static-inverted.css +43 -0
- package/modern/components/dynamic/static.css +43 -0
- package/modern/components/runner/Component.d.ts +5 -0
- package/modern/components/runner/Component.js +33 -0
- package/modern/components/runner/default.css +41 -0
- package/modern/components/runner/index.css +37 -0
- package/modern/components/runner/index.d.ts +1 -0
- package/modern/components/runner/index.js +1 -0
- package/modern/components/runner/inverted.css +41 -0
- package/modern/components/runner/static-inverted.css +41 -0
- package/modern/components/runner/static.css +41 -0
- package/modern/components/step/Component.d.ts +5 -0
- package/modern/components/step/Component.js +29 -0
- package/modern/components/step/default.css +41 -0
- package/modern/components/step/index.css +44 -0
- package/modern/components/step/index.d.ts +1 -0
- package/modern/components/step/index.js +1 -0
- package/modern/components/step/inverted.css +41 -0
- package/modern/components/step/static-inverted.css +41 -0
- package/modern/components/step/static.css +41 -0
- package/modern/index.d.ts +1 -0
- package/modern/index.js +4 -0
- package/modern/types.d.ts +129 -0
- package/modern/types.js +1 -0
- package/moderncssm/Component.d.ts +5 -0
- package/moderncssm/Component.js +4 -0
- package/moderncssm/components/bullet/Component.d.ts +4 -0
- package/moderncssm/components/bullet/Component.js +40 -0
- package/moderncssm/components/bullet/default.module.css +22 -0
- package/moderncssm/components/bullet/index.d.ts +1 -0
- package/moderncssm/components/bullet/index.js +1 -0
- package/moderncssm/components/bullet/index.module.css +56 -0
- package/moderncssm/components/bullet/inverted.module.css +22 -0
- package/moderncssm/components/bullet/static-inverted.module.css +22 -0
- package/moderncssm/components/bullet/static.module.css +22 -0
- package/moderncssm/components/bullet/utils/index.d.ts +1 -0
- package/moderncssm/components/bullet/utils/index.js +1 -0
- package/moderncssm/components/bullet/utils/utils.d.ts +9 -0
- package/moderncssm/components/bullet/utils/utils.js +114 -0
- package/moderncssm/components/dynamic/Component.d.ts +5 -0
- package/moderncssm/components/dynamic/Component.js +73 -0
- package/moderncssm/components/dynamic/default.module.css +24 -0
- package/moderncssm/components/dynamic/index.d.ts +1 -0
- package/moderncssm/components/dynamic/index.js +1 -0
- package/moderncssm/components/dynamic/index.module.css +40 -0
- package/moderncssm/components/dynamic/inverted.module.css +24 -0
- package/moderncssm/components/dynamic/static-inverted.module.css +24 -0
- package/moderncssm/components/dynamic/static.module.css +24 -0
- package/moderncssm/components/runner/Component.d.ts +5 -0
- package/moderncssm/components/runner/Component.js +23 -0
- package/moderncssm/components/runner/default.module.css +22 -0
- package/moderncssm/components/runner/index.d.ts +1 -0
- package/moderncssm/components/runner/index.js +1 -0
- package/moderncssm/components/runner/index.module.css +18 -0
- package/moderncssm/components/runner/inverted.module.css +22 -0
- package/moderncssm/components/runner/static-inverted.module.css +22 -0
- package/moderncssm/components/runner/static.module.css +22 -0
- package/moderncssm/components/step/Component.d.ts +5 -0
- package/moderncssm/components/step/Component.js +19 -0
- package/moderncssm/components/step/default.module.css +22 -0
- package/moderncssm/components/step/index.d.ts +1 -0
- package/moderncssm/components/step/index.js +1 -0
- package/moderncssm/components/step/index.module.css +27 -0
- package/moderncssm/components/step/inverted.module.css +22 -0
- package/moderncssm/components/step/static-inverted.module.css +22 -0
- package/moderncssm/components/step/static.module.css +22 -0
- package/moderncssm/index.d.ts +1 -0
- package/moderncssm/index.js +4 -0
- package/moderncssm/types.d.ts +129 -0
- package/moderncssm/types.js +1 -0
- package/moderncssm/vars.css +12 -0
- package/package.json +28 -0
- package/src/Component.tsx +6 -0
- package/src/components/bullet/Component.tsx +84 -0
- package/src/components/bullet/default.module.css +9 -0
- package/src/components/bullet/index.module.css +42 -0
- package/src/components/bullet/index.ts +1 -0
- package/src/components/bullet/inverted.module.css +9 -0
- package/src/components/bullet/static-inverted.module.css +9 -0
- package/src/components/bullet/static.module.css +9 -0
- package/src/components/bullet/utils/index.ts +1 -0
- package/src/components/bullet/utils/utils.ts +153 -0
- package/src/components/dynamic/Component.tsx +126 -0
- package/src/components/dynamic/default.module.css +11 -0
- package/src/components/dynamic/index.module.css +25 -0
- package/src/components/dynamic/index.ts +1 -0
- package/src/components/dynamic/inverted.module.css +11 -0
- package/src/components/dynamic/static-inverted.module.css +11 -0
- package/src/components/dynamic/static.module.css +11 -0
- package/src/components/runner/Component.tsx +39 -0
- package/src/components/runner/default.module.css +9 -0
- package/src/components/runner/index.module.css +6 -0
- package/src/components/runner/index.ts +1 -0
- package/src/components/runner/inverted.module.css +9 -0
- package/src/components/runner/static-inverted.module.css +9 -0
- package/src/components/runner/static.module.css +9 -0
- package/src/components/step/Component.tsx +37 -0
- package/src/components/step/default.module.css +9 -0
- package/src/components/step/index.module.css +14 -0
- package/src/components/step/index.ts +1 -0
- package/src/components/step/inverted.module.css +9 -0
- package/src/components/step/static-inverted.module.css +9 -0
- package/src/components/step/static.module.css +9 -0
- package/src/index.ts +1 -0
- package/src/types.ts +131 -0
- package/src/vars.css +22 -0
- package/types.d.ts +129 -0
- package/types.js +2 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React, { useMemo, createRef } from 'react';
|
|
2
|
+
import { CSSTransition } from 'react-transition-group';
|
|
3
|
+
import cn from 'classnames';
|
|
4
|
+
import { calcParams } from './utils/utils.js';
|
|
5
|
+
import defaultColors from './default.module.css';
|
|
6
|
+
import styles from './index.module.css';
|
|
7
|
+
import invertedColors from './inverted.module.css';
|
|
8
|
+
import staticColors from './static.module.css';
|
|
9
|
+
import staticInvertedColors from './static-inverted.module.css';
|
|
10
|
+
|
|
11
|
+
const colorsStyle = {
|
|
12
|
+
inverted: invertedColors,
|
|
13
|
+
default: defaultColors,
|
|
14
|
+
static: staticColors,
|
|
15
|
+
'static-inverted': staticInvertedColors,
|
|
16
|
+
};
|
|
17
|
+
const transitionClassess = {};
|
|
18
|
+
const PageIndicatorBullet = ({ elements: count = 10, activeElement: activeElementIndex, size = 8, gap = 8, colors = 'default', }) => {
|
|
19
|
+
const refs = useMemo(() => Array.from({ length: count }, (createRef)), [count]);
|
|
20
|
+
const [height, width, offset, elementSize, firstVisibleElementIndex, lastVisibleElementIndex] = useMemo(() => calcParams(size, gap, activeElementIndex, count), [activeElementIndex, count, gap, size]);
|
|
21
|
+
return (React.createElement("div", { className: cn(styles.pageIndicator, styles.bullet), style: { height, width } },
|
|
22
|
+
React.createElement("ol", { className: styles.elementsList, style: { gap, transform: `translate(${offset}px)` } }, refs.map((ref, index) => {
|
|
23
|
+
const sizeOfElement = elementSize(index);
|
|
24
|
+
const isActive = activeElementIndex === index;
|
|
25
|
+
const isVisible = firstVisibleElementIndex <= index && index <= lastVisibleElementIndex;
|
|
26
|
+
const addListTransitionEndListener = (done) => {
|
|
27
|
+
const parentElement = ref.current?.parentElement;
|
|
28
|
+
parentElement?.addEventListener('transitionend', done, { once: true });
|
|
29
|
+
};
|
|
30
|
+
return (React.createElement(CSSTransition
|
|
31
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
32
|
+
, {
|
|
33
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
34
|
+
key: index, nodeRef: ref, addEndListener: addListTransitionEndListener, in: isVisible,
|
|
35
|
+
// passed empty object so any classes aren't added
|
|
36
|
+
classNames: transitionClassess }, (status) => (React.createElement("li", { ref: ref, "data-index": index, className: cn(styles.element, colorsStyle[colors].element, { [colorsStyle[colors].active]: isActive }, styles[status]), style: { height: sizeOfElement, width: sizeOfElement } }))));
|
|
37
|
+
}))));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { PageIndicatorBullet };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
|
|
5
|
+
/* default */
|
|
6
|
+
--page-indicator-color: var(--color-light-neutral-translucent-300);
|
|
7
|
+
--page-indicator-active-color: var(--color-light-neutral-translucent-1300);
|
|
8
|
+
|
|
9
|
+
/* inverted */
|
|
10
|
+
|
|
11
|
+
/* static */
|
|
12
|
+
|
|
13
|
+
/* static-inverted */
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.element {
|
|
17
|
+
background: var(--page-indicator-color)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.element.active {
|
|
21
|
+
background: var(--page-indicator-active-color);
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Component";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PageIndicatorBullet } from './Component.js';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
--page-indicator-animation-duration: 0.2s;
|
|
5
|
+
--page-indicator-animation-timing-function: ease-in-out;
|
|
6
|
+
|
|
7
|
+
/* default */
|
|
8
|
+
|
|
9
|
+
/* inverted */
|
|
10
|
+
|
|
11
|
+
/* static */
|
|
12
|
+
|
|
13
|
+
/* static-inverted */
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.pageIndicator.bullet {
|
|
17
|
+
overflow: hidden;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.elementsList {
|
|
21
|
+
margin: 0;
|
|
22
|
+
padding: 0;
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
will-change: transform;
|
|
26
|
+
transition: transform var(--page-indicator-animation-duration)
|
|
27
|
+
var(--page-indicator-animation-timing-function);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.element {
|
|
31
|
+
list-style-type: none;
|
|
32
|
+
flex-shrink: 0;
|
|
33
|
+
transition: background var(--page-indicator-animation-duration)
|
|
34
|
+
var(--page-indicator-animation-timing-function);
|
|
35
|
+
border-radius: var(--border-radius-circle)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.element.entering {
|
|
39
|
+
opacity: 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.element.entered {
|
|
43
|
+
opacity: 1;
|
|
44
|
+
transition: background var(--page-indicator-animation-duration)
|
|
45
|
+
var(--page-indicator-animation-timing-function),
|
|
46
|
+
opacity var(--page-indicator-animation-duration)
|
|
47
|
+
var(--page-indicator-animation-timing-function);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.element.exiting {
|
|
51
|
+
opacity: 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.element.exited {
|
|
55
|
+
opacity: 0;
|
|
56
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
|
|
5
|
+
/* default */
|
|
6
|
+
|
|
7
|
+
/* inverted */
|
|
8
|
+
--page-indicator-color-inverted: var(--color-light-neutral-translucent-300-inverted);
|
|
9
|
+
--page-indicator-active-color-inverted: var(--color-light-neutral-translucent-1300-inverted);
|
|
10
|
+
|
|
11
|
+
/* static */
|
|
12
|
+
|
|
13
|
+
/* static-inverted */
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.element {
|
|
17
|
+
background: var(--page-indicator-color-inverted)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.element.active {
|
|
21
|
+
background: var(--page-indicator-active-color-inverted);
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
|
|
5
|
+
/* default */
|
|
6
|
+
|
|
7
|
+
/* inverted */
|
|
8
|
+
|
|
9
|
+
/* static */
|
|
10
|
+
|
|
11
|
+
/* static-inverted */
|
|
12
|
+
--page-indicator-color-static-inverted: var(--color-static-neutral-translucent-300-inverted);
|
|
13
|
+
--page-indicator-active-color-static-inverted: var(--color-static-neutral-1300-inverted);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.element {
|
|
17
|
+
background: var(--page-indicator-color-static-inverted)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.element.active {
|
|
21
|
+
background: var(--page-indicator-active-color-static-inverted);
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
|
|
5
|
+
/* default */
|
|
6
|
+
|
|
7
|
+
/* inverted */
|
|
8
|
+
|
|
9
|
+
/* static */
|
|
10
|
+
--page-indicator-color-static: var(--color-static-neutral-translucent-300);
|
|
11
|
+
--page-indicator-active-color-static: var(--color-static-neutral-1300);
|
|
12
|
+
|
|
13
|
+
/* static-inverted */
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.element {
|
|
17
|
+
background: var(--page-indicator-color-static)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.element.active {
|
|
21
|
+
background: var(--page-indicator-active-color-static);
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./utils";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { calcParams } from './utils.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare function calcParams(size: number, gap: number, activeElementIndex: number, elementsCount: number): [
|
|
2
|
+
height: number,
|
|
3
|
+
width: number,
|
|
4
|
+
offset: number,
|
|
5
|
+
elementSize: (index: number) => number,
|
|
6
|
+
firstVisibleElementIndex: number,
|
|
7
|
+
lastVisibleElementIndex: number
|
|
8
|
+
];
|
|
9
|
+
export { calcParams };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
const RENDER_ELEMENTS_COUNT = 5;
|
|
2
|
+
function calcParams(size, gap, activeElementIndex, elementsCount) {
|
|
3
|
+
const renderElementsCount = Math.min(elementsCount, RENDER_ELEMENTS_COUNT);
|
|
4
|
+
const firstIndex = 0;
|
|
5
|
+
const lastIndex = elementsCount - 1;
|
|
6
|
+
function findFirstVisibleElementIndex() {
|
|
7
|
+
const middle = (renderElementsCount - 1) / 2;
|
|
8
|
+
let leadingOffset;
|
|
9
|
+
let tailingOffset;
|
|
10
|
+
if (middle % 1 === 0) {
|
|
11
|
+
leadingOffset = middle;
|
|
12
|
+
tailingOffset = middle;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
leadingOffset = Math.floor(middle);
|
|
16
|
+
tailingOffset = Math.ceil(middle);
|
|
17
|
+
}
|
|
18
|
+
// rebalance leadingOffset
|
|
19
|
+
const maybeFirstVisibleElementIndex = activeElementIndex - leadingOffset;
|
|
20
|
+
if (maybeFirstVisibleElementIndex < firstIndex) {
|
|
21
|
+
leadingOffset -= firstIndex - maybeFirstVisibleElementIndex;
|
|
22
|
+
}
|
|
23
|
+
const maybeLastActiveElementIndex = activeElementIndex + tailingOffset;
|
|
24
|
+
if (maybeLastActiveElementIndex > lastIndex) {
|
|
25
|
+
leadingOffset += maybeLastActiveElementIndex - lastIndex;
|
|
26
|
+
}
|
|
27
|
+
return activeElementIndex - leadingOffset;
|
|
28
|
+
}
|
|
29
|
+
const firstVisibleElementIndex = findFirstVisibleElementIndex();
|
|
30
|
+
const lastVisibleElementIndex = renderElementsCount + firstVisibleElementIndex - 1;
|
|
31
|
+
const largeSize = size;
|
|
32
|
+
const middleSize = 0.75 * size;
|
|
33
|
+
const smallSize = 0.5 * size;
|
|
34
|
+
// eslint-disable-next-line complexity
|
|
35
|
+
function computeElementSize(_, index) {
|
|
36
|
+
if (index < firstVisibleElementIndex || index > lastVisibleElementIndex) {
|
|
37
|
+
return smallSize;
|
|
38
|
+
}
|
|
39
|
+
if (elementsCount === RENDER_ELEMENTS_COUNT + 1 /* totalCount === 6 */) {
|
|
40
|
+
if ((index === firstVisibleElementIndex &&
|
|
41
|
+
!(firstVisibleElementIndex === firstIndex)) ||
|
|
42
|
+
(index === lastVisibleElementIndex && !(lastVisibleElementIndex === lastIndex))) {
|
|
43
|
+
return middleSize;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (elementsCount > RENDER_ELEMENTS_COUNT + 1 /* totalCount > 6 */) {
|
|
47
|
+
if (firstVisibleElementIndex === firstIndex) {
|
|
48
|
+
if (!(lastVisibleElementIndex === lastIndex)) {
|
|
49
|
+
if (index === lastVisibleElementIndex) {
|
|
50
|
+
if (activeElementIndex === lastVisibleElementIndex - 1) {
|
|
51
|
+
return middleSize;
|
|
52
|
+
}
|
|
53
|
+
return smallSize;
|
|
54
|
+
}
|
|
55
|
+
if (index === lastVisibleElementIndex - 1) {
|
|
56
|
+
return middleSize;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (lastVisibleElementIndex === lastIndex) {
|
|
61
|
+
if (!(firstVisibleElementIndex === firstIndex)) {
|
|
62
|
+
if (index === firstVisibleElementIndex) {
|
|
63
|
+
if (activeElementIndex === firstVisibleElementIndex + 1) {
|
|
64
|
+
return middleSize;
|
|
65
|
+
}
|
|
66
|
+
return smallSize;
|
|
67
|
+
}
|
|
68
|
+
if (index === firstVisibleElementIndex + 1) {
|
|
69
|
+
return middleSize;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if ((index === firstVisibleElementIndex &&
|
|
74
|
+
!(firstVisibleElementIndex === firstIndex)) ||
|
|
75
|
+
(index === lastVisibleElementIndex && !(lastVisibleElementIndex === lastIndex))) {
|
|
76
|
+
return middleSize;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return largeSize;
|
|
80
|
+
}
|
|
81
|
+
const elementSizes = Array.from({ length: elementsCount }, computeElementSize);
|
|
82
|
+
const width = renderElementsCount * (largeSize + gap) - gap;
|
|
83
|
+
function actualWidth() {
|
|
84
|
+
return elementSizes
|
|
85
|
+
.slice(firstVisibleElementIndex, lastVisibleElementIndex + 1)
|
|
86
|
+
.map((elementSize, index, array) => index === array.length - 1 ? elementSize : elementSize + gap)
|
|
87
|
+
.reduce((a, b) => a + b, 0);
|
|
88
|
+
}
|
|
89
|
+
function offset() {
|
|
90
|
+
const extraOffset = firstVisibleElementIndex === firstIndex
|
|
91
|
+
? 0
|
|
92
|
+
: (width - actualWidth()) / (lastVisibleElementIndex === lastIndex ? 1 : 2);
|
|
93
|
+
return (extraOffset -
|
|
94
|
+
elementSizes
|
|
95
|
+
.slice(firstIndex, firstVisibleElementIndex)
|
|
96
|
+
.map((elementSize) => elementSize + gap)
|
|
97
|
+
.reduce((a, b) => a + b, 0));
|
|
98
|
+
}
|
|
99
|
+
function height() {
|
|
100
|
+
return Math.max(size, largeSize, middleSize, smallSize);
|
|
101
|
+
}
|
|
102
|
+
return [
|
|
103
|
+
height(),
|
|
104
|
+
width,
|
|
105
|
+
offset(),
|
|
106
|
+
function elementSize(index) {
|
|
107
|
+
return elementSizes[index];
|
|
108
|
+
},
|
|
109
|
+
firstVisibleElementIndex,
|
|
110
|
+
lastVisibleElementIndex,
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { calcParams };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { hasOwnProperty, isNonNullable, isFn, noop, isNullable } from '@alfalab/core-components-shared/moderncssm';
|
|
4
|
+
import defaultColors from './default.module.css';
|
|
5
|
+
import styles from './index.module.css';
|
|
6
|
+
import invertedColors from './inverted.module.css';
|
|
7
|
+
import staticColors from './static.module.css';
|
|
8
|
+
import staticInvertedColors from './static-inverted.module.css';
|
|
9
|
+
|
|
10
|
+
const colorsStyle = {
|
|
11
|
+
inverted: invertedColors,
|
|
12
|
+
default: defaultColors,
|
|
13
|
+
static: staticColors,
|
|
14
|
+
'static-inverted': staticInvertedColors,
|
|
15
|
+
};
|
|
16
|
+
const FULL_PROGRESS = 100;
|
|
17
|
+
const PageIndicatorDynamic = (props) => {
|
|
18
|
+
const { size: height = 8, gap = 8, activeElementWidth = height * 7, elements: count = 10, activeElement: indexFromProps, onActiveElementChange, defaultActiveElement: defaultIndex = 0, active = true, duration: durationFromProps = 3000, cycle = false, colors = 'default', } = props;
|
|
19
|
+
const [activeIndex, setActiveIndex] = useState(indexFromProps ?? defaultIndex);
|
|
20
|
+
const [progress, setProgress] = useState(0);
|
|
21
|
+
const inProgress = progress < FULL_PROGRESS;
|
|
22
|
+
const activeIndexInProps = hasOwnProperty(props, 'activeElement');
|
|
23
|
+
let duration;
|
|
24
|
+
if (active && isNonNullable(activeIndex) && inProgress) {
|
|
25
|
+
duration = isFn(durationFromProps) ? durationFromProps(activeIndex) : durationFromProps;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
duration = -1;
|
|
29
|
+
}
|
|
30
|
+
// getDerivedStateFromProps
|
|
31
|
+
if (activeIndexInProps && !(activeIndex === indexFromProps)) {
|
|
32
|
+
setActiveIndex(indexFromProps);
|
|
33
|
+
setProgress(0);
|
|
34
|
+
}
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (duration === -1) {
|
|
37
|
+
return noop;
|
|
38
|
+
}
|
|
39
|
+
const interval = duration / FULL_PROGRESS;
|
|
40
|
+
const timer = setInterval(() => setProgress((prevProgress) => Math.min(prevProgress + 1, FULL_PROGRESS)), interval);
|
|
41
|
+
return () => clearInterval(timer);
|
|
42
|
+
}, [duration]);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
const isLast = activeIndex === count - 1;
|
|
45
|
+
if (inProgress || isNullable(activeIndex) || (isLast && !cycle)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const nextActiveIndex = isLast && cycle ? 0 : activeIndex + 1;
|
|
49
|
+
onActiveElementChange?.(nextActiveIndex);
|
|
50
|
+
if (activeIndexInProps) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
setActiveIndex(nextActiveIndex);
|
|
54
|
+
setProgress(0);
|
|
55
|
+
}, [activeIndex, activeIndexInProps, count, cycle, inProgress, onActiveElementChange]);
|
|
56
|
+
return (React.createElement("ol", { className: styles.pageIndicator, style: { height, gap } }, Array.from({ length: count }, (_, index) => {
|
|
57
|
+
const isActive = index === activeIndex;
|
|
58
|
+
const style = {
|
|
59
|
+
width: isActive ? activeElementWidth : height,
|
|
60
|
+
borderRadius: height / 2,
|
|
61
|
+
};
|
|
62
|
+
const progressStyle = isActive
|
|
63
|
+
? { transform: `translateX(${progress - FULL_PROGRESS}%)` }
|
|
64
|
+
: undefined;
|
|
65
|
+
return (React.createElement("li", { key: index, style: style, className: cn(styles.element, colorsStyle[colors].element, {
|
|
66
|
+
[styles.active]: isActive,
|
|
67
|
+
[colorsStyle[colors].active]: isActive,
|
|
68
|
+
}) },
|
|
69
|
+
React.createElement("div", { style: progressStyle, className: cn(styles.progress, colorsStyle[colors].progress) })));
|
|
70
|
+
})));
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export { PageIndicatorDynamic };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
|
|
5
|
+
/* default */
|
|
6
|
+
--page-indicator-color: var(--color-light-neutral-translucent-300);
|
|
7
|
+
--page-indicator-active-color: var(--color-light-neutral-translucent-1300);
|
|
8
|
+
|
|
9
|
+
/* inverted */
|
|
10
|
+
|
|
11
|
+
/* static */
|
|
12
|
+
|
|
13
|
+
/* static-inverted */
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.element {
|
|
17
|
+
background: var(--page-indicator-color)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.element.active {
|
|
21
|
+
.progress {
|
|
22
|
+
background: var(--page-indicator-active-color);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Component";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PageIndicatorDynamic } from './Component.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
--page-indicator-animation-duration: 0.2s;
|
|
5
|
+
|
|
6
|
+
/* default */
|
|
7
|
+
|
|
8
|
+
/* inverted */
|
|
9
|
+
|
|
10
|
+
/* static */
|
|
11
|
+
|
|
12
|
+
/* static-inverted */
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.pageIndicator {
|
|
16
|
+
margin: 0;
|
|
17
|
+
padding: 0;
|
|
18
|
+
display: flex;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.element {
|
|
22
|
+
list-style-type: none;
|
|
23
|
+
overflow: hidden;
|
|
24
|
+
transition: width var(--page-indicator-animation-duration) linear
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.element:not(.active) {
|
|
28
|
+
.progress {
|
|
29
|
+
display: none;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.element {
|
|
34
|
+
|
|
35
|
+
.progress {
|
|
36
|
+
width: 100%;
|
|
37
|
+
height: 100%;
|
|
38
|
+
will-change: transform;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
|
|
5
|
+
/* default */
|
|
6
|
+
|
|
7
|
+
/* inverted */
|
|
8
|
+
--page-indicator-color-inverted: var(--color-light-neutral-translucent-300-inverted);
|
|
9
|
+
--page-indicator-active-color-inverted: var(--color-light-neutral-translucent-1300-inverted);
|
|
10
|
+
|
|
11
|
+
/* static */
|
|
12
|
+
|
|
13
|
+
/* static-inverted */
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.element {
|
|
17
|
+
background: var(--page-indicator-color-inverted)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.element.active {
|
|
21
|
+
.progress {
|
|
22
|
+
background: var(--page-indicator-active-color-inverted);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
|
|
5
|
+
/* default */
|
|
6
|
+
|
|
7
|
+
/* inverted */
|
|
8
|
+
|
|
9
|
+
/* static */
|
|
10
|
+
|
|
11
|
+
/* static-inverted */
|
|
12
|
+
--page-indicator-color-static-inverted: var(--color-static-neutral-translucent-300-inverted);
|
|
13
|
+
--page-indicator-active-color-static-inverted: var(--color-static-neutral-1300-inverted);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.element {
|
|
17
|
+
background: var(--page-indicator-color-static-inverted)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.element.active {
|
|
21
|
+
.progress {
|
|
22
|
+
background: var(--page-indicator-active-color-static-inverted);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
|
|
5
|
+
/* default */
|
|
6
|
+
|
|
7
|
+
/* inverted */
|
|
8
|
+
|
|
9
|
+
/* static */
|
|
10
|
+
--page-indicator-color-static: var(--color-static-neutral-translucent-300);
|
|
11
|
+
--page-indicator-active-color-static: var(--color-static-neutral-1300);
|
|
12
|
+
|
|
13
|
+
/* static-inverted */
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.element {
|
|
17
|
+
background: var(--page-indicator-color-static)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.element.active {
|
|
21
|
+
.progress {
|
|
22
|
+
background: var(--page-indicator-active-color-static);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import defaultColors from './default.module.css';
|
|
4
|
+
import styles from './index.module.css';
|
|
5
|
+
import invertedColors from './inverted.module.css';
|
|
6
|
+
import staticColors from './static.module.css';
|
|
7
|
+
import staticInvertedColors from './static-inverted.module.css';
|
|
8
|
+
|
|
9
|
+
const colorsStyle = {
|
|
10
|
+
inverted: invertedColors,
|
|
11
|
+
default: defaultColors,
|
|
12
|
+
static: staticColors,
|
|
13
|
+
'static-inverted': staticInvertedColors,
|
|
14
|
+
};
|
|
15
|
+
const PageIndicatorRunner = ({ activeElement, elements: count = 10, size = 4, colors = 'default', }) => (React.createElement("div", { className: cn(styles.pageIndicator, colorsStyle[colors].pageIndicator), style: { height: size, borderRadius: size / 2 } },
|
|
16
|
+
React.createElement("div", { style: {
|
|
17
|
+
transform: `translate(${activeElement * 100}%, 0)`,
|
|
18
|
+
height: size,
|
|
19
|
+
width: `${100 / count}%`,
|
|
20
|
+
borderRadius: size / 2,
|
|
21
|
+
}, className: cn(styles.element, colorsStyle[colors].element) })));
|
|
22
|
+
|
|
23
|
+
export { PageIndicatorRunner };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
|
|
5
|
+
/* default */
|
|
6
|
+
--page-indicator-color: var(--color-light-neutral-translucent-300);
|
|
7
|
+
--page-indicator-active-color: var(--color-light-neutral-translucent-1300);
|
|
8
|
+
|
|
9
|
+
/* inverted */
|
|
10
|
+
|
|
11
|
+
/* static */
|
|
12
|
+
|
|
13
|
+
/* static-inverted */
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.pageIndicator {
|
|
17
|
+
background: var(--page-indicator-color);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.element {
|
|
21
|
+
background: var(--page-indicator-active-color);
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Component";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PageIndicatorRunner } from './Component.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
--page-indicator-animation-duration: 0.2s;
|
|
5
|
+
|
|
6
|
+
/* default */
|
|
7
|
+
|
|
8
|
+
/* inverted */
|
|
9
|
+
|
|
10
|
+
/* static */
|
|
11
|
+
|
|
12
|
+
/* static-inverted */
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.element {
|
|
16
|
+
transition: transform var(--page-indicator-animation-duration) linear;
|
|
17
|
+
will-change: transition;
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
|
|
5
|
+
/* default */
|
|
6
|
+
|
|
7
|
+
/* inverted */
|
|
8
|
+
--page-indicator-color-inverted: var(--color-light-neutral-translucent-300-inverted);
|
|
9
|
+
--page-indicator-active-color-inverted: var(--color-light-neutral-translucent-1300-inverted);
|
|
10
|
+
|
|
11
|
+
/* static */
|
|
12
|
+
|
|
13
|
+
/* static-inverted */
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.pageIndicator {
|
|
17
|
+
background: var(--page-indicator-color-inverted);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.element {
|
|
21
|
+
background: var(--page-indicator-active-color-inverted);
|
|
22
|
+
}
|