-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(progress): add progress component
- Loading branch information
Artur Bien
committed
Nov 29, 2020
1 parent
aad32ce
commit f727234
Showing
5 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { Panel, Progress, Fieldset } from 'react95-native'; | ||
|
||
const DividerExample = () => { | ||
return ( | ||
<Panel style={{ flex: 1, padding: 20 }}> | ||
<Fieldset label='Default' style={[{ padding: 20 }]}> | ||
<Progress percent={50} /> | ||
</Fieldset> | ||
<Fieldset label='Tile' style={[{ padding: 20 }]}> | ||
<Progress variant='tile' percent={50} /> | ||
</Fieldset> | ||
</Panel> | ||
); | ||
}; | ||
|
||
export default DividerExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React, { useState } from 'react'; | ||
import { | ||
StyleProp, | ||
StyleSheet, | ||
View, | ||
ViewStyle, | ||
LayoutChangeEvent, | ||
} from 'react-native'; | ||
|
||
import { original as theme } from '../common/themes'; | ||
import { blockSizes } from '../common/styles'; | ||
import { Border } from '../common/styleElements'; | ||
|
||
type Props = { | ||
style?: StyleProp<ViewStyle>; | ||
// come up with a better name than 'raised' | ||
variant?: 'default' | 'tile' | 'indeterminate'; | ||
percent: number; | ||
}; | ||
|
||
const tileWidth = 17; | ||
|
||
// TODO: accessibility | ||
const Progress = ({ variant = 'default', percent = 0, style = {} }: Props) => { | ||
const [tilesNumber, setTilesNumber] = useState(0); | ||
|
||
function updateTilesNumber(e: LayoutChangeEvent) { | ||
const { width } = e.nativeEvent.layout; | ||
setTilesNumber(Math.round((percent / 100) * (width / tileWidth))); | ||
} | ||
|
||
return ( | ||
<View | ||
style={[ | ||
styles.wrapper, | ||
{ | ||
height: blockSizes.md, | ||
}, | ||
style, | ||
]} | ||
> | ||
<View style={[styles.progressWrapper]}> | ||
{variant === 'tile' ? ( | ||
<View style={[styles.tilesWrapper]} onLayout={updateTilesNumber}> | ||
{Array(tilesNumber) | ||
.fill(null) | ||
.map((_, index) => ( | ||
<View style={[styles.tile, styles.progress]} key={index} /> | ||
))} | ||
</View> | ||
) : ( | ||
<View style={[styles.progress, { width: `${percent}%` }]} /> | ||
)} | ||
</View> | ||
<Border variant='cutout' /> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
wrapper: { | ||
position: 'relative', | ||
padding: 4, | ||
}, | ||
progressWrapper: { | ||
width: '100%', | ||
height: '100%', | ||
}, | ||
progress: { | ||
height: '100%', | ||
backgroundColor: theme.progress, | ||
}, | ||
tilesWrapper: { | ||
flexDirection: 'row', | ||
flex: 1, | ||
borderWidth: 1, | ||
borderColor: theme.material, | ||
}, | ||
tile: { | ||
width: tileWidth, | ||
borderWidth: 1, | ||
borderColor: theme.material, | ||
}, | ||
}); | ||
|
||
export default Progress; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './Progress'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters