UNPKG

1.23 kBJavaScriptView Raw
1import React from 'react';
2
3function processChildren(c) {
4 const slides = [];
5 React.Children.toArray(c).forEach(child => {
6 if (child.type && child.type.displayName === 'SwiperSlide') {
7 slides.push(child);
8 } else if (child.props && child.props.children) {
9 processChildren(child.props.children).forEach(slide => slides.push(slide));
10 }
11 });
12 return slides;
13}
14
15function getChildren(c) {
16 const slides = [];
17 const slots = {
18 'container-start': [],
19 'container-end': [],
20 'wrapper-start': [],
21 'wrapper-end': []
22 };
23 React.Children.toArray(c).forEach(child => {
24 if (child.type && child.type.displayName === 'SwiperSlide') {
25 slides.push(child);
26 } else if (child.props && child.props.slot && slots[child.props.slot]) {
27 slots[child.props.slot].push(child);
28 } else if (child.props && child.props.children) {
29 const foundSlides = processChildren(child.props.children);
30
31 if (foundSlides.length > 0) {
32 foundSlides.forEach(slide => slides.push(slide));
33 } else {
34 slots['container-end'].push(child);
35 }
36 } else {
37 slots['container-end'].push(child);
38 }
39 });
40 return {
41 slides,
42 slots
43 };
44}
45
46export { getChildren };
\No newline at end of file