From f72723480e2811e5c7f19283314f311a108173d1 Mon Sep 17 00:00:00 2001 From: Artur Bien Date: Sun, 29 Nov 2020 19:16:52 +0100 Subject: [PATCH] feat(progress): add progress component --- example/src/examples/ProgressExample.tsx | 17 +++++ example/src/examples/index.tsx | 2 + src/Progress/Progress.tsx | 86 ++++++++++++++++++++++++ src/Progress/index.tsx | 1 + src/index.ts | 1 + 5 files changed, 107 insertions(+) create mode 100644 example/src/examples/ProgressExample.tsx create mode 100644 src/Progress/Progress.tsx create mode 100644 src/Progress/index.tsx diff --git a/example/src/examples/ProgressExample.tsx b/example/src/examples/ProgressExample.tsx new file mode 100644 index 0000000..d2b8fee --- /dev/null +++ b/example/src/examples/ProgressExample.tsx @@ -0,0 +1,17 @@ +import React from 'react'; +import { Panel, Progress, Fieldset } from 'react95-native'; + +const DividerExample = () => { + return ( + +
+ +
+
+ +
+
+ ); +}; + +export default DividerExample; diff --git a/example/src/examples/index.tsx b/example/src/examples/index.tsx index 1e176b6..f57ead5 100644 --- a/example/src/examples/index.tsx +++ b/example/src/examples/index.tsx @@ -9,6 +9,7 @@ import CheckboxExample from './CheckboxExample'; import WindowExample from './WindowExample'; import FieldsetExample from './FieldsetExample'; import MenuExample from './MenuExample'; +import ProgressExample from './ProgressExample'; export default [ { name: 'ButtonExample', component: ButtonExample, title: 'Button' }, @@ -22,6 +23,7 @@ export default [ { name: 'WindowExample', component: WindowExample, title: 'Window' }, { name: 'FieldsetExample', component: FieldsetExample, title: 'Fieldset' }, { name: 'MenuExample', component: MenuExample, title: 'Menu' }, + { name: 'ProgressExample', component: ProgressExample, title: 'Progress' }, ].sort((a, b) => { /* Sort screens alphabetically */ if (a.title < b.title) return -1; diff --git a/src/Progress/Progress.tsx b/src/Progress/Progress.tsx new file mode 100644 index 0000000..8599369 --- /dev/null +++ b/src/Progress/Progress.tsx @@ -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; + // 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 ( + + + {variant === 'tile' ? ( + + {Array(tilesNumber) + .fill(null) + .map((_, index) => ( + + ))} + + ) : ( + + )} + + + + ); +}; + +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; diff --git a/src/Progress/index.tsx b/src/Progress/index.tsx new file mode 100644 index 0000000..70ffd51 --- /dev/null +++ b/src/Progress/index.tsx @@ -0,0 +1 @@ +export { default } from './Progress'; diff --git a/src/index.ts b/src/index.ts index 3eed804..a347f5a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ export { default as Window } from './Window'; export { default as Divider } from './Divider'; export { default as Checkbox } from './Checkbox'; export { default as Fieldset } from './Fieldset'; +export { default as Progress } from './Progress'; export { MenuItem, default as Menu } from './Menu'; export * from './common/themes';