Rocket.Chat.ReactNative/app/containers/Passcode/Base/Dots.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-04-23 16:08:50 +00:00
import React from 'react';
import { View } from 'react-native';
import _ from 'lodash';
2020-04-24 12:17:38 +00:00
import PropTypes from 'prop-types';
2020-04-23 16:08:50 +00:00
import styles from './styles';
2020-04-23 20:11:17 +00:00
import { themes } from '../../../constants/colors';
2020-04-23 16:08:50 +00:00
const SIZE_EMPTY = 8;
const SIZE_FULL = 12;
2020-04-24 12:17:38 +00:00
const Dots = ({ passcode, theme, length }) => (
2020-04-23 16:38:27 +00:00
<View style={[styles.topViewCirclePasscode]}>
{_.range(length).map((val) => {
2020-04-24 12:17:38 +00:00
const lengthSup = (passcode.length >= val + 1);
2020-04-23 16:08:50 +00:00
const opacity = lengthSup ? 1 : 0.5;
const height = lengthSup ? SIZE_FULL : SIZE_EMPTY;
const width = lengthSup ? SIZE_FULL : SIZE_EMPTY;
2020-04-24 12:17:38 +00:00
let backgroundColor = '';
if (lengthSup && passcode.length > 0) {
backgroundColor = themes[theme].titleText;
2020-04-23 16:08:50 +00:00
} else {
2020-04-24 12:17:38 +00:00
backgroundColor = themes[theme].bodyText;
2020-04-23 16:08:50 +00:00
}
2020-04-24 12:17:38 +00:00
const borderRadius = lengthSup ? SIZE_FULL / 2 : SIZE_EMPTY / 2;
const marginRight = lengthSup ? 10 - (SIZE_FULL - SIZE_EMPTY) / 2 : 10;
const marginLeft = lengthSup ? 10 - (SIZE_FULL - SIZE_EMPTY) / 2 : 10;
2020-04-23 16:08:50 +00:00
return (
<View style={styles.viewCircles}>
<View
style={[{
opacity,
height,
width,
borderRadius,
2020-04-24 12:17:38 +00:00
backgroundColor,
2020-04-23 16:08:50 +00:00
marginRight,
marginLeft
}]}
/>
</View>
);
})}
</View>
);
2020-04-24 12:17:38 +00:00
Dots.propTypes = {
passcode: PropTypes.string,
theme: PropTypes.string,
length: PropTypes.string
};
2020-04-23 16:38:27 +00:00
export default Dots;