Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add linear and circular progress bars #332

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/components/menu-grid-list.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ export const MenuGridList = (props: MenuGridListProps): ListElement => {
<Card
style={styles.item}
onPress={() => props.onItemPress(info.index)}>
{info.item.icon({ width: 64, height: 64, alignSelf: 'center' })}
<Text
style={styles.itemTitle}
category='s2'>
{info.item.title}
</Text>
<>
{info.item.icon({ width: 64, height: 64, alignSelf: 'center' })}
<Text
style={styles.itemTitle}
category='s2'>
{info.item.title}
</Text>
</>
</Card>
);

Expand Down Expand Up @@ -55,5 +57,6 @@ const styles = StyleSheet.create({
itemTitle: {
alignSelf: 'center',
marginTop: 8,
textAlign: 'center',
},
});
4 changes: 4 additions & 0 deletions src/navigation/components.navigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { TextScreen } from '../scenes/components/text/text.component';
import { ToggleScreen } from '../scenes/components/toggle/toggle.component';
import { TooltipScreen } from '../scenes/components/tooltip/tooltip.component';
import { TopNavigationScreen } from '../scenes/components/top-navigation/top-navigation.component';
import { ProgressBarScreen } from '../scenes/components/progress-bar/progressBar.component';
import { CircularProgressBarScreen } from '../scenes/components/circular-progress-bar/circularProgressBar.component';

const Stack = createStackNavigator();

