1 | import React, { useState } from 'react';
|
2 | import classNames from 'classnames';
|
3 | const classPrefix = `adm-index-bar`;
|
4 | export const Sidebar = props => {
|
5 | const [interacting, setInteracting] = useState(false);
|
6 | return React.createElement("div", {
|
7 | className: classNames(`${classPrefix}-sidebar`, {
|
8 | [`${classPrefix}-sidebar-interacting`]: interacting
|
9 | }),
|
10 | onMouseDown: () => {
|
11 | setInteracting(true);
|
12 | },
|
13 | onMouseUp: () => {
|
14 | setInteracting(false);
|
15 | },
|
16 | onTouchStart: () => {
|
17 | setInteracting(true);
|
18 | },
|
19 | onTouchEnd: () => {
|
20 | setInteracting(false);
|
21 | },
|
22 | onTouchMove: e => {
|
23 | if (!interacting) return;
|
24 | const {
|
25 | clientX,
|
26 | clientY
|
27 | } = e.touches[0];
|
28 | const target = document.elementFromPoint(clientX, clientY);
|
29 | if (!target) return;
|
30 | const index = target.dataset['index'];
|
31 | if (index) {
|
32 | props.onActive(index);
|
33 | }
|
34 | }
|
35 | }, props.indexItems.map(({
|
36 | index,
|
37 | brief
|
38 | }) => {
|
39 | const active = index === props.activeIndex;
|
40 | return React.createElement("div", {
|
41 | className: `${classPrefix}-sidebar-row`,
|
42 | onMouseDown: () => {
|
43 | props.onActive(index);
|
44 | },
|
45 | onTouchStart: () => {
|
46 | props.onActive(index);
|
47 | },
|
48 | onMouseEnter: () => {
|
49 | if (interacting) {
|
50 | props.onActive(index);
|
51 | }
|
52 | },
|
53 | "data-index": index,
|
54 | key: index
|
55 | }, interacting && active && React.createElement("div", {
|
56 | className: `${classPrefix}-sidebar-bubble`
|
57 | }, brief), React.createElement("div", {
|
58 | className: classNames(`${classPrefix}-sidebar-item`, {
|
59 | [`${classPrefix}-sidebar-item-active`]: active
|
60 | }),
|
61 | "data-index": index
|
62 | }, React.createElement("div", null, brief)));
|
63 | }));
|
64 | }; |
\ | No newline at end of file |