-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IOPLT-362] Adds the ProgressLoader component (#196)
## Short description This PR makes the new ProgressLoader component available ## List of changes proposed in this pull request - ProgressLoader Component - Loaders page in example app - ProgressLoader Storybook page ## How to test Check both example app and storybook page --------- Co-authored-by: Damiano Plebani <damiano.plebani@pagopa.it>
- Loading branch information
1 parent
d70bff3
commit bd42339
Showing
9 changed files
with
138 additions
and
12 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
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
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 |
---|---|---|
@@ -1,17 +1,43 @@ | ||
import { IOColors, LoadingSpinner } from "@pagopa/io-app-design-system"; | ||
import { | ||
H3, | ||
IOColors, | ||
LoadingSpinner, | ||
ProgressLoader | ||
} from "@pagopa/io-app-design-system"; | ||
import React from "react"; | ||
import { View } from "react-native"; | ||
import { Screen } from "../components/Screen"; | ||
|
||
export const Loaders = () => ( | ||
<Screen> | ||
<View style={{ borderRadius: 8, overflow: "hidden" }}> | ||
<View style={{ backgroundColor: IOColors.white, padding: 16 }}> | ||
<LoadingSpinner color="blueIO-500" /> | ||
export const Loaders = () => { | ||
const [progress, setProgress] = React.useState(0); | ||
React.useEffect(() => { | ||
const interval = setInterval(() => { | ||
// console.log("progress", progress, (progress + 10) % 100); | ||
setProgress(prev => (prev + 10) % 100); | ||
}, 500); | ||
return () => clearInterval(interval); | ||
}, []); | ||
|
||
return ( | ||
<Screen> | ||
<H3>LoadingSpinner</H3> | ||
<View style={{ borderRadius: 8, overflow: "hidden" }}> | ||
<View style={{ backgroundColor: IOColors.white, padding: 16 }}> | ||
<LoadingSpinner color="blueIO-500" /> | ||
</View> | ||
<View style={{ backgroundColor: IOColors["blueIO-500"], padding: 16 }}> | ||
<LoadingSpinner color="white" /> | ||
</View> | ||
</View> | ||
<View style={{ backgroundColor: IOColors["blueIO-500"], padding: 16 }}> | ||
<LoadingSpinner color="white" /> | ||
<H3>ProgressLoader</H3> | ||
<View style={{ borderRadius: 8, overflow: "hidden" }}> | ||
<View style={{ backgroundColor: IOColors.white, padding: 16 }}> | ||
<ProgressLoader progress={progress} /> | ||
</View> | ||
<View style={{ backgroundColor: IOColors["blueIO-500"], padding: 16 }}> | ||
<ProgressLoader progress={90} /> | ||
</View> | ||
</View> | ||
</View> | ||
</Screen> | ||
); | ||
</Screen> | ||
); | ||
}; |
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,60 @@ | ||
import * as React from "react"; | ||
import { StyleSheet, View } from "react-native"; | ||
import Animated, { | ||
useAnimatedStyle, | ||
useSharedValue, | ||
withSpring | ||
} from "react-native-reanimated"; | ||
import { IOColors, IOSpringValues } from "../../core"; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
width: "100%", | ||
height: 4, | ||
backgroundColor: IOColors.white | ||
} | ||
}); | ||
|
||
export type ProgressLoader = { | ||
progress: number; | ||
color?: IOColors; | ||
}; | ||
|
||
/** | ||
* ProgressLoader component | ||
* @param progress - the progress percentage | ||
* @param color - IOColors value or undefined to define the color of the progress bar | ||
*/ | ||
export const ProgressLoader = ({ | ||
progress, | ||
color = "blueIO-500" | ||
}: ProgressLoader) => { | ||
const [width, setWidth] = React.useState(0); | ||
const progressWidth = useSharedValue(0); | ||
|
||
React.useEffect(() => { | ||
// eslint-disable-next-line functional/immutable-data | ||
progressWidth.value = withSpring( | ||
(progress / 100) * width, | ||
IOSpringValues.accordion | ||
); | ||
}, [progressWidth, progress, width]); | ||
|
||
const animatedStyle = useAnimatedStyle(() => ({ | ||
width: progressWidth.value | ||
})); | ||
|
||
return ( | ||
<View | ||
style={styles.container} | ||
onLayout={e => setWidth(e.nativeEvent.layout.width)} | ||
> | ||
<Animated.View | ||
style={[ | ||
animatedStyle, | ||
{ height: "100%", backgroundColor: IOColors[color] } | ||
]} | ||
/> | ||
</View> | ||
); | ||
}; |
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 * from "./ProgressLoader"; |
27 changes: 27 additions & 0 deletions
27
stories/foundation/progressLoader/ProgressLoader.stories.tsx
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,27 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { ProgressLoader } from "../../../src/components"; | ||
import { withMaxWitdth } from "../../utils"; | ||
|
||
// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export | ||
const meta = { | ||
title: "Foundation/ProgressLoader/ProgressLoader", | ||
component: ProgressLoader, | ||
parameters: { | ||
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/react/configure/story-layout | ||
layout: "centered" | ||
}, | ||
decorators: [withMaxWitdth], | ||
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs | ||
tags: ["autodocs"] | ||
} satisfies Meta<typeof ProgressLoader>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args | ||
export const Primary: Story = { | ||
args: { | ||
progress: 15 | ||
} | ||
}; |