summaryrefslogtreecommitdiff
path: root/frontend/app/components/paginationIndicator.js
blob: 6a043d0524217a05515cf26a4c6de38005c11123 (plain)
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
import React from 'react';
import { View } from 'react-native';
import { RkStyleSheet } from 'react-native-ui-kitten';
import PropTypes from 'prop-types';

export class PaginationIndicator extends React.Component {
  static propTypes = {
    current: PropTypes.number,
    length: PropTypes.number.isRequired,
  };
  static defaultProps = {
    current: 0,
  };

  renderIndicatorItem = (index, selected) => (
    <View style={selected ? [styles.base, styles.selected] : styles.base} key={index} />
  );

  renderIndicators = () => {
    const indicators = [];
    for (let i = 0; i < this.props.length; i += 1) {
      indicators.push(this.renderIndicatorItem(i, i === this.props.current));
    }
    return indicators;
  };

  render = () => (
    <View style={styles.container}>
      {this.renderIndicators()}
    </View>
  );
}

const styles = RkStyleSheet.create(theme => ({
  container: {
    flexDirection: 'row',
  },
  base: {
    width: 8,
    height: 8,
    borderRadius: 5,
    borderColor: theme.colors.brand,
    borderWidth: 1,
    marginHorizontal: 5,
  },
  selected: {
    backgroundColor: theme.colors.brand,
  },
}));