Expand All @@ -44,6 +46,7 @@ export const ComponentsNavigator = (): React.ReactElement => (
<Stack.Screen name='Calendar' component={CalendarScreen}/>
<Stack.Screen name='Card' component={CardScreen}/>
<Stack.Screen name='CheckBox' component={CheckBoxScreen}/>
<Stack.Screen name='CircularProgressBar' component={CircularProgressBarScreen}/>
<Stack.Screen name='Datepicker' component={DatepickerScreen}/>
<Stack.Screen name='Drawer' component={DrawerScreen}/>
<Stack.Screen name='Icon' component={IconScreen}/>
Expand All @@ -54,6 +57,7 @@ export const ComponentsNavigator = (): React.ReactElement => (
<Stack.Screen name='Modal' component={ModalScreen}/>
<Stack.Screen name='OverflowMenu' component={OverflowMenuScreen}/>
<Stack.Screen name='Popover' component={PopoverScreen}/>
<Stack.Screen name='ProgressBar' component={ProgressBarScreen}/>
<Stack.Screen name='Radio' component={RadioScreen}/>
<Stack.Screen name='RadioGroup' component={RadioGroupScreen}/>
<Stack.Screen name='RangeCalendar' component={RangeCalendarScreen}/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import { CircularProgressBar, ProgressBarElement, ProgressBarProps } from '@ui-kitten/components';
import { useProgress } from '../progress-bar/progress.hook';

export const CircularProgressBarShowcase = (props?: ProgressBarProps): ProgressBarElement => {
return (
<CircularProgressBar {...props} progress={useProgress(props.status)} />
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { ShowcaseContainer } from '../../../components/showcase-container.component';
import { circularProgressBarSettings, circularProgressBarShowcase } from './type';
import { CircularProgressBarShowcase } from './circularProgressBar-showcase.component';

export const CircularProgressBarScreen = ({ navigation }): React.ReactElement => (
<ShowcaseContainer
showcase={circularProgressBarShowcase}
settings={circularProgressBarSettings}
renderItem={CircularProgressBarShowcase}
onBackPress={navigation.goBack}>
</ShowcaseContainer>
);

96 changes: 96 additions & 0 deletions src/scenes/components/circular-progress-bar/type.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React from 'react';
import { StarIcon } from '../../../components/icons';

import {
ComponentShowcase,
ComponentShowcaseItem,
ComponentShowcaseSection,
ComponentShowcaseSetting,
} from '../../../model/showcase.model';

const giant: ComponentShowcaseItem = {
title: 'Giant',
props: {
accessoryLeft: StarIcon,
size: 'giant',
},
};

const large: ComponentShowcaseItem = {
title: 'Large',
props: {
accessoryLeft: StarIcon,
size: 'large',
},
};

const medium: ComponentShowcaseItem = {
title: 'Medium',
props: {
size: 'medium',
},
};

const small: ComponentShowcaseItem = {
title: 'Small',
props: {
size: 'small',
},
};

const tiny: ComponentShowcaseItem = {
title: 'Tiny',
props: {
size: 'tiny',
},
};

const sizeSection: ComponentShowcaseSection = {
title: 'Size',
items: [
giant,
large,
medium,
small,
tiny,
],
};

export const circularProgressBarSettings: ComponentShowcaseSetting[] = [
{
propertyName: 'status',
value: 'primary',
},
{
propertyName: 'status',
value: 'success',
},
{
propertyName: 'status',
value: 'info',
},
{
propertyName: 'status',
value: 'warning',
},
{
propertyName: 'status',
value: 'danger',
},
{
propertyName: 'status',
value: 'control',
},
{
propertyName: 'status',
value: 'basic',
},
];

export const circularProgressBarShowcase: ComponentShowcase = {
title: 'ProgressBar',
sections: [
sizeSection,
],
};

20 changes: 20 additions & 0 deletions src/scenes/components/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ export const data: ComponentData[] = [
);
},
},
{
title: 'Circular Progress Bar',
route: 'CircularProgressBar',
icon: (style: ImageStyle) => {
return React.createElement(
ThemedIcon,
{ ...style, light: AssetCheckBoxIcon, dark: AssetCheckBoxDarkIcon },
);
},
},
{
title: 'Datepicker',
route: 'Datepicker',
Expand Down Expand Up @@ -240,6 +250,16 @@ export const data: ComponentData[] = [
);
},
},
{
title: 'Progress Bar',
route: 'ProgressBar',
icon: (style: ImageStyle) => {
return React.createElement(
ThemedIcon,
{ ...style, light: AssetPopoverIcon, dark: AssetPopoverDarkIcon },
);
},
},
{
title: 'Radio',
route: 'Radio',
Expand Down
14 changes: 14 additions & 0 deletions src/scenes/components/progress-bar/progress.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useEffect, useState } from 'react';

export const useProgress = (clearValue: any, initialProgress: number = 0,
intervalMs: number = 250, step: number = 0.1) => {
const [progress, setProgress] = useState(initialProgress);
useEffect(() => {
const interval = setInterval(() => setProgress(progress + step > 1 ? 1 : progress + step), intervalMs);
return () => clearInterval(interval);
}, [progress, setProgress]);
useEffect(() => {
setProgress(initialProgress);
}, [clearValue]);
return progress;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import { ProgressBar, ProgressBarElement, ProgressBarProps } from '@ui-kitten/components';
import { useProgress } from './progress.hook';

export const ProgressBarShowcase = (props?: ProgressBarProps): ProgressBarElement => {
return (
<ProgressBar {...props} style={{ flex: 1 }} progress={useProgress(props.status)} />
);
};
14 changes: 14 additions & 0 deletions src/scenes/components/progress-bar/progressBar.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { progressBarSettings, progressBarShowcase } from './type';
import { ShowcaseContainer } from '../../../components/showcase-container.component';
import { ProgressBarShowcase } from './progressBar-showcase.component';

export const ProgressBarScreen = ({ navigation }): React.ReactElement => (
<ShowcaseContainer
showcase={progressBarShowcase}
settings={progressBarSettings}
renderItem={ProgressBarShowcase}
onBackPress={navigation.goBack}>
</ShowcaseContainer>
);

95 changes: 95 additions & 0 deletions src/scenes/components/progress-bar/type.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import React from 'react';
import { StarIcon } from '../../../components/icons';
import {
ComponentShowcase,
ComponentShowcaseItem,
ComponentShowcaseSection,
ComponentShowcaseSetting,
} from '../../../model/showcase.model';

const giant: ComponentShowcaseItem = {
title: 'Giant',
props: {
accessoryLeft: StarIcon,
size: 'giant',
},
};

const large: ComponentShowcaseItem = {
title: 'Large',
props: {
accessoryLeft: StarIcon,
size: 'large',
},
};

const medium: ComponentShowcaseItem = {
title: 'Medium',
props: {
size: 'medium',
},
};

const small: ComponentShowcaseItem = {
title: 'Small',
props: {
size: 'small',
},
};

const tiny: ComponentShowcaseItem = {
title: 'Tiny',
props: {
size: 'tiny',
},
};

const sizeSection: ComponentShowcaseSection = {
title: 'Size',
items: [
giant,
large,
medium,
small,
tiny,
],
};

export const progressBarSettings: ComponentShowcaseSetting[] = [
{
propertyName: 'status',
value: 'primary',
},
{
propertyName: 'status',
value: 'success',
},
{
propertyName: 'status',
value: 'info',
},
{
propertyName: 'status',
value: 'warning',
},
{
propertyName: 'status',
value: 'danger',
},
{
propertyName: 'status',
value: 'control',
},
{
propertyName: 'status',
value: 'basic',
},
];

export const progressBarShowcase: ComponentShowcase = {
title: 'ProgressBar',
sections: [
sizeSection,
],
};