-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathtabs.jsx
More file actions
100 lines (92 loc) · 2.57 KB
/
tabs.jsx
File metadata and controls
100 lines (92 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React, { useRef } from 'react';
import { useIsomorphicLayoutEffect } from '../shared/use-isomorphic-layout-effect.js';
import { classNames, getExtraAttrs } from '../shared/utils.js';
import { colorClasses } from '../shared/mixins.js';
import { TabsSwipeableContext } from '../shared/tabs-swipeable-context.js';
import { f7ready, f7 } from '../shared/f7.js';
import { setRef } from '../shared/set-ref.js';
/* dts-imports
import { SwiperOptions } from 'swiper';
*/
/* dts-props
id?: string | number;
className?: string;
style?: React.CSSProperties;
animated? : boolean
swipeable? : boolean
routable? : boolean
swiperParams? : SwiperOptions
COLOR_PROPS
ref?: React.MutableRefObject<{el: HTMLElement | null}>;
children?: React.ReactNode;
*/
const Tabs = (props) => {
const { className, id, style, children, animated, swipeable, routable, swiperParams, ref } =
props;
const extraAttrs = getExtraAttrs(props);
const elRef = useRef(null);
useIsomorphicLayoutEffect(() => {
if (swipeable) {
f7ready(() => {
// It only initializes in pageInit callback
// We may need to manually call init() to update the instance
f7.swiper.init(elRef.current)
});
}
if (!swipeable || !swiperParams) return;
if (!elRef.current) return;
Object.assign(elRef.current, swiperParams);
elRef.current.initialize();
}, []);
const classes = classNames(className, colorClasses(props));
const tabsClasses = classNames({ tabs: true, 'tabs-routable': routable });
if (animated) {
return (
<div
id={id}
style={style}
className={classNames('tabs-animated-wrap', classes)}
ref={(el) => {
elRef.current = el;
setRef(ref, el);
}}
{...extraAttrs}
>
<div className={tabsClasses}>{children}</div>
</div>
);
}
if (swipeable) {
return (
<swiper-container
id={id}
style={style}
class={classNames(tabsClasses, classes)}
ref={(el) => {
elRef.current = el;
setRef(ref, el);
}}
init={swiperParams ? 'false' : 'true'}
{...extraAttrs}
>
<TabsSwipeableContext.Provider value={true}>{children}</TabsSwipeableContext.Provider>
</swiper-container>
);
}
return (
<div
id={id}
style={style}
className={classNames(tabsClasses, classes)}
ref={(el) => {
elRef.current = el;
setRef(ref, el);
}}
{...extraAttrs}
>
{children}
</div>
);
};
Tabs.displayName = 'f7-tabs';
export default Tabs;