Skip to content

Instantly share code, notes, and snippets.

@dcangulo
Created January 11, 2022 06:10
Show Gist options
  • Save dcangulo/c89bc397fe125ed402e93f6f1cf22213 to your computer and use it in GitHub Desktop.
Save dcangulo/c89bc397fe125ed402e93f6f1cf22213 to your computer and use it in GitHub Desktop.
Progress Bar
import React from 'react';
import { View } from 'react-native';
import PropTypes from 'prop-types';
import styled from 'styled-components/native';
// SEPARATE FILE
const Colors = {
success: 'green',
error: 'red',
};
//
const StyledView = styled.View`
background-color: #000;
width: 100%;
height: 5px;
`;
const StyledProgress = styled.View`
background-color: ${(props) => props.state === 'success' ? Colors.success : Colors.error};
width: ${(props) => props.progress}%;
height: 5px;
`;
function ProgressBar(props) {
return (
<StyledView>
<StyledProgress
progress={props.progress}
state={props.state}
/>
</StyledView>
);
}
ProgressBar.defaultProps = {
progress: 50,
state: 'success',
}
ProgressBar.propTypes = {
progress: PropTypes.number,
state: PropTypes.oneOf(['success', 'error']),
};
// MAIN APP
export default function App() {
return (
<>
<ProgressBar progress={50} state='error' />
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